Show number unread inbox for accounts

This commit is contained in:
M66B 2020-10-21 19:19:22 +02:00
parent 4c6aeab96b
commit d21f9e6edb
4 changed files with 36 additions and 3 deletions

View File

@ -88,6 +88,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private ImageView ivNotify;
private TextView tvName;
private ImageView ivSync;
private TextView tvInbox;
private ImageButton ibInbox;
private TextView tvUser;
private ImageView ivState;
@ -110,6 +111,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
view = itemView.findViewById(R.id.clItem);
vwColor = itemView.findViewById(R.id.vwColor);
ivSync = itemView.findViewById(R.id.ivSync);
tvInbox = itemView.findViewById(R.id.tvInbox);
ibInbox = itemView.findViewById(R.id.ibInbox);
ivOAuth = itemView.findViewById(R.id.ivOAuth);
ivPrimary = itemView.findViewById(R.id.ivPrimary);
@ -132,6 +134,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private void wire() {
view.setOnClickListener(this);
view.setOnLongClickListener(this);
tvInbox.setOnClickListener(this);
ibInbox.setOnClickListener(this);
btnHelp.setOnClickListener(this);
}
@ -139,6 +142,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private void unwire() {
view.setOnClickListener(null);
view.setOnLongClickListener(null);
tvInbox.setOnClickListener(null);
ibInbox.setOnClickListener(null);
btnHelp.setOnClickListener(null);
}
@ -166,6 +170,10 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvName.setTypeface(account.unseen > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
tvName.setTextColor(account.unseen > 0 ? colorUnread : textColorSecondary);
tvInbox.setText(NF.format(account.inbox));
tvInbox.setTypeface(account.inbox > 0 ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
tvInbox.setTextColor(account.inbox > 0 ? colorUnread : textColorSecondary);
}
tvUser.setText(account.user);
@ -211,6 +219,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvError.setVisibility(account.error == null ? View.GONE : View.VISIBLE);
btnHelp.setVisibility(account.error == null ? View.GONE : View.VISIBLE);
tvInbox.setVisibility(settings ? View.GONE : View.VISIBLE);
ibInbox.setVisibility(settings ? View.GONE : View.VISIBLE);
grpSettings.setVisibility(settings ? View.VISIBLE : View.GONE);
}
@ -228,7 +237,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
if (account.tbd != null)
return;
if (view.getId() == R.id.ibInbox) {
int id = view.getId();
if (id == R.id.tvInbox || id == R.id.ibInbox) {
Bundle args = new Bundle();
args.putLong("id", account.id);
@ -263,7 +273,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
} else {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(settings ? ActivitySetup.ACTION_EDIT_ACCOUNT : ActivityView.ACTION_VIEW_FOLDERS)
new Intent(settings
? ActivitySetup.ACTION_EDIT_ACCOUNT
: ActivityView.ACTION_VIEW_FOLDERS)
.putExtra("id", account.id)
.putExtra("protocol", account.protocol));
}

View File

@ -62,6 +62,13 @@ public interface DaoAccount {
" AND folder.type <> '" + EntityFolder.OUTBOX + "'" +
" AND NOT ui_seen" +
" AND NOT ui_hide) AS unseen" +
", (SELECT COUNT(DISTINCT message.id)" +
" FROM message" +
" JOIN folder ON folder.id = message.folder" +
" WHERE message.account = account.id" +
" AND folder.type = '" + EntityFolder.INBOX + "'" +
" AND NOT ui_seen" +
" AND NOT ui_hide) AS inbox" +
", (SELECT COUNT(identity.id)" +
" FROM identity" +
" WHERE identity.account = account.id" +

View File

@ -23,6 +23,7 @@ import java.util.Objects;
public class TupleAccountEx extends EntityAccount {
public int unseen;
public int inbox;
public int identities; // synchronizing
public Long drafts;
@ -32,6 +33,7 @@ public class TupleAccountEx extends EntityAccount {
TupleAccountEx other = (TupleAccountEx) obj;
return (super.equals(obj) &&
this.unseen == other.unseen &&
this.inbox == other.inbox &&
this.identities == other.identities &&
Objects.equals(this.drafts, other.drafts));
} else

View File

@ -100,10 +100,22 @@
android:layout_marginEnd="6dp"
android:contentDescription="@string/title_legend_synchronize_on"
app:layout_constraintBottom_toBottomOf="@+id/tvName"
app:layout_constraintEnd_toStartOf="@+id/ibInbox"
app:layout_constraintEnd_toStartOf="@+id/tvInbox"
app:layout_constraintTop_toTopOf="@+id/tvName"
app:srcCompat="@drawable/twotone_sync_24" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvInbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:singleLine="true"
android:text="123"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/tvName"
app:layout_constraintEnd_toStartOf="@id/ibInbox"
app:layout_constraintTop_toTopOf="@+id/tvName" />
<ImageButton
android:id="@+id/ibInbox"
android:layout_width="36dp"