diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 2d08ccae71..882645c502 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -283,17 +283,18 @@ public interface DaoMessage { " AND message.ui_snoozed IS NULL" + " AND (NOT :unseen OR NOT message.ui_seen)" + " AND (NOT :flagged OR message.ui_flagged)" + - " GROUP BY account.id, CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + + " GROUP BY account.id" + + ", CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " ORDER BY message.received DESC" + " LIMIT 100"; @Query(widget) @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) - LiveData> liveWidgetUnified(boolean unseen, boolean flagged); + LiveData> liveWidgetUnified(boolean threading, boolean unseen, boolean flagged); @Query(widget) @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) - List getWidgetUnified(boolean unseen, boolean flagged); + List getWidgetUnified(boolean threading, boolean unseen, boolean flagged); @Query("SELECT COUNT(message.id) FROM message" + " JOIN account ON account.id = message.account" + diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index c23ab4e4a0..02665ba60f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -162,6 +162,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("threading", checked).apply(); + WidgetUnified.update(getContext()); } }); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f02dcd81c8..a816689661 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -216,7 +216,7 @@ public class ServiceSynchronize extends ServiceBase { } }); - db.message().liveWidgetUnified(false, false).observe(this, new Observer>() { + db.message().liveWidgetUnified(false, false, false).observe(this, new Observer>() { private List last = null; @Override @@ -230,12 +230,13 @@ public class ServiceSynchronize extends ServiceBase { TupleMessageWidget m1 = last.get(i); TupleMessageWidget m2 = messages.get(i); if (!m1.id.equals(m2.id) || + !Objects.equals(m1.account, m2.account) || + !Objects.equals(m1.accountName, m2.accountName) || !MessageHelper.equal(m1.from, m2.from) || !m1.received.equals(m2.received) || !Objects.equals(m1.subject, m2.subject) || !(m1.unseen == m2.unseen) || - !(m1.unflagged == m2.unflagged) || - !Objects.equals(m1.accountName, m2.accountName)) { + !(m1.unflagged == m2.unflagged)) { changed = true; break; } diff --git a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java index c67286c4d4..c568abb687 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java @@ -63,6 +63,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot Log.i("Widget factory changed id=" + appWidgetId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean threading = prefs.getBoolean("threading", true); account = prefs.getLong("widget." + appWidgetId + ".account", -1L); unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); @@ -70,7 +71,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot messages.clear(); DB db = DB.getInstance(context); - List wmessages = db.message().getWidgetUnified(unseen, flagged); + List wmessages = db.message().getWidgetUnified(threading, unseen, flagged); for (TupleMessageWidget wmessage : wmessages) if (account < 0 || wmessage.account == account) messages.add(wmessage);