- // Update the WebView pager every time a tab is modified.
- webViewViewPager2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
- override fun onPageSelected(position: Int) {
- // Close the find on page bar if it is open.
- closeFindOnPage(null)
-
- // Set the current WebView.
- setCurrentWebView(position)
-
- // Wait until the new tab has been created.
- tabLayout.post {
- // Select the corresponding tab if it does not match the currently selected page. This will happen if the page was scrolled by creating a new tab.
- // The checking of the position was moved inside the post block to prevent a race condition that caused the tab to be selected twice and the encryption dialog to be displayed.
- // <https://redmine.stoutner.com/issues/1020>
- if (tabLayout.selectedTabPosition != position) {
- // Get a handle for the tab.
- val tab = tabLayout.getTabAt(position)!!
-
- // Select the tab.
- tab.select()
- }
- }
- }
- })
-