/*
- * Copyright 2015-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2015-2024 Soren Stoutner <soren@stoutner.com>.
*
* Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
*
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.ActionBar
-import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources
private lateinit var userAgentNamesArrayAdapter: ArrayAdapter<CharSequence>
// Define the class variables.
- private var actionBarDrawerToggle: ActionBarDrawerToggle? = null
private var appBarHeight = 0
private var bookmarksCursor: Cursor? = null
private var bookmarksDatabaseHelper: BookmarksDatabaseHelper? = null
urlRelativeLayout = findViewById(R.id.url_relativelayout)
urlEditText = findViewById(R.id.url_edittext)
- // Create the hamburger icon at the start of the AppBar.
- actionBarDrawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_navigation_drawer, R.string.close_navigation_drawer)
-
// Initially disable the sliding drawers. They will be enabled once the filter lists are loaded.
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
drawerLayout.visibility = View.GONE
// Initialize the WebView state adapter.
- webViewStateAdapter = WebViewStateAdapter(this)
+ 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.
}
}
- public override fun onPostCreate(savedInstanceState: Bundle?) {
- // Run the default commands.
- super.onPostCreate(savedInstanceState)
-
- // Sync the state of the DrawerToggle after the default `onRestoreInstanceState()` has finished. This creates the navigation drawer icon.
- // If the app is restarting to change the app theme the action bar drawer toggle will not yet be populated.
- actionBarDrawerToggle?.syncState()
- }
-
override fun onNewIntent(intent: Intent) {
// Run the default commands.
super.onNewIntent(intent)
// Add the extra information to the intent.
domainsIntent.putExtra(LOAD_DOMAIN, currentWebView!!.domainSettingsDatabaseId)
domainsIntent.putExtra(CLOSE_ON_BACK, true)
- domainsIntent.putExtra(CURRENT_URL, currentWebView!!.url)
domainsIntent.putExtra(CURRENT_IP_ADDRESSES, currentWebView!!.currentIpAddresses)
// Get the current certificate.
// 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
// Add the extra information to the intent.
domainsIntent.putExtra(LOAD_DOMAIN, newDomainDatabaseId)
domainsIntent.putExtra(CLOSE_ON_BACK, true)
- domainsIntent.putExtra(CURRENT_URL, currentWebView!!.url)
domainsIntent.putExtra(CURRENT_IP_ADDRESSES, currentWebView!!.currentIpAddresses)
// Get the current certificate.
val domainsIntent = Intent(this, DomainsActivity::class.java)
// Add the extra information to the intent.
- domainsIntent.putExtra(CURRENT_URL, currentWebView!!.url)
domainsIntent.putExtra(CURRENT_IP_ADDRESSES, currentWebView!!.currentIpAddresses)
// Get the current certificate.
// 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. <https://redmine.stoutner.com/issues/1136>
+ 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) {
fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean(getString(R.string.full_screen_browsing_mode_key), false)
hideAppBar = sharedPreferences.getBoolean(getString(R.string.hide_app_bar_key), true)
downloadWithExternalApp = sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)
- scrollAppBar = sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true)
+ scrollAppBar = sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), false)
// Apply the saved proxy mode if the app has been restarted.
if (savedProxyMode != null) {
override fun onDrawerOpened(drawerView: View) {}
- override fun onDrawerClosed(drawerView: View) {
- // Reset the drawer icon when the drawer is closed. Otherwise, it remains an arrow if the drawer is open when the app is restarted.
- actionBarDrawerToggle!!.syncState()
- }
+ override fun onDrawerClosed(drawerView: View) {}
override fun onDrawerStateChanged(newState: Int) {
if (newState == DrawerLayout.STATE_SETTLING || newState == DrawerLayout.STATE_DRAGGING) { // A drawer is opening or closing.
currentWebView!!.loadUrl(openFilePath)
}
}
+ // The view parameter cannot be removed because it is called from the layout onClick.
+ fun openNavigationDrawer(@Suppress("UNUSED_PARAMETER")view: View) {
+ // Open the navigation drawer.
+ drawerLayout.openDrawer(GravityCompat.START)
+ }
private fun openWithApp(url: String) {
// Create an open with app intent with `ACTION_VIEW`.