diff --git a/app/src/main/java/eu/faircode/email/ActivityMain.java b/app/src/main/java/eu/faircode/email/ActivityMain.java index fe66f28a51..704894f7b1 100644 --- a/app/src/main/java/eu/faircode/email/ActivityMain.java +++ b/app/src/main/java/eu/faircode/email/ActivityMain.java @@ -147,7 +147,14 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack } DB db = DB.getInstance(context); - return db.message().getMessage(id); + EntityMessage message = db.message().getMessage(id); + if (message != null) { + EntityFolder folder = db.folder().getFolder(message.folder); + if (folder != null) + args.putString("type", folder.type); + } + + return message; } @Override @@ -157,13 +164,16 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack if (message == null) return; + String type = args.getString("type"); + Intent thread = new Intent(ActivityMain.this, ActivityView.class); thread.setAction("thread:" + message.id); thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); thread.putExtra("account", message.account); thread.putExtra("folder", message.folder); + thread.putExtra("type", type); thread.putExtra("thread", message.thread); - thread.putExtra("filter_archive", true); + thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type)); thread.putExtra("pinned", true); thread.putExtra("msgid", message.msgid); diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 68b92121e0..ce8865611b 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -1987,11 +1987,31 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } else if (action.startsWith("thread")) { long id = Long.parseLong(action.split(":", 2)[1]); + long account = intent.getLongExtra("account", -1); + long folder = intent.getLongExtra("folder", -1); + String type = intent.getStringExtra("type"); boolean ignore = intent.getBooleanExtra("ignore", false); long group = intent.getLongExtra("group", -1L); if (ignore) ServiceUI.ignore(this, id, group); intent.putExtra("id", id); + if (account > 0 && folder > 0 && !TextUtils.isEmpty(type) && BuildConfig.DEBUG) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { + getSupportFragmentManager().popBackStack("messages", FragmentManager.POP_BACK_STACK_INCLUSIVE); + + Bundle args = new Bundle(); + args.putLong("account", account); + args.putLong("folder", folder); + args.putString("type", type); + + FragmentMessages fragment = new FragmentMessages(); + fragment.setArguments(args); + + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("messages"); + fragmentTransaction.commit(); + } + } onViewThread(intent); } else if (action.startsWith("widget")) { diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index a36463bb17..651e0f99b7 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -5861,6 +5861,7 @@ class Core { thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); thread.putExtra("account", message.account); thread.putExtra("folder", message.folder); + thread.putExtra("type", message.folderType); thread.putExtra("thread", message.thread); thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(message.folderType)); thread.putExtra("ignore", notify_remove); diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 97d8fea9b5..252948661c 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -278,7 +278,7 @@ public interface DaoMessage { " AND ui_hide") LiveData> liveHiddenThread(long account, String thread); - @Query("SELECT message.* FROM message" + + @Query("SELECT message.id FROM message" + " JOIN folder_view AS folder ON folder.id = message.folder" + " WHERE message.account = :account" + " AND message.thread = :thread" + @@ -288,7 +288,7 @@ public interface DaoMessage { " AND folder.type <> '" + EntityFolder.ARCHIVE + "'" + " AND NOT ui_seen" + " AND NOT ui_hide") - LiveData> liveUnreadThread(long account, String thread); + LiveData> liveUnreadThread(long account, String thread); static String FTS_STATS = "SELECT SUM(fts) AS fts, COUNT(*) AS total FROM message" + " JOIN folder_view AS folder ON folder.id = message.folder" + diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 74abbfbeaf..744fd1e222 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -6337,21 +6337,21 @@ public class FragmentCompose extends FragmentBase { boolean threading = prefs.getBoolean("threading", true); if (threading) - db.message().liveUnreadThread(data.draft.account, data.draft.thread).observe(getViewLifecycleOwner(), new Observer>() { + db.message().liveUnreadThread(data.draft.account, data.draft.thread).observe(getViewLifecycleOwner(), new Observer>() { private int lastDiff = 0; - private List base = null; + private List base = null; @Override - public void onChanged(List messages) { - if (messages == null) + public void onChanged(List ids) { + if (ids == null) return; if (base == null) { - base = messages; + base = ids; return; } - int diff = (messages.size() - base.size()); + int diff = (ids.size() - base.size()); if (diff > lastDiff) { lastDiff = diff; String msg = getResources().getQuantityString( @@ -6362,21 +6362,51 @@ public class FragmentCompose extends FragmentBase { snackbar.setAction(R.string.title_show, new View.OnClickListener() { @Override public void onClick(View v) { - EntityMessage message = messages.get(0); - boolean notify_remove = prefs.getBoolean("notify_remove", true); + Bundle args = new Bundle(); + args.putLong("id", ids.get(0)); - Intent thread = new Intent(v.getContext(), ActivityView.class); - thread.setAction("thread:" + message.id); - // No group - thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - thread.putExtra("account", message.account); - thread.putExtra("folder", message.folder); - thread.putExtra("thread", message.thread); - thread.putExtra("filter_archive", true); - thread.putExtra("ignore", notify_remove); + new SimpleTask() { + @Override + protected EntityMessage onExecute(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); - v.getContext().startActivity(thread); - getActivity().finish(); + DB db = DB.getInstance(context); + EntityMessage message = db.message().getMessage(id); + if (message != null) { + EntityFolder folder = db.folder().getFolder(message.id); + if (folder != null) + args.putString("type", folder.type); + } + + return message; + } + + @Override + protected void onExecuted(Bundle args, EntityMessage message) { + boolean notify_remove = prefs.getBoolean("notify_remove", true); + + String type = args.getString("type"); + + Intent thread = new Intent(v.getContext(), ActivityView.class); + thread.setAction("thread:" + message.id); + // No group + thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + thread.putExtra("account", message.account); + thread.putExtra("folder", message.folder); + thread.putExtra("type", type); + thread.putExtra("thread", message.thread); + thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type)); + thread.putExtra("ignore", notify_remove); + + v.getContext().startActivity(thread); + getActivity().finish(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentCompose.this, args, "compose:unread"); } }); snackbar.show(); diff --git a/app/src/main/java/eu/faircode/email/Shortcuts.java b/app/src/main/java/eu/faircode/email/Shortcuts.java index 77b2ac8a56..ae234c33b3 100644 --- a/app/src/main/java/eu/faircode/email/Shortcuts.java +++ b/app/src/main/java/eu/faircode/email/Shortcuts.java @@ -278,14 +278,15 @@ class Shortcuts { } @NonNull - static ShortcutInfoCompat.Builder getShortcut(Context context, EntityMessage message, String label, ContactInfo[] contactInfo) { + static ShortcutInfoCompat.Builder getShortcut(Context context, TupleMessageEx message, String label, ContactInfo[] contactInfo) { Intent thread = new Intent(context, ActivityView.class); thread.setAction("thread:" + message.id); thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); thread.putExtra("account", message.account); thread.putExtra("folder", message.folder); + thread.putExtra("type", message.folderType); thread.putExtra("thread", message.thread); - thread.putExtra("filter_archive", true); + thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(message.folderType)); thread.putExtra("pinned", true); thread.putExtra("msgid", message.msgid);