X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FPopulateBlocklists.java;h=99ccd45fd83e23f8258c1cf6c230c002b918e5c7;hp=f732f47534aadcf354cf089bbe160755ba6ec137;hb=8142ac5fc2489de735de4b6fa21a1eae733ccfce;hpb=8a72caf321663f9549997695af01d89db45fe7d1 diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java index f732f475..99ccd45f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java @@ -1,20 +1,20 @@ /* - * Copyright © 2019 Soren Stoutner . + * Copyright © 2019,2021-2022 Soren Stoutner . * - * This file is part of Privacy Browser . + * This file is part of Privacy Browser Android . * - * Privacy Browser is free software: you can redistribute it and/or modify + * 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 is distributed in the hope that it will be useful, + * 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. If not, see . + * along with Privacy Browser Android. If not, see . */ package com.stoutner.privacybrowser.asynctasks; @@ -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>>> { // The public interface is used to send information back to the parent activity. public interface PopulateBlocklistsListener { void finishedPopulatingBlocklists(ArrayList>> combinedBlocklists); } - // Declare a populate blocklists listener. - private PopulateBlocklistsListener populateBlocklistsListener; + // Define a populate blocklists listener. + private final PopulateBlocklistsListener populateBlocklistsListener; - // Declare weak references for the activity and context. - private WeakReference contextWeakReference; - private WeakReference activityWeakReference; + // 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); @@ -60,13 +62,42 @@ public class PopulateBlocklists extends AsyncTask>> 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(); + BlocklistHelper blocklistHelper = new BlocklistHelper(); // Create a combined array list. ArrayList>> combinedBlocklists = new ArrayList<>(); @@ -77,35 +108,77 @@ public class PopulateBlocklists extends AsyncTask> easyList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/easylist.txt"); + 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"); + 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"); + 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"); + 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"); + 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. @@ -113,6 +186,7 @@ public class PopulateBlocklists extends AsyncTask