]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java
Use the Content-Disposition header to get file names for downloads. https://redmine...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / asynctasks / PopulateBlocklists.java
index f7fa50886569b72c544afe3dac3adca794c61850..75306368addbffd4e508ba2865430fbcf73383d9 100644 (file)
@@ -43,13 +43,14 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
         void finishedPopulatingBlocklists(ArrayList<ArrayList<List<String[]>>> combinedBlocklists);
     }
 
-    // Declare a populate blocklists listener.
+    // Define a populate blocklists listener.
     private PopulateBlocklistsListener populateBlocklistsListener;
 
-    // Declare weak references for the activity and context.
+    // Define weak references for the activity and context.
     private WeakReference<Context> contextWeakReference;
     private WeakReference<Activity> activityWeakReference;
 
+    // The public constructor.
     public PopulateBlocklists(Context context, Activity activity) {
         // Populate the weak reference to the context.
         contextWeakReference = new WeakReference<>(context);
@@ -61,6 +62,30 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
         populateBlocklistsListener = (PopulateBlocklistsListener) context;
     }
 
+    // `onPreExecute()` operates on the UI thread.
+    @Override
+    protected void onPreExecute() {
+        // Get a handle for the activity.
+        Activity activity = activityWeakReference.get();
+
+        // Abort if the activity is gone.
+        if ((activity == null) || activity.isFinishing()) {
+            return;
+        }
+
+        // Get handles for the views.
+        Toolbar toolbar = activity.findViewById(R.id.toolbar);
+        LinearLayout tabsLinearLayout = activity.findViewById(R.id.tabs_linearlayout);
+        RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout);
+
+        // Hide the toolbar and tabs linear layout, which will be visible if this is being run after the app process has been killed in the background.
+        toolbar.setVisibility(View.GONE);
+        tabsLinearLayout.setVisibility(View.GONE);
+
+        // Show the loading blocklists screen.
+        loadingBlocklistsRelativeLayout.setVisibility(View.VISIBLE);
+    }
+
     @Override
     protected ArrayList<ArrayList<List<String[]>>> doInBackground(Void... none) {
         // Get a handle for the context.
@@ -102,6 +127,12 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             ArrayList<List<String[]>> fanboysSocialList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/fanboy-social.txt");
 
 
+            // Update the progress.
+            publishProgress(context.getString(R.string.loading_ultralist));
+
+            // Populate UltraList.
+            ArrayList<List<String[]>> ultraList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/ultralist.txt");
+
             // Update the progress.
             publishProgress(context.getString(R.string.loading_ultraprivacy));
 
@@ -114,6 +145,7 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             combinedBlocklists.add(easyPrivacy);
             combinedBlocklists.add(fanboysAnnoyanceList);
             combinedBlocklists.add(fanboysSocialList);
+            combinedBlocklists.add(ultraList);
             combinedBlocklists.add(ultraPrivacy);
         }