/*
* Copyright 2017-2024 Soren Stoutner <soren@stoutner.com>.
*
- * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android/>.
*
* Privacy Browser Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import android.content.Context
import android.database.Cursor
import android.os.Bundle
-import android.os.Handler
import android.view.Menu
import android.view.MenuItem
import android.view.View
}
} else { // The snackbar was dismissed without the undo button being pushed.
// Delete the selected domain.
- domainsDatabaseHelper.deleteDomain(databaseIdToDelete)
-
- // Enable the delete menu item if the system was waiting for a snackbar to be dismissed.
- if (dismissingSnackbar) {
- // Create a runnable to enable the delete menu item.
- val enableDeleteMenuItemRunnable = Runnable {
- // Enable or show the delete menu item according to the display mode.
- if (twoPanedMode)
- deleteMenuItem.isEnabled = true
- else
- deleteMenuItem.isVisible = true
-
- // Reset the dismissing snackbar tracker.
- dismissingSnackbar = false
- }
-
- // Instantiate a handler running the main looper.
- val handler = Handler(mainLooper)
-
- // Enable or show the delete menu icon after 100 milliseconds to make sure that the previous domain has been deleted from the database.
- handler.postDelayed(enableDeleteMenuItemRunnable, 100)
+ val rowsDeleted = domainsDatabaseHelper.deleteDomain(databaseIdToDelete)
+
+ // Enable the delete menu item.
+ // The rows deleted should always be greater than 0, but in all cases they should be greater than -1.
+ // This has the effect of tricking the compiler into waiting until after the delete finishes to reenable the delete menu item,
+ // because the compiler (probably) can't tell that the response will never be less than -1, so it doesn't compile out the delay.
+ if (rowsDeleted > -1) {
+ // Enable or show the delete menu item according to the display mode.
+ if (twoPanedMode)
+ deleteMenuItem.isEnabled = true
+ else
+ deleteMenuItem.isVisible = true
+
+ // Reset the dismissing snackbar tracker.
+ dismissingSnackbar = false
}
// Close the activity if back was pressed.
return true
}
- override fun onSaveInstanceState(savedInstanceState: Bundle) {
+ override fun onSaveInstanceState(outState: Bundle) {
// Run the default commands.
- super.onSaveInstanceState(savedInstanceState)
+ super.onSaveInstanceState(outState)
// Get a handle for the domain settings scrollview.
val domainSettingsScrollView = findViewById<ScrollView>(R.id.domain_settings_scrollview)
// Check to see if the domain settings scrollview exists.
if (domainSettingsScrollView == null) { // The domain settings are not displayed.
// Store the domain settings status in the bundle.
- savedInstanceState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, false)
- savedInstanceState.putInt(DOMAIN_SETTINGS_DATABASE_ID, -1)
- savedInstanceState.putInt(DOMAIN_SETTINGS_SCROLL_Y, 0)
+ outState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, false)
+ outState.putInt(DOMAIN_SETTINGS_DATABASE_ID, -1)
+ outState.putInt(DOMAIN_SETTINGS_SCROLL_Y, 0)
} else { // The domain settings are displayed.
// Save any changes that have been made to the domain settings.
saveDomainSettings(coordinatorLayout)
val domainSettingsScrollY = domainSettingsScrollView.scrollY
// Store the domain settings status in the bundle.
- savedInstanceState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, true)
- savedInstanceState.putInt(DOMAIN_SETTINGS_DATABASE_ID, DomainSettingsFragment.databaseId)
- savedInstanceState.putInt(DOMAIN_SETTINGS_SCROLL_Y, domainSettingsScrollY)
+ outState.putBoolean(DOMAIN_SETTINGS_DISPLAYED, true)
+ outState.putInt(DOMAIN_SETTINGS_DATABASE_ID, DomainSettingsFragment.databaseId)
+ outState.putInt(DOMAIN_SETTINGS_SCROLL_Y, domainSettingsScrollY)
}
// Check to see if the domains listview exists.
val domainsListViewPosition = domainsListView!!.firstVisiblePosition
// Store the listview position in the bundle.
- savedInstanceState.putInt(LISTVIEW_POSITION, domainsListViewPosition)
+ outState.putInt(LISTVIEW_POSITION, domainsListViewPosition)
}
}
val javaScriptSpinner = view.findViewById<Spinner>(R.id.javascript_spinner)
val cookiesSpinner = view.findViewById<Spinner>(R.id.cookies_spinner)
val domStorageSpinner = view.findViewById<Spinner>(R.id.dom_storage_spinner)
- val formDataSpinner = view.findViewById<Spinner>(R.id.form_data_spinner) // Form data can be removed once the minimum API >= 26.
val userAgentSpinner = view.findViewById<Spinner>(R.id.user_agent_spinner)
val customUserAgentEditText = view.findViewById<EditText>(R.id.custom_user_agent_edittext)
val easyListSpinner = view.findViewById<Spinner>(R.id.easylist_spinner)
val javaScriptInt = javaScriptSpinner.selectedItemPosition
val cookiesInt = cookiesSpinner.selectedItemPosition
val domStorageInt = domStorageSpinner.selectedItemPosition
- val formDataInt = formDataSpinner.selectedItemPosition // Form data can be removed once the minimum API >= 26.
val userAgentSwitchPosition = userAgentSpinner.selectedItemPosition
val easyListInt = easyListSpinner.selectedItemPosition
val easyPrivacyInt = easyPrivacySpinner.selectedItemPosition
fontSizeInt = customFontSizeEditText.text.toString().toInt()
// Save the domain settings.
- domainsDatabaseHelper.updateDomain(currentDomainDatabaseId, domainNameString, javaScriptInt, cookiesInt, domStorageInt, formDataInt, userAgentName, easyListInt, easyPrivacyInt, fanboysAnnoyanceInt,
+ domainsDatabaseHelper.updateDomain(currentDomainDatabaseId, domainNameString, javaScriptInt, cookiesInt, domStorageInt, userAgentName, easyListInt, easyPrivacyInt, fanboysAnnoyanceInt,
fanboysSocialBlockingInt, ultraListInt, ultraPrivacyInt, blockAllThirdPartyRequestsInt, fontSizeInt, swipeToRefreshInt, webViewThemeInt, wideViewportInt, displayWebpageImagesInt,
pinnedSslCertificate, pinnedIpAddress)