Prevent filtering snoozed drafts

This commit is contained in:
M66B 2019-09-11 12:37:50 +02:00
parent 9dcb6c2741
commit ff9803e075
8 changed files with 39 additions and 32 deletions

View File

@ -836,16 +836,19 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private void onMenuOutbox() {
Bundle args = new Bundle();
new SimpleTask<Long>() {
new SimpleTask<EntityFolder>() {
@Override
protected Long onExecute(Context context, Bundle args) {
protected EntityFolder onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
EntityFolder outbox = db.folder().getOutbox();
return (outbox == null ? -1 : outbox.id);
return outbox;
}
@Override
protected void onExecuted(Bundle args, Long folder) {
protected void onExecuted(Bundle args, EntityFolder outbox) {
if (outbox == null)
return;
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getSupportFragmentManager().popBackStack("unified", 0);
@ -853,7 +856,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", -1L)
.putExtra("folder", folder));
.putExtra("folder", outbox.id)
.putExtra("type", outbox.type));
}
@Override

View File

@ -317,7 +317,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", folder.account)
.putExtra("folder", folder.id));
.putExtra("folder", folder.id)
.putExtra("type", folder.type));
} else {
if (disabledIds.contains(folder.id))
return;

View File

@ -144,7 +144,8 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", folder.account)
.putExtra("folder", folder.id));
.putExtra("folder", folder.id)
.putExtra("type", folder.type));
}
}

View File

@ -138,7 +138,8 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", folder.account)
.putExtra("folder", folder.id));
.putExtra("folder", folder.id)
.putExtra("type", folder.type));
}
@Override

View File

@ -38,6 +38,9 @@ public interface DaoMessage {
// all bare columns in the result set take values from the input row which also contains the minimum or maximum."
// https://www.sqlite.org/lang_select.html
String is_drafts = "folder.type = '" + EntityFolder.DRAFTS + "'";
String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'";
@Query("SELECT message.*" +
", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" +
@ -67,7 +70,7 @@ public interface DaoMessage {
" ELSE SUM(CASE WHEN folder.type = :type THEN 1 ELSE 0 END) > 0 END)" +
" AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" +
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" +
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL)" +
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" +
" ORDER BY CASE" +
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
@ -86,8 +89,6 @@ public interface DaoMessage {
boolean found,
boolean debug);
String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'";
@Query("SELECT message.*" +
", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" +
@ -112,7 +113,7 @@ public interface DaoMessage {
" HAVING SUM(CASE WHEN folder.id = :folder THEN 1 ELSE 0 END) > 0" +
" AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" +
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" +
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + ")" +
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + " OR " + is_drafts + ")" +
" ORDER BY CASE" +
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +

View File

@ -143,7 +143,8 @@ public class FragmentAccounts extends FragmentBase {
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id));
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override

View File

@ -207,7 +207,8 @@ public class FragmentFolders extends FragmentBase {
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id));
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override

View File

@ -212,8 +212,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private int colorAccent;
private long primary;
private boolean trash = false;
private boolean outbox = false;
private boolean connected;
private boolean reset = false;
private String searching = null;
@ -340,8 +338,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
viewType = AdapterMessage.ViewType.SEARCH;
setTitle(R.string.title_search);
}
outbox = (viewType == AdapterMessage.ViewType.FOLDER);
}
@Override
@ -790,7 +786,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id));
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override
@ -2246,14 +2243,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
folders.add(folder);
updateState(folders);
boolean trash = (folder != null && EntityFolder.TRASH.equals(folder.type));
boolean outbox = (folder != null && EntityFolder.OUTBOX.equals(folder.type));
if (FragmentMessages.this.trash != trash || FragmentMessages.this.outbox != outbox) {
FragmentMessages.this.trash = trash;
FragmentMessages.this.outbox = outbox;
getActivity().invalidateOptionsMenu();
}
}
});
db.message().liveHiddenFolder(folder, null).observe(getViewLifecycleOwner(), new Observer<List<Long>>() {
@ -2482,6 +2471,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
boolean compact = prefs.getBoolean("compact", false);
boolean experiments = prefs.getBoolean("experiments", false);
boolean outbox = EntityFolder.OUTBOX.equals(type);
boolean folder =
(viewType == AdapterMessage.ViewType.UNIFIED ||
(viewType == AdapterMessage.ViewType.FOLDER && !outbox));
boolean canSnooze =
(viewType == AdapterMessage.ViewType.UNIFIED && !EntityFolder.DRAFTS.equals(type)) ||
(viewType == AdapterMessage.ViewType.FOLDER && !EntityFolder.DRAFTS.equals(type));
menu.findItem(R.id.menu_search).setVisible(
viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER);
@ -2521,7 +2519,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
menu.findItem(R.id.menu_filter).setVisible(viewType != AdapterMessage.ViewType.SEARCH && !outbox);
menu.findItem(R.id.menu_filter_seen).setVisible(viewType != AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_unflagged).setVisible(viewType != AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_snoozed).setVisible(viewType != AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_snoozed).setVisible(viewType != AdapterMessage.ViewType.THREAD && canSnooze);
menu.findItem(R.id.menu_filter_duplicates).setVisible(viewType == AdapterMessage.ViewType.THREAD);
menu.findItem(R.id.menu_filter_seen).setChecked(filter_seen);
menu.findItem(R.id.menu_filter_unflagged).setChecked(filter_unflagged);
@ -2532,7 +2530,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
menu.findItem(R.id.menu_select_all).setVisible(!outbox &&
(viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER));
menu.findItem(R.id.menu_empty_trash).setVisible(trash);
menu.findItem(R.id.menu_empty_trash).setVisible(
viewType == AdapterMessage.ViewType.FOLDER && EntityFolder.TRASH.equals(type));
menu.findItem(R.id.menu_force_sync).setVisible(viewType == AdapterMessage.ViewType.UNIFIED);
@ -2540,11 +2539,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
ibUnflagged.setImageResource(filter_unflagged ? R.drawable.baseline_star_border_24 : R.drawable.baseline_star_24);
ibSnoozed.setImageResource(filter_snoozed ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24);
boolean folder = (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER);
ibSeen.setVisibility(experiments && folder ? View.VISIBLE : View.GONE);
ibUnflagged.setVisibility(experiments && folder ? View.VISIBLE : View.GONE);
ibSnoozed.setVisibility(experiments && folder ? View.VISIBLE : View.GONE);
ibSnoozed.setVisibility(experiments && folder && canSnooze ? View.VISIBLE : View.GONE);
super.onPrepareOptionsMenu(menu);
}