From f740ecd661b6be32fa7e42213e14e6a9c02c4048 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 19 Sep 2018 10:00:58 +0000 Subject: [PATCH] Long press to delete from trash --- .idea/misc.xml | 2 +- .../eu/faircode/email/AdapterMessage.java | 113 +++++++++++++----- 2 files changed, 81 insertions(+), 34 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 99202cc2..c0f68edd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 5fd86084..7fec0ef8 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -23,6 +23,7 @@ import android.Manifest; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -57,6 +58,7 @@ import javax.mail.Address; import javax.mail.internet.InternetAddress; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.core.content.ContextCompat; import androidx.lifecycle.LifecycleOwner; @@ -96,8 +98,9 @@ public class AdapterMessage extends PagedListAdapter() { - @Override - protected Void onLoad(Context context, Bundle args) { - long id = args.getLong("id"); - int action = args.getInt("action"); - - DB db = DB.getInstance(context); - try { - db.beginTransaction(); - - EntityMessage message = db.message().getMessage(id); - for (EntityMessage tmessage : db.message().getMessageByThread(message.account, message.thread)) - if (action == action_flag) { - db.message().setMessageUiFlagged(tmessage.id, !message.ui_flagged); - EntityOperation.queue(db, tmessage, EntityOperation.FLAG, !tmessage.ui_flagged); - } else if (action == action_seen) { - db.message().setMessageUiSeen(tmessage.id, !message.ui_seen); - EntityOperation.queue(db, tmessage, EntityOperation.SEEN, !tmessage.ui_seen); + if (target.getItemId() == action_delete) { + new AlertDialog.Builder(context) + .setMessage(R.string.title_ask_delete) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Bundle args = new Bundle(); + args.putLong("id", message.id); + + new SimpleTask() { + @Override + protected Void onLoad(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + db.message().setMessageUiHide(id, true); + EntityOperation.queue(db, message, EntityOperation.DELETE); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + EntityOperation.process(context); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(context, ex); + } + }.load(context, owner, args); } + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } else + new SimpleTask() { + @Override + protected Void onLoad(final Context context, Bundle args) { + long id = args.getLong("id"); + int action = args.getInt("action"); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + for (EntityMessage tmessage : db.message().getMessageByThread(message.account, message.thread)) + if (action == action_flag) { + db.message().setMessageUiFlagged(tmessage.id, !message.ui_flagged); + EntityOperation.queue(db, tmessage, EntityOperation.FLAG, !tmessage.ui_flagged); + } else if (action == action_seen) { + db.message().setMessageUiSeen(tmessage.id, !message.ui_seen); + EntityOperation.queue(db, tmessage, EntityOperation.SEEN, !tmessage.ui_seen); + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - EntityOperation.process(context); + EntityOperation.process(context); - return null; - } + return null; + } - @Override - public void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(context, ex); - } - }.load(context, owner, args); + @Override + public void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(context, ex); + } + }.load(context, owner, args); return true; }