Skip confirmation if leave deleted is enabled

pull/202/head
M66B 3 years ago
parent 0ad40cac20
commit 33d70afdb6

@ -19,6 +19,11 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B) Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/ */
import static android.app.Activity.RESULT_OK;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON;
import android.Manifest; import android.Manifest;
import android.animation.Animator; import android.animation.Animator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -188,11 +193,6 @@ import biweekly.property.Organizer;
import biweekly.property.RawProperty; import biweekly.property.RawProperty;
import biweekly.util.ICalDate; import biweekly.util.ICalDate;
import static android.app.Activity.RESULT_OK;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON;
public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHolder> { public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHolder> {
private Fragment parentFragment; private Fragment parentFragment;
private String type; private String type;
@ -4352,28 +4352,53 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onActionDelete(TupleMessageEx message) { private void onActionDelete(TupleMessageEx message) {
Bundle aargs = new Bundle(); Bundle args = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete)); args.putLong("account", message.account == null ? -1 : message.account);
aargs.putString("remark", message.getRemark());
aargs.putLong("id", message.id);
aargs.putInt("faq", 160);
aargs.putString("notagain", "delete_asked");
aargs.putString("accept", context.getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); new SimpleTask<EntityAccount>() {
boolean delete_asked = prefs.getBoolean("delete_asked", false); @Override
if (delete_asked) { protected EntityAccount onExecute(Context context, Bundle args) throws Throwable {
Intent data = new Intent(); long aid = args.getLong("account");
data.putExtra("args", aargs);
parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk(); DB db = DB.getInstance(context);
ask.setArguments(aargs); return db.account().getAccount(aid);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE); }
ask.show(parentFragment.getParentFragmentManager(), "message:delete");
@Override
protected void onExecuted(Bundle args, EntityAccount account) {
boolean leave_deleted = (account != null &&
account.protocol == EntityAccount.TYPE_POP &&
account.leave_deleted);
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark());
aargs.putLong("id", message.id);
aargs.putInt("faq", 160);
aargs.putString("notagain", "delete_asked");
aargs.putString("accept", context.getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked || leave_deleted) {
Intent data = new Intent();
data.putExtra("args", aargs);
parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE);
ask.show(parentFragment.getParentFragmentManager(), "message:delete");
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "message:delete");
} }
private void onActionJunk(TupleMessageEx message) { private void onActionJunk(TupleMessageEx message) {

@ -2951,8 +2951,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
hasArchive = (archive != null && archive.selectable); hasArchive = (archive != null && archive.selectable);
hasTrash = (trash != null && trash.selectable); hasTrash = (trash != null && trash.selectable);
hasJunk = (junk != null && junk.selectable); hasJunk = (junk != null && junk.selectable);
} else } else {
result.hasPop = true; result.hasPop = true;
if (result.leave_deleted == null)
result.leave_deleted = account.leave_deleted;
else
result.leave_deleted = (result.leave_deleted && account.leave_deleted);
}
result.hasInbox = (result.hasInbox == null ? hasInbox : result.hasInbox && hasInbox); result.hasInbox = (result.hasInbox == null ? hasInbox : result.hasInbox && hasInbox);
result.hasArchive = (result.hasArchive == null ? hasArchive : result.hasArchive && hasArchive); result.hasArchive = (result.hasArchive == null ? hasArchive : result.hasArchive && hasArchive);
@ -3129,7 +3134,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionMoveSelection(EntityFolder.TRASH); onActionMoveSelection(EntityFolder.TRASH);
return true; return true;
} else if (itemId == R.string.title_delete_permanently) { } else if (itemId == R.string.title_delete_permanently) {
onActionDeleteSelection(result.hasPop && !result.hasImap); onActionDeleteSelection(
result.hasPop && !result.hasImap,
result.leave_deleted != null && result.leave_deleted);
return true; return true;
} else if (itemId == R.string.title_raw_send) { } else if (itemId == R.string.title_raw_send) {
onActionRaw(); onActionRaw();
@ -3417,7 +3424,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "messages:set:importance"); }.execute(this, args, "messages:set:importance");
} }
private void onActionDeleteSelection(boolean pop) { private void onActionDeleteSelection(boolean popOnly, Boolean leave_delete) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("selected", getSelection()); args.putLongArray("selected", getSelection());
@ -3460,7 +3467,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", getResources() aargs.putString("question", getResources()
.getQuantityString(R.plurals.title_deleting_messages, ids.size(), ids.size())); .getQuantityString(R.plurals.title_deleting_messages, ids.size(), ids.size()));
boolean remark = (pop || boolean remark = (popOnly ||
EntityFolder.TRASH.equals(type) || EntityFolder.TRASH.equals(type) ||
EntityFolder.JUNK.equals(type)); EntityFolder.JUNK.equals(type));
aargs.putString(remark ? "remark" : "confirm", getString(R.string.title_no_undo)); aargs.putString(remark ? "remark" : "confirm", getString(R.string.title_no_undo));
@ -3468,6 +3475,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
aargs.putLongArray("ids", Helper.toLongArray(ids)); aargs.putLongArray("ids", Helper.toLongArray(ids));
aargs.putBoolean("warning", true); aargs.putBoolean("warning", true);
if (popOnly && leave_delete) {
Intent data = new Intent();
data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGES_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk(); FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs); ask.setArguments(aargs);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_DELETE); ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_DELETE);
@ -3818,6 +3832,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
try { try {
db.beginTransaction(); db.beginTransaction();
EntityAccount account = db.account().getAccount(aid);
if (account != null &&
account.protocol == EntityAccount.TYPE_POP &&
account.leave_deleted)
args.putBoolean("leave_deleted", true);
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null); aid, thread, threading ? null : id, null);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
@ -3850,6 +3870,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
aargs.putLongArray("ids", Helper.toLongArray(ids)); aargs.putLongArray("ids", Helper.toLongArray(ids));
aargs.putBoolean("warning", true); aargs.putBoolean("warning", true);
boolean leave_deleted = args.getBoolean("leave_deleted");
if (leave_deleted) {
Intent data = new Intent();
data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGES_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk(); FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs); ask.setArguments(aargs);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_DELETE); ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_DELETE);
@ -8412,8 +8440,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Boolean isTrash; Boolean isTrash;
Boolean isJunk; Boolean isJunk;
Boolean isDrafts; Boolean isDrafts;
boolean hasPop;
boolean hasImap; boolean hasImap;
boolean hasPop;
Boolean leave_deleted;
List<Long> folders; List<Long> folders;
List<EntityAccount> accounts; List<EntityAccount> accounts;
EntityAccount copyto; EntityAccount copyto;

Loading…
Cancel
Save