Added delete xml method inside the yes dialogue.

This commit is contained in:
Vincent Tanumihardja 2022-10-29 09:52:22 +11:00 committed by TobiGr
parent 23de9bf93e
commit 81ad50e82a
1 changed files with 11 additions and 16 deletions

View File

@ -1,7 +1,6 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -98,31 +97,27 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
// A dialogue will pop up to confirm if user intends to reset all settings // A dialogue will pop up to confirm if user intends to reset all settings
assert resetSettings != null; assert resetSettings != null;
resetSettings.setOnPreferenceClickListener(preference -> { resetSettings.setOnPreferenceClickListener(preference -> {
// Show Alert Dialogue
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage("Resetting all settings will discard " builder.setMessage("Resetting all settings will discard "
+ "all of your preferred settings and restarts the app. " + "all of your preferred settings and restarts the app. "
+ "Are you sure you want to proceed?"); + "Are you sure you want to proceed?");
builder.setCancelable(true); builder.setCancelable(true);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { builder.setPositiveButton("Yes", (dialogInterface, i) -> {
@Override // Deletes all shared preferences xml files.
public void onClick(final DialogInterface dialogInterface, final int i) { final SharedPreferences sharedPreferences =
NavigationHelper.restartApp(getActivity()); PreferenceManager.getDefaultSharedPreferences(requireContext());
sharedPreferences.edit().clear().apply();
// Restarts the app
if (getActivity() == null) {
return;
} }
NavigationHelper.restartApp(getActivity());
}); });
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { builder.setNegativeButton("Cancel", (dialogInterface, i) -> {
@Override
public void onClick(final DialogInterface dialogInterface, final int i) {
}
}); });
final AlertDialog alertDialog = builder.create(); final AlertDialog alertDialog = builder.create();
alertDialog.show(); alertDialog.show();
// delete all shared preferences xml files.
final SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(requireContext());
sharedPreferences.edit().clear().apply();
return true; return true;
}); });
} }