Swipe delete / keep deleted

This commit is contained in:
M66B 2021-08-08 12:01:49 +02:00
parent c4763d4b12
commit 2444aad6c7
1 changed files with 44 additions and 19 deletions

View File

@ -2437,29 +2437,54 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private void onSwipeDelete(@NonNull TupleMessageEx message) { private void onSwipeDelete(@NonNull TupleMessageEx message) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete)); args.putLong("account", message.account == null ? -1 : message.account);
args.putString("remark", message.getRemark());
args.putLong("id", message.id); new SimpleTask<EntityAccount>() {
args.putInt("faq", 160); @Override
args.putString("notagain", "delete_asked"); protected EntityAccount onExecute(Context context, Bundle args) throws Throwable {
args.putString("accept", getString(R.string.title_ask_delete_accept)); long aid = args.getLong("account");
args.putBoolean("warning", true);
DB db = DB.getInstance(context);
return db.account().getAccount(aid);
}
@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", 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", getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean delete_asked = prefs.getBoolean("delete_asked", false); boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked) { if (delete_asked || leave_deleted) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("args", args); data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data); onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return; return;
} }
FragmentDialogAsk ask = new FragmentDialogAsk(); FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(args); ask.setArguments(aargs);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE); ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE);
ask.show(getParentFragmentManager(), "swipe:delete"); ask.show(getParentFragmentManager(), "swipe:delete");
} }
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "message:delete");
}
private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) { private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);