Added explicit cleanup

pull/157/head
M66B 5 years ago
parent 35f254eade
commit 2067d89666

@ -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<Void>() {
@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);

@ -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<Void>() {
@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());

@ -161,6 +161,30 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDebug" />
<Button
android:id="@+id/btnCleanup"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_advanced_cleanup"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDebugHint" />
<TextView
android:id="@+id/tvCleanupHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_cleanup_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnCleanup" />
<TextView
android:id="@+id/tvProcessors"
android:layout_width="0dp"
@ -172,7 +196,7 @@
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDebugHint" />
app:layout_constraintTop_toBottomOf="@id/tvCleanupHint" />
<TextView
android:id="@+id/tvMemoryClass"

@ -247,6 +247,7 @@
<string name="title_advanced_updates">Check for updates</string>
<string name="title_advanced_crash_reports">Send error reports</string>
<string name="title_advanced_debug">Debug mode</string>
<string name="title_advanced_cleanup">Cleanup</string>
<string name="title_advanced_processors" translatable="false">Processors: %1$d</string>
<string name="title_advanced_memory_class" translatable="false">Memory class: %1$s</string>
<string name="title_advanced_last_cleanup" translatable="false">Last cleanup: %1$s</string>
@ -278,6 +279,7 @@
<string name="title_advanced_subscribed_only_hint">Enabling this will delete all local folders without subscription</string>
<string name="title_advanced_english_hint">This will restart the app</string>
<string name="title_advanced_debug_hint">Enable extra logging and show debug information at various places</string>
<string name="title_advanced_cleanup_hint">This will delete all temporary files</string>
<string name="title_select">Select &#8230;</string>
<string name="title_identity_name">Your name</string>

Loading…
Cancel
Save