Browse Source

Allow swiping conversations to archive/trash

main
M66B 6 years ago
parent
commit
f7be8576ea
2 changed files with 69 additions and 33 deletions
  1. +15
    -9
      app/src/main/java/eu/faircode/email/DaoMessage.java
  2. +54
    -24
      app/src/main/java/eu/faircode/email/FragmentMessages.java

+ 15
- 9
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -113,15 +113,15 @@ public interface DaoMessage {
" 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, String thread, String sort, boolean debug);
@Query("SELECT *" +
@Query("SELECT COUNT(id)" +
" FROM message" + " FROM message" +
" WHERE id = :id") " WHERE id = :id")
EntityMessage getMessage(long id);
int countMessage(long id);
@Query("SELECT COUNT(id)" +
@Query("SELECT *" +
" FROM message" + " FROM message" +
" WHERE id = :id") " WHERE id = :id")
int countMessage(long id);
EntityMessage getMessage(long id);
@Query("SELECT *" + @Query("SELECT *" +
" FROM message" + " FROM message" +
@ -129,6 +129,17 @@ public interface DaoMessage {
" AND uid = :uid") " AND uid = :uid")
EntityMessage getMessageByUid(long folder, long uid); EntityMessage getMessageByUid(long folder, long uid);
@Query("SELECT *" +
" FROM message" +
" WHERE folder = :folder")
List<EntityMessage> getMessageByFolder(long folder);
@Query("SELECT *" +
" FROM message" +
" WHERE account = :account" +
" AND thread = :thread")
List<EntityMessage> getMessageByThread(long account, String thread);
@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" +
@ -136,11 +147,6 @@ public interface DaoMessage {
" OR message.msgid = :reference)") " OR message.msgid = :reference)")
List<EntityMessage> getMessageByMsgId(long account, String msgid, String reference); List<EntityMessage> getMessageByMsgId(long account, String msgid, String reference);
@Query("SELECT *" +
" FROM message" +
" WHERE folder = :folder")
List<EntityMessage> getMessageByFolder(long folder);
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.name AS accountName, account.color AS accountColor" + ", account.name AS accountName, account.color AS accountColor" +
", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType" +


+ 54
- 24
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -42,6 +42,7 @@ import android.widget.TextView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -234,7 +235,6 @@ public class FragmentMessages extends FragmentEx {
TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos); TupleMessageEx message = ((AdapterMessage) rvMessage.getAdapter()).getCurrentList().get(pos);
if (message == null || if (message == null ||
expanded.contains(message.id) || expanded.contains(message.id) ||
viewType != AdapterMessage.ViewType.THREAD ||
EntityFolder.OUTBOX.equals(message.folderType)) EntityFolder.OUTBOX.equals(message.folderType))
return 0; return 0;
@ -299,13 +299,17 @@ public class FragmentMessages extends FragmentEx {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
args.putBoolean("thread", viewType != AdapterMessage.ViewType.THREAD);
args.putInt("direction", direction); args.putInt("direction", direction);
new SimpleTask<String[]>() {
new SimpleTask<MessageTarget>() {
@Override @Override
protected String[] onLoad(Context context, Bundle args) {
protected MessageTarget onLoad(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
boolean thread = args.getBoolean("thread");
int direction = args.getInt("direction"); int direction = args.getInt("direction");
MessageTarget result = new MessageTarget();
EntityFolder target = null; EntityFolder target = null;
// Get target folder and hide message // Get target folder and hide message
@ -327,37 +331,56 @@ public class FragmentMessages extends FragmentEx {
target = db.folder().getFolderByType(message.account, EntityFolder.INBOX); target = db.folder().getFolderByType(message.account, EntityFolder.INBOX);
} }
db.message().setMessageUiHide(message.id, true);
result.target = target.name;
result.display = (target.display == null ? target.name : target.display);
if (thread) {
List<EntityMessage> messages =
db.message().getMessageByThread(message.account, message.thread);
for (EntityMessage threaded : messages) {
if (!threaded.ui_hide && threaded.folder.equals(message.folder))
result.ids.add(threaded.id);
}
} else
result.ids.add(message.id);
for (long mid : result.ids) {
Log.i(Helper.TAG, "Move hide id=" + mid + " target=" + result.target);
db.message().setMessageUiHide(mid, true);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
Log.i(Helper.TAG, "Move id=" + id + " target=" + target.name);
return new String[]{target.name, target.display == null ? target.name : target.display};
return result;
} }
@Override @Override
protected void onLoaded(final Bundle args, final String[] target) {
protected void onLoaded(final Bundle args, final MessageTarget result) {
// Show undo snackbar // Show undo snackbar
final Snackbar snackbar = Snackbar.make( final Snackbar snackbar = Snackbar.make(
view, view,
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), target[1])),
getString(R.string.title_moving, Helper.localizeFolderName(getContext(), result.display)),
Snackbar.LENGTH_INDEFINITE); Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.title_undo, new View.OnClickListener() { snackbar.setAction(R.string.title_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
snackbar.dismiss(); snackbar.dismiss();
Bundle args = new Bundle();
args.putSerializable("result", result);
// Show message again // Show message again
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onLoad(Context context, Bundle args) { protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
Log.i(Helper.TAG, "Undo move id=" + id);
DB.getInstance(context).message().setMessageUiHide(id, false);
MessageTarget result = (MessageTarget) args.getSerializable("result");
for (long id : result.ids) {
Log.i(Helper.TAG, "Move undo id=" + id);
DB.getInstance(context).message().setMessageUiHide(id, false);
}
return null; return null;
} }
@ -374,14 +397,14 @@ public class FragmentMessages extends FragmentEx {
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i(Helper.TAG, "Move timeout shown=" + snackbar.isShown());
Log.i(Helper.TAG, "Move timeout");
// Remove snackbar // Remove snackbar
if (snackbar.isShown()) if (snackbar.isShown())
snackbar.dismiss(); snackbar.dismiss();
final Context context = getContext();
args.putString("target", target[0]);
final Bundle args = new Bundle();
args.putSerializable("result", result);
// Process move in a thread // Process move in a thread
// - the fragment could be gone // - the fragment could be gone
@ -389,18 +412,19 @@ public class FragmentMessages extends FragmentEx {
@Override @Override
public void run() { public void run() {
try { try {
long id = args.getLong("id");
String target = args.getString("target");
MessageTarget result = (MessageTarget) args.getSerializable("result");
DB db = DB.getInstance(context);
DB db = DB.getInstance(snackbar.getContext());
try { try {
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message != null && message.ui_hide) {
Log.i(Helper.TAG, "Moving id=" + id + " target=" + target);
EntityFolder folder = db.folder().getFolderByName(message.account, target);
EntityOperation.queue(db, message, EntityOperation.MOVE, folder.id);
for (long id : result.ids) {
EntityMessage message = db.message().getMessage(id);
if (message != null && message.ui_hide) {
Log.i(Helper.TAG, "Move id=" + id + " target=" + result.target);
EntityFolder folder = db.folder().getFolderByName(message.account, result.target);
EntityOperation.queue(db, message, EntityOperation.MOVE, folder.id);
}
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -408,7 +432,7 @@ public class FragmentMessages extends FragmentEx {
db.endTransaction(); db.endTransaction();
} }
EntityOperation.process(context);
EntityOperation.process(snackbar.getContext());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -425,6 +449,12 @@ public class FragmentMessages extends FragmentEx {
} }
}.load(FragmentMessages.this, args); }.load(FragmentMessages.this, args);
} }
class MessageTarget implements Serializable {
List<Long> ids = new ArrayList<>();
String target;
String display;
}
}).attachToRecyclerView(rvMessage); }).attachToRecyclerView(rvMessage);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {


Loading…
Cancel
Save