Browse Source

Show unread in subtitle

Fixes #35
main
M66B 6 years ago
parent
commit
1a9e54b3c4
2 changed files with 37 additions and 2 deletions
  1. +10
    -0
      app/src/main/java/eu/faircode/email/DaoFolder.java
  2. +27
    -2
      app/src/main/java/eu/faircode/email/FragmentMessages.java

+ 10
- 0
app/src/main/java/eu/faircode/email/DaoFolder.java View File

@ -52,6 +52,16 @@ public interface DaoFolder {
" GROUP BY folder.id") " GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(long account); LiveData<List<TupleFolderEx>> liveFolders(long account);
@Query("SELECT folder.*, account.name AS accountName" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" WHERE folder.type = '" + EntityFolder.INBOX + "'" +
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveUnified();
@Query("SELECT folder.* FROM folder WHERE folder.id = :id") @Query("SELECT folder.* FROM folder WHERE folder.id = :id")
LiveData<EntityFolder> liveFolder(long id); LiveData<EntityFolder> liveFolder(long id);


+ 27
- 2
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -36,6 +36,8 @@ import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
@ -139,15 +141,38 @@ public class FragmentMessages extends FragmentEx {
boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false); boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
if (thread < 0) if (thread < 0)
if (folder < 0) { if (folder < 0) {
setSubtitle(R.string.title_folder_unified);
db.folder().liveUnified().observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override
public void onChanged(List<TupleFolderEx> folders) {
int unseen = 0;
if (folders != null)
for (TupleFolderEx folder : folders)
unseen += folder.unseen;
String name = getString(R.string.title_folder_unified);
if (unseen > 0)
setSubtitle(getString(R.string.title_folder_unseen, name, unseen));
else
setSubtitle(name);
}
});
messages = new LivePagedListBuilder<>(db.message().pagedUnifiedInbox(debug), PAGE_SIZE).build(); messages = new LivePagedListBuilder<>(db.message().pagedUnifiedInbox(debug), PAGE_SIZE).build();
} else { } else {
db.folder().liveFolderEx(folder).observe(getViewLifecycleOwner(), new Observer<TupleFolderEx>() { db.folder().liveFolderEx(folder).observe(getViewLifecycleOwner(), new Observer<TupleFolderEx>() {
@Override @Override
public void onChanged(@Nullable TupleFolderEx folder) { public void onChanged(@Nullable TupleFolderEx folder) {
setSubtitle(folder == null ? null : Helper.localizeFolderName(getContext(), folder.name));
if (folder == null)
setSubtitle(null);
else {
String name = Helper.localizeFolderName(getContext(), folder.name);
if (folder.unseen > 0)
setSubtitle(getString(R.string.title_folder_unseen, name, folder.unseen));
else
setSubtitle(name);
}
} }
}); });
messages = new LivePagedListBuilder<>(db.message().pagedFolder(folder, debug), PAGE_SIZE).build(); messages = new LivePagedListBuilder<>(db.message().pagedFolder(folder, debug), PAGE_SIZE).build();
} }
else { else {


Loading…
Cancel
Save