Simplification

pull/156/head
M66B 6 years ago
parent 3de52ddcd6
commit c65a771209

@ -115,17 +115,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private TwoStateOwner cowner = new TwoStateOwner(owner, "FolderChilds"); private TwoStateOwner cowner = new TwoStateOwner(owner, "FolderChilds");
private TwoStateOwner powner = new TwoStateOwner(owner, "FolderPopup"); private TwoStateOwner powner = new TwoStateOwner(owner, "FolderPopup");
private final static int action_synchronize_now = 1;
private final static int action_synchronize = 2;
private final static int action_delete_local = 3;
private final static int action_delete_browsed = 4;
private final static int action_empty_trash = 5;
private final static int action_edit_rules = 6;
private final static int action_edit_properties = 7;
private final static int action_create_channel = 8;
private final static int action_edit_channel = 9;
private final static int action_delete_channel = 10;
ViewHolder(View itemView) { ViewHolder(View itemView) {
super(itemView); super(itemView);
@ -393,33 +382,33 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, vwRipple); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, vwRipple);
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now); popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_now, 1, R.string.title_synchronize_now);
if (folder.account != null) if (folder.account != null)
popupMenu.getMenu().add(Menu.NONE, action_synchronize, 2, R.string.title_synchronize_enabled) popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 2, R.string.title_synchronize_enabled)
.setCheckable(true).setChecked(folder.synchronize); .setCheckable(true).setChecked(folder.synchronize);
if (folder.account != null) { // outbox if (folder.account != null) { // outbox
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 3, R.string.title_delete_local); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_local, 3, R.string.title_delete_local);
popupMenu.getMenu().add(Menu.NONE, action_delete_browsed, 4, R.string.title_delete_browsed); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_browsed, 4, R.string.title_delete_browsed);
} }
if (EntityFolder.TRASH.equals(folder.type)) if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, action_empty_trash, 5, R.string.title_empty_trash); popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, 5, R.string.title_empty_trash);
if (folder.account != null) { if (folder.account != null) {
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 6, R.string.title_edit_rules); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 6, R.string.title_edit_rules);
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 7, R.string.title_edit_properties); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, 7, R.string.title_edit_properties);
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityFolder.getNotificationChannelId(folder.id); String channelId = EntityFolder.getNotificationChannelId(folder.id);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = nm.getNotificationChannel(channelId); NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel == null) if (channel == null)
popupMenu.getMenu().add(Menu.NONE, action_create_channel, 6, R.string.title_create_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 6, R.string.title_create_channel);
else { else {
popupMenu.getMenu().add(Menu.NONE, action_edit_channel, 7, R.string.title_edit_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 7, R.string.title_edit_channel);
popupMenu.getMenu().add(Menu.NONE, action_delete_channel, 8, R.string.title_delete_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 8, R.string.title_delete_channel);
} }
} }
} }
@ -428,43 +417,43 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case action_synchronize_now: case R.string.title_synchronize_now:
onActionSynchronizeNow(); onActionSynchronizeNow();
return true; return true;
case action_synchronize: case R.string.title_synchronize_enabled:
onActionSync(!item.isChecked()); onActionSync(!item.isChecked());
return true; return true;
case action_delete_local: case R.string.title_delete_local:
OnActionDeleteLocal(false); OnActionDeleteLocal(false);
return true; return true;
case action_delete_browsed: case R.string.title_delete_browsed:
OnActionDeleteLocal(true); OnActionDeleteLocal(true);
return true; return true;
case action_empty_trash: case R.string.title_empty_trash:
onActionEmptyTrash(); onActionEmptyTrash();
return true; return true;
case action_edit_rules: case R.string.title_edit_rules:
onActionEditRules(); onActionEditRules();
return true; return true;
case action_edit_properties: case R.string.title_edit_properties:
onActionEditProperties(); onActionEditProperties();
return true; return true;
case action_create_channel: case R.string.title_create_channel:
onActionCreateChannel(); onActionCreateChannel();
return true; return true;
case action_edit_channel: case R.string.title_edit_channel:
onActionEditChannel(); onActionEditChannel();
return true; return true;
case action_delete_channel: case R.string.title_delete_channel:
onActionDeleteChannel(); onActionDeleteChannel();
return true; return true;

@ -183,18 +183,6 @@ public class FragmentMessages extends FragmentBase {
private LongSparseArray<List<EntityAttachment>> attachments = new LongSparseArray<>(); private LongSparseArray<List<EntityAttachment>> attachments = new LongSparseArray<>();
private LongSparseArray<TupleAccountSwipes> accountSwipes = new LongSparseArray<>(); private LongSparseArray<TupleAccountSwipes> accountSwipes = new LongSparseArray<>();
private final int action_seen = 1;
private final int action_unseen = 2;
private final int action_snooze = 3;
private final int action_flag = 4;
private final int action_unflag = 5;
private final int action_flag_color = 6;
private final int action_archive = 7;
private final int action_trash = 8;
private final int action_delete = 9;
private final int action_junk = 10;
private final int action_move = 11;
private NumberFormat nf = NumberFormat.getNumberInstance(); private NumberFormat nf = NumberFormat.getNumberInstance();
private static final int UNDO_TIMEOUT = 5000; // milliseconds private static final int UNDO_TIMEOUT = 5000; // milliseconds
@ -1393,30 +1381,30 @@ public class FragmentMessages extends FragmentBase {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabMore); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabMore);
if (result.unseen) // Unseen, not draft if (result.unseen) // Unseen, not draft
popupMenu.getMenu().add(Menu.NONE, action_seen, 1, R.string.title_seen); popupMenu.getMenu().add(Menu.NONE, R.string.title_seen, 1, R.string.title_seen);
if (result.seen) // Seen, not draft if (result.seen) // Seen, not draft
popupMenu.getMenu().add(Menu.NONE, action_unseen, 2, R.string.title_unseen); popupMenu.getMenu().add(Menu.NONE, R.string.title_unseen, 2, R.string.title_unseen);
popupMenu.getMenu().add(Menu.NONE, action_snooze, 3, R.string.title_snooze); popupMenu.getMenu().add(Menu.NONE, R.string.title_snooze, 3, R.string.title_snooze);
if (result.unflagged) if (result.unflagged)
popupMenu.getMenu().add(Menu.NONE, action_flag, 4, R.string.title_flag); popupMenu.getMenu().add(Menu.NONE, R.string.title_flag, 4, R.string.title_flag);
if (result.flagged) if (result.flagged)
popupMenu.getMenu().add(Menu.NONE, action_unflag, 5, R.string.title_unflag); popupMenu.getMenu().add(Menu.NONE, R.string.title_unflag, 5, R.string.title_unflag);
if (result.unflagged || result.flagged) if (result.unflagged || result.flagged)
popupMenu.getMenu().add(Menu.NONE, action_flag_color, 6, R.string.title_flag_color); popupMenu.getMenu().add(Menu.NONE, R.string.title_flag_color, 6, R.string.title_flag_color);
if (result.hasArchive && !result.isArchive) // has archive and not is archive/drafts if (result.hasArchive && !result.isArchive) // has archive and not is archive/drafts
popupMenu.getMenu().add(Menu.NONE, action_archive, 7, R.string.title_archive); popupMenu.getMenu().add(Menu.NONE, R.string.title_archive, 7, R.string.title_archive);
if (result.isTrash) // is trash if (result.isTrash) // is trash
popupMenu.getMenu().add(Menu.NONE, action_delete, 8, R.string.title_delete); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 8, R.string.title_delete);
if (!result.isTrash && result.hasTrash) // not trash and has trash if (!result.isTrash && result.hasTrash) // not trash and has trash
popupMenu.getMenu().add(Menu.NONE, action_trash, 9, R.string.title_trash); popupMenu.getMenu().add(Menu.NONE, R.string.title_trash, 9, R.string.title_trash);
if (result.hasJunk && !result.isJunk && !result.isDrafts) // has junk and not junk/drafts if (result.hasJunk && !result.isJunk && !result.isDrafts) // has junk and not junk/drafts
popupMenu.getMenu().add(Menu.NONE, action_junk, 10, R.string.title_spam); popupMenu.getMenu().add(Menu.NONE, R.string.title_spam, 10, R.string.title_spam);
int order = 11; int order = 11;
for (EntityAccount account : result.accounts) { for (EntityAccount account : result.accounts) {
@ -1424,7 +1412,7 @@ public class FragmentMessages extends FragmentBase {
.addSubMenu(Menu.NONE, 0, order++, getString(R.string.title_move_to, account.name)); .addSubMenu(Menu.NONE, 0, order++, getString(R.string.title_move_to, account.name));
int sorder = 1; int sorder = 1;
for (EntityFolder target : result.targets.get(account)) { for (EntityFolder target : result.targets.get(account)) {
MenuItem item = smenu.add(Menu.NONE, action_move, sorder++, target.getDisplayName(getContext())); MenuItem item = smenu.add(Menu.NONE, R.string.title_move_to, sorder++, target.getDisplayName(getContext()));
item.setIntent(new Intent().putExtra("target", target.id)); item.setIntent(new Intent().putExtra("target", target.id));
} }
} }
@ -1433,37 +1421,37 @@ public class FragmentMessages extends FragmentBase {
@Override @Override
public boolean onMenuItemClick(MenuItem target) { public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) { switch (target.getItemId()) {
case action_seen: case R.string.title_seen:
onActionSeenSelection(true); onActionSeenSelection(true);
return true; return true;
case action_unseen: case R.string.title_unseen:
onActionSeenSelection(false); onActionSeenSelection(false);
return true; return true;
case action_snooze: case R.string.title_snooze:
onActionSnoozeSelection(); onActionSnoozeSelection();
return true; return true;
case action_flag: case R.string.title_flag:
onActionFlagSelection(true, null); onActionFlagSelection(true, null);
return true; return true;
case action_unflag: case R.string.title_unflag:
onActionFlagSelection(false, null); onActionFlagSelection(false, null);
return true; return true;
case action_flag_color: case R.string.title_flag_color:
onActionFlagColorSelection(); onActionFlagColorSelection();
return true; return true;
case action_archive: case R.string.title_archive:
onActionMoveSelection(EntityFolder.ARCHIVE); onActionMoveSelection(EntityFolder.ARCHIVE);
return true; return true;
case action_trash: case R.string.title_delete:
onActionMoveSelection(EntityFolder.TRASH);
return true;
case action_delete:
onActionDeleteSelection(); onActionDeleteSelection();
return true; return true;
case action_junk: case R.string.title_trash:
onActionMoveSelection(EntityFolder.TRASH);
return true;
case R.string.title_spam:
onActionJunkSelection(); onActionJunkSelection();
return true; return true;
case action_move: case R.string.title_move_to:
onActionMoveSelection(target.getIntent().getLongExtra("target", -1)); onActionMoveSelection(target.getIntent().getLongExtra("target", -1));
return true; return true;
default: default:

Loading…
Cancel
Save