Browse Source

fix: trash messages are showing in threads

main
Distopico Vegan 6 years ago
parent
commit
573aba16bc
6 changed files with 62 additions and 19 deletions
  1. +2
    -0
      app/src/main/java/org/dystopia/email/ActivityView.java
  2. +2
    -1
      app/src/main/java/org/dystopia/email/AdapterFolder.java
  3. +19
    -12
      app/src/main/java/org/dystopia/email/AdapterMessage.java
  4. +22
    -2
      app/src/main/java/org/dystopia/email/DaoMessage.java
  5. +6
    -4
      app/src/main/java/org/dystopia/email/FragmentMessages.java
  6. +11
    -0
      app/src/main/java/org/dystopia/email/ServiceSynchronize.java

+ 2
- 0
app/src/main/java/org/dystopia/email/ActivityView.java View File

@ -770,6 +770,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", intent.getLongExtra("account", -1)); args.putLong("account", intent.getLongExtra("account", -1));
args.putLong("folder", intent.getLongExtra("folder", -1)); args.putLong("folder", intent.getLongExtra("folder", -1));
args.putString("folderType", intent.getStringExtra("folderType"));
FragmentMessages fragment = new FragmentMessages(); FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(args); fragment.setArguments(args);
@ -784,6 +785,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", intent.getLongExtra("account", -1)); args.putLong("account", intent.getLongExtra("account", -1));
args.putLong("folder", intent.getLongExtra("folder", -1));
args.putString("thread", intent.getStringExtra("thread")); args.putString("thread", intent.getStringExtra("thread"));
FragmentMessages fragment = new FragmentMessages(); FragmentMessages fragment = new FragmentMessages();


+ 2
- 1
app/src/main/java/org/dystopia/email/AdapterFolder.java View File

@ -157,7 +157,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES) new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", folder.account) .putExtra("account", folder.account)
.putExtra("folder", folder.id));
.putExtra("folder", folder.id)
.putExtra("folderType", folder.type));
} }
@Override @Override


+ 19
- 12
app/src/main/java/org/dystopia/email/AdapterMessage.java View File

@ -109,6 +109,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private LifecycleOwner owner; private LifecycleOwner owner;
private FragmentManager fragmentManager; private FragmentManager fragmentManager;
private ViewType viewType; private ViewType viewType;
private long folder;
private IProperties properties; private IProperties properties;
private boolean contacts; private boolean contacts;
@ -511,17 +512,20 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
else else
onExpandMessage(pos, message); onExpandMessage(pos, message);
} else { } else {
if (EntityFolder.DRAFTS.equals(message.folderType))
context.startActivity(
new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", message.id));
else {
if (EntityFolder.DRAFTS.equals(message.folderType)) {
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", message.id));
} else {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
Intent intent = new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", message.account) .putExtra("account", message.account)
.putExtra("thread", message.thread));
.putExtra("thread", message.thread);
if (viewType == ViewType.FOLDER) {
intent.putExtra("folder", folder);
}
lbm.sendBroadcast(intent);
} }
} }
} }
@ -534,10 +538,12 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
// https://developer.android.com/training/contacts-provider/modify-data // https://developer.android.com/training/contacts-provider/modify-data
Intent edit = new Intent(); Intent edit = new Intent();
if (!TextUtils.isEmpty(name))
if (!TextUtils.isEmpty(name)) {
edit.putExtra(ContactsContract.Intents.Insert.NAME, name); edit.putExtra(ContactsContract.Intents.Insert.NAME, name);
if (!TextUtils.isEmpty(email))
}
if (!TextUtils.isEmpty(email)) {
edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email); edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
}
Cursor cursor = null; Cursor cursor = null;
try { try {
@ -1398,12 +1404,13 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
} }
} }
AdapterMessage(Context context, LifecycleOwner owner, FragmentManager fragmentManager, ViewType viewType, IProperties properties) {
AdapterMessage(Context context, LifecycleOwner owner, FragmentManager fragmentManager, ViewType viewType, long folder, IProperties properties) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
this.context = context; this.context = context;
this.owner = owner; this.owner = owner;
this.fragmentManager = fragmentManager; this.fragmentManager = fragmentManager;
this.viewType = viewType; this.viewType = viewType;
this.folder = folder;
this.properties = properties; this.properties = properties;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);


+ 22
- 2
app/src/main/java/org/dystopia/email/DaoMessage.java View File

@ -54,6 +54,7 @@ public interface DaoMessage {
" WHERE account.`synchronize`" + " WHERE account.`synchronize`" +
" AND (NOT message.ui_hide OR :debug)" + " AND (NOT message.ui_hide OR :debug)" +
" AND NOT ui_found" + " AND NOT ui_found" +
" AND folder.unified " +
" GROUP BY account.id, CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + " GROUP BY account.id, CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" +
" HAVING SUM(unified) > 0" + " HAVING SUM(unified) > 0" +
" ORDER BY CASE" + " ORDER BY CASE" +
@ -81,6 +82,11 @@ public interface DaoMessage {
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" JOIN folder f ON f.id = :folder" + " JOIN folder f ON f.id = :folder" +
" WHERE (message.account = f.account OR folder.type = '" + EntityFolder.OUTBOX + "')" + " WHERE (message.account = f.account OR folder.type = '" + EntityFolder.OUTBOX + "')" +
" AND CASE WHEN (:folderType = '" + EntityFolder.TRASH + "' " +
" OR :folderType = '" + EntityFolder.OUTBOX + "') " +
" THEN 1" +
" ELSE folder.id = :folder" +
" END" +
" AND (NOT message.ui_hide OR :debug)" + " AND (NOT message.ui_hide OR :debug)" +
" AND ui_found = :found" + " AND ui_found = :found" +
" GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + " GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" +
@ -90,7 +96,7 @@ public interface DaoMessage {
" WHEN 'starred' = :sort THEN message.ui_flagged" + " WHEN 'starred' = :sort THEN message.ui_flagged" +
" ELSE 0" + " ELSE 0" +
" END DESC, message.received DESC, message.sent DESC") " END DESC, message.received DESC, message.sent DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedFolder(long folder, String sort, boolean found, boolean debug);
DataSource.Factory<Integer, TupleMessageEx> pagedFolder(long folder, String folderType, String sort, boolean found, boolean debug);
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, account.color AS accountColor" + ", account.name AS accountName, account.color AS accountColor" +
@ -105,12 +111,13 @@ public interface DaoMessage {
" WHERE message.account = :account" + " WHERE message.account = :account" +
" AND message.thread = :thread" + " AND message.thread = :thread" +
" AND (NOT message.ui_hide OR :debug)" + " AND (NOT message.ui_hide OR :debug)" +
" AND NOT (folder.type = '" + EntityFolder.TRASH + "' AND folder.id <> :folder)" +
" ORDER BY CASE" + " ORDER BY CASE" +
" WHEN 'unread' = :sort THEN NOT message.ui_seen" + " WHEN 'unread' = :sort THEN NOT message.ui_seen" +
" WHEN 'starred' = :sort THEN message.ui_flagged" + " WHEN 'starred' = :sort THEN message.ui_flagged" +
" ELSE 0" + " ELSE 0" +
" END DESC, message.received DESC, message.sent DESC") " END DESC, message.received DESC, message.sent DESC")
DataSource.Factory<Integer, TupleMessageEx> pagedThread(long account, String thread, String sort, boolean debug);
DataSource.Factory<Integer, TupleMessageEx> pagedThread(long account, long folder, String thread, String sort, boolean debug);
@Query("SELECT COUNT(id)" + @Query("SELECT COUNT(id)" +
" FROM message" + " FROM message" +
@ -142,6 +149,19 @@ public interface DaoMessage {
" AND NOT ui_found") " AND NOT ui_found")
List<EntityMessage> getMessageByThread(long account, String thread); List<EntityMessage> getMessageByThread(long account, String thread);
@Query("SELECT message.*" +
", account.name AS accountName, account.color AS accountColor" +
", folder.name AS folderName, folder.display AS folderDisplay, 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" +
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" +
" WHERE message.id = :id")
TupleMessageEx getAccountByMessage(long id);
@Query("SELECT message.* FROM message" + @Query("SELECT message.* FROM message" +
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" WHERE message.account = :account" + " WHERE message.account = :account" +


+ 6
- 4
app/src/main/java/org/dystopia/email/FragmentMessages.java View File

@ -93,6 +93,7 @@ public class FragmentMessages extends FragmentEx {
private long folder = -1; private long folder = -1;
private long account = -1; private long account = -1;
private String folderType = null;
private String thread = null; private String thread = null;
private String search = null; private String search = null;
@ -130,6 +131,7 @@ public class FragmentMessages extends FragmentEx {
Bundle args = getArguments(); Bundle args = getArguments();
account = args.getLong("account", -1); account = args.getLong("account", -1);
folder = args.getLong("folder", -1); folder = args.getLong("folder", -1);
folderType = args.getString("folderType");
thread = args.getString("thread"); thread = args.getString("thread");
search = args.getString("search"); search = args.getString("search");
@ -200,7 +202,7 @@ public class FragmentMessages extends FragmentEx {
LinearLayoutManager llm = new LinearLayoutManager(getContext()); LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvMessage.setLayoutManager(llm); rvMessage.setLayoutManager(llm);
adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), getFragmentManager(), viewType, new AdapterMessage.IProperties() {
adapter = new AdapterMessage(getContext(), getViewLifecycleOwner(), getFragmentManager(), viewType, folder, new AdapterMessage.IProperties() {
@Override @Override
public void setExpanded(long id, boolean expand) { public void setExpanded(long id, boolean expand) {
if (expand) { if (expand) {
@ -1060,14 +1062,14 @@ public class FragmentMessages extends FragmentEx {
.setPrefetchDistance(REMOTE_PAGE_SIZE) .setPrefetchDistance(REMOTE_PAGE_SIZE)
.build(); .build();
LivePagedListBuilder<Integer, TupleMessageEx> builder = new LivePagedListBuilder<>( LivePagedListBuilder<Integer, TupleMessageEx> builder = new LivePagedListBuilder<>(
db.message().pagedFolder(folder, sort, false, debug), config);
db.message().pagedFolder(folder, folderType, sort, false, debug), config);
if (browse) if (browse)
builder.setBoundaryCallback(searchCallback); builder.setBoundaryCallback(searchCallback);
messages = builder.build(); messages = builder.build();
break; break;
case THREAD: case THREAD:
messages = new LivePagedListBuilder<>(db.message().pagedThread(account, thread, sort, debug), LOCAL_PAGE_SIZE).build();
messages = new LivePagedListBuilder<>(db.message().pagedThread(account, folder, thread, sort, debug), LOCAL_PAGE_SIZE).build();
break; break;
} }
} else { } else {
@ -1105,7 +1107,7 @@ public class FragmentMessages extends FragmentEx {
.setPrefetchDistance(REMOTE_PAGE_SIZE) .setPrefetchDistance(REMOTE_PAGE_SIZE)
.build(); .build();
LivePagedListBuilder<Integer, TupleMessageEx> builder = new LivePagedListBuilder<>( LivePagedListBuilder<Integer, TupleMessageEx> builder = new LivePagedListBuilder<>(
db.message().pagedFolder(folder, "time", true, false), config);
db.message().pagedFolder(folder, folderType,"time", true, false), config);
builder.setBoundaryCallback(searchCallback); builder.setBoundaryCallback(searchCallback);
messages = builder.build(); messages = builder.build();
} }


+ 11
- 0
app/src/main/java/org/dystopia/email/ServiceSynchronize.java View File

@ -34,6 +34,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
@ -412,6 +413,8 @@ public class ServiceSynchronize extends LifecycleService {
for (EntityMessage message : messages) { for (EntityMessage message : messages) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
//final DB db = DB.getInstance(getBaseContext());
//TupleMessageEx messageEx = db.message().getAccountByMessage(message.id);
Intent thread = new Intent(this, ActivityView.class); Intent thread = new Intent(this, ActivityView.class);
thread.setAction("thread:" + message.thread); thread.setAction("thread:" + message.thread);
@ -461,9 +464,17 @@ public class ServiceSynchronize extends LifecycleService {
.setVisibility(Notification.VISIBILITY_PRIVATE) .setVisibility(Notification.VISIBILITY_PRIVATE)
.setGroup(BuildConfig.APPLICATION_ID) .setGroup(BuildConfig.APPLICATION_ID)
.setGroupSummary(false) .setGroupSummary(false)
.setSortKey(message.account_name)
.addAction(actionSeen.build()) .addAction(actionSeen.build())
.addAction(actionTrash.build()); .addAction(actionTrash.build());
//if (messageEx != null && messageEx.accountColor != null) {
// mbuilder.setColor(ContextCompat.getColor(getBaseContext(), messageEx.accountColor));
//}
if (messages.size() == 1) {
mbuilder.setColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
}
if (!TextUtils.isEmpty(message.subject)) { if (!TextUtils.isEmpty(message.subject)) {
mbuilder.setContentText(message.subject); mbuilder.setContentText(message.subject);
} }


Loading…
Cancel
Save