X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FPopulateBlocklists.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FPopulateBlocklists.java;h=0000000000000000000000000000000000000000;hp=af2bea14001fe28ea2b0f288a36c0f58a0cb96d0;hb=c2b5bdf009503f6761dc830fb65502ad2910c284;hpb=58dbf864ccd5dd341517e1ff0adaf681476d4a4f diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java deleted file mode 100644 index af2bea14..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright © 2019,2021-2022 Soren Stoutner . - * - * This file is part of Privacy Browser Android . - * - * Privacy Browser Android is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privacy Browser Android is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser Android. If not, see . - */ - -package com.stoutner.privacybrowser.asynctasks; - -import android.app.Activity; -import android.content.Context; -import android.os.AsyncTask; -import android.view.View; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.drawerlayout.widget.DrawerLayout; - -import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.helpers.BlocklistHelper; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -public class PopulateBlocklists extends AsyncTask>>> { - // The public interface is used to send information back to the parent activity. - public interface PopulateBlocklistsListener { - void finishedPopulatingBlocklists(ArrayList>> combinedBlocklists); - } - - // Define a populate blocklists listener. - private final PopulateBlocklistsListener populateBlocklistsListener; - - // Define weak references for the activity and context. - private final WeakReference contextWeakReference; - private final WeakReference activityWeakReference; - - // The public constructor. - public PopulateBlocklists(Context context, Activity activity) { - // Populate the weak reference to the context. - contextWeakReference = new WeakReference<>(context); - - // Populate the weak reference to the activity. - activityWeakReference = new WeakReference<>(activity); - - // Get a handle for the populate blocklists listener from the launching activity. - 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. - RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout); - - // Show the loading blocklists screen. - loadingBlocklistsRelativeLayout.setVisibility(View.VISIBLE); - } - - @Override - protected ArrayList>> 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(); - - // Instantiate the blocklist helper. - BlocklistHelper blocklistHelper = new BlocklistHelper(); - - // Create a combined array list. - ArrayList>> combinedBlocklists = new ArrayList<>(); - - // Load the blocklists if the context still exists. - if (context != null) { - // Update the progress. - publishProgress(context.getString(R.string.loading_easylist)); - - // Populate EasyList. - ArrayList> 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)); - - // Populate EasyPrivacy. - ArrayList> 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)); - - // Populate Fanboy's Annoyance List. - ArrayList> 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)); - - // Populate Fanboy's Social Blocking List. - ArrayList> 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> 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> 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); - } - - // Return the combined array list. - return combinedBlocklists; - } - - @Override - protected void onProgressUpdate(String... loadingBlocklist) { - // Get a handle for the activity. - Activity activity = activityWeakReference.get(); - - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { - return; - } - - // Get a handle for the loading blocklist text view. - TextView loadingBlocklistTextView = activity.findViewById(R.id.loading_blocklist_textview); - - // Update the status. - loadingBlocklistTextView.setText(loadingBlocklist[0]); - } - - @Override - protected void onPostExecute(ArrayList>> combinedBlocklists) { - // 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. - DrawerLayout drawerLayout = activity.findViewById(R.id.drawerlayout); - RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout); - - // Show the drawer layout. - drawerLayout.setVisibility(View.VISIBLE); - - // 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