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=e9e151f5df069c77273e6860c2995dcfb9cea4bb;hp=106c8d9c919a8ddbad8e16fbe92c1fd7c0bcd0a2;hb=d4f39c36beb5e6c3568a1e075274ad66defd8e8e;hpb=2a28c6401f60afa40ca93b18fc0b9a0ab196ff88 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 106c8d9c..e9e151f5 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Soren Stoutner . + * Copyright © 2019,2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -24,7 +24,6 @@ import android.content.Context; import android.os.AsyncTask; import android.view.View; import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; @@ -44,13 +43,14 @@ public class PopulateBlocklists extends AsyncTask>> 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); @@ -88,6 +88,11 @@ 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(); @@ -105,6 +110,11 @@ public class PopulateBlocklists extends AsyncTask> 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> 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> 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> 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)); @@ -133,12 +174,19 @@ public class PopulateBlocklists extends AsyncTask> 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); }