]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java
Finish tabbed browsing. https://redmine.stoutner.com/issues/22
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
index c22da979983282c4ef40409db5ff6e17d954d9e5..4001345b14037b1497f734f58b6e30b4b1b42c2f 100644 (file)
@@ -25,6 +25,7 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.preference.Preference;
 import android.preference.PreferenceCategory;
 import android.preference.PreferenceFragment;
@@ -942,11 +943,23 @@ public class SettingsFragment extends PreferenceFragment {
                     // Assert that the intent is not null to remove the lint error below.
                     assert allowScreenshotsRestartIntent != null;
 
-                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.  TODO.
+                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
                     allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 
-                    // Make it so.
-                    startActivity(allowScreenshotsRestartIntent);
+                    // Create a handler to restart the activity.
+                    Handler allowScreenshotsRestartHandler = new Handler();
+
+                    // Create a runnable to restart the activity.
+                    Runnable allowScreenshotsRestartRunnable = () -> {
+                        // Restart the activity.
+                        startActivity(allowScreenshotsRestartIntent);
+
+                        // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
+                        System.exit(0);
+                    };
+
+                    // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
+                    allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 100);
                     break;
 
                 case "easylist":
@@ -1482,17 +1495,26 @@ public class SettingsFragment extends PreferenceFragment {
                     // Assert that the intent is not null to remove the lint error below.
                     assert changeThemeRestartIntent != null;
 
-                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.  TODO.
+                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
                     changeThemeRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 
-                    // Make it so.
-                    startActivity(changeThemeRestartIntent);
+                    // Create a handler to restart the activity.
+                    Handler changeThemeRestartHandler = new Handler();
+
+                    // Create a runnable to restart the activity.
+                    Runnable changeThemeRestartRunnable = () -> {
+                        // Restart the activity.
+                        startActivity(changeThemeRestartIntent);
+
+                        // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
+                        System.exit(0);
+                    };
+
+                    // Restart the activity after 100 milliseconds, so that the app has enought time to save the change to the preference.
+                    changeThemeRestartHandler.postDelayed(changeThemeRestartRunnable, 100);
                     break;
 
                 case "night_mode":
-                    // Set the URL to be reloaded on restart to apply the new night mode setting.
-                    MainWebViewActivity.reloadOnRestart = true;
-
                     // Store the current night mode status.
                     boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
                     boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false);
@@ -1551,9 +1573,6 @@ public class SettingsFragment extends PreferenceFragment {
                         } else {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
                         }
-
-                        // `mainWebView` does not need to be reloaded because unloaded images will load automatically.
-                        MainWebViewActivity.reloadOnRestart = false;
                     } else {
                         // Update the icon.
                         if (darkTheme) {
@@ -1561,9 +1580,6 @@ public class SettingsFragment extends PreferenceFragment {
                         } else {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
                         }
-
-                        // Set `mainWebView` to reload on restart to remove the current images.
-                        MainWebViewActivity.reloadOnRestart = true;
                     }
                     break;
             }