|
1 | 1 | package org.schabi.newpipe.settings; |
2 | 2 |
|
| 3 | +import android.app.AlertDialog; |
| 4 | +import android.content.DialogInterface; |
3 | 5 | import android.content.Intent; |
4 | 6 | import android.os.Bundle; |
5 | 7 |
|
|
10 | 12 | import org.schabi.newpipe.error.ErrorUtil; |
11 | 13 | import org.schabi.newpipe.error.UserAction; |
12 | 14 | import org.schabi.newpipe.local.feed.notifications.NotificationWorker; |
13 | | -import org.schabi.newpipe.util.Constants; |
| 15 | +import org.schabi.newpipe.util.NavigationHelper; |
14 | 16 | import org.schabi.newpipe.util.PicassoHelper; |
15 | | -import org.schabi.newpipe.util.ThemeHelper; |
16 | 17 |
|
17 | 18 | import java.util.Optional; |
18 | 19 |
|
@@ -91,12 +92,30 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro |
91 | 92 | return true; |
92 | 93 | }); |
93 | 94 |
|
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 |
95 | 97 | 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; |
100 | 119 | return true; |
101 | 120 | }); |
102 | 121 | } |
|
0 commit comments