Fixed widget init

pull/162/head
M66B 5 years ago
parent 50f48fb4c6
commit bdbdaba839

@ -248,14 +248,19 @@ public interface DaoMessage {
" WHERE message.id = :id")
LiveData<TupleMessageEx> liveMessage(long id);
@Query("SELECT COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
String widget = "SELECT COUNT(message.id) AS unseen, SUM(ABS(notifying)) AS notifying" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND folder.notify" +
" AND NOT (message.ui_seen OR message.ui_hide <> 0)")
LiveData<TupleMessageStats> liveUnseen();
" AND NOT (message.ui_seen OR message.ui_hide <> 0)";
@Query(widget)
LiveData<TupleMessageStats> liveUnseenWidget();
@Query(widget)
TupleMessageStats getUnseenWidget();
@Query("SELECT message.*" +
", account.pop AS accountPop, account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
@ -279,7 +284,7 @@ public interface DaoMessage {
" ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify();
String widget = "SELECT message.*, account.name AS accountName" +
String widget_unified = "SELECT message.*, account.name AS accountName" +
", SUM(1 - message.ui_seen) AS unseen" +
", COUNT(message.id) - SUM(message.ui_flagged) AS unflagged" +
", MAX(message.received) AS dummy" +
@ -297,26 +302,14 @@ public interface DaoMessage {
" ORDER BY message.received DESC" +
" LIMIT 100";
@Query(widget)
@Query(widget_unified)
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
LiveData<List<TupleMessageWidget>> liveWidgetUnified(boolean threading, boolean unseen, boolean flagged);
@Query(widget)
@Query(widget_unified)
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
List<TupleMessageWidget> getWidgetUnified(boolean threading, boolean unseen, boolean flagged);
@Query("SELECT COUNT(message.id) FROM message" +
" JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND folder.unified" +
" AND (account.created IS NULL OR message.received > account.created)" +
" AND NOT message.ui_seen" +
" AND NOT message.ui_ignored" +
" AND message.ui_hide = 0" +
" ORDER BY message.received")
int getUnseenUnified();
@Query("SELECT uid FROM message" +
" WHERE folder = :folder" +
" AND (:received IS NULL OR received >= :received)" +

@ -147,9 +147,9 @@ public class ServiceSynchronize extends ServiceBase {
}
});
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
db.message().liveUnseen().observe(this, new Observer<TupleMessageStats>() {
db.message().liveUnseenWidget().observe(this, new Observer<TupleMessageStats>() {
private Integer lastUnseen = null;
@Override

@ -25,8 +25,11 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.RemoteViews;
import androidx.preference.PreferenceManager;
import java.text.NumberFormat;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -41,7 +44,15 @@ public class Widget extends AppWidgetProvider {
@Override
public void run() {
DB db = DB.getInstance(context);
update(context, appWidgetManager, appWidgetIds, db.message().getUnseenUnified());
TupleMessageStats stats = db.message().getUnseenWidget();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean unseen_ignored = prefs.getBoolean("unseen_ignored", false);
Integer unseen = (unseen_ignored ? stats.notifying : stats.unseen);
if (unseen == null)
unseen = 0;
update(context, appWidgetManager, appWidgetIds, unseen);
}
});
}

Loading…
Cancel
Save