Added keyboard shortcuts

pull/177/head
M66B 6 years ago
parent d21d9c329e
commit 215bdb42b1

@ -202,6 +202,7 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static android.text.format.DateUtils.DAY_IN_MILLIS; import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE; import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY; import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY;
import static android.view.KeyEvent.ACTION_UP;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_KEY_MISSING; import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_KEY_MISSING;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_NO_SIGNATURE; import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_NO_SIGNATURE;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED; import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED;
@ -907,20 +908,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabCompose.setOnClickListener(new View.OnClickListener() { fabCompose.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
boolean identities_asked = prefs.getBoolean("identities_asked", false); onCompose();
if (identities_asked)
startActivity(new Intent(getContext(), ActivityCompose.class)
.putExtra("action", "new")
.putExtra("account", account)
);
else {
Bundle args = new Bundle();
args.putLong("account", account);
FragmentDialogIdentity fragment = new FragmentDialogIdentity();
fragment.setArguments(args);
fragment.show(getParentFragmentManager(), "messages:identities");
}
} }
}); });
@ -2174,6 +2162,24 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "message:answer"); }.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "message:answer");
} }
private void onCompose() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean identities_asked = prefs.getBoolean("identities_asked", false);
if (identities_asked)
startActivity(new Intent(getContext(), ActivityCompose.class)
.putExtra("action", "new")
.putExtra("account", account)
);
else {
Bundle args = new Bundle();
args.putLong("account", account);
FragmentDialogIdentity fragment = new FragmentDialogIdentity();
fragment.setArguments(args);
fragment.show(getParentFragmentManager(), "messages:identities");
}
}
private void onMore() { private void onMore() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", getSelection());
@ -4423,33 +4429,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private ActivityBase.IKeyPressedListener onBackPressedListener = new ActivityBase.IKeyPressedListener() { private ActivityBase.IKeyPressedListener onBackPressedListener = new ActivityBase.IKeyPressedListener() {
@Override @Override
public boolean onKeyPressed(KeyEvent event) { public boolean onKeyPressed(KeyEvent event) {
if (viewType != AdapterMessage.ViewType.THREAD)
return false;
Context context = getContext(); Context context = getContext();
if (context == null) if (context == null)
return false; return false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean up = (event.getAction() == ACTION_UP);
boolean volumenav = prefs.getBoolean("volumenav", false);
if (!volumenav)
return false;
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_UP:
if (next == null) { return !up || onNext(context);
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_left);
view.startAnimation(bounce);
} else
navigate(next, false);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_DOWN:
if (prev == null) { return !up || onPrevious(context);
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_right); case KeyEvent.KEYCODE_A:
view.startAnimation(bounce); return up && onArchive(context);
} else case KeyEvent.KEYCODE_C:
navigate(prev, true); return up && onCompose(context);
return true; case KeyEvent.KEYCODE_D:
return up && onDelete(context);
case KeyEvent.KEYCODE_R:
return up && onReply(context);
default: default:
return false; return false;
} }
@ -4482,6 +4480,69 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return false; return false;
} }
private boolean onNext(Context context) {
if (!canNavigate(context))
return false;
if (next == null) {
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_left);
view.startAnimation(bounce);
} else
navigate(next, false);
return true;
}
private boolean onPrevious(Context context) {
if (!canNavigate(context))
return false;
if (prev == null) {
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_right);
view.startAnimation(bounce);
} else
navigate(prev, true);
return true;
}
private boolean canNavigate(Context context) {
if (viewType != AdapterMessage.ViewType.THREAD)
return false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("volumenav", false);
}
private boolean onArchive(Context context) {
if (bottom_navigation == null)
return false;
MenuItem archive = bottom_navigation.getMenu().findItem(R.id.action_archive);
if (archive == null || !archive.isVisible() || !archive.isEnabled())
return false;
bottom_navigation.getMenu().performIdentifierAction(R.id.action_archive, 0);
return true;
}
private boolean onDelete(Context context) {
if (bottom_navigation == null)
return false;
MenuItem delete = bottom_navigation.getMenu().findItem(R.id.action_delete);
if (delete == null || !delete.isVisible() || !delete.isEnabled())
return false;
bottom_navigation.getMenu().performIdentifierAction(R.id.action_delete, 0);
return true;
}
private boolean onReply(Context context) {
if (!fabReply.isOrWillBeShown())
return false;
fabReply.performClick();
return true;
}
private boolean onCompose(Context context) {
if (!fabCompose.isOrWillBeShown())
return false;
fabCompose.performClick();
return true;
}
}; };
@Override @Override

Loading…
Cancel
Save