Simplification/fix

pull/162/head
M66B 5 years ago
parent ebd6269379
commit 43440e3b07

@ -248,7 +248,7 @@ public interface DaoMessage {
" WHERE message.id = :id") " WHERE message.id = :id")
LiveData<TupleMessageEx> liveMessage(long 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" + " FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +

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

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

Loading…
Cancel
Save