X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FPopulateBlocklistsCoroutine.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FPopulateBlocklistsCoroutine.kt;h=0000000000000000000000000000000000000000;hb=c51155ed36754975d2b8673e37e58df6201702b8;hp=32a4b3b3d170cd8a884d3962f01fed1daf5bd852;hpb=5f1a770884ec933217ba377e92e0e7466572e92d;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/coroutines/PopulateBlocklistsCoroutine.kt b/app/src/main/java/com/stoutner/privacybrowser/coroutines/PopulateBlocklistsCoroutine.kt deleted file mode 100644 index 32a4b3b3..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/coroutines/PopulateBlocklistsCoroutine.kt +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2019,2021-2023 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.coroutines - -import android.app.Activity -import android.content.Context -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.ParseBlocklistHelper - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext - -import java.util.ArrayList - -class PopulateBlocklistsCoroutine(context: Context) { - // The public interface is used to send information back to the parent activity. - interface PopulateBlocklistsListener { - fun finishedPopulatingBlocklists(combinedBlocklists: ArrayList>>>) - } - - // Define a populate blocklists listener. - private val populateBlocklistsListener: PopulateBlocklistsListener - - // Define the class variables. - private val context: Context - - // The public constructor. - init { - // Get a handle for the populate blocklists listener from the launching activity. - populateBlocklistsListener = context as PopulateBlocklistsListener - - // Store the context. - this.context = context - } - - fun populateBlocklists(activity: Activity) { - // Use a coroutine to populate the blocklists. - CoroutineScope(Dispatchers.Main).launch { - // Get handles for the views. - val drawerLayout = activity.findViewById(R.id.drawerlayout) - val loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout) - val loadingBlocklistTextView = activity.findViewById(R.id.loading_blocklist_textview) - - // Show the loading blocklists screen. - loadingBlocklistsRelativeLayout.visibility = View.VISIBLE - - // Instantiate the blocklist helper. - val parseBlocklistHelper = ParseBlocklistHelper() - - // Create a combined array list. - val combinedBlocklists = ArrayList>>>() - - // Advertise the loading of EasyList. - loadingBlocklistTextView.text = context.getString(R.string.loading_easylist) - - // Populate the blocklists on the IO thread. - withContext(Dispatchers.IO) { - // Populate EasyList. - val easyList = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/easylist.txt") - - // Advertise the loading of EasyPrivacy. - withContext(Dispatchers.Main) { - loadingBlocklistTextView.text = context.getString(R.string.loading_easyprivacy) - } - - // Populate EasyPrivacy. - val easyPrivacy = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/easyprivacy.txt") - - // Advertise the loading of Fanboy's Annoyance List. - withContext(Dispatchers.Main) { - loadingBlocklistTextView.text = context.getString(R.string.loading_fanboys_annoyance_list) - } - - // Populate Fanboy's Annoyance List. - val fanboysAnnoyanceList = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/fanboy-annoyance.txt") - - // Advertise the loading of Fanboy's social blocking list. - withContext(Dispatchers.Main) { - loadingBlocklistTextView.text = context.getString(R.string.loading_fanboys_social_blocking_list) - } - - // Populate Fanboy's Social Blocking List. - val fanboysSocialList = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/fanboy-social.txt") - - // Advertise the loading of UltraList - withContext(Dispatchers.Main) { - loadingBlocklistTextView.text = context.getString(R.string.loading_ultralist) - } - - // Populate UltraList. - val ultraList = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/ultralist.txt") - - // Advertise the loading of UltraPrivacy. - withContext(Dispatchers.Main) { - loadingBlocklistTextView.text = context.getString(R.string.loading_ultraprivacy) - } - - // Populate UltraPrivacy. - val ultraPrivacy = parseBlocklistHelper.parseBlocklist(context.assets, "blocklists/ultraprivacy.txt") - - // Populate the combined array list. - combinedBlocklists.add(easyList) - combinedBlocklists.add(easyPrivacy) - combinedBlocklists.add(fanboysAnnoyanceList) - combinedBlocklists.add(fanboysSocialList) - combinedBlocklists.add(ultraList) - combinedBlocklists.add(ultraPrivacy) - - // Update the UI. - withContext(Dispatchers.Main) { - // Show the drawer layout. - drawerLayout.visibility = View.VISIBLE - - // Hide the loading blocklists screen. - loadingBlocklistsRelativeLayout.visibility = View.GONE - - // Enable the sliding drawers. - drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) - - // Add the first tab. - populateBlocklistsListener.finishedPopulatingBlocklists(combinedBlocklists) - } - } - } - } -}