Improved compose focus

pull/198/head 1.1573
M66B 4 years ago
parent c6b9acb1bd
commit 282d23a035

@ -3320,6 +3320,8 @@ public class FragmentCompose extends FragmentBase {
private void onAction(int action, @NonNull Bundle extras, String reason) { private void onAction(int action, @NonNull Bundle extras, String reason) {
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
View focus = view.findFocus();
// Workaround underlines left by Android // Workaround underlines left by Android
etBody.clearComposingText(); etBody.clearComposingText();
@ -3348,6 +3350,7 @@ public class FragmentCompose extends FragmentBase {
args.putBoolean("notext", notext); args.putBoolean("notext", notext);
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.putBundle("extras", extras); args.putBundle("extras", extras);
Log.i("Run execute id=" + working + " reason=" + reason); Log.i("Run execute id=" + working + " reason=" + reason);
@ -5223,7 +5226,7 @@ public class FragmentCompose extends FragmentBase {
showDraft(draft); showDraft(draft);
} else if (action == R.id.action_save) { } else if (action == R.id.action_save) {
focus(); setFocus(args.getInt("focus"));
} else if (action == R.id.action_check) { } else if (action == R.id.action_check) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -5526,7 +5529,7 @@ public class FragmentCompose extends FragmentBase {
return; return;
state = State.LOADED; state = State.LOADED;
focus(); setFocus(null);
} }
@Override @Override
@ -5536,20 +5539,30 @@ public class FragmentCompose extends FragmentBase {
}.execute(this, args, "compose:show"); }.execute(this, args, "compose:show");
} }
private void focus() { private void setFocus(Integer v) {
final View target; final View target;
if (TextUtils.isEmpty(etTo.getText().toString().trim())) if (v != null)
target = view.findViewById(v);
else if (TextUtils.isEmpty(etTo.getText().toString().trim()))
target = etTo; target = etTo;
else if (TextUtils.isEmpty(etSubject.getText().toString())) else if (TextUtils.isEmpty(etSubject.getText().toString()))
target = etSubject; target = etSubject;
else else
target = etBody; target = etBody;
if (target == null)
return;
getMainHandler().post(new Runnable() { getMainHandler().post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
target.requestFocus(); target.requestFocus();
if (target.getId() != R.id.etSubject && target.getId() != R.id.etBody) {
EditText et = (EditText) target;
String text = et.getText().toString();
et.setSelection(text.length());
}
Context context = target.getContext(); Context context = target.getContext();

Loading…
Cancel
Save