]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Add a back arrow to the header of the bookmarks drawer. https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Sat, 12 Sep 2020 22:07:40 +0000 (15:07 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 12 Sep 2020 22:07:40 +0000 (15:07 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/res/layout-w900dp/bookmarks_drawer.xml
app/src/main/res/layout/bookmarks_drawer.xml
app/src/main/res/layout/main_framelayout.xml

index 735d3e39793c951699bb31475e881deb6d2fab0d..8a1bb956c18abaec1457b5f2a20735af88df0fe5 100644 (file)
@@ -816,7 +816,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
     }
 
     @Override
-    public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, Bitmap favoriteIconBitmap) {
+    public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, @NonNull Bitmap favoriteIconBitmap) {
         // Get the dialog from the dialog fragment.
         Dialog dialog = dialogFragment.getDialog();
 
index b2d9afa3fa48e3b801c6b293b912aa2d637910f6..f9f1780f61c8575eec3a8671a2ac88d5be000073 100644 (file)
@@ -235,11 +235,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     private int savedTabPosition;
     private String savedProxyMode;
 
-    // Define the class views.
-    private AppBarLayout appBarLayout;
-    private TabLayout tabLayout;
-    private ViewPager webViewPager;
-
     // Define the class variables.
     @SuppressWarnings("rawtypes")
     AsyncTask populateBlocklists;
@@ -338,6 +333,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     private String saveWebpageUrl;
     private String saveWebpageFilePath;
 
+    // Declare the class views.
+    private DrawerLayout drawerLayout;
+    private AppBarLayout appBarLayout;
+    private TabLayout tabLayout;
+    private ViewPager webViewPager;
+
     @Override
     // Remove the warning about needing to override `performClick()` when using an `OnTouchListener` with `WebView`.
     @SuppressLint("ClickableViewAccessibility")
@@ -401,7 +402,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         setContentView(R.layout.main_framelayout);
 
         // Get handles for the views.
-        DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
+        drawerLayout = findViewById(R.id.drawerlayout);
         appBarLayout = findViewById(R.id.appbar_layout);
         Toolbar toolbar = findViewById(R.id.toolbar);
         tabLayout = findViewById(R.id.tablayout);
@@ -504,9 +505,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                     loadUrl(currentWebView, url);
                 }
 
-                // Get a handle for the drawer layout.
-                DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
-
                 // Close the navigation drawer if it is open.
                 if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
                     drawerLayout.closeDrawer(GravityCompat.START);
@@ -574,9 +572,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
         // Update the bookmarks drawer if returning from the Bookmarks activity.
         if (restartFromBookmarksActivity) {
-            // Get a handle for the drawer layout.
-            DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
-
             // Close the bookmarks drawer.
             drawerLayout.closeDrawer(GravityCompat.END);
 
@@ -1132,9 +1127,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 return true;
 
             case R.id.bookmarks:
-                // Get a handle for the drawer layout.
-                DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
-
                 // Open the bookmarks drawer.
                 drawerLayout.openDrawer(GravityCompat.END);
 
@@ -2111,9 +2103,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 break;
         }
 
-        // Get a handle for the drawer layout.
-        DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
-
         // Close the navigation drawer.
         drawerLayout.closeDrawer(GravityCompat.START);
         return true;
@@ -2649,26 +2638,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         bookmarksCursorAdapter.changeCursor(bookmarksCursor);
     }
 
-    // Override `onBackPressed` to handle the navigation drawer and and the WebViews.
+    // Override `onBackPressed()` to handle the navigation drawer and and the WebViews.
     @Override
     public void onBackPressed() {
-        // Get a handle for the drawer layout.
-        DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
-
+        // Check the different options for processing `back`.
         if (drawerLayout.isDrawerVisible(GravityCompat.START)) {  // The navigation drawer is open.
             // Close the navigation drawer.
             drawerLayout.closeDrawer(GravityCompat.START);
         } else if (drawerLayout.isDrawerVisible(GravityCompat.END)){  // The bookmarks drawer is open.
-            if (currentBookmarksFolder.isEmpty()) {  // The home folder is displayed.
-                // close the bookmarks drawer.
-                drawerLayout.closeDrawer(GravityCompat.END);
-            } else {  // A subfolder is displayed.
-                // Place the former parent folder in `currentFolder`.
-                currentBookmarksFolder = bookmarksDatabaseHelper.getParentFolderName(currentBookmarksFolder);
-
-                // Load the new folder.
-                loadBookmarksFolder();
-            }
+            // close the bookmarks drawer.
+            drawerLayout.closeDrawer(GravityCompat.END);
         } else if (displayingFullScreenVideo) {  // A full screen video is shown.
             // Get a handle for the layouts.
             FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout);
@@ -3333,7 +3312,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         this.registerReceiver(orbotStatusBroadcastReceiver, new IntentFilter("org.torproject.android.intent.action.STATUS"));
 
         // Get handles for views that need to be modified.
-        DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
         NavigationView navigationView = findViewById(R.id.navigationview);
         SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
         ListView bookmarksListView = findViewById(R.id.bookmarks_drawer_listview);
@@ -5074,6 +5052,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         System.exit(0);
     }
 
+    public void bookmarksBack(View view) {
+        if (currentBookmarksFolder.isEmpty()) {  // The home folder is displayed.
+            // close the bookmarks drawer.
+            drawerLayout.closeDrawer(GravityCompat.END);
+        } else {  // A subfolder is displayed.
+            // Place the former parent folder in `currentFolder`.
+            currentBookmarksFolder = bookmarksDatabaseHelper.getParentFolderName(currentBookmarksFolder);
+
+            // Load the new folder.
+            loadBookmarksFolder();
+        }
+    }
+
     private void setCurrentWebView(int pageNumber) {
         // Get handles for the URL views.
         RelativeLayout urlRelativeLayout = findViewById(R.id.url_relativelayout);
@@ -5227,7 +5218,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
         // Get handles for the activity views.
         FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout);
-        DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
         RelativeLayout mainContentRelativeLayout = findViewById(R.id.main_content_relativelayout);
         ActionBar actionBar = appCompatDelegate.getSupportActionBar();
         LinearLayout tabsLinearLayout = findViewById(R.id.tabs_linearlayout);
index e1e5042c199e33e8f5267fffb26dcabb3c715068..e49aaf9cca0d3548fb594bf7c49a1e2ad15d2b72 100644 (file)
 
 <!-- `android:layout_width="400dp"` keeps the bookmarks drawer from filling the whole screen on a tablet. -->
 <FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/bookmarks_framelayout"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_height="match_parent"
     android:layout_width="400dp"
     android:layout_gravity="end" >
         android:orientation="vertical"
         android:background="?android:attr/colorBackground" >
 
-        <TextView
-            android:id="@+id/bookmarks_title_textview"
+        <!-- A compound drawable doesn't work well because only the image view should execute the `onClick()`. -->
+        <LinearLayout
             android:layout_height="wrap_content"
             android:layout_width="match_parent"
-            android:textStyle="bold"
-            android:textSize="20sp"
-            android:textColor="?android:attr/textColorPrimary"
-            android:layout_margin="10dp" />
+            android:orientation="horizontal"
+            tools:ignore="UseCompoundDrawables" >
+
+            <ImageView
+                android:layout_height="match_parent"
+                android:layout_width="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:paddingStart="15dp"
+                android:paddingEnd="15dp"
+                android:src="@drawable/back"
+                android:background="?attr/selectableItemBackground"
+                android:onClick="bookmarksBack"
+                android:contentDescription="@string/back"
+                app:tint="?android:attr/textColorPrimary" />
+
+            <TextView
+                android:id="@+id/bookmarks_title_textview"
+                android:layout_height="wrap_content"
+                android:layout_width="match_parent"
+                android:textStyle="bold"
+                android:textSize="20sp"
+                android:textColor="?android:attr/textColorPrimary"
+                android:layout_margin="10dp" />
+        </LinearLayout>
 
         <ListView
             android:id="@+id/bookmarks_drawer_listview"
index 87b9d0daca6a80462782a96fcda4ac1998d93cbd..62955c55308f9d6ec7a9c1517dae15cf8a665d9b 100644 (file)
   along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
 
 <FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/bookmarks_framelayout"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_height="match_parent"
     android:layout_width="match_parent"
-    android:layout_gravity="end" >
+    android:layout_gravity="end">
 
     <LinearLayout
         android:layout_height="match_parent"
         android:orientation="vertical"
         android:background="?android:attr/colorBackground" >
 
-        <TextView
-            android:id="@+id/bookmarks_title_textview"
+        <!-- A compound drawable doesn't work well because only the image view should execute the `onClick()`. -->
+        <LinearLayout
             android:layout_height="wrap_content"
             android:layout_width="match_parent"
-            android:textStyle="bold"
-            android:textSize="20sp"
-            android:textColor="?android:attr/textColorPrimary"
-            android:layout_margin="10dp" />
+            android:orientation="horizontal"
+            tools:ignore="UseCompoundDrawables" >
+
+            <ImageView
+                android:layout_height="match_parent"
+                android:layout_width="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:paddingStart="15dp"
+                android:paddingEnd="15dp"
+                android:src="@drawable/back"
+                android:background="?attr/selectableItemBackground"
+                android:onClick="bookmarksBack"
+                android:contentDescription="@string/back"
+                app:tint="?android:attr/textColorPrimary" />
+
+            <TextView
+                android:id="@+id/bookmarks_title_textview"
+                android:layout_height="wrap_content"
+                android:layout_width="match_parent"
+                android:textStyle="bold"
+                android:textSize="20sp"
+                android:textColor="?android:attr/textColorPrimary"
+                android:layout_margin="10dp" />
+        </LinearLayout>
 
         <ListView
             android:id="@+id/bookmarks_drawer_listview"
index f067aad2a9748b0b754a8c1a79c4f96c825f7cc6..61a196ee4ba9693f01f3fbd5a75bb3681c902aeb 100644 (file)
@@ -92,6 +92,7 @@
                             android:layout_marginEnd="4dp"
                             android:text="@string/zero_of_zero" />
 
+                        <!-- `android:background="?attr/selectableItemBackground"` adds a ripple animation on touch. -->
                         <ImageView
                             android:id="@+id/find_previous"
                             android:src="@drawable/previous"
                             android:layout_marginStart="4dp"
                             android:layout_marginEnd="4dp"
                             android:layout_gravity="center_vertical"
-                            android:tint="?attr/findOnPageIconTintColor"
+                            android:background="?attr/selectableItemBackground"
                             android:contentDescription="@string/previous"
-                            android:onClick="findPreviousOnPage" />
+                            android:onClick="findPreviousOnPage"
+                            app:tint="?attr/findOnPageIconTintColor" />
 
+                        <!-- `android:background="?attr/selectableItemBackground"` adds a ripple animation on touch. -->
                         <ImageView
                             android:id="@+id/find_next"
                             android:src="@drawable/next"
                             android:layout_marginStart="4dp"
                             android:layout_marginEnd="4dp"
                             android:layout_gravity="center_vertical"
-                            android:tint="?attr/findOnPageIconTintColor"
+                            android:background="?attr/selectableItemBackground"
                             android:contentDescription="@string/next"
-                            android:onClick="findNextOnPage" />
+                            android:onClick="findNextOnPage"
+                            app:tint="?attr/findOnPageIconTintColor" />
 
+                        <!-- `android:background="?attr/selectableItemBackground"` adds a ripple animation on touch. -->
                         <ImageView
                             android:id="@+id/close_find"
                             android:src="@drawable/close_day"
                             android:layout_marginStart="4dp"
                             android:layout_marginEnd="8dp"
                             android:layout_gravity="center_vertical"
-                            android:tint="?attr/findOnPageIconTintColor"
+                            android:background="?attr/selectableItemBackground"
                             android:contentDescription="@string/close"
-                            android:onClick="closeFindOnPage" />
+                            android:onClick="closeFindOnPage"
+                            app:tint="?attr/findOnPageIconTintColor" />
                     </LinearLayout>
 
                     <!-- The tab linear layout.  It sets the background to the right of the add tab button.  It is initially `visibility="gone"` so it doesn't display while the blocklists are loading. -->
                             android:paddingStart="10dp"
                             android:paddingEnd="10dp"
                             android:src="@drawable/close_day"
-                            android:tint="?attr/addTabIconTintColor"
                             android:background="?attr/selectableItemBackground"
                             android:onClick="closeTab"
-                            android:contentDescription="@string/close_tab" />
+                            android:contentDescription="@string/close_tab"
+                            app:tint="?attr/addTabIconTintColor" />
 
                         <com.google.android.material.tabs.TabLayout
                             android:id="@+id/tablayout"
                             android:paddingStart="10dp"
                             android:paddingEnd="10dp"
                             android:src="@drawable/add"
-                            android:tint="?attr/addTabIconTintColor"
                             android:background="?attr/selectableItemBackground"
                             android:onClick="addTab"
-                            android:contentDescription="@string/add_tab" />
+                            android:contentDescription="@string/add_tab"
+                            app:tint="?attr/addTabIconTintColor" />
                     </LinearLayout>
                 </com.google.android.material.appbar.AppBarLayout>