Fix app initialization when the theme is set to the opposite of the OS theme. https...
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / asynctasks / PopulateBlocklists.java
index 75306368addbffd4e508ba2865430fbcf73383d9..4474285f934d00d423471d5c85e86750b0b18ea1 100644 (file)
@@ -88,6 +88,11 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
 
     @Override
     protected ArrayList<ArrayList<List<String[]>>> doInBackground(Void... none) {
+        // Exit the AsyncTask if the app has been restarted.
+        if (isCancelled()) {
+            return null;
+        }
+
         // Get a handle for the context.
         Context context = contextWeakReference.get();
 
@@ -105,6 +110,11 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // Populate EasyList.
             ArrayList<List<String[]>> easyList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/easylist.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_easyprivacy));
@@ -112,6 +122,12 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // Populate EasyPrivacy.
             ArrayList<List<String[]>> easyPrivacy = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/easyprivacy.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
+
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_fanboys_annoyance_list));
@@ -119,6 +135,12 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // Populate Fanboy's Annoyance List.
             ArrayList<List<String[]>> fanboysAnnoyanceList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/fanboy-annoyance.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
+
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_fanboys_social_blocking_list));
@@ -126,6 +148,12 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // Populate Fanboy's Social Blocking List.
             ArrayList<List<String[]>> fanboysSocialList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/fanboy-social.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
+
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_ultralist));
@@ -133,12 +161,25 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // Populate UltraList.
             ArrayList<List<String[]>> ultraList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/ultralist.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
+
+
             // Update the progress.
             publishProgress(context.getString(R.string.loading_ultraprivacy));
 
             // Populate UltraPrivacy.
             ArrayList<List<String[]>> ultraPrivacy = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/ultraprivacy.txt");
 
+            // Exit the AsyncTask if the app has been restarted.
+            if (isCancelled()) {
+                return null;
+            }
+
+
 
             // Populate the combined array list.
             combinedBlocklists.add(easyList);