From 08dbb4e600dc1e39dd5fd5efccda3132c3375aaa Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 4 May 2021 19:57:55 +0200 Subject: [PATCH] Restore keyboard state --- .../java/eu/faircode/email/FragmentCompose.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 0dce8918fc..940ce42b4d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -102,6 +102,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; import androidx.core.content.FileProvider; +import androidx.core.view.WindowInsetsCompat; import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.documentfile.provider.DocumentFile; import androidx.exifinterface.media.ExifInterface; @@ -3319,6 +3320,8 @@ public class FragmentCompose extends FragmentBase { EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem(); 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 etBody.clearComposingText(); @@ -3349,8 +3352,10 @@ public class FragmentCompose extends FragmentBase { args.putBoolean("formatted", formatted); args.putBoolean("interactive", getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)); args.putInt("focus", focus == null ? -1 : focus.getId()); + args.putBoolean("ime", ime); args.putBundle("extras", extras); + Log.i("Run execute id=" + working + " reason=" + reason); actionLoader.execute(this, args, "compose:action:" + action); } @@ -5232,7 +5237,7 @@ public class FragmentCompose extends FragmentBase { showDraft(draft); } 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) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); @@ -5535,7 +5540,7 @@ public class FragmentCompose extends FragmentBase { return; state = State.LOADED; - setFocus(null); + setFocus(null, true); } @Override @@ -5545,7 +5550,7 @@ public class FragmentCompose extends FragmentBase { }.execute(this, args, "compose:show"); } - private void setFocus(Integer v) { + private void setFocus(Integer v, boolean restore) { final View target; if (v != null) target = view.findViewById(v); @@ -5569,7 +5574,7 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean keyboard = prefs.getBoolean("keyboard", true); - if (!keyboard) + if (!keyboard || !restore) return; InputMethodManager imm =