Browse Source

Show account name in unified inbox

main
M66B 6 years ago
parent
commit
ea66c6100e
5 changed files with 46 additions and 15 deletions
  1. +12
    -4
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  2. +8
    -4
      app/src/main/java/eu/faircode/email/DaoMessage.java
  3. +11
    -6
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  4. +3
    -0
      app/src/main/java/eu/faircode/email/TupleMessageEx.java
  5. +12
    -1
      app/src/main/res/layout/item_message.xml

+ 12
- 4
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

@ -52,7 +52,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private boolean debug;
private DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.LONG);
enum ViewType {FOLDER, THREAD}
enum ViewType {UNIFIED, FOLDER, THREAD}
public class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, View.OnLongClickListener {
@ -61,6 +61,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
TextView tvTime;
ImageView ivAttachments;
TextView tvSubject;
TextView tvFolder;
TextView tvCount;
TextView tvError;
ProgressBar pbLoading;
@ -73,6 +74,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
tvTime = itemView.findViewById(R.id.tvTime);
ivAttachments = itemView.findViewById(R.id.ivAttachments);
tvSubject = itemView.findViewById(R.id.tvSubject);
tvFolder = itemView.findViewById(R.id.tvFolder);
tvCount = itemView.findViewById(R.id.tvCount);
tvError = itemView.findViewById(R.id.tvError);
pbLoading = itemView.findViewById(R.id.pbLoading);
@ -113,12 +115,18 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivAttachments.setVisibility(message.attachments > 0 ? View.VISIBLE : View.GONE);
tvSubject.setText(message.subject);
if (viewType == ViewType.FOLDER) {
if (viewType == ViewType.UNIFIED) {
tvFolder.setText(message.accountName);
tvCount.setText(Integer.toString(message.count));
tvCount.setVisibility(debug || message.count > 1 ? View.VISIBLE : View.GONE);
} else if (viewType == ViewType.FOLDER) {
tvFolder.setVisibility(View.GONE);
tvCount.setText(Integer.toString(message.count));
tvCount.setVisibility(debug || message.count > 1 ? View.VISIBLE : View.GONE);
} else {
tvCount.setText(Helper.localizeFolderName(context, message.folderName));
tvCount.setVisibility(View.VISIBLE);
tvCount.setVisibility(View.GONE);
tvFolder.setText(Helper.localizeFolderName(context, message.folderName));
tvFolder.setVisibility(View.VISIBLE);
}
if (debug) {


+ 8
- 4
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -35,12 +35,13 @@ public interface DaoMessage {
// all bare columns in the result set take values from the input row which also contains the minimum or maximum."
// https://www.sqlite.org/lang_select.html
@Query("SELECT message.*, folder.name as folderName, folder.type as folderType" +
@Query("SELECT message.*, account.name AS accountName, folder.name as folderName, folder.type as folderType" +
", COUNT(message.id) as count" +
", SUM(CASE WHEN message.ui_seen THEN 0 ELSE 1 END) as unseen" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", MAX(CASE WHEN folder.type = '" + EntityFolder.INBOX + "' THEN message.id ELSE 0 END) as dummy" +
" FROM message" +
" LEFT JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE (NOT message.ui_hide OR :debug)" +
" GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" +
@ -48,12 +49,13 @@ public interface DaoMessage {
" ORDER BY message.received DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedUnifiedInbox(boolean debug);
@Query("SELECT message.*, folder.name as folderName, folder.type as folderType" +
@Query("SELECT message.*, account.name AS accountName, folder.name as folderName, folder.type as folderType" +
", COUNT(message.id) as count" +
", SUM(CASE WHEN message.ui_seen THEN 0 ELSE 1 END) as unseen" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", MAX(CASE WHEN folder.id = :folder THEN message.id ELSE 0 END) as dummy" +
" FROM message" +
" LEFT JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" LEFT JOIN folder f ON f.id = :folder" +
" WHERE (NOT message.ui_hide OR :debug)" +
@ -62,11 +64,12 @@ public interface DaoMessage {
" ORDER BY message.received DESC, message.sent DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedFolder(long folder, boolean debug);
@Query("SELECT message.*, folder.name as folderName, folder.type as folderType" +
@Query("SELECT message.*, account.name AS accountName, folder.name as folderName, folder.type as folderType" +
", 1 AS count" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
" FROM message" +
" LEFT JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE (NOT message.ui_hide OR :debug)" +
" AND message.account = (SELECT m1.account FROM message m1 WHERE m1.id = :msgid)" +
@ -105,11 +108,12 @@ public interface DaoMessage {
" AND folder.type <> '" + EntityFolder.OUTBOX + "'")
List<EntityMessage> getMessageByThread(long account, String thread);
@Query("SELECT message.*, folder.name as folderName, folder.type as folderType" +
@Query("SELECT message.*, account.name AS accountName, folder.name as folderName, 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" +
", (SELECT COUNT(m2.id) FROM message m2 WHERE m2.account = message.account AND m2.thread = message.thread AND NOT m2.ui_hide AND NOT m2.ui_seen) AS unseen" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
" FROM message" +
" LEFT JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE message.id = :id")
LiveData<TupleMessageEx> liveMessage(long id);


+ 11
- 6
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -66,6 +66,7 @@ public class FragmentMessages extends FragmentEx {
// Get arguments
Bundle args = getArguments();
long folder = (args == null ? -1 : args.getLong("folder", -1));
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
setHasOptionsMenu(true);
@ -83,12 +84,16 @@ public class FragmentMessages extends FragmentEx {
LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvMessage.setLayoutManager(llm);
adapter = new AdapterMessage(
getContext(),
getViewLifecycleOwner(),
thread < 0
? AdapterMessage.ViewType.FOLDER
: AdapterMessage.ViewType.THREAD);
AdapterMessage.ViewType viewType;
if (thread < 0)
if (folder < 0)
viewType = AdapterMessage.ViewType.UNIFIED;
else
viewType = AdapterMessage.ViewType.FOLDER;
else
viewType = AdapterMessage.ViewType.THREAD;
adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), viewType);
rvMessage.setAdapter(adapter);
fab.setOnClickListener(new View.OnClickListener() {


+ 3
- 0
app/src/main/java/eu/faircode/email/TupleMessageEx.java View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
public class TupleMessageEx extends EntityMessage {
public String accountName;
public String folderName;
public String folderType;
public int count;
@ -31,6 +32,8 @@ public class TupleMessageEx extends EntityMessage {
if (obj instanceof TupleMessageEx) {
TupleMessageEx other = (TupleMessageEx) obj;
return (super.equals(obj) &&
(this.accountName == null ? other.accountName == null : this.accountName.equals(other.accountName)) &&
this.folderName.equals(other.folderName) &&
this.folderType.equals(other.folderType) &&
this.count == other.count &&
this.unseen == other.unseen &&


+ 12
- 1
app/src/main/res/layout/item_message.xml View File

@ -50,10 +50,21 @@
android:maxLines="1"
android:text="Subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@+id/tvCount"
app:layout_constraintEnd_toStartOf="@+id/tvFolder"
app:layout_constraintStart_toEndOf="@id/ivAttachments"
app:layout_constraintTop_toBottomOf="@id/tvFrom" />
<TextView
android:id="@+id/tvFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:maxLines="1"
android:text="folder"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/tvSubject"
app:layout_constraintEnd_toStartOf="@+id/tvCount" />
<TextView
android:id="@+id/tvCount"
android:layout_width="wrap_content"


Loading…
Cancel
Save