From f8486dc082d82deead08a6747670e22ce7263c97 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 27 Jul 2023 18:13:42 -0700 Subject: [PATCH] Scroll the navigation menu to the bottom with the bottom app bar. https://redmine.stoutner.com/issues/1047 --- .../activities/MainWebViewActivity.kt | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt index 1553146f..ac27dcd6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt @@ -104,6 +104,8 @@ import androidx.cursoradapter.widget.CursorAdapter import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.DialogFragment import androidx.preference.PreferenceManager +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.viewpager2.widget.ViewPager2 import androidx.webkit.WebSettingsCompat @@ -280,6 +282,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook private lateinit var navigationForwardMenuItem: MenuItem private lateinit var navigationHistoryMenuItem: MenuItem private lateinit var navigationRequestsMenuItem: MenuItem + private lateinit var navigationView: NavigationView private lateinit var optionsAddOrEditDomainMenuItem: MenuItem private lateinit var optionsBlockAllThirdPartyRequestsMenuItem: MenuItem private lateinit var optionsClearCookiesMenuItem: MenuItem @@ -375,6 +378,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook private var inFullScreenBrowsingMode = false private var incognitoModeEnabled = false private var loadingNewIntent = false + private var navigationDrawerFirstView = true private var objectAnimator = ObjectAnimator() private var optionsMenu: Menu? = null private var orbotStatusBroadcastReceiver: BroadcastReceiver? = null @@ -589,7 +593,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook tabLayout = findViewById(R.id.tablayout) swipeRefreshLayout = findViewById(R.id.swiperefreshlayout) webViewViewPager2 = findViewById(R.id.webview_viewpager2) - val navigationView = findViewById(R.id.navigationview) + navigationView = findViewById(R.id.navigationview) bookmarksListView = findViewById(R.id.bookmarks_drawer_listview) bookmarksTitleTextView = findViewById(R.id.bookmarks_title_textview) bookmarksDrawerPinnedImageView = findViewById(R.id.bookmarks_drawer_pinned_imageview) @@ -1008,6 +1012,9 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Run the default commands. super.onConfigurationChanged(newConfig) + // Reset the navigation drawer first view flag. + navigationDrawerFirstView = true + // Get the current page. val currentPage = webViewViewPager2.currentItem @@ -4444,6 +4451,20 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Clear the focus from from the WebView if it is not null, which can happen if a user opens a drawer while the browser is being resumed. // Clearing the focus from the WebView removes any text selection markers and context menus, which otherwise draw above the open drawers. currentWebView?.clearFocus() + + if (bottomAppBar && navigationDrawerFirstView) { + // Reset the navigation drawer first view flag. + navigationDrawerFirstView = false + + // Get a handle for the navigation recycler view. + val navigationRecyclerView = navigationView.getChildAt(0) as RecyclerView + + // Get the navigation linear layout manager. + val navigationLinearLayoutManager = navigationRecyclerView.layoutManager as LinearLayoutManager + + // Scroll the navigation drawer to the bottom. + navigationLinearLayoutManager.scrollToPositionWithOffset(13, 0) + } } } }) -- 2.45.2