Allow move instead of archive in bottom navigation view

pull/191/head
M66B 4 years ago
parent 3a5306749c
commit 2ea62d1545

@ -793,12 +793,39 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}); });
final Runnable moveThread = new Runnable() {
@Override
public void run() {
Bundle args = new Bundle();
args.putString("title", getString(R.string.title_move_to_folder));
args.putLong("account", account);
args.putString("thread", thread);
args.putLong("id", -1);
args.putBoolean("filter_archive", filter_archive);
args.putLongArray("disabled", new long[]{folder});
FragmentDialogFolder fragment = new FragmentDialogFolder();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentMessages.this, REQUEST_THREAD_MOVE);
fragment.show(getParentFragmentManager(), "thread:move");
}
};
bottom_navigation.findViewById(R.id.action_archive).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
moveThread.run();
return true;
}
});
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
ActionData data = (ActionData) bottom_navigation.getTag();
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.action_delete: case R.id.action_delete:
if ((Boolean) bottom_navigation.getTag()) if (data.delete)
onActionDelete(); onActionDelete();
else else
onActionMove(EntityFolder.TRASH); onActionMove(EntityFolder.TRASH);
@ -809,7 +836,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return true; return true;
case R.id.action_archive: case R.id.action_archive:
if (data.archivable)
onActionMove(EntityFolder.ARCHIVE); onActionMove(EntityFolder.ARCHIVE);
else
moveThread.run();
return true; return true;
case R.id.action_prev: case R.id.action_prev:
@ -3380,7 +3410,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return result; return result;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null); aid, thread, threading || id < 0 ? null : id, null);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
EntityFolder sourceFolder = db.folder().getFolder(threaded.folder); EntityFolder sourceFolder = db.folder().getFolder(threaded.folder);
if (sourceFolder != null && !sourceFolder.read_only && if (sourceFolder != null && !sourceFolder.read_only &&
@ -4842,9 +4872,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
args.putString("thread", thread); args.putString("thread", thread);
args.putLong("id", id); args.putLong("id", id);
new SimpleTask<Boolean[]>() { new SimpleTask<ActionData>() {
@Override @Override
protected Boolean[] onExecute(Context context, Bundle args) { protected ActionData onExecute(Context context, Bundle args) {
long aid = args.getLong("account"); long aid = args.getLong("account");
String thread = args.getString("thread"); String thread = args.getString("thread");
long id = args.getLong("id"); long id = args.getLong("id");
@ -4898,16 +4928,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
return new Boolean[]{ ActionData data = new ActionData();
trash == null || data.delete = (trash == null ||
(account != null && account.protocol == EntityAccount.TYPE_POP), (account != null && account.protocol == EntityAccount.TYPE_POP));
trashable, data.trashable = trashable;
snoozable, data.snoozable = snoozable;
archivable && archive != null}; data.archivable = (archivable && archive != null);
data.moveable = (account != null && account.protocol == EntityAccount.TYPE_IMAP);
return data;
} }
@Override @Override
protected void onExecuted(Bundle args, Boolean[] data) { protected void onExecuted(Bundle args, ActionData data) {
if (actionbar_color && args.containsKey("color")) { if (actionbar_color && args.containsKey("color")) {
int color = args.getInt("color"); int color = args.getInt("color");
bottom_navigation.setBackgroundColor(color); bottom_navigation.setBackgroundColor(color);
@ -4919,10 +4951,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
bottom_navigation.setItemIconTintList(ColorStateList.valueOf(Color.WHITE)); bottom_navigation.setItemIconTintList(ColorStateList.valueOf(Color.WHITE));
} }
bottom_navigation.setTag(data[0]); bottom_navigation.setTag(data);
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data[1]);
bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data[2]); bottom_navigation.getMenu().findItem(R.id.action_archive).setIcon(
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data[3]); !data.archivable && data.moveable ? R.drawable.twotone_folder_24 : R.drawable.twotone_archive_24);
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data.trashable);
bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data.snoozable);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data.archivable || data.moveable);
bottom_navigation.setVisibility(View.VISIBLE); bottom_navigation.setVisibility(View.VISIBLE);
} }
@ -7583,6 +7618,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
private static class ActionData {
private boolean delete;
private boolean trashable;
private boolean snoozable;
private boolean archivable;
private boolean moveable;
}
private class ReplyData { private class ReplyData {
List<TupleIdentityEx> identities; List<TupleIdentityEx> identities;
List<EntityAnswer> answers; List<EntityAnswer> answers;

Loading…
Cancel
Save