]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Fix changes to Download with External App not applying to existing tabs. https:...
authorSoren Stoutner <soren@stoutner.com>
Wed, 22 May 2019 18:58:56 +0000 (11:58 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 22 May 2019 18:58:56 +0000 (11:58 -0700)
app/src/main/assets/blocklists/ultraprivacy.txt
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/asynctasks/PopulateBlocklists.java [new file with mode: 0644]
app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.java
app/src/main/res/layout/main_framelayout.xml
app/src/main/res/values/strings.xml

index 1afe7e2f1023784962c0aea9f9d4b696ddbff371..77d9c6d29cb38ead718f436ada93829c1c7b7690 100644 (file)
@@ -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
index fbab8bfb37d977d82e659f28b4ab3fe100d60669..33687f9a48512202c96d3a5a5086fc49cee92d0b 100644 (file)
@@ -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<List<String[]>> easyList;
     private ArrayList<List<String[]>> easyPrivacy;
     private ArrayList<List<String[]>> 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<ArrayList<List<String[]>>> 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 (file)
index 0000000..f732f47
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright © 2019 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser <https://www.stoutner.com/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 <http://www.gnu.org/licenses/>.
+ */
+
+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<Void, String, ArrayList<ArrayList<List<String[]>>>> {
+    // The public interface is used to send information back to the parent activity.
+    public interface PopulateBlocklistsListener {
+        void finishedPopulatingBlocklists(ArrayList<ArrayList<List<String[]>>> combinedBlocklists);
+    }
+
+    // Declare a populate blocklists listener.
+    private PopulateBlocklistsListener populateBlocklistsListener;
+
+    // Declare weak references for the activity and context.
+    private WeakReference<Context> contextWeakReference;
+    private WeakReference<Activity> 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<ArrayList<List<String[]>>> 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<ArrayList<List<String[]>>> 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<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");
+
+
+            // 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");
+
+
+            // 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");
+
+
+            // Update the progress.
+            publishProgress(context.getString(R.string.loading_ultraprivacy));
+
+            // Populate UltraPrivacy.
+            ArrayList<List<String[]>> 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<ArrayList<List<String[]>>> 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);
+    }
+}
index a524d266c02c0e34c07591b3f0904ae7442d521b..69ab1ecc5900628c8f605366350f8274f29c44ee 100644 (file)
@@ -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;
     }
 
index 36dbf3654211f851d20aabc5b2255bb5badea83b..cfd7f4eb224c7d6af3575a95bd0c1a93e243df48 100644 (file)
@@ -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" />
 
                     <!-- The find on page linear layout.  It is initially `visibility="gone"`. -->
                     <LinearLayout
                         android:layout_height="wrap_content"
                         android:layout_width="wrap_content"
                         android:orientation="horizontal"
-                        app:layout_scrollFlags="scroll|enterAlways|snap" >
+                        app:layout_scrollFlags="scroll|enterAlways|snap"
+                        android:visibility="gone" >
 
                         <ImageView
                             android:layout_height="wrap_content"
         <include layout="@layout/bookmarks_drawer" />
     </androidx.drawerlayout.widget.DrawerLayout>
 
-    <!-- `The full screen video frame layout is used to display full screen videos.  It is initially `android:visibility="gone"` to hide it from view. -->
+    <!-- The full screen video frame layout is used to display full screen videos.  It is initially `android:visibility="gone"` to hide it from view. -->
     <FrameLayout
         android:id="@+id/full_screen_video_framelayout"
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:visibility="gone" />
+
+    <!-- The loading blocklists relative layout displays when the app first starts.  It is hidden once the blocklists are populated. -->
+    <RelativeLayout
+        android:id="@+id/loading_blocklists_relativelayout"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageView
+            android:id="@+id/privacy_browser_logo"
+            android:layout_height="256dp"
+            android:layout_width="256dp"
+            android:layout_centerInParent="true"
+            android:src="@drawable/privacy_browser_foreground"
+            tools:ignore="contentDescription" />
+
+        <TextView
+            android:id="@+id/loading_blocklist_textview"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/privacy_browser_logo"
+            android:layout_centerHorizontal="true" />
+    </RelativeLayout>
 </FrameLayout>
\ No newline at end of file
index 3c8dd00a1737c4d272913d60995e3ad5cb899aa6..111103d1846af8521ba8d900458ae559f0020095 100644 (file)
     <string name="new_tab">New tab</string>
     <string name="loading">Loading…</string>
 
+    <!-- Loading Blocklists. -->
+    <string name="loading_easylist">Loading EasyList</string>
+    <string name="loading_easyprivacy">Loading EasyPrivacy</string>
+    <string name="loading_fanboys_annoyance_list">Loading Fanboy’s Annoyance List</string>
+    <string name="loading_fanboys_social_blocking_list">Loading Fanboy’s Social Blocking List</string>
+    <string name="loading_ultraprivacy">Loading UltraPrivacy</string>
+
     <!-- Save As. -->
     <string name="save_as">Save As</string>
     <string name="save_image_as">Save Image As</string>