Simplification/fix

This commit is contained in:
M66B 2019-09-22 14:42:43 +02:00
parent ebd6269379
commit 43440e3b07
3 changed files with 12 additions and 12 deletions

View File

@ -248,7 +248,7 @@ public interface DaoMessage {
" WHERE message.id = :id")
LiveData<TupleMessageEx> liveMessage(long id);
@Query("SELECT COUNT(message.id) AS unseen, SUM(message.ui_ignored) AS ignored" +
@Query("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" +

View File

@ -150,7 +150,7 @@ public class ServiceSynchronize extends ServiceBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
db.message().liveUnseen().observe(this, new Observer<TupleMessageStats>() {
private TupleMessageStats lastStats = null;
private Integer lastUnseen = null;
@Override
public void onChanged(TupleMessageStats stats) {
@ -158,14 +158,14 @@ public class ServiceSynchronize extends ServiceBase {
stats = new TupleMessageStats();
boolean unseen_ignored = prefs.getBoolean("unseen_ignored", false);
if (!unseen_ignored || stats.ignored == null)
stats.ignored = 0;
Integer unseen = (unseen_ignored ? stats.notifying : stats.unseen);
if (unseen == null)
unseen = 0;
if (!stats.equals(lastStats)) {
if (lastUnseen == null || !lastUnseen.equals(unseen)) {
Log.i("Stats " + stats);
lastStats = stats;
setUnseen(stats.unseen - stats.ignored);
lastUnseen = unseen;
setUnseen(unseen);
}
}
});

View File

@ -25,15 +25,15 @@ import androidx.annotation.Nullable;
import java.util.Objects;
public class TupleMessageStats {
public Integer unseen = 0;
public Integer ignored = 0;
public Integer unseen;
public Integer notifying;
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof TupleMessageStats) {
TupleMessageStats other = (TupleMessageStats) obj;
return (Objects.equals(this.unseen, other.unseen) &&
Objects.equals(this.ignored, other.ignored));
Objects.equals(this.notifying, other.notifying));
} else
return false;
}
@ -41,6 +41,6 @@ public class TupleMessageStats {
@NonNull
@Override
public String toString() {
return "unseen=" + unseen + " ignored=" + ignored;
return "unseen=" + unseen + " notify=" + notifying;
}
}