Skip to content

Commit 076e9ee

Browse files
vincetzrTobiGr
authored andcommitted
Added alert dialogue and restarts the app when resetting settings.
1 parent 2103a04 commit 076e9ee

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.settings;
22

3+
import android.app.AlertDialog;
4+
import android.content.DialogInterface;
35
import android.content.Intent;
46
import android.os.Bundle;
57

@@ -10,9 +12,8 @@
1012
import org.schabi.newpipe.error.ErrorUtil;
1113
import org.schabi.newpipe.error.UserAction;
1214
import org.schabi.newpipe.local.feed.notifications.NotificationWorker;
13-
import org.schabi.newpipe.util.Constants;
15+
import org.schabi.newpipe.util.NavigationHelper;
1416
import org.schabi.newpipe.util.PicassoHelper;
15-
import org.schabi.newpipe.util.ThemeHelper;
1617

1718
import java.util.Optional;
1819

@@ -91,12 +92,30 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
9192
return true;
9293
});
9394

94-
// reset appearance to light theme
95+
// Resets all settings by deleting shared preference and restarting the app
96+
// A dialogue will pop up to confirm if user intends to reset all settings
9597
resetSettings.setOnPreferenceClickListener(preference -> {
96-
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
97-
defaultPreferences.edit().putString(getString(R.string.theme_key),
98-
getString(R.string.light_theme_key)).apply();
99-
ThemeHelper.setDayNightMode(requireContext(), "light_theme");
98+
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
99+
builder.setMessage("Resetting all settings will discard "
100+
+ "all of your preferred settings and restarts the app. "
101+
+ "Are you sure you want to do this?");
102+
builder.setCancelable(true);
103+
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
104+
@Override
105+
public void onClick(final DialogInterface dialogInterface, final int i) {
106+
NavigationHelper.restartApp(getActivity());
107+
}
108+
});
109+
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
110+
@Override
111+
public void onClick(final DialogInterface dialogInterface, final int i) {
112+
}
113+
});
114+
final AlertDialog alertDialog = builder.create();
115+
alertDialog.show();
116+
// SharedPreferences sharedPreferences =
117+
// PreferenceManager.getDefaultSharedPreferences(requireContext());
118+
// sharedPreferences = null;
100119
return true;
101120
});
102121
}

0 commit comments

Comments
 (0)