From 890122154846b5bd12829d9dd8d59a8da60357ec Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Oct 2018 09:15:44 +0000 Subject: [PATCH] Show conversations by thread ID --- .../java/eu/faircode/email/ActivityView.java | 12 +++-- .../java/eu/faircode/email/AdapterFolder.java | 1 + .../eu/faircode/email/AdapterMessage.java | 3 +- .../java/eu/faircode/email/DaoMessage.java | 8 ++-- .../eu/faircode/email/FragmentMessages.java | 44 ++++++------------- .../eu/faircode/email/ServiceSynchronize.java | 3 +- 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 0121193a..4ee0e219 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -302,7 +302,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB setIntent(intent); getSupportFragmentManager().popBackStack("unified", 0); - intent.putExtra("id", Long.parseLong(action.split(":")[1])); + intent.putExtra("thread", action.split(":", 2)[1]); onViewThread(intent); } } @@ -752,8 +752,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB }; private void onViewMessages(Intent intent) { + Bundle args = new Bundle(); + args.putLong("account", intent.getLongExtra("account", -1)); + args.putLong("folder", intent.getLongExtra("folder", -1)); + FragmentMessages fragment = new FragmentMessages(); - fragment.setArguments(intent.getExtras()); + fragment.setArguments(args); + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("messages"); fragmentTransaction.commit(); @@ -761,7 +766,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private void onViewThread(Intent intent) { Bundle args = new Bundle(); - args.putLong("thread", intent.getLongExtra("id", -1)); + args.putLong("account", intent.getLongExtra("account", -1)); + args.putString("thread", intent.getStringExtra("thread")); FragmentMessages fragment = new FragmentMessages(); fragment.setArguments(args); diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 696e7171..be8b401d 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -156,6 +156,7 @@ public class AdapterFolder extends RecyclerView.Adapter pagedThread(long msgid, String sort, boolean debug); + DataSource.Factory pagedThread(long account, String thread, String sort, boolean debug); @Query("SELECT *" + " FROM message" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 2e85c918..a6b00136 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -76,7 +76,8 @@ public class FragmentMessages extends FragmentEx { private FloatingActionButton fab; private long folder = -1; - private long thread = -1; + private long account = -1; + private String thread = null; private String search = null; private long primary = -1; @@ -106,8 +107,9 @@ public class FragmentMessages extends FragmentEx { // Get arguments Bundle args = getArguments(); if (args != null) { + account = args.getLong("account", -1); folder = args.getLong("folder", -1); - thread = args.getLong("thread", -1); // message ID + thread = args.getString("thread"); search = args.getString("search"); } } @@ -166,7 +168,7 @@ public class FragmentMessages extends FragmentEx { rvMessage.setLayoutManager(llm); if (TextUtils.isEmpty(search)) - if (thread < 0) + if (thread == null) if (folder < 0) viewType = AdapterMessage.ViewType.UNIFIED; else @@ -531,38 +533,18 @@ public class FragmentMessages extends FragmentEx { // Compose FAB if (viewType != AdapterMessage.ViewType.THREAD) { Bundle args = new Bundle(); - args.putLong("folder", folder); - args.putLong("thread", thread); + args.putLong("account", account); new SimpleTask() { @Override protected Long onLoad(Context context, Bundle args) { - long fid = args.getLong("folder", -1); - long thread = args.getLong("thread", -1); // message ID + long account = args.getLong("account", -1); - DB db = DB.getInstance(context); - - Long account = null; - if (thread < 0) { - if (folder >= 0) { - EntityFolder folder = db.folder().getFolder(fid); - if (folder != null) - account = folder.account; - } - } else { - EntityMessage threaded = db.message().getMessage(thread); - if (threaded != null) - account = threaded.account; - } - - if (account == null) { - // outbox - EntityFolder primary = db.folder().getPrimaryDrafts(); - if (primary != null) - account = primary.account; - } - - return account; + if (account < 0) { + EntityFolder primary = DB.getInstance(context).folder().getPrimaryDrafts(); + return (primary == null ? null : primary.account); + } else + return account; } @Override @@ -751,7 +733,7 @@ public class FragmentMessages extends FragmentEx { break; case THREAD: - messages = new LivePagedListBuilder<>(db.message().pagedThread(thread, sort, debug), LOCAL_PAGE_SIZE).build(); + messages = new LivePagedListBuilder<>(db.message().pagedThread(account, thread, sort, debug), LOCAL_PAGE_SIZE).build(); break; } } else { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index e0ed9a4e..77a67552 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -409,8 +409,9 @@ public class ServiceSynchronize extends LifecycleService { args.putLong("id", message.id); Intent thread = new Intent(this, ActivityView.class); - thread.setAction("thread:" + message.id); + thread.setAction("thread:" + message.thread); thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + thread.putExtra("account", message.account); PendingIntent piContent = PendingIntent.getActivity( this, ActivityView.REQUEST_THREAD, thread, PendingIntent.FLAG_UPDATE_CURRENT);