Refactoring

This commit is contained in:
M66B 2020-03-28 10:02:00 +01:00
parent fa7723695d
commit 5e5213f5b8
3 changed files with 68 additions and 68 deletions

View File

@ -350,29 +350,6 @@ public interface DaoMessage {
" WHERE message.id = :id")
LiveData<TupleKeyword.Persisted> liveMessageKeywords(long id);
@Transaction
@Query("SELECT account.id AS account, COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
" FROM message" +
" JOIN account_view AS account ON account.id = message.account" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE (:account IS NULL OR account.id = :account)" +
" AND account.`synchronize`" +
" AND folder.notify" +
" AND NOT (message.ui_seen OR message.ui_hide)" +
" GROUP BY account.id" +
" ORDER BY account.id")
LiveData<List<TupleMessageStats>> liveUnseenWidget(Long account);
@Query("SELECT :account AS account, COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
" FROM message" +
" JOIN account_view AS account ON account.id = message.account" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE (:account IS NULL OR account.id = :account)" +
" AND account.`synchronize`" +
" AND folder.notify" +
" AND NOT (message.ui_seen OR message.ui_hide)")
TupleMessageStats getUnseenWidget(Long account);
@Transaction
@Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
@ -401,6 +378,29 @@ public interface DaoMessage {
" ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify();
@Transaction
@Query("SELECT account.id AS account, COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
" FROM message" +
" JOIN account_view AS account ON account.id = message.account" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE (:account IS NULL OR account.id = :account)" +
" AND account.`synchronize`" +
" AND folder.notify" +
" AND NOT (message.ui_seen OR message.ui_hide)" +
" GROUP BY account.id" +
" ORDER BY account.id")
LiveData<List<TupleMessageStats>> liveWidgetUnseen(Long account);
@Query("SELECT :account AS account, COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
" FROM message" +
" JOIN account_view AS account ON account.id = message.account" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE (:account IS NULL OR account.id = :account)" +
" AND account.`synchronize`" +
" AND folder.notify" +
" AND NOT (message.ui_seen OR message.ui_hide)")
TupleMessageStats getWidgetUnseen(Long account);
@Transaction
@Query("SELECT folder, COUNT(*) AS total" +
", SUM(ui_seen) AS seen" +

View File

@ -433,50 +433,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
});
db.message().liveUnseenWidget(null).observe(cowner, new Observer<List<TupleMessageStats>>() {
private List<TupleMessageStats> last = null;
@Override
public void onChanged(List<TupleMessageStats> stats) {
if (stats == null)
stats = new ArrayList<>();
boolean changed = false;
if (last == null || last.size() != stats.size())
changed = true;
else
for (int i = 0; i < stats.size(); i++)
if (!last.get(i).equals(stats.get(i))) {
changed = true;
break;
}
if (!changed)
return;
Widget.update(ServiceSynchronize.this);
boolean badge = prefs.getBoolean("badge", true);
boolean unseen_ignored = prefs.getBoolean("unseen_ignored", false);
int count = 0;
for (TupleMessageStats stat : stats) {
Integer unseen = (unseen_ignored ? stat.notifying : stat.unseen);
if (unseen != null)
count += unseen;
}
try {
if (count == 0 || !badge)
ShortcutBadger.removeCount(ServiceSynchronize.this);
else
ShortcutBadger.applyCount(ServiceSynchronize.this, count);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
Map<Long, List<Long>> groupNotifying = new HashMap<>();
// Get existing notifications
@ -535,6 +491,50 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
});
db.message().liveWidgetUnseen(null).observe(cowner, new Observer<List<TupleMessageStats>>() {
private List<TupleMessageStats> last = null;
@Override
public void onChanged(List<TupleMessageStats> stats) {
if (stats == null)
stats = new ArrayList<>();
boolean changed = false;
if (last == null || last.size() != stats.size())
changed = true;
else
for (int i = 0; i < stats.size(); i++)
if (!last.get(i).equals(stats.get(i))) {
changed = true;
break;
}
if (!changed)
return;
Widget.update(ServiceSynchronize.this);
boolean badge = prefs.getBoolean("badge", true);
boolean unseen_ignored = prefs.getBoolean("unseen_ignored", false);
int count = 0;
for (TupleMessageStats stat : stats) {
Integer unseen = (unseen_ignored ? stat.notifying : stat.unseen);
if (unseen != null)
count += unseen;
}
try {
if (count == 0 || !badge)
ShortcutBadger.removeCount(ServiceSynchronize.this);
else
ShortcutBadger.applyCount(ServiceSynchronize.this, count);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
db.message().liveWidgetUnified().observe(cowner, new Observer<List<TupleMessageWidgetCount>>() {
private List<TupleMessageWidgetCount> last = null;

View File

@ -72,7 +72,7 @@ public class Widget extends AppWidgetProvider {
pi = PendingIntent.getActivity(context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);
}
TupleMessageStats stats = db.message().getUnseenWidget(account < 0 ? null : account);
TupleMessageStats stats = db.message().getWidgetUnseen(account < 0 ? null : account);
Integer unseen = (unseen_ignored ? stats.notifying : stats.unseen);
if (unseen == null)
unseen = 0;