Fixed resetting notification count

This commit is contained in:
M66B
2019-05-21 14:29:45 +02:00
parent 8324b893a4
commit 1b409ad7ab
2 changed files with 15 additions and 12 deletions

View File

@@ -112,6 +112,8 @@ import me.leolin.shortcutbadger.ShortcutBadger;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
class Core {
private static int lastUnseen = -1;
private static final int MAX_NOTIFICATION_COUNT = 10; // per group
private static final int SYNC_BATCH_SIZE = 20;
private static final int DOWNLOAD_BATCH_SIZE = 20;
@@ -1706,6 +1708,16 @@ class Core {
db.message().setMessageSize(message.id, size);
}
static void notifyReset(Context context) {
lastUnseen = -1;
Widget.update(context, -1);
try {
ShortcutBadger.removeCount(context);
} catch (Throwable ex) {
Log.e(ex);
}
}
static void notifyMessages(Context context, Map<String, List<Long>> groupNotifying, List<TupleMessageEx> messages) {
Log.i("Notify messages=" + messages.size());
@@ -1715,10 +1727,8 @@ class Core {
boolean badge = prefs.getBoolean("badge", true);
// Update widget/badge count
int lastUnseen = 0;
for (String group : groupNotifying.keySet())
lastUnseen += groupNotifying.get(group).size();
if (messages.size() != lastUnseen) {
if (lastUnseen < 0 || messages.size() != lastUnseen) {
lastUnseen = messages.size();
Widget.update(context, messages.size());
try {
ShortcutBadger.applyCount(context, badge ? messages.size() : 0);

View File

@@ -84,8 +84,6 @@ import javax.mail.event.MessageCountEvent;
import javax.mail.event.StoreEvent;
import javax.mail.event.StoreListener;
import me.leolin.shortcutbadger.ShortcutBadger;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
public class ServiceSynchronize extends LifecycleService {
@@ -168,12 +166,7 @@ public class ServiceSynchronize extends LifecycleService {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cm.unregisterNetworkCallback(networkCallback);
Widget.update(this, -1);
try {
ShortcutBadger.applyCount(this, 0);
} catch (Throwable ex) {
Log.e(ex);
}
Core.notifyReset(this);
WorkerCleanup.cancel(this);