X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.kt;h=ed6ecb36ac89fd847a21bde9a5c4a826bbaafe0f;hp=85b3ae76e0f60987e9f86304201d246ab40e597c;hb=70da2a558d6e35c38adb596479c36f7e451dc9a5;hpb=6ab00381e1005dbfd4e05302afa54614f96cbea1 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 85b3ae76..ed6ecb36 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Soren Stoutner . + * Copyright 2015-2024 Soren Stoutner . * * Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner . * @@ -646,7 +646,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Initialize the WebView state adapter. webViewStateAdapter = WebViewStateAdapter(this, bottomAppBar) - // Set the pager adapter on the web view pager. + // Set the WebView pager adapter. webViewViewPager2.adapter = webViewStateAdapter // Store up to 100 tabs in memory. @@ -2221,7 +2221,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Set the font size integer. val fontSizeInt = if (textZoomInt == defaultFontSizeString.toInt()) // The current system default is used, which is encoded as a zoom of `0`. - 0 + SYSTEM_DEFAULT else // A custom font size is used. textZoomInt @@ -3007,17 +3007,21 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Clear the focus from the URL edit text, so that it will be populated with the information from the new tab. urlEditText.clearFocus() - // Get the new tab position. - val newTabPosition = if (adjacent) // The new tab position is immediately to the right of the current tab position. - tabLayout.selectedTabPosition + 1 - else // The new tab position is at the end. The tab positions are 0 indexed, so the new page number will match the current count. - tabLayout.tabCount + // Add the new tab after the tab layout has quiesced. + // Otherwise, there can be problems when restoring a large number of tabs and processing a new intent at the same time. + tabLayout.post { + // Get the new tab position. + val newTabPosition = if (adjacent) // The new tab position is immediately to the right of the current tab position. + tabLayout.selectedTabPosition + 1 + else // The new tab position is at the end. The tab positions are 0 indexed, so the new page number will match the current count. + tabLayout.tabCount - // Add the new WebView page. - webViewStateAdapter!!.addPage(newTabPosition, urlString) + // Add the new WebView page. + webViewStateAdapter!!.addPage(newTabPosition, urlString) - // Add the new tab. - addNewTab(newTabPosition, moveToTab) + // Add the new tab. + addNewTab(newTabPosition, moveToTab) + } } private fun addNewTab(newTabPosition: Int, moveToTab: Boolean) {