]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java
Redesign file access to work with the scoped storage. https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / asynctasks / PopulateBlocklists.java
index 7a7fc4da126af15f92cad38ee273dff90b5e5a51..e9e151f5df069c77273e6860c2995dcfb9cea4bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2019,2021 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -44,11 +44,11 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
     }
 
     // Define a populate blocklists listener.
-    private PopulateBlocklistsListener populateBlocklistsListener;
+    private final PopulateBlocklistsListener populateBlocklistsListener;
 
     // Define weak references for the activity and context.
-    private WeakReference<Context> contextWeakReference;
-    private WeakReference<Activity> activityWeakReference;
+    private final WeakReference<Context> contextWeakReference;
+    private final WeakReference<Activity> activityWeakReference;
 
     // The public constructor.
     public PopulateBlocklists(Context context, Activity activity) {
@@ -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,25 @@ 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));
+
+            // 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));
@@ -133,12 +174,19 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             // 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);
             combinedBlocklists.add(easyPrivacy);
             combinedBlocklists.add(fanboysAnnoyanceList);
             combinedBlocklists.add(fanboysSocialList);
+            combinedBlocklists.add(ultraList);
             combinedBlocklists.add(ultraPrivacy);
         }