Show unread count per account

pull/147/head
M66B 6 years ago
parent c402a97016
commit 3b2ee071f7

@ -48,9 +48,9 @@ public class ActivityMain extends AppCompatActivity implements FragmentManager.O
if (prefs.getBoolean("eula", false)) {
super.onCreate(savedInstanceState);
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<TupleAccountEx>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
public void onChanged(@Nullable List<TupleAccountEx> accounts) {
if (accounts == null || accounts.size() == 0)
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
else {

@ -65,9 +65,9 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
fragmentTransaction.commit();
}
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<TupleAccountEx>>() {
@Override
public void onChanged(List<EntityAccount> accounts) {
public void onChanged(List<TupleAccountEx> accounts) {
hasAccount = (accounts != null && accounts.size() > 0);
}
});

@ -248,9 +248,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
getSupportFragmentManager().addOnBackStackChangedListener(this);
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<TupleAccountEx>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
public void onChanged(@Nullable List<TupleAccountEx> accounts) {
if (accounts == null)
accounts = new ArrayList<>();
@ -266,11 +266,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
});
for (EntityAccount account : accounts)
for (TupleAccountEx account : accounts)
drawerArray.add(new DrawerItem(
R.layout.item_drawer, -1,
"connected".equals(account.state) ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24,
account.color, account.name, account.id));
account.color,
account.unseen > 0 ? getString(R.string.title_unseen_count, account.name, account.unseen) : account.name,
account.unseen > 0,
account.id));
drawerArray.add(new DrawerItem(R.layout.item_drawer_separator));
@ -1129,6 +1132,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private int icon;
private Integer color;
private String title;
private boolean highlight;
private Object data;
DrawerItem(int layout) {
@ -1143,12 +1147,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
this.title = context.getString(title);
}
DrawerItem(int layout, int id, int icon, Integer color, String title, Object data) {
DrawerItem(int layout, int id, int icon, Integer color, String title, boolean highlight, Object data) {
this.layout = layout;
this.id = id;
this.icon = icon;
this.color = color;
this.title = title;
this.highlight = highlight;
this.data = data;
}
@ -1179,9 +1184,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (item.color != null)
iv.setColorFilter(item.color);
}
if (tv != null)
if (tv != null) {
tv.setText(item.title);
tv.setTextColor(Helper.resolveColor(getContext(),
item.highlight ? R.attr.colorUnread : android.R.attr.textColorSecondary));
}
return row;
}
}

@ -155,7 +155,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
String name = folder.getDisplayName(context);
if (folder.unseen > 0)
tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen));
tvName.setText(context.getString(R.string.title_unseen_count, name, folder.unseen));
else
tvName.setText(name);
tvName.setTypeface(null, folder.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);

@ -41,8 +41,18 @@ public interface DaoAccount {
@Query("SELECT * FROM account")
LiveData<List<EntityAccount>> liveAccounts();
@Query("SELECT * FROM account WHERE synchronize = :synchronize")
LiveData<List<EntityAccount>> liveAccounts(boolean synchronize);
@Query("SELECT *" +
", (SELECT COUNT(message.id)" +
" FROM message" +
" JOIN folder ON folder.id = message.folder" +
" WHERE message.account = account.id" +
" AND folder.type <> '" + EntityFolder.ARCHIVE + "'" +
" AND folder.type <> '" + EntityFolder.TRASH + "'" +
" AND folder.type <> '" + EntityFolder.DRAFTS + "'" +
" AND NOT ui_seen) AS unseen" +
" FROM account" +
" WHERE synchronize = :synchronize")
LiveData<List<TupleAccountEx>> liveAccounts(boolean synchronize);
@Query("SELECT * FROM account WHERE id = :id")
EntityAccount getAccount(long id);

@ -1366,11 +1366,11 @@ public class FragmentCompose extends FragmentEx {
final DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<TupleAccountEx>>() {
private LiveData<List<EntityIdentity>> liveIdentities = null;
@Override
public void onChanged(List<EntityAccount> accounts) {
public void onChanged(List<TupleAccountEx> accounts) {
if (accounts == null)
accounts = new ArrayList<>();
@ -1780,11 +1780,11 @@ public class FragmentCompose extends FragmentEx {
EntityAccount account;
}
public class AccountAdapter extends ArrayAdapter<EntityAccount> {
public class AccountAdapter extends ArrayAdapter<TupleAccountEx> {
private Context context;
private List<EntityAccount> accounts;
private List<TupleAccountEx> accounts;
AccountAdapter(@NonNull Context context, List<EntityAccount> accounts) {
AccountAdapter(@NonNull Context context, List<TupleAccountEx> accounts) {
super(context, 0, accounts);
this.context = context;
this.accounts = accounts;

@ -1239,7 +1239,7 @@ public class FragmentMessages extends FragmentEx {
unseen += folder.unseen;
String name = getString(R.string.title_folder_unified);
if (unseen > 0)
setSubtitle(getString(R.string.title_folder_unseen, name, unseen));
setSubtitle(getString(R.string.title_unseen_count, name, unseen));
else
setSubtitle(name);
@ -1264,7 +1264,7 @@ public class FragmentMessages extends FragmentEx {
else {
String name = folder.getDisplayName(getContext());
if (folder.unseen > 0)
setSubtitle(getString(R.string.title_folder_unseen, name, folder.unseen));
setSubtitle(getString(R.string.title_unseen_count, name, folder.unseen));
else
setSubtitle(name);

@ -354,13 +354,13 @@ public class FragmentSetup extends FragmentEx {
final DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<TupleAccountEx>>() {
private boolean done = false;
private LiveData<EntityFolder> livePrimaryDrafts = null;
private LiveData<EntityFolder> livePrimaryArchive = null;
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
public void onChanged(@Nullable List<TupleAccountEx> accounts) {
done = (accounts != null && accounts.size() > 0);
btnIdentity.setEnabled(done);

@ -0,0 +1,34 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
public class TupleAccountEx extends EntityAccount {
public int unseen;
@Override
public boolean equals(Object obj) {
if (obj instanceof TupleAccountEx) {
TupleAccountEx other = (TupleAccountEx) obj;
return (super.equals(obj) &&
this.unseen == other.unseen);
} else
return false;
}
}

@ -189,7 +189,7 @@
<string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_pop">POP is not supported</string>
<string name="title_folder_unseen" translatable="false">%1$s (%2$d)</string>
<string name="title_unseen_count" translatable="false">%1$s (%2$d)</string>
<string name="title_synchronize_now">Synchronize now</string>
<string name="title_delete_local">Delete local messages</string>

Loading…
Cancel
Save