From 967ba621fdcc8a73c8c85ece33c93bc1db969f4d Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 17 Nov 2023 09:46:02 +0100 Subject: [PATCH] Revert "Removed repair button" This reverts commit f2902fe6bc049bfece1e2f505737adf43275afa6. --- .../faircode/email/FragmentOptionsMisc.java | 75 +++++++++++++++++++ .../main/res/layout/fragment_options_misc.xml | 14 +++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 7cda5fe1c6..bb793326ba 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -162,6 +162,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swTest4; private SwitchCompat swTest5; + private Button btnRepair; private Button btnDaily; private TextView tvLastDaily; private SwitchCompat swAutostart; @@ -397,6 +398,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swTest4 = view.findViewById(R.id.swTest4); swTest5 = view.findViewById(R.id.swTest5); + btnRepair = view.findViewById(R.id.btnRepair); btnDaily = view.findViewById(R.id.btnDaily); tvLastDaily = view.findViewById(R.id.tvLastDaily); swAutostart = view.findViewById(R.id.swAutostart); @@ -972,6 +974,79 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + btnRepair.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (BuildConfig.DEBUG) + new AlertDialog.Builder(view.getContext()) + .setIcon(R.drawable.twotone_bug_report_24) + .setTitle(R.string.title_advanced_repair) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new SimpleTask() { + @Override + protected void onPostExecute(Bundle args) { + prefs.edit().remove("debug").apply(); + } + + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + DB db = DB.getInstance(context); + + List accounts = db.account().getAccounts(); + if (accounts == null) + return null; + + for (EntityAccount account : accounts) { + if (account.protocol != EntityAccount.TYPE_IMAP) + continue; + + List folders = db.folder().getFolders(account.id, false, false); + if (folders == null) + continue; + + EntityFolder inbox = db.folder().getFolderByType(account.id, EntityFolder.INBOX); + for (EntityFolder folder : folders) { + if (inbox == null && "inbox".equalsIgnoreCase(folder.name)) + folder.type = EntityFolder.INBOX; + + if (!EntityFolder.USER.equals(folder.type) && + !EntityFolder.SYSTEM.equals(folder.type)) { + EntityLog.log(context, "Repairing " + account.name + ":" + folder.type); + folder.setProperties(); + folder.setSpecials(account); + db.folder().updateFolder(folder); + } + } + } + + return null; + } + + @Override + protected void onExecuted(Bundle args, Void data) { + ToastEx.makeText(v.getContext(), R.string.title_completed, Toast.LENGTH_LONG).show(); + ServiceSynchronize.reload(v.getContext(), null, true, "repair"); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentOptionsMisc.this, new Bundle(), "repair"); + } + }) + .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Do nothing + } + }) + .show(); + } + }); + btnDaily.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 7ac957dc98..8f4db07f52 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -927,6 +927,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> +