|
1 | 1 | package org.schabi.newpipe.settings; |
2 | 2 |
|
3 | 3 | import android.app.AlertDialog; |
4 | | -import android.content.DialogInterface; |
5 | 4 | import android.content.Intent; |
6 | 5 | import android.content.SharedPreferences; |
7 | 6 | import android.os.Bundle; |
@@ -98,31 +97,27 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro |
98 | 97 | // A dialogue will pop up to confirm if user intends to reset all settings |
99 | 98 | assert resetSettings != null; |
100 | 99 | resetSettings.setOnPreferenceClickListener(preference -> { |
| 100 | + // Show Alert Dialogue |
101 | 101 | final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); |
102 | 102 | builder.setMessage("Resetting all settings will discard " |
103 | 103 | + "all of your preferred settings and restarts the app. " |
104 | 104 | + "Are you sure you want to proceed?"); |
105 | 105 | builder.setCancelable(true); |
106 | | - builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { |
107 | | - @Override |
108 | | - public void onClick(final DialogInterface dialogInterface, final int i) { |
109 | | - NavigationHelper.restartApp(getActivity()); |
| 106 | + builder.setPositiveButton("Yes", (dialogInterface, i) -> { |
| 107 | + // Deletes all shared preferences xml files. |
| 108 | + final SharedPreferences sharedPreferences = |
| 109 | + PreferenceManager.getDefaultSharedPreferences(requireContext()); |
| 110 | + sharedPreferences.edit().clear().apply(); |
| 111 | + // Restarts the app |
| 112 | + if (getActivity() == null) { |
| 113 | + return; |
110 | 114 | } |
| 115 | + NavigationHelper.restartApp(getActivity()); |
111 | 116 | }); |
112 | | - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
113 | | - @Override |
114 | | - public void onClick(final DialogInterface dialogInterface, final int i) { |
115 | | - } |
| 117 | + builder.setNegativeButton("Cancel", (dialogInterface, i) -> { |
116 | 118 | }); |
117 | 119 | final AlertDialog alertDialog = builder.create(); |
118 | 120 | alertDialog.show(); |
119 | | - |
120 | | - // delete all shared preferences xml files. |
121 | | - final SharedPreferences sharedPreferences = |
122 | | - PreferenceManager.getDefaultSharedPreferences(requireContext()); |
123 | | - sharedPreferences.edit().clear().apply(); |
124 | | - |
125 | | - |
126 | 121 | return true; |
127 | 122 | }); |
128 | 123 | } |
|
0 commit comments