From: Soren Stoutner Date: Wed, 22 May 2019 18:58:56 +0000 (-0700) Subject: Fix changes to Download with External App not applying to existing tabs. https:... X-Git-Tag: v3.1~3 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=8a72caf321663f9549997695af01d89db45fe7d1;p=PrivacyBrowserAndroid.git Fix changes to Download with External App not applying to existing tabs. https://redmine.stoutner.com/issues/451 --- diff --git a/app/src/main/assets/blocklists/ultraprivacy.txt b/app/src/main/assets/blocklists/ultraprivacy.txt index 1afe7e2f..77d9c6d2 100644 --- a/app/src/main/assets/blocklists/ultraprivacy.txt +++ b/app/src/main/assets/blocklists/ultraprivacy.txt @@ -1,10 +1,12 @@ [Adblock Plus 2.0] -! Version: 1 +! Version: 2 ! Title: UltraPrivacy -! Last modified: 25 Jul 2018 20:41 UTC +! Last modified: 22 May 2019 18:11 UTC ! Expires: 90 days (update frequency) ! Homepage: https://www.stoutner.com/privacy-browser/blocklists/ultraprivacy/ ! Licence: GPLv3+ http://www.gnu.org/licenses/gpl-3.0.html ! ! I can't imagine that anything that includes `analytics` is good for your privacy. https://redmine.stoutner.com/issues/312. analytics +! Block Google Tag Services. https://redmine.stoutner.com/issues/449 +googletagservices diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index fbab8bfb..33687f9a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -115,6 +115,7 @@ import com.stoutner.privacybrowser.BuildConfig; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.adapters.WebViewPagerAdapter; import com.stoutner.privacybrowser.asynctasks.GetHostIpAddresses; +import com.stoutner.privacybrowser.asynctasks.PopulateBlocklists; import com.stoutner.privacybrowser.dialogs.AdConsentDialog; import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog; import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog; @@ -157,7 +158,7 @@ import java.util.Set; // AppCompatActivity from android.support.v7.app.AppCompatActivity must be used to have access to the SupportActionBar until the minimum API is >= 21. public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, DownloadLocationPermissionDialog.DownloadLocationPermissionDialogListener, EditBookmarkDialog.EditBookmarkListener, - EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, WebViewTabFragment.NewTabListener { + EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, PopulateBlocklists.PopulateBlocklistsListener, WebViewTabFragment.NewTabListener { // `orbotStatus` is public static so it can be accessed from `OrbotProxyHelper`. It is also used in `onCreate()`, `onResume()`, and `applyProxyThroughOrbot()`. public static String orbotStatus; @@ -199,7 +200,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The options menu is set in `onCreateOptionsMenu()` and used in `onOptionsItemSelected()`, `updatePrivacyIcons()`, and `initializeWebView()`. private Menu optionsMenu; - // The blocklists are populated in `onCreate()` and accessed from `initializeWebView()`. + // The blocklists are populated in `finishedPopulatingBlocklists()` and accessed from `initializeWebView()`. private ArrayList> easyList; private ArrayList> easyPrivacy; private ArrayList> fanboysAnnoyanceList; @@ -443,16 +444,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Register `orbotStatusBroadcastReceiver` on `this` context. this.registerReceiver(orbotStatusBroadcastReceiver, new IntentFilter("org.torproject.android.intent.action.STATUS")); - // Instantiate the blocklist helper. - BlockListHelper blockListHelper = new BlockListHelper(); - - // Parse the block lists. - easyList = blockListHelper.parseBlockList(getAssets(), "blocklists/easylist.txt"); - easyPrivacy = blockListHelper.parseBlockList(getAssets(), "blocklists/easyprivacy.txt"); - fanboysAnnoyanceList = blockListHelper.parseBlockList(getAssets(), "blocklists/fanboy-annoyance.txt"); - fanboysSocialList = blockListHelper.parseBlockList(getAssets(), "blocklists/fanboy-social.txt"); - ultraPrivacy = blockListHelper.parseBlockList(getAssets(), "blocklists/ultraprivacy.txt"); - // Get handles for views that need to be modified. DrawerLayout drawerLayout = findViewById(R.id.drawerlayout); NavigationView navigationView = findViewById(R.id.navigationview); @@ -550,9 +541,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } }); - // Add the first tab. - addTab(null); - // Set the bookmarks drawer resources according to the theme. This can't be done in the layout due to compatibility issues with the `DrawerLayout` support widget. // The deprecated `getResources().getDrawable()` must be used until the minimum API >= 21 and and `getResources().getColor()` must be used until the minimum API >= 23. if (darkTheme) { @@ -805,6 +793,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Destroy the bare WebView. bareWebView.destroy(); + + // Populate the blocklists. + new PopulateBlocklists(this, this).execute(); } @Override @@ -3053,7 +3044,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook assert inputMethodManager != null; // Hide the keyboard. - inputMethodManager.hideSoftInputFromWindow(currentWebView.getWindowToken(), 0); + inputMethodManager.hideSoftInputFromWindow(toolbar.getWindowToken(), 0); } private void applyAppSettings() { @@ -4023,6 +4014,18 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook return url; } + public void finishedPopulatingBlocklists(ArrayList>> combinedBlocklists) { + // Store the blocklists. + easyList = combinedBlocklists.get(0); + easyPrivacy = combinedBlocklists.get(1); + fanboysAnnoyanceList = combinedBlocklists.get(2); + fanboysSocialList = combinedBlocklists.get(3); + ultraPrivacy = combinedBlocklists.get(4); + + // Add the first tab. + addNewTab(""); + } + public void addTab(View view) { // Add a new tab with a blank URL. addNewTab(""); @@ -4404,9 +4407,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get a handle for the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - // Get the relevant preferences. - boolean downloadWithExternalApp = sharedPreferences.getBoolean("download_with_external_app", false); - // Initialize the favorite icon. nestedScrollWebView.initializeFavoriteIcon(); @@ -4527,7 +4527,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Allow the downloading of files. nestedScrollWebView.setDownloadListener((String downloadUrl, String userAgent, String contentDisposition, String mimetype, long contentLength) -> { // Check if the download should be processed by an external app. - if (downloadWithExternalApp) { // Download with an external app. + if (sharedPreferences.getBoolean("download_with_external_app", false)) { // Download with an external app. // Create a download intent. Not specifying the action type will display the maximum number of options. Intent downloadIntent = new Intent(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java new file mode 100644 index 00000000..f732f475 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java @@ -0,0 +1,165 @@ +/* + * Copyright © 2019 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser 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, + * 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 . + */ + +package com.stoutner.privacybrowser.asynctasks; + +import android.app.Activity; +import android.content.Context; +import android.os.AsyncTask; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.stoutner.privacybrowser.R; +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; + + // Declare weak references for the activity and context. + private WeakReference contextWeakReference; + private WeakReference activityWeakReference; + + 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; + } + + @Override + protected ArrayList>> doInBackground(Void... none) { + // 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"); + + + // Update the progress. + publishProgress(context.getString(R.string.loading_easyprivacy)); + + // Populate EasyPrivacy. + ArrayList> 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> 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> fanboysSocialList = blockListHelper.parseBlockList(context.getAssets(), "blocklists/fanboy-social.txt"); + + + // Update the progress. + publishProgress(context.getString(R.string.loading_ultraprivacy)); + + // Populate UltraPrivacy. + ArrayList> ultraPrivacy = blockListHelper.parseBlockList(context.getAssets(), "blocklists/ultraprivacy.txt"); + + + // Populate the combined array list. + combinedBlocklists.add(easyList); + combinedBlocklists.add(easyPrivacy); + combinedBlocklists.add(fanboysAnnoyanceList); + combinedBlocklists.add(fanboysSocialList); + 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. + Toolbar toolbar = activity.findViewById(R.id.toolbar); + LinearLayout tabsLinearLayout = activity.findViewById(R.id.tabs_linearlayout); + RelativeLayout loadingBlocklistsRelativeLayout = activity.findViewById(R.id.loading_blocklists_relativelayout); + + // Show the toolbar and tabs linear layout. + toolbar.setVisibility(View.VISIBLE); + tabsLinearLayout.setVisibility(View.VISIBLE); + + // Hide the loading blocklists screen. + loadingBlocklistsRelativeLayout.setVisibility(View.GONE); + + // Add the first tab. + populateBlocklistsListener.finishedPopulatingBlocklists(combinedBlocklists); + } +} diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java index a524d266..69ab1ecc 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java @@ -56,7 +56,7 @@ public class CreateBookmarkDialog extends DialogFragment { // Run the default commands. super.onAttach(context); - // Get a handle for `CreateBookmarkListener` from the launching context. + // Get a handle for the create bookmark listener from the launching context. createBookmarkListener = (CreateBookmarkListener) context; } diff --git a/app/src/main/res/layout/main_framelayout.xml b/app/src/main/res/layout/main_framelayout.xml index 36dbf365..cfd7f4eb 100644 --- a/app/src/main/res/layout/main_framelayout.xml +++ b/app/src/main/res/layout/main_framelayout.xml @@ -62,7 +62,8 @@ android:id="@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" - app:layout_scrollFlags="scroll|enterAlways|snap" /> + app:layout_scrollFlags="scroll|enterAlways|snap" + android:visibility="gone" /> + app:layout_scrollFlags="scroll|enterAlways|snap" + android:visibility="gone" > - + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c8dd00a..111103d1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,6 +56,13 @@ New tab Loading… + + Loading EasyList + Loading EasyPrivacy + Loading Fanboy’s Annoyance List + Loading Fanboy’s Social Blocking List + Loading UltraPrivacy + Save As Save Image As