Restore keyboard state

This commit is contained in:
M66B 2021-05-04 19:57:55 +02:00
parent 22c283f351
commit 08dbb4e600
1 changed files with 9 additions and 4 deletions

View File

@ -102,6 +102,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.core.view.WindowInsetsCompat;
import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.documentfile.provider.DocumentFile; import androidx.documentfile.provider.DocumentFile;
import androidx.exifinterface.media.ExifInterface; import androidx.exifinterface.media.ExifInterface;
@ -3319,6 +3320,8 @@ public class FragmentCompose extends FragmentBase {
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
View focus = view.findFocus(); View focus = view.findFocus();
boolean ime = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R ||
view.getRootWindowInsets().isVisible(WindowInsetsCompat.Type.ime()));
// Workaround underlines left by Android // Workaround underlines left by Android
etBody.clearComposingText(); etBody.clearComposingText();
@ -3349,8 +3352,10 @@ public class FragmentCompose extends FragmentBase {
args.putBoolean("formatted", formatted); args.putBoolean("formatted", formatted);
args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)); args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED));
args.putInt("focus", focus == null ? -1 : focus.getId()); args.putInt("focus", focus == null ? -1 : focus.getId());
args.putBoolean("ime", ime);
args.putBundle("extras", extras); args.putBundle("extras", extras);
Log.i("Run execute id=" + working + " reason=" + reason); Log.i("Run execute id=" + working + " reason=" + reason);
actionLoader.execute(this, args, "compose:action:" + action); actionLoader.execute(this, args, "compose:action:" + action);
} }
@ -5232,7 +5237,7 @@ public class FragmentCompose extends FragmentBase {
showDraft(draft); showDraft(draft);
} else if (action == R.id.action_save) { } else if (action == R.id.action_save) {
setFocus(args.getInt("focus")); setFocus(args.getInt("focus"), args.getBoolean("ime"));
} else if (action == R.id.action_check) { } else if (action == R.id.action_check) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -5535,7 +5540,7 @@ public class FragmentCompose extends FragmentBase {
return; return;
state = State.LOADED; state = State.LOADED;
setFocus(null); setFocus(null, true);
} }
@Override @Override
@ -5545,7 +5550,7 @@ public class FragmentCompose extends FragmentBase {
}.execute(this, args, "compose:show"); }.execute(this, args, "compose:show");
} }
private void setFocus(Integer v) { private void setFocus(Integer v, boolean restore) {
final View target; final View target;
if (v != null) if (v != null)
target = view.findViewById(v); target = view.findViewById(v);
@ -5569,7 +5574,7 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean keyboard = prefs.getBoolean("keyboard", true); boolean keyboard = prefs.getBoolean("keyboard", true);
if (!keyboard) if (!keyboard || !restore)
return; return;
InputMethodManager imm = InputMethodManager imm =