From 35c9a0f60a21bcfeb05b614331596ad41c18cbfe Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 24 Oct 2021 18:28:40 +0200 Subject: [PATCH] Added long press to delete account/identity --- .../eu/faircode/email/AdapterAccount.java | 67 +++++++++++++++++-- .../eu/faircode/email/AdapterIdentity.java | 62 +++++++++++++++-- 2 files changed, 117 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index ea6f18ed62..006805a30a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -26,6 +26,7 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; @@ -51,6 +52,7 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.Group; import androidx.fragment.app.Fragment; @@ -350,14 +352,15 @@ public class AdapterAccount extends RecyclerView.Adapter() { + @Override + protected Void onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + db.account().setAccountTbd(id); + + ServiceSynchronize.eval(context, "delete account"); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "account:delete"); + } }); popupMenu.show(); diff --git a/app/src/main/java/eu/faircode/email/AdapterIdentity.java b/app/src/main/java/eu/faircode/email/AdapterIdentity.java index 085eb7a7f2..d0a2f5ac82 100644 --- a/app/src/main/java/eu/faircode/email/AdapterIdentity.java +++ b/app/src/main/java/eu/faircode/email/AdapterIdentity.java @@ -20,11 +20,13 @@ package eu.faircode.email; */ import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; import android.text.SpannableString; +import android.text.TextUtils; import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.view.LayoutInflater; @@ -36,6 +38,7 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.fragment.app.Fragment; import androidx.lifecycle.Lifecycle; @@ -199,20 +202,22 @@ public class AdapterIdentity extends RecyclerView.Adapter() { + @Override + protected Void onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + db.identity().deleteIdentity(id); + + Core.clearIdentities(); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "identity:delete"); + } }); popupMenu.show();