Fixed message count

This commit is contained in:
M66B 2018-12-30 07:58:02 +00:00
parent 50775a10d8
commit 367ba228f4
3 changed files with 16 additions and 12 deletions

View File

@ -412,13 +412,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
else else
ivExpander.setVisibility(View.GONE); ivExpander.setVisibility(View.GONE);
boolean flagged; int flagged = (message.count - message.unflagged);
if (viewType == ViewType.THREAD) ivFlagged.setImageResource(flagged > 0 ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
flagged = (message.unflagged == 0); ivFlagged.setImageTintList(ColorStateList.valueOf(flagged > 0 ? colorAccent : textColorSecondary));
else
flagged = (message.count - message.unflagged > 0);
ivFlagged.setImageResource(flagged ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
ivFlagged.setImageTintList(ColorStateList.valueOf(flagged ? colorAccent : textColorSecondary));
ivFlagged.setVisibility(message.uid == null ? View.INVISIBLE : View.VISIBLE); ivFlagged.setVisibility(message.uid == null ? View.INVISIBLE : View.VISIBLE);
tvFrom.setText(MessageHelper.getFormattedAddresses(outgoing ? message.to : message.from, false)); tvFrom.setText(MessageHelper.getFormattedAddresses(outgoing ? message.to : message.from, false));
@ -446,7 +442,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvCount.setVisibility(View.GONE); tvCount.setVisibility(View.GONE);
ivThread.setVisibility(View.GONE); ivThread.setVisibility(View.GONE);
} else { } else {
tvCount.setText(Integer.toString(message.count)); tvCount.setText(Integer.toString(message.visible));
ivThread.setVisibility(View.VISIBLE); ivThread.setVisibility(View.VISIBLE);
} }

View File

@ -49,11 +49,12 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +
", COUNT(DISTINCT message.msgid) AS count" + ", COUNT(message.id) AS count" +
", " + unseen_unified + " AS unseen" + ", " + unseen_unified + " AS unseen" +
", " + unflagged_unified + " AS unflagged" + ", " + unflagged_unified + " AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", 0 AS duplicate" + ", 0 AS duplicate" +
", COUNT(DISTINCT message.msgid) AS visible" +
", MAX(CASE WHEN folder.unified THEN message.received ELSE 0 END) AS dummy" + ", MAX(CASE WHEN folder.unified THEN message.received ELSE 0 END) AS dummy" +
" FROM message" + " FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
@ -85,10 +86,11 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +
", COUNT(DISTINCT message.msgid) AS count" + ", COUNT(message.id) AS count" +
", " + unseen_folder + " AS unseen" + ", " + unseen_folder + " AS unseen" +
", " + unflagged_folder + " AS unflagged" + ", " + unflagged_folder + " AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", COUNT(DISTINCT message.msgid) AS visible" +
", 0 AS duplicate" + ", 0 AS duplicate" +
", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" + ", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
" FROM message" + " FROM message" +
@ -114,10 +116,11 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +
", (SELECT COUNT(m1.id) FROM message m1 WHERE m1.account = message.account AND m1.thread = message.thread AND NOT m1.ui_hide) AS count" + ", 1 AS count" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", 1 AS visible" +
", ((folder.type = '" + EntityFolder.ARCHIVE + "' OR folder.type = '" + EntityFolder.SENT + "')" + ", ((folder.type = '" + EntityFolder.ARCHIVE + "' OR folder.type = '" + EntityFolder.SENT + "')" +
" AND EXISTS (" + " AND EXISTS (" +
@ -194,10 +197,11 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, identity.color AS accountColor, account.notify AS accountNotify" + ", account.name AS accountName, identity.color AS accountColor, account.notify AS accountNotify" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +
", (SELECT COUNT(m1.id) FROM message m1 WHERE m1.account = message.account AND m1.thread = message.thread AND NOT m1.ui_hide) AS count" + ", 1 AS count" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + ", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", 1 AS visible" +
", 0 AS duplicate" + ", 0 AS duplicate" +
" FROM message" + " FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
@ -213,6 +217,7 @@ public interface DaoMessage {
", 1 AS unseen" + ", 1 AS unseen" +
", 0 AS unflagged" + ", 0 AS unflagged" +
", 0 AS attachments" + ", 0 AS attachments" +
", 1 AS visible" +
", 0 AS duplicate" + ", 0 AS duplicate" +
" FROM message" + " FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +

View File

@ -30,6 +30,7 @@ public class TupleMessageEx extends EntityMessage {
public int unseen; public int unseen;
public int unflagged; public int unflagged;
public int attachments; public int attachments;
public int visible;
public boolean duplicate; public boolean duplicate;
@Override @Override
@ -47,6 +48,7 @@ public class TupleMessageEx extends EntityMessage {
this.unseen == other.unseen && this.unseen == other.unseen &&
this.unflagged == other.unflagged && this.unflagged == other.unflagged &&
this.attachments == other.attachments && this.attachments == other.attachments &&
this.visible == other.visible &&
this.duplicate == other.duplicate); this.duplicate == other.duplicate);
} }
return false; return false;
@ -67,6 +69,7 @@ public class TupleMessageEx extends EntityMessage {
this.unseen == other.unseen && this.unseen == other.unseen &&
this.unflagged == other.unflagged && this.unflagged == other.unflagged &&
this.attachments == other.attachments && this.attachments == other.attachments &&
this.visible == other.visible &&
this.duplicate == other.duplicate); this.duplicate == other.duplicate);
} }
return false; return false;