diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index afac6bfd..5b96f4f8 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -52,6 +52,16 @@ public interface DaoFolder { " GROUP BY folder.id") LiveData> 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> liveUnified(); + @Query("SELECT folder.* FROM folder WHERE folder.id = :id") LiveData liveFolder(long id); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6656549f..31a4ebfa 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -36,6 +36,8 @@ import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import java.util.List; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; @@ -139,15 +141,38 @@ public class FragmentMessages extends FragmentEx { boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false); if (thread < 0) if (folder < 0) { - setSubtitle(R.string.title_folder_unified); + db.folder().liveUnified().observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(List 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(); } else { db.folder().liveFolderEx(folder).observe(getViewLifecycleOwner(), new Observer() { @Override 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(); } else {