]> 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 f732f47534aadcf354cf089bbe160755ba6ec137..75306368addbffd4e508ba2865430fbcf73383d9 100644 (file)
@@ -27,28 +27,30 @@ import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
+import androidx.appcompat.widget.Toolbar;
+import androidx.drawerlayout.widget.DrawerLayout;
+
 import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.helpers.BlockListHelper;
+import com.stoutner.privacybrowser.helpers.BlocklistHelper;
 
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.List;
 
-import androidx.appcompat.widget.Toolbar;
-
 public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayList<List<String[]>>>> {
     // The public interface is used to send information back to the parent activity.
     public interface PopulateBlocklistsListener {
         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);
@@ -60,13 +62,37 @@ 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.
         Context context = contextWeakReference.get();
 
         // Instantiate the blocklist helper.
-        BlockListHelper blockListHelper = new BlockListHelper();
+        BlocklistHelper blocklistHelper = new BlocklistHelper();
 
         // Create a combined array list.
         ArrayList<ArrayList<List<String[]>>> combinedBlocklists = new ArrayList<>();
@@ -77,35 +103,41 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
             publishProgress(context.getString(R.string.loading_easylist));
 
             // Populate EasyList.
-            ArrayList<List<String[]>> easyList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/easylist.txt");
+            ArrayList<List<String[]>> easyList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/easylist.txt");
 
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_easyprivacy));
 
             // Populate EasyPrivacy.
-            ArrayList<List<String[]>> easyPrivacy = blockListHelper.parseBlockList(context.getAssets(), "blocklists/easyprivacy.txt");
+            ArrayList<List<String[]>> easyPrivacy = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/easyprivacy.txt");
 
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_fanboys_annoyance_list));
 
             // Populate Fanboy's Annoyance List.
-            ArrayList<List<String[]>> fanboysAnnoyanceList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/fanboy-annoyance.txt");
+            ArrayList<List<String[]>> fanboysAnnoyanceList = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/fanboy-annoyance.txt");
 
 
             // Update the progress.
             publishProgress(context.getString(R.string.loading_fanboys_social_blocking_list));
 
             // Populate Fanboy's Social Blocking List.
-            ArrayList<List<String[]>> fanboysSocialList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/fanboy-social.txt");
+            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));
 
             // Populate UltraPrivacy.
-            ArrayList<List<String[]>> ultraPrivacy = blockListHelper.parseBlockList(context.getAssets(), "blocklists/ultraprivacy.txt");
+            ArrayList<List<String[]>> ultraPrivacy = blocklistHelper.parseBlocklist(context.getAssets(), "blocklists/ultraprivacy.txt");
 
 
             // Populate the combined array list.
@@ -113,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);
         }
 
@@ -149,6 +182,7 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
 
         // Get handles for the views.
         Toolbar toolbar = activity.findViewById(R.id.toolbar);
+        DrawerLayout drawerLayout = activity.findViewById(R.id.drawerlayout);
         LinearLayout tabsLinearLayout = activity.findViewById(R.id.tabs_linearlayout);
         RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout);
 
@@ -159,7 +193,10 @@ public class PopulateBlocklists extends AsyncTask<Void, String, ArrayList<ArrayL
         // Hide the loading blocklists screen.
         loadingBlocklistsRelativeLayout.setVisibility(View.GONE);
 
+        // Enable the sliding drawers.
+        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
+
         // Add the first tab.
         populateBlocklistsListener.finishedPopulatingBlocklists(combinedBlocklists);
     }
-}
+}
\ No newline at end of file