import android.os.AsyncTask;
import android.view.View;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
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 {
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<>();
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_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.
// 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);
// 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