mirror of https://github.com/M66B/FairEmail.git
Added keyboard shortcuts
This commit is contained in:
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.FORMAT_SHOW_DATE;
|
||||
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_NO_SIGNATURE;
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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");
|
||||
}
|
||||
onCompose();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2174,6 +2162,24 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}.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() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLongArray("ids", getSelection());
|
||||
|
@ -4423,33 +4429,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
private ActivityBase.IKeyPressedListener onBackPressedListener = new ActivityBase.IKeyPressedListener() {
|
||||
@Override
|
||||
public boolean onKeyPressed(KeyEvent event) {
|
||||
if (viewType != AdapterMessage.ViewType.THREAD)
|
||||
return false;
|
||||
|
||||
Context context = getContext();
|
||||
if (context == null)
|
||||
return false;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean volumenav = prefs.getBoolean("volumenav", false);
|
||||
if (!volumenav)
|
||||
return false;
|
||||
boolean up = (event.getAction() == ACTION_UP);
|
||||
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (next == null) {
|
||||
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_left);
|
||||
view.startAnimation(bounce);
|
||||
} else
|
||||
navigate(next, false);
|
||||
return true;
|
||||
return !up || onNext(context);
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (prev == null) {
|
||||
Animation bounce = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_right);
|
||||
view.startAnimation(bounce);
|
||||
} else
|
||||
navigate(prev, true);
|
||||
return true;
|
||||
return !up || onPrevious(context);
|
||||
case KeyEvent.KEYCODE_A:
|
||||
return up && onArchive(context);
|
||||
case KeyEvent.KEYCODE_C:
|
||||
return up && onCompose(context);
|
||||
case KeyEvent.KEYCODE_D:
|
||||
return up && onDelete(context);
|
||||
case KeyEvent.KEYCODE_R:
|
||||
return up && onReply(context);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -4482,6 +4480,69 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue