X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FDomainsActivity.kt;h=4996568e1e79084b865a75b4098f670a89a2a53a;hb=HEAD;hp=5c5107c59fec21f544bad07de558ed734bd2ba6b;hpb=09795c801b5e5d85beb63259a2d9cb39f756fa61;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt index 5c5107c5..e0e06876 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt @@ -1,7 +1,7 @@ /* - * Copyright 2017-2023 Soren Stoutner . + * Copyright 2017-2024 Soren Stoutner . * - * This file is part of Privacy Browser Android . + * This file is part of 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 @@ -23,7 +23,6 @@ import android.app.Activity 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 @@ -49,8 +48,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton 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 @@ -157,9 +156,6 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI // 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) @@ -200,7 +196,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI // 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)) @@ -573,27 +569,21 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI } } 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. @@ -613,9 +603,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI 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(R.id.domain_settings_scrollview) @@ -623,9 +613,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI // 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) @@ -634,9 +624,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI 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. @@ -645,7 +635,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI val domainsListViewPosition = domainsListView!!.firstVisiblePosition // Store the listview position in the bundle. - savedInstanceState.putInt(LISTVIEW_POSITION, domainsListViewPosition) + outState.putInt(LISTVIEW_POSITION, domainsListViewPosition) } } @@ -697,7 +687,8 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI val javaScriptSpinner = view.findViewById(R.id.javascript_spinner) val cookiesSpinner = view.findViewById(R.id.cookies_spinner) val domStorageSpinner = view.findViewById(R.id.dom_storage_spinner) - val formDataSpinner = view.findViewById(R.id.form_data_spinner) // Form data can be removed once the minimum API >= 26. + val userAgentSpinner = view.findViewById(R.id.user_agent_spinner) + val customUserAgentEditText = view.findViewById(R.id.custom_user_agent_edittext) val easyListSpinner = view.findViewById(R.id.easylist_spinner) val easyPrivacySpinner = view.findViewById(R.id.easyprivacy_spinner) val fanboysAnnoyanceSpinner = view.findViewById(R.id.fanboys_annoyance_list_spinner) @@ -705,8 +696,6 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI val ultraListSpinner = view.findViewById(R.id.ultralist_spinner) val ultraPrivacySpinner = view.findViewById(R.id.ultraprivacy_spinner) val blockAllThirdPartyRequestsSpinner = view.findViewById(R.id.block_all_third_party_requests_spinner) - val userAgentSpinner = view.findViewById(R.id.user_agent_spinner) - val customUserAgentEditText = view.findViewById(R.id.custom_user_agent_edittext) val fontSizeSpinner = view.findViewById(R.id.font_size_spinner) val customFontSizeEditText = view.findViewById(R.id.custom_font_size_edittext) val swipeToRefreshSpinner = view.findViewById(R.id.swipe_to_refresh_spinner) @@ -723,7 +712,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI 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 @@ -731,7 +720,6 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI 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 @@ -765,8 +753,8 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI 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.