From 573aba16bcf35816c8acaefe5662bcba37f06dab Mon Sep 17 00:00:00 2001 From: Distopico Vegan Date: Sat, 10 Nov 2018 18:48:29 -0500 Subject: [PATCH] fix: trash messages are showing in threads --- .../java/org/dystopia/email/ActivityView.java | 2 ++ .../org/dystopia/email/AdapterFolder.java | 3 +- .../org/dystopia/email/AdapterMessage.java | 31 ++++++++++++------- .../java/org/dystopia/email/DaoMessage.java | 24 ++++++++++++-- .../org/dystopia/email/FragmentMessages.java | 10 +++--- .../dystopia/email/ServiceSynchronize.java | 11 +++++++ 6 files changed, 62 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/dystopia/email/ActivityView.java b/app/src/main/java/org/dystopia/email/ActivityView.java index acb4656a..8f876a5d 100644 --- a/app/src/main/java/org/dystopia/email/ActivityView.java +++ b/app/src/main/java/org/dystopia/email/ActivityView.java @@ -770,6 +770,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack Bundle args = new Bundle(); args.putLong("account", intent.getLongExtra("account", -1)); args.putLong("folder", intent.getLongExtra("folder", -1)); + args.putString("folderType", intent.getStringExtra("folderType")); FragmentMessages fragment = new FragmentMessages(); fragment.setArguments(args); @@ -784,6 +785,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack Bundle args = new Bundle(); args.putLong("account", intent.getLongExtra("account", -1)); + args.putLong("folder", intent.getLongExtra("folder", -1)); args.putString("thread", intent.getStringExtra("thread")); FragmentMessages fragment = new FragmentMessages(); diff --git a/app/src/main/java/org/dystopia/email/AdapterFolder.java b/app/src/main/java/org/dystopia/email/AdapterFolder.java index 2b130266..00d9cea5 100644 --- a/app/src/main/java/org/dystopia/email/AdapterFolder.java +++ b/app/src/main/java/org/dystopia/email/AdapterFolder.java @@ -157,7 +157,8 @@ public class AdapterFolder extends RecyclerView.Adapter 0" + " ORDER BY CASE" + @@ -81,6 +82,11 @@ public interface DaoMessage { " JOIN folder ON folder.id = message.folder" + " JOIN folder f ON f.id = :folder" + " WHERE (message.account = f.account OR folder.type = '" + EntityFolder.OUTBOX + "')" + + " AND CASE WHEN (:folderType = '" + EntityFolder.TRASH + "' " + + " OR :folderType = '" + EntityFolder.OUTBOX + "') " + + " THEN 1" + + " ELSE folder.id = :folder" + + " END" + " AND (NOT message.ui_hide OR :debug)" + " AND ui_found = :found" + " GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + @@ -90,7 +96,7 @@ public interface DaoMessage { " WHEN 'starred' = :sort THEN message.ui_flagged" + " ELSE 0" + " END DESC, message.received DESC, message.sent DESC") - DataSource.Factory pagedFolder(long folder, String sort, boolean found, boolean debug); + DataSource.Factory pagedFolder(long folder, String folderType, String sort, boolean found, boolean debug); @Query("SELECT message.*" + ", account.name AS accountName, account.color AS accountColor" + @@ -105,12 +111,13 @@ public interface DaoMessage { " WHERE message.account = :account" + " AND message.thread = :thread" + " AND (NOT message.ui_hide OR :debug)" + + " AND NOT (folder.type = '" + EntityFolder.TRASH + "' AND folder.id <> :folder)" + " ORDER BY CASE" + " WHEN 'unread' = :sort THEN NOT message.ui_seen" + " WHEN 'starred' = :sort THEN message.ui_flagged" + " ELSE 0" + " END DESC, message.received DESC, message.sent DESC") - DataSource.Factory pagedThread(long account, String thread, String sort, boolean debug); + DataSource.Factory pagedThread(long account, long folder, String thread, String sort, boolean debug); @Query("SELECT COUNT(id)" + " FROM message" + @@ -142,6 +149,19 @@ public interface DaoMessage { " AND NOT ui_found") List getMessageByThread(long account, String thread); + @Query("SELECT message.*" + + ", account.name AS accountName, account.color AS accountColor" + + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + + ", (SELECT COUNT(m1.id) FROM message m1 WHERE m1.account = message.account AND m1.thread = message.thread AND NOT m1.ui_hide) AS count" + + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + + " FROM message" + + " JOIN account ON account.id = message.account" + + " JOIN folder ON folder.id = message.folder" + + " WHERE message.id = :id") + TupleMessageEx getAccountByMessage(long id); + @Query("SELECT message.* FROM message" + " JOIN folder ON folder.id = message.folder" + " WHERE message.account = :account" + diff --git a/app/src/main/java/org/dystopia/email/FragmentMessages.java b/app/src/main/java/org/dystopia/email/FragmentMessages.java index a3892861..4bde91bd 100644 --- a/app/src/main/java/org/dystopia/email/FragmentMessages.java +++ b/app/src/main/java/org/dystopia/email/FragmentMessages.java @@ -93,6 +93,7 @@ public class FragmentMessages extends FragmentEx { private long folder = -1; private long account = -1; + private String folderType = null; private String thread = null; private String search = null; @@ -130,6 +131,7 @@ public class FragmentMessages extends FragmentEx { Bundle args = getArguments(); account = args.getLong("account", -1); folder = args.getLong("folder", -1); + folderType = args.getString("folderType"); thread = args.getString("thread"); search = args.getString("search"); @@ -200,7 +202,7 @@ public class FragmentMessages extends FragmentEx { LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvMessage.setLayoutManager(llm); - adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), getFragmentManager(), viewType, new AdapterMessage.IProperties() { + adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), getFragmentManager(), viewType, folder, new AdapterMessage.IProperties() { @Override public void setExpanded(long id, boolean expand) { if (expand) { @@ -1060,14 +1062,14 @@ public class FragmentMessages extends FragmentEx { .setPrefetchDistance(REMOTE_PAGE_SIZE) .build(); LivePagedListBuilder builder = new LivePagedListBuilder<>( - db.message().pagedFolder(folder, sort, false, debug), config); + db.message().pagedFolder(folder, folderType, sort, false, debug), config); if (browse) builder.setBoundaryCallback(searchCallback); messages = builder.build(); break; case THREAD: - messages = new LivePagedListBuilder<>(db.message().pagedThread(account, thread, sort, debug), LOCAL_PAGE_SIZE).build(); + messages = new LivePagedListBuilder<>(db.message().pagedThread(account, folder, thread, sort, debug), LOCAL_PAGE_SIZE).build(); break; } } else { @@ -1105,7 +1107,7 @@ public class FragmentMessages extends FragmentEx { .setPrefetchDistance(REMOTE_PAGE_SIZE) .build(); LivePagedListBuilder builder = new LivePagedListBuilder<>( - db.message().pagedFolder(folder, "time", true, false), config); + db.message().pagedFolder(folder, folderType,"time", true, false), config); builder.setBoundaryCallback(searchCallback); messages = builder.build(); } diff --git a/app/src/main/java/org/dystopia/email/ServiceSynchronize.java b/app/src/main/java/org/dystopia/email/ServiceSynchronize.java index 1cdfe3b1..c1c396ae 100644 --- a/app/src/main/java/org/dystopia/email/ServiceSynchronize.java +++ b/app/src/main/java/org/dystopia/email/ServiceSynchronize.java @@ -34,6 +34,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; +import android.graphics.Color; import android.graphics.drawable.Icon; import android.media.RingtoneManager; import android.net.ConnectivityManager; @@ -412,6 +413,8 @@ public class ServiceSynchronize extends LifecycleService { for (EntityMessage message : messages) { Bundle args = new Bundle(); args.putLong("id", message.id); + //final DB db = DB.getInstance(getBaseContext()); + //TupleMessageEx messageEx = db.message().getAccountByMessage(message.id); Intent thread = new Intent(this, ActivityView.class); thread.setAction("thread:" + message.thread); @@ -461,9 +464,17 @@ public class ServiceSynchronize extends LifecycleService { .setVisibility(Notification.VISIBILITY_PRIVATE) .setGroup(BuildConfig.APPLICATION_ID) .setGroupSummary(false) + .setSortKey(message.account_name) .addAction(actionSeen.build()) .addAction(actionTrash.build()); + //if (messageEx != null && messageEx.accountColor != null) { + // mbuilder.setColor(ContextCompat.getColor(getBaseContext(), messageEx.accountColor)); + //} + if (messages.size() == 1) { + mbuilder.setColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary)); + } + if (!TextUtils.isEmpty(message.subject)) { mbuilder.setContentText(message.subject); }