From 2067d8966600122fe8271cebcb2e700b4f1b518c Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 10 Jul 2019 09:35:20 +0200 Subject: [PATCH] Added explicit cleanup --- .../java/eu/faircode/email/ActivitySetup.java | 21 ---------- .../faircode/email/FragmentOptionsMisc.java | 41 +++++++++++++++++++ .../main/res/layout/fragment_options_misc.xml | 26 +++++++++++- app/src/main/res/values/strings.xml | 2 + 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 10fc066814..2f62a4f4f0 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -233,12 +233,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac drawerLayout.closeDrawer(drawerContainer); onMenuPrivacy(); } - }, new Runnable() { - @Override - public void run() { - drawerLayout.closeDrawer(drawerContainer); - onCleanup(); - } })); menus.add(new NavMenuItem(R.drawable.baseline_info_24, R.string.menu_about, new Runnable() { @@ -437,21 +431,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac Helper.view(this, Helper.getIntentPrivacy()); } - private void onCleanup() { - new SimpleTask() { - @Override - protected Void onExecute(Context context, Bundle args) { - WorkerCleanup.cleanup(context, true); - return null; - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getSupportFragmentManager(), ex); - } - }.execute(this, new Bundle(), "cleanup:run"); - } - private void onMenuAbout() { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) getSupportFragmentManager().popBackStack("about", FragmentManager.POP_BACK_STACK_INCLUSIVE); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index bf3453d3d3..e931df79cb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -31,8 +31,10 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.CompoundButton; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -54,6 +56,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swUpdates; private SwitchCompat swCrashReports; private SwitchCompat swDebug; + private Button btnCleanup; private TextView tvProcessors; private TextView tvMemoryClass; @@ -89,6 +92,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swUpdates = view.findViewById(R.id.swUpdates); swCrashReports = view.findViewById(R.id.swCrashReports); swDebug = view.findViewById(R.id.swDebug); + btnCleanup = view.findViewById(R.id.btnCleanup); tvProcessors = view.findViewById(R.id.tvProcessors); tvMemoryClass = view.findViewById(R.id.tvMemoryClass); @@ -175,6 +179,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + btnCleanup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + onCleanup(); + } + }); + setLastCleanup(prefs.getLong("last_cleanup", -1)); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); @@ -223,6 +234,36 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc editor.apply(); } + private void onCleanup() { + new SimpleTask() { + @Override + protected void onPreExecute(Bundle args) { + btnCleanup.setEnabled(false); + } + + @Override + protected void onPostExecute(Bundle args) { + btnCleanup.setEnabled(true); + } + + @Override + protected Void onExecute(Context context, Bundle args) { + WorkerCleanup.cleanup(context, true); + return null; + } + + @Override + protected void onExecuted(Bundle args, Void data) { + Toast.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getFragmentManager(), ex); + } + }.execute(this, new Bundle(), "cleanup:run"); + } + private void setOptions() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index b0182e9f91..35bd8edddf 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -161,6 +161,30 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swDebug" /> +