/*
- * Copyright 2017-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2017-2024 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
*
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
import com.google.android.material.snackbar.Snackbar
import com.stoutner.privacybrowser.R
+import com.stoutner.privacybrowser.dialogs.AddDomainDialog
import com.stoutner.privacybrowser.dialogs.AddDomainDialog.AddDomainListener
-import com.stoutner.privacybrowser.dialogs.AddDomainDialog.Companion.addDomain
import com.stoutner.privacybrowser.fragments.DomainSettingsFragment
import com.stoutner.privacybrowser.fragments.DomainsListFragment
import com.stoutner.privacybrowser.fragments.DomainsListFragment.DismissSnackbarInterface
// Get the status of close-on-back, which is true when the domains activity is called from the options menu.
closeOnBack = intent.getBooleanExtra(CLOSE_ON_BACK, false)
- // Get the current URL.
- val currentUrl = intent.getStringExtra(CURRENT_URL)
-
// Store the current SSL certificate information in class variables.
sslIssuedToCName = intent.getStringExtra(SSL_ISSUED_TO_CNAME)
sslIssuedToOName = intent.getStringExtra(SSL_ISSUED_TO_ONAME)
// Configure the add domain floating action button.
addDomainFAB.setOnClickListener {
// Create an add domain dialog.
- val addDomainDialog: DialogFragment = addDomain(currentUrl)
+ val addDomainDialog: DialogFragment = AddDomainDialog()
// Show the add domain dialog.
addDomainDialog.show(supportFragmentManager, resources.getString(R.string.add_domain))
}
} 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.
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 easyPrivacySpinner = view.findViewById<Spinner>(R.id.easyprivacy_spinner)
val fanboysAnnoyanceSpinner = view.findViewById<Spinner>(R.id.fanboys_annoyance_list_spinner)
val ultraListSpinner = view.findViewById<Spinner>(R.id.ultralist_spinner)
val ultraPrivacySpinner = view.findViewById<Spinner>(R.id.ultraprivacy_spinner)
val blockAllThirdPartyRequestsSpinner = view.findViewById<Spinner>(R.id.block_all_third_party_requests_spinner)
- val userAgentSpinner = view.findViewById<Spinner>(R.id.user_agent_spinner)
- val customUserAgentEditText = view.findViewById<EditText>(R.id.custom_user_agent_edittext)
val fontSizeSpinner = view.findViewById<Spinner>(R.id.font_size_spinner)
val customFontSizeEditText = view.findViewById<EditText>(R.id.custom_font_size_edittext)
val swipeToRefreshSpinner = view.findViewById<Spinner>(R.id.swipe_to_refresh_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
val fanboysAnnoyanceInt = fanboysAnnoyanceSpinner.selectedItemPosition
val ultraListInt = ultraListSpinner.selectedItemPosition
val ultraPrivacyInt = ultraPrivacySpinner.selectedItemPosition
val blockAllThirdPartyRequestsInt = blockAllThirdPartyRequestsSpinner.selectedItemPosition
- val userAgentSwitchPosition = userAgentSpinner.selectedItemPosition
val fontSizeSwitchPosition = fontSizeSpinner.selectedItemPosition
val swipeToRefreshInt = swipeToRefreshSpinner.selectedItemPosition
val webViewThemeInt = webViewThemeSpinner.selectedItemPosition
fontSizeInt = customFontSizeEditText.text.toString().toInt()
// Save the domain settings.
- domainsDatabaseHelper.updateDomain(currentDomainDatabaseId, domainNameString, javaScriptInt, cookiesInt, domStorageInt, formDataInt, easyListInt, easyPrivacyInt, fanboysAnnoyanceInt,
- fanboysSocialBlockingInt, ultraListInt, ultraPrivacyInt, blockAllThirdPartyRequestsInt, userAgentName, fontSizeInt, swipeToRefreshInt, webViewThemeInt, wideViewportInt, displayWebpageImagesInt,
+ domainsDatabaseHelper.updateDomain(currentDomainDatabaseId, domainNameString, javaScriptInt, cookiesInt, domStorageInt, userAgentName, easyListInt, easyPrivacyInt, fanboysAnnoyanceInt,
+ fanboysSocialBlockingInt, ultraListInt, ultraPrivacyInt, blockAllThirdPartyRequestsInt, fontSizeInt, swipeToRefreshInt, webViewThemeInt, wideViewportInt, displayWebpageImagesInt,
pinnedSslCertificate, pinnedIpAddress)
// Update the pinned SSL certificate if a new one is checked.