]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Refactor for Androidx AppCompat 1.7.0.
authorSoren Stoutner <soren@stoutner.com>
Wed, 28 Aug 2024 23:07:22 +0000 (16:07 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 28 Aug 2024 23:07:22 +0000 (16:07 -0700)
25 files changed:
app/build.gradle
app/src/main/assets/de/about_changelog.html
app/src/main/assets/en/about_changelog.html
app/src/main/assets/es/about_changelog.html
app/src/main/assets/fr/about_changelog.html
app/src/main/assets/it/about_changelog.html
app/src/main/assets/pt-rBR/about_changelog.html
app/src/main/assets/ru/about_changelog.html
app/src/main/assets/tr/about_changelog.html
app/src/main/assets/zh-rCN/about_changelog.html
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.kt
app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.kt
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
app/src/main/java/com/stoutner/privacybrowser/backgroundtasks/GetHeadersBackgroundTask.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/AboutWebViewFragment.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.kt
app/src/main/res/layout-w900dp/domains_fragments.xml
app/src/main/res/layout-w900dp/domains_list_fragment.xml
app/src/main/res/layout/domains_list_fragment.xml
app/src/main/res/menu/domains_options_menu.xml
build.gradle

index adc38235bf95046542c595175f164a6838fca188..c2f97b402c1027d5783c32e3a43d3bd4763ef2ab 100644 (file)
@@ -82,15 +82,15 @@ android {
 
 dependencies {
     // Include the following AndroidX libraries.
-    implementation "androidx.activity:activity-ktx:1.9.0"
+    implementation "androidx.activity:activity-ktx:1.9.1"
     implementation 'androidx.arch.core:core-common:2.2.0'
     implementation 'androidx.arch.core:core-runtime:2.2.0'
-    implementation 'androidx.appcompat:appcompat:1.6.1'
+    implementation 'androidx.appcompat:appcompat:1.7.0'
     implementation 'androidx.cardview:cardview:1.0.0'
     implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
     implementation 'androidx.core:core-ktx:1.13.1'
     implementation 'androidx.drawerlayout:drawerlayout:1.2.0'
-    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3'
+    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4'
     implementation 'androidx.preference:preference-ktx:1.2.1'
     implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
     implementation 'androidx.viewpager:viewpager:1.0.0'
@@ -100,5 +100,5 @@ dependencies {
     implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.20'
 
     // Include the Google material library.
-    implementation 'com.google.android.material:material:1.13.0-alpha04'
+    implementation 'com.google.android.material:material:1.13.0-alpha05'
 }
index 66c530db9556152a4873b6de9544a99010c387e4..cac143e063dcc6eb2a36795f04fda6e306ecb0cb 100644 (file)
@@ -35,7 +35,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (Version Code 75)</h3>
-        <p>22. Juli 2024 - Mindest-API 26, Ziel-API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22. Juli 2024</a> - Mindest-API 26, Ziel-API 34</p>
         <ul>
             <li>Fehler behoben, <a href="https://redmine.stoutner.com/issues/1208">durch den Elemente der Navigations-Leiste nicht korrekt angezeigt wurden, wenn sie aktiviert waren</a>.</li>
         </ul>
index 1a7ec5a0cf4dabfbe2637cb260656b7caa43cfba..8dcbaef09355d8a72480ff66ea2336e683e86f31 100644 (file)
@@ -29,7 +29,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (version code 75)</h3>
-        <p>22 July 2024 - minimum API 26, target API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 July 2024</a> - minimum API 26, target API 34</p>
         <ul>
             <li>Fix a bug with the items in the Navigation Drawer <a href="https://redmine.stoutner.com/issues/1208">not properly displaying if they are enabled</a>.</li>
         </ul>
index a1a7f0eec847164f7044ccdee86ed81b2cf1d484..7af1eff0b6c0cba3b98610fbc0aadb9c36d2ef73 100644 (file)
@@ -31,7 +31,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (código de versión 75)</h3>
-        <p>22 de julio de 2024 - API mínimo 26, API objetivo 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 de julio de 2024</a> - API mínimo 26, API objetivo 34</p>
         <ul>
             <li>Corrección de un error por el que los elementos del Cajón de Navegación <a href="https://redmine.stoutner.com/issues/1208">no se mostraban correctamente si estaban activados</a>.</li>
         </ul>
index 7484fe8963e06c5219be5fe819dfc3a2a71f4858..6716a51375801fd4560f4cc6f64906e57f1641b1 100644 (file)
@@ -31,7 +31,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (version du code 75)</h3>
-        <p>22 Juillet 2024 - API minimale : 26, API optimale : 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 Juillet 2024</a> - API minimale : 26, API optimale : 34</p>
         <ul>
             <li>Fix a bug with the items in the Navigation Drawer <a href="https://redmine.stoutner.com/issues/1208">not properly displaying if they are enabled</a>.</li>
         </ul>
index 757344f685b78998523fe8d37db059b250404bda..cc45b73a21090108398a46b2e46836082ac92ae5 100644 (file)
@@ -31,7 +31,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (versione codice 75)</h3>
-        <p>22 Luglio 2024 - minima API 26, target API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 Luglio 2024</a> - minima API 26, target API 34</p>
         <ul>
             <li>Correzione di un baco per cui gli elementi del Cassetto di Navigazione <a href="https://redmine.stoutner.com/issues/1208">non erano mostrati correttamente se abilitati</a>.</li>
         </ul>
index c156d84760645ebbbc4151aac26d1106d16f124b..2d01884ef29eee2ba85ff878cec8ed72d8f740f0 100644 (file)
@@ -31,7 +31,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (código de versão 75)</h3>
-        <p>22 de julho de 2024 - minimum API 26, target API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 de julho de 2024</a> - minimum API 26, target API 34</p>
         <ul>
             <li>Fix a bug with the items in the Navigation Drawer <a href="https://redmine.stoutner.com/issues/1208">not properly displaying if they are enabled</a>.</li>
         </ul>
index 743e30a7339b81ed912d30f676c3a6e977a266cf..75327f1e44e8f86a394000909a0b8a56d387dc1d 100644 (file)
@@ -29,7 +29,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (код версии 75)</h3>
-        <p>22 июля 2024 года - минимальный API 26, целевой API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 июля 2024 года</a> - минимальный API 26, целевой API 34</p>
         <ul>
             <li>Исправлена ошибка, из-за которой элементы в навигационной панели <a href="https://redmine.stoutner.com/issues/1208">не отображались должным образом, даже если они были включены</a>.</li>
         </ul>
index 684d29a1a3eddcf65301c02e298c077d80b20bea..7a3b0f651fba10800bb70e76485cf560c6fd7ad8 100644 (file)
@@ -29,7 +29,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (version code 75)</h3>
-        <p>22 Temmuz 2024 - minimum API 26, target API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 Temmuz 2024</a> - minimum API 26, target API 34</p>
         <ul>
             <li>Fix a bug with the items in the Navigation Drawer <a href="https://redmine.stoutner.com/issues/1208">not properly displaying if they are enabled</a>.</li>
         </ul>
index 77ae1cb6ef88f4e187a852b64c929c2b8d8e4fc6..fae0ebe49e3796f1bdafc5025cd7d260e2c82ede 100644 (file)
@@ -31,7 +31,7 @@
 
     <body>
         <h3><a href="https://www.stoutner.com/privacy-browser-android-3-18-1/">3.18.1</a> (version code 75)</h3>
-        <p>22 July 2024 - 最低支持API 26, 最高支持API 34</p>
+        <p><a href="https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=bc4a87300d0ba4c50b040234a1608259a7f3aefd">22 July 2024</a> - 最低支持API 26, 最高支持API 34</p>
         <ul>
             <li>Fix a bug with the items in the Navigation Drawer <a href="https://redmine.stoutner.com/issues/1208">not properly displaying if they are enabled</a>.</li>
         </ul>
index 4199dd4e4436da81725128dc46842997b0473f3e..5d7ca2d78475eddccf9eb123eeb5fb807e1ad8c9 100644 (file)
@@ -189,7 +189,7 @@ class BookmarksDatabaseViewActivity : AppCompatActivity(), EditBookmarkDatabaseV
                             subfolderSpacerTextView.text = bookmarksDatabaseHelper.getSubfolderSpacer(cursor.getLong(cursor.getColumnIndexOrThrow(FOLDER_ID)))
                         } else {  // The folder is in the home folder.
                             // Reset the subfolder spacer.
-                            subfolderSpacerTextView.text = ""
+                            subfolderSpacerTextView.text = null
                         }
                     }
 
index e0e068769ea1ed8888aee4ab4e7d7169c3858606..47ffe90f5872b6fb715ec72adcfc246544ac7497 100644 (file)
@@ -23,7 +23,10 @@ import android.app.Activity
 import android.content.Context
 import android.database.Cursor
 import android.os.Bundle
+import android.os.Handler
+import android.os.Looper
 import android.view.Menu
+import android.view.MenuInflater
 import android.view.MenuItem
 import android.view.View
 import android.view.ViewGroup
@@ -40,8 +43,11 @@ import androidx.appcompat.app.AppCompatActivity
 import androidx.appcompat.widget.SwitchCompat
 import androidx.appcompat.widget.Toolbar
 import androidx.core.app.NavUtils
+import androidx.core.view.MenuProvider
 import androidx.cursoradapter.widget.CursorAdapter
 import androidx.fragment.app.DialogFragment
+import androidx.fragment.app.commitNow
+import androidx.lifecycle.Lifecycle
 import androidx.preference.PreferenceManager
 
 import com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -52,8 +58,6 @@ import com.stoutner.privacybrowser.dialogs.AddDomainDialog
 import com.stoutner.privacybrowser.dialogs.AddDomainDialog.AddDomainListener
 import com.stoutner.privacybrowser.fragments.DomainSettingsFragment
 import com.stoutner.privacybrowser.fragments.DomainsListFragment
-import com.stoutner.privacybrowser.fragments.DomainsListFragment.DismissSnackbarInterface
-import com.stoutner.privacybrowser.fragments.DomainsListFragment.SaveDomainSettingsInterface
 import com.stoutner.privacybrowser.helpers.DOMAIN_NAME
 import com.stoutner.privacybrowser.helpers.ID
 import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper
@@ -61,6 +65,7 @@ import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper
 // Define the public constants.
 const val CLOSE_ON_BACK = "close_on_back"
 const val CURRENT_IP_ADDRESSES = "current_ip_addresses"
+const val DOMAIN_SETTINGS_FRAGMENT_TAG = "domain_settings_fragment"
 const val LOAD_DOMAIN = "load_domain"
 const val SSL_END_DATE = "ssl_end_date"
 const val SSL_ISSUED_BY_CNAME = "ssl_issued_by_cname"
@@ -77,19 +82,17 @@ private const val DOMAIN_SETTINGS_DISPLAYED = "domain_settings_displayed"
 private const val DOMAIN_SETTINGS_SCROLL_Y = "domain_settings_scroll_y"
 private const val LISTVIEW_POSITION = "listview_position"
 
-class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarInterface, SaveDomainSettingsInterface {
+class DomainsActivity : AppCompatActivity(), AddDomainListener, DomainsListFragment.DismissSnackbarInterface, DomainsListFragment.SaveDomainSettingsInterface {
     companion object {
         // Define the public variables.
         var currentDomainDatabaseId = 0  // Used in `DomainsListFragment`.
+        var deleteMenuItemEnabled = true
         var dismissingSnackbar = false  // Used in `DomainsListFragment`.
         var domainsListViewPosition = 0  // Used in `DomainsListFragment`.
         var sslEndDateLong: Long = 0  // Used in `DomainsSettingsFragment`.
         var sslStartDateLong: Long = 0  // Used in `DomainSettingsFragment`.
         var twoPanedMode = false  // Used in `DomainsListFragment`.
 
-        // Declare the public views.  They are used in `DomainsListFragment`.
-        lateinit var deleteMenuItem: MenuItem
-
         // Declare the SSL certificate and IP address strings.
         var currentIpAddresses: String? = null  // Used in `DomainSettingsFragment`.
         var sslIssuedToCName: String? = null  // Used in `DomainSettingsFragment`.
@@ -103,6 +106,8 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
     // Declare the class views.
     private lateinit var addDomainFAB: FloatingActionButton
     private lateinit var coordinatorLayout: View
+
+    // Define the class views.
     private var domainsListView: ListView? = null
     private var undoDeleteSnackbar: Snackbar? = null
 
@@ -235,16 +240,15 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                     val domainsListFragment = DomainsListFragment()
 
                     // Display the domains list fragment.
-                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
+                    supportFragmentManager.commitNow {
+                        replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                    }
 
                     // Populate the list of domains.  `-1` highlights the first domain if in two-paned mode.  It has no effect in single-paned mode.
                     populateDomainsListView(-1, domainsListViewPosition)
 
                     // Show the add domain floating action button.
                     addDomainFAB.show()
-
-                    // Hide the delete menu item.
-                    deleteMenuItem.isVisible = false
                 } else {  // The device is in single-paned mode and the domain list fragment is displayed.
                     // Dismiss the undo delete SnackBar if it is shown.
                     if (undoDeleteSnackbar != null && undoDeleteSnackbar!!.isShown) {
@@ -261,22 +265,279 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             }
         }
 
-        // Register the on back pressed callback.
-        onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
-    }
+        // Get a handle for the activity (used in an inner class below).
+        val activity: Activity = this
+
+        // Add the menu provider.  This runs each time a fragment is replaced.
+        addMenuProvider(object : MenuProvider {
+            override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
+                // Inflate the menu.
+                menuInflater.inflate(R.menu.domains_options_menu, menu)
+
+                // Get a handle for the delete menu item.
+                val deleteMenuItem = menu.findItem(R.id.delete_domain)
+
+                // Get the domain settings fragment.
+                val domainSettingsFragment = supportFragmentManager.findFragmentByTag(DOMAIN_SETTINGS_FRAGMENT_TAG)
+
+                // Update the visibility of the delete menu item.
+                if (twoPanedMode)  // The device is in two-paned mode and a domain is selected.
+                    deleteMenuItem.isVisible = true
+                else if ((domainSettingsFragment != null) && domainSettingsFragment.isVisible)  // The device is in single-paned mode and the domain settings fragment is visible.
+                    deleteMenuItem.isVisible = true
+                else  // The device is in two-paned mode but no domain is selected (like after deleting a domain) or the device is in single-paned mode and the domains list is visible.
+                    deleteMenuItem.isVisible = false
+
+                // Update the status of the delete menu item.
+                deleteMenuItem.isEnabled = deleteMenuItemEnabled
+            }
+
+            override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
+                // Run the command according to the selected menu item.
+                when (menuItem.itemId) {
+                    android.R.id.home -> {  // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
+                        // Check if the device is in two-paned mode.
+                        if (twoPanedMode) {  // The device is in two-paned mode.
+                            // Save the current domain settings if the domain settings fragment is displayed.
+                            if (findViewById<View?>(R.id.domain_settings_scrollview) != null)
+                                saveDomainSettings(coordinatorLayout)
+
+                            // Dismiss the undo delete snackbar if it is shown.
+                            if (undoDeleteSnackbar != null && undoDeleteSnackbar!!.isShown) {
+                                // Set the close flag.
+                                closeActivityAfterDismissingSnackbar = true
+
+                                // Dismiss the snackbar.
+                                undoDeleteSnackbar!!.dismiss()
+                            } else {
+                                // Go home.
+                                finish()
+                            }
+                        } else if (closeOnBack) {  // Go directly back to the main WebView activity because the domains activity was launched from the options menu.
+                            // Save the current domain settings.
+                            saveDomainSettings(coordinatorLayout)
+
+                            // Go home.
+                            finish()
+                        } else if (findViewById<View?>(R.id.domain_settings_scrollview) != null) {  // The device is in single-paned mode and the domain settings fragment is displayed.
+                            // Save the current domain settings.
+                            saveDomainSettings(coordinatorLayout)
+
+                            // Instantiate a new domains list fragment.
+                            val domainsListFragment = DomainsListFragment()
+
+                            // Display the domains list fragment.
+                            supportFragmentManager.commitNow {
+                                replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                            }
+
+                            // Populate the list of domains.  `-1` highlights the first domain if in two-paned mode.  It has no effect in single-paned mode.
+                            populateDomainsListView(-1, domainsListViewPosition)
+
+                            // Show the add domain floating action button.
+                            addDomainFAB.show()
+                        } else {  // The device is in single-paned mode and domains list fragment is displayed.
+                            // Dismiss the undo delete snackbar if it is shown.
+                            if (undoDeleteSnackbar != null && undoDeleteSnackbar!!.isShown) {
+                                // Set the close flag.
+                                closeActivityAfterDismissingSnackbar = true
+
+                                // Dismiss the snackbar.
+                                undoDeleteSnackbar!!.dismiss()
+                            } else {
+                                // Go home.
+                                finish()
+                            }
+                        }
+                    }
+
+                    R.id.delete_domain -> {  // Delete.
+                        // Check to see if the domain settings were loaded directly for editing of this app in single-paned mode.
+                        if (closeOnBack && !twoPanedMode) {  // The activity should delete the domain settings and exit straight to the the main WebView activity.
+                            // Delete the selected domain.
+                            domainsDatabaseHelper.deleteDomain(currentDomainDatabaseId)
+
+                            // Go home.
+                            NavUtils.navigateUpFromSameTask(activity)
+                        } else {  // A snackbar should be shown before deleting the domain settings.
+                            // Reset close-on-back, which otherwise can cause errors if the system attempts to save settings for a domain that no longer exists.
+                            closeOnBack = false
+
+                            // Store a copy of the current domain database ID because it could change while the snackbar is displayed.
+                            val databaseIdToDelete = currentDomainDatabaseId
+
+                            // Update the fragments and menu items.
+                            if (twoPanedMode) {  // Two-paned mode.
+                                // Store the deleted domain position, which is needed if undo is selected in the snackbar.
+                                deletedDomainPosition = domainsListView!!.checkedItemPosition
+
+                                // Disable the delete menu item.
+                                deleteMenuItemEnabled = false
+
+                                // Get a handle for the domain settings fragment.
+                                val domainSettingsFragment = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container)!!
+
+                                // Get a handle for the domain settings fragment view.
+                                val domainSettingsFragmentView = domainSettingsFragment.requireView()
+
+                                // Hide the domain settings fragment.
+                                domainSettingsFragmentView.visibility = View.INVISIBLE
+
+                                // Disable the delete menu item.
+                                deleteMenuItemEnabled = false
+
+                                // Invalidate the options menu.
+                                invalidateMenu()
+
+                            } else {  // Single-paned mode.
+                                // Instantiate a new domains list fragment.
+                                val domainsListFragment = DomainsListFragment()
+
+                                // Display the domains list fragment.
+                                supportFragmentManager.commitNow {
+                                    replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                                }
+
+                                // Show the add domain floating action button.
+                                addDomainFAB.show()
+                            }
+
+                            // Get a cursor that does not show the domain to be deleted.
+                            val domainsPendingDeleteCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomainExcept(databaseIdToDelete)
+
+                            // Setup the domains pending delete cursor adapter.
+                            val domainsPendingDeleteCursorAdapter: CursorAdapter = object : CursorAdapter(applicationContext, domainsPendingDeleteCursor, false) {
+                                override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
+                                    // Inflate the individual item layout.
+                                    return layoutInflater.inflate(R.layout.domain_name_linearlayout, parent, false)
+                                }
+
+                                override fun bindView(view: View, context: Context, cursor: Cursor) {
+                                    // Get the domain name string.
+                                    val domainNameString = cursor.getString(cursor.getColumnIndexOrThrow(DOMAIN_NAME))
 
-    override fun onCreateOptionsMenu(menu: Menu): Boolean {
-        // Inflate the menu.
-        menuInflater.inflate(R.menu.domains_options_menu, menu)
+                                    // Get a handle for the domain name text view.
+                                    val domainNameTextView = view.findViewById<TextView>(R.id.domain_name_textview)
 
-        // Get a handle for the delete menu item.
-        deleteMenuItem = menu.findItem(R.id.delete_domain)
+                                    // Display the domain name.
+                                    domainNameTextView.text = domainNameString
+                                }
+                            }
+
+                            // Update the handle for the current domains list view.
+                            domainsListView = findViewById(R.id.domains_listview)
+
+                            // Update the list view.
+                            domainsListView!!.adapter = domainsPendingDeleteCursorAdapter
+
+                            // Display a snackbar.
+                            undoDeleteSnackbar = Snackbar.make(domainsListView!!, R.string.domain_deleted, Snackbar.LENGTH_LONG)
+                                .setAction(R.string.undo) {}  // Do nothing because everything will be handled by `onDismissed()` below.
+                                .addCallback(object : Snackbar.Callback() {
+                                    override fun onDismissed(snackbar: Snackbar, event: Int) {
+                                        // Run commands based on the event.
+                                        if (event == DISMISS_EVENT_ACTION) {  // The user pushed the `Undo` button.
+                                            // Create an arguments bundle.
+                                            val argumentsBundle = Bundle()
+
+                                            // Store the domains settings in the arguments bundle.
+                                            argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, databaseIdToDelete)
+                                            argumentsBundle.putInt(DomainSettingsFragment.SCROLL_Y, domainSettingsScrollY)
+
+                                            // Instantiate a new domain settings fragment.
+                                            val domainSettingsFragment = DomainSettingsFragment()
+
+                                            // Add the arguments bundle to the domain settings fragment.
+                                            domainSettingsFragment.arguments = argumentsBundle
+
+                                            // Display the correct fragments.
+                                            if (twoPanedMode) {  // The device in in two-paned mode.
+                                                // Get a cursor with the current contents of the domains database.
+                                                val undoDeleteDomainsCursor = domainsDatabaseHelper.domainNameCursorOrderedByDomain
+
+                                                // Setup the domains cursor adapter.
+                                                val undoDeleteDomainsCursorAdapter: CursorAdapter = object : CursorAdapter(applicationContext, undoDeleteDomainsCursor, false) {
+                                                    override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
+                                                        // Inflate the individual item layout.
+                                                        return layoutInflater.inflate(R.layout.domain_name_linearlayout, parent, false)
+                                                    }
+
+                                                    override fun bindView(view: View, context: Context, cursor: Cursor) {
+                                                        /// Get the domain name string.
+                                                        val domainNameString = cursor.getString(cursor.getColumnIndexOrThrow(DOMAIN_NAME))
+
+                                                        // Get a handle for the domain name text view.
+                                                        val domainNameTextView = view.findViewById<TextView>(R.id.domain_name_textview)
+
+                                                        // Display the domain name.
+                                                        domainNameTextView.text = domainNameString
+                                                    }
+                                                }
+
+                                                // Update the domains list view.
+                                                domainsListView!!.adapter = undoDeleteDomainsCursorAdapter
+
+                                                // Select the previously deleted domain in the list view.
+                                                domainsListView!!.setItemChecked(deletedDomainPosition, true)
+
+                                                // Enable the delete menu item.
+                                                deleteMenuItemEnabled = true
+
+                                                // Display the domain settings fragment.
+                                                supportFragmentManager.commitNow {
+                                                    replace(R.id.domain_settings_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                                                }
+                                            } else {  // The device in in one-paned mode.
+                                                // Hide the add domain floating action button.
+                                                addDomainFAB.hide()
+
+                                                // Display the domain settings fragment.
+                                                supportFragmentManager.commitNow {
+                                                    replace(R.id.domains_listview_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                                                }
+                                            }
+                                        } else {  // The snackbar was dismissed without the undo button being pushed.
+                                            // Delete the selected domain.
+                                            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 the delete menu item if in two-paned mode.
+                                                if (twoPanedMode) {
+                                                    // Enable the delete menu item.
+                                                    deleteMenuItemEnabled = true
+
+                                                    // Invalidate the options menu.
+                                                    invalidateMenu()
+                                                }
+
+                                                // Reset the dismissing snackbar tracker.
+                                                dismissingSnackbar = false
+                                            }
+
+                                            // Close the activity if back was pressed.
+                                            if (closeActivityAfterDismissingSnackbar)
+                                                NavUtils.navigateUpFromSameTask(activity)
+                                        }
+                                    }
+                                })
+
+                            // Show the Snackbar.
+                            undoDeleteSnackbar!!.show()
+                        }
+                    }
+                }
 
-        // Only display the delete menu item (initially) in two-paned mode.
-        deleteMenuItem.isVisible = twoPanedMode
+                // Consume the event.
+                return true
+            }
+        }, this, Lifecycle.State.RESUMED)
 
-        // Display the fragments.  This must be done from `onCreateOptionsMenu()` instead of `onCreate()` because `populateDomainsListView()` needs `deleteMenuItem` to be inflated.
-        if (appRestarted && domainSettingsDisplayedBeforeRestart) {  // The app was restarted, possibly because the device was rotated, and domain settings were displayed previously.
+        // Display the fragments.
+        if (appRestarted && domainSettingsDisplayedBeforeRestart) {  // The app was restarted and domain settings were displayed previously.
             // Reset the app restarted flag.
             appRestarted = false
 
@@ -285,10 +546,20 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                 val domainsListFragment = DomainsListFragment()
 
                 // Display the domains list fragment.
-                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
+                supportFragmentManager.commitNow {
+                    replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                }
+
+                // Create a populate domains list view handler.
+                val populateDomainsListViewHandler = Handler(Looper.getMainLooper())
+
+                // Create a populate domains list view runnable.
+                val populateDomainsListViewRunnable = Runnable {
+                    populateDomainsListView(domainSettingsDatabaseIdBeforeRestart, domainsListViewPosition)
+                }
 
-                // Populate the list of domains and highlight the domain that was highlighted before the restart.
-                populateDomainsListView(domainSettingsDatabaseIdBeforeRestart, domainsListViewPosition)
+                // Populate the domains list view.  For some reason, beginning with appcompat 1.7.0, this needs to be in a runnable instead of being called directly, or the system crashes.
+                populateDomainsListViewHandler.post(populateDomainsListViewRunnable)
             } else {  // The device is in single-paned mode.
                 // Store the current domain database ID.
                 currentDomainDatabaseId = domainSettingsDatabaseIdBeforeRestart
@@ -306,14 +577,13 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                 // Add the arguments bundle to the domain settings fragment.
                 domainSettingsFragment.arguments = argumentsBundle
 
-                // Show the delete menu item.
-                deleteMenuItem.isVisible = true
-
                 // Hide the add domain floating action button.
                 addDomainFAB.hide()
 
                 // Display the domain settings fragment.
-                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commitNow()
+                supportFragmentManager.commitNow {
+                    replace(R.id.domains_listview_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                }
             }
         } else {  // The device was not restarted or, if it was, domain settings were not displayed previously.
             if (goDirectlyToDatabaseId >= 0) {  // Load the indicated domain settings.
@@ -326,10 +596,20 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                     val domainsListFragment = DomainsListFragment()
 
                     // Display the domains list fragment.
-                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
+                    supportFragmentManager.commitNow {
+                        replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                    }
 
-                    // Populate the list of domains.
-                    populateDomainsListView(goDirectlyToDatabaseId, domainsListViewPosition)
+                    // Create a populate domains list view handler.
+                    val populateDomainsListViewHandler = Handler(Looper.getMainLooper())
+
+                    // Create a populate domains list view runnable.
+                    val populateDomainsListViewRunnable = Runnable {
+                        populateDomainsListView(goDirectlyToDatabaseId, domainsListViewPosition)
+                    }
+
+                    // Populate the domains list view.  For some reason, beginning with appcompat 1.7.0, this needs to be in a runnable instead of being called directly, or the system crashes.
+                    populateDomainsListViewHandler.post(populateDomainsListViewRunnable)
                 } else {  // The device is in single-paned mode.
                     // Create an arguments bundle.
                     val argumentsBundle = Bundle()
@@ -344,263 +624,38 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
                     // Add the arguments bundle to the domain settings fragment.
                     domainSettingsFragment.arguments = argumentsBundle
 
-                    // Show the delete menu item.
-                    deleteMenuItem.isVisible = true
-
                     // Hide the add domain floating action button.
                     addDomainFAB.hide()
 
                     // Display the domain settings fragment.
-                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commitNow()
+                    supportFragmentManager.commitNow {
+                        replace(R.id.domains_listview_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                    }
                 }
-            } else {  // Highlight the first domain.
-                // Instantiate a new domains list fragment.
+            } else {  // Display the domains list view.
+                // Instantiate a new domain settings fragment.
                 val domainsListFragment = DomainsListFragment()
 
-                // Display the domain list fragment.
-                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
-
-                // Populate the list of domains.  `-1` highlights the first domain.
-                populateDomainsListView(-1, domainsListViewPosition)
-            }
-        }
-
-        // Success!
-        return true
-    }
-
-    override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
-        // Run the command according to the selected menu item.
-        when (menuItem.itemId) {
-            android.R.id.home -> {  // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
-                // Check if the device is in two-paned mode.
-                if (twoPanedMode) {  // The device is in two-paned mode.
-                    // Save the current domain settings if the domain settings fragment is displayed.
-                    if (findViewById<View?>(R.id.domain_settings_scrollview) != null)
-                        saveDomainSettings(coordinatorLayout)
-
-                    // Dismiss the undo delete snackbar if it is shown.
-                    if (undoDeleteSnackbar != null && undoDeleteSnackbar!!.isShown) {
-                        // Set the close flag.
-                        closeActivityAfterDismissingSnackbar = true
-
-                        // Dismiss the snackbar.
-                        undoDeleteSnackbar!!.dismiss()
-                    } else {
-                        // Go home.
-                        finish()
-                    }
-                } else if (closeOnBack) {  // Go directly back to the main WebView activity because the domains activity was launched from the options menu.
-                    // Save the current domain settings.
-                    saveDomainSettings(coordinatorLayout)
-
-                    // Go home.
-                    finish()
-                } else if (findViewById<View?>(R.id.domain_settings_scrollview) != null) {  // The device is in single-paned mode and the domain settings fragment is displayed.
-                    // Save the current domain settings.
-                    saveDomainSettings(coordinatorLayout)
-
-                    // Instantiate a new domains list fragment.
-                    val domainsListFragment = DomainsListFragment()
+                // Display the domains list fragment.
+                supportFragmentManager.commitNow {
+                    replace(R.id.domains_listview_fragment_container, domainsListFragment)
+                }
 
-                    // Display the domains list fragment.
-                    supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
+                // Create a populate domains list view handler.
+                val populateDomainsListViewHandler = Handler(Looper.getMainLooper())
 
-                    // Populate the list of domains.  `-1` highlights the first domain if in two-paned mode.  It has no effect in single-paned mode.
+                // Create a populate domains list view runnable.
+                val populateDomainsListViewRunnable = Runnable {
                     populateDomainsListView(-1, domainsListViewPosition)
-
-                    // Show the add domain floating action button.
-                    addDomainFAB.show()
-
-                    // Hide the delete menu item.
-                    deleteMenuItem.isVisible = false
-                } else {  // The device is in single-paned mode and domains list fragment is displayed.
-                    // Dismiss the undo delete snackbar if it is shown.
-                    if (undoDeleteSnackbar != null && undoDeleteSnackbar!!.isShown) {
-                        // Set the close flag.
-                        closeActivityAfterDismissingSnackbar = true
-
-                        // Dismiss the snackbar.
-                        undoDeleteSnackbar!!.dismiss()
-                    } else {
-                        // Go home.
-                        finish()
-                    }
                 }
-            }
-
-            R.id.delete_domain -> {  // Delete.
-                // Get a handle for the activity (used in an inner class below).
-                val activity: Activity = this
-
-                // Check to see if the domain settings were loaded directly for editing of this app in single-paned mode.
-                if (closeOnBack && !twoPanedMode) {  // The activity should delete the domain settings and exit straight to the the main WebView activity.
-                    // Delete the selected domain.
-                    domainsDatabaseHelper.deleteDomain(currentDomainDatabaseId)
-
-                    // Go home.
-                    NavUtils.navigateUpFromSameTask(activity)
-                } else {  // A snackbar should be shown before deleting the domain settings.
-                    // Reset close-on-back, which otherwise can cause errors if the system attempts to save settings for a domain that no longer exists.
-                    closeOnBack = false
 
-                    // Store a copy of the current domain database ID because it could change while the snackbar is displayed.
-                    val databaseIdToDelete = currentDomainDatabaseId
-
-                    // Update the fragments and menu items.
-                    if (twoPanedMode) {  // Two-paned mode.
-                        // Store the deleted domain position, which is needed if undo is selected in the snackbar.
-                        deletedDomainPosition = domainsListView!!.checkedItemPosition
-
-                        // Disable the delete menu item.
-                        deleteMenuItem.isEnabled = false
-
-                        // Remove the domain settings fragment.
-                        supportFragmentManager.beginTransaction().remove(supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container)!!).commitNow()
-                    } else {  // Single-paned mode.
-                        // Instantiate a new domains list fragment.
-                        val domainsListFragment = DomainsListFragment()
-
-                        // Display the domains list fragment.
-                        supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainsListFragment).commitNow()
-
-                        // Show the add domain floating action button.
-                        addDomainFAB.show()
-
-                        // Hide the delete menu item.
-                        deleteMenuItem.isVisible = false
-                    }
-
-                    // Get a cursor that does not show the domain to be deleted.
-                    val domainsPendingDeleteCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomainExcept(databaseIdToDelete)
-
-                    // Setup the domains pending delete cursor adapter.
-                    val domainsPendingDeleteCursorAdapter: CursorAdapter = object : CursorAdapter(this, domainsPendingDeleteCursor, false) {
-                        override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
-                            // Inflate the individual item layout.
-                            return layoutInflater.inflate(R.layout.domain_name_linearlayout, parent, false)
-                        }
-
-                        override fun bindView(view: View, context: Context, cursor: Cursor) {
-                            // Get the domain name string.
-                            val domainNameString = cursor.getString(cursor.getColumnIndexOrThrow(DOMAIN_NAME))
-
-                            // Get a handle for the domain name text view.
-                            val domainNameTextView = view.findViewById<TextView>(R.id.domain_name_textview)
-
-                            // Display the domain name.
-                            domainNameTextView.text = domainNameString
-                        }
-                    }
-
-                    // Update the handle for the current domains list view.
-                    domainsListView = findViewById(R.id.domains_listview)
-
-                    // Update the list view.
-                    domainsListView!!.adapter = domainsPendingDeleteCursorAdapter
-
-                    // Display a snackbar.
-                    undoDeleteSnackbar = Snackbar.make(domainsListView!!, R.string.domain_deleted, Snackbar.LENGTH_LONG)
-                        .setAction(R.string.undo) {}  // Do nothing because everything will be handled by `onDismissed()` below.
-                        .addCallback(object : Snackbar.Callback() {
-                            override fun onDismissed(snackbar: Snackbar, event: Int) {
-                                // Run commands based on the event.
-                                if (event == DISMISS_EVENT_ACTION) {  // The user pushed the `Undo` button.
-                                    // Create an arguments bundle.
-                                    val argumentsBundle = Bundle()
-
-                                    // Store the domains settings in the arguments bundle.
-                                    argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, databaseIdToDelete)
-                                    argumentsBundle.putInt(DomainSettingsFragment.SCROLL_Y, domainSettingsScrollY)
-
-                                    // Instantiate a new domain settings fragment.
-                                    val domainSettingsFragment = DomainSettingsFragment()
-
-                                    // Add the arguments bundle to the domain settings fragment.
-                                    domainSettingsFragment.arguments = argumentsBundle
-
-                                    // Display the correct fragments.
-                                    if (twoPanedMode) {  // The device in in two-paned mode.
-                                        // Get a cursor with the current contents of the domains database.
-                                        val undoDeleteDomainsCursor = domainsDatabaseHelper.domainNameCursorOrderedByDomain
-
-                                        // Setup the domains cursor adapter.
-                                        val undoDeleteDomainsCursorAdapter: CursorAdapter = object : CursorAdapter(applicationContext, undoDeleteDomainsCursor, false) {
-                                            override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
-                                                // Inflate the individual item layout.
-                                                return layoutInflater.inflate(R.layout.domain_name_linearlayout, parent, false)
-                                            }
-
-                                            override fun bindView(view: View, context: Context, cursor: Cursor) {
-                                                /// Get the domain name string.
-                                                val domainNameString = cursor.getString(cursor.getColumnIndexOrThrow(DOMAIN_NAME))
-
-                                                // Get a handle for the domain name text view.
-                                                val domainNameTextView = view.findViewById<TextView>(R.id.domain_name_textview)
-
-                                                // Display the domain name.
-                                                domainNameTextView.text = domainNameString
-                                            }
-                                        }
-
-                                        // Update the domains list view.
-                                        domainsListView!!.adapter = undoDeleteDomainsCursorAdapter
-
-                                        // Select the previously deleted domain in the list view.
-                                        domainsListView!!.setItemChecked(deletedDomainPosition, true)
-
-                                        // Display the domain settings fragment.
-                                        supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commitNow()
-
-                                        // Enable the delete menu item.
-                                        deleteMenuItem.isEnabled = true
-                                    } else {  // The device in in one-paned mode.
-                                        // Display the domain settings fragment.
-                                        supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commitNow()
-
-                                        // Hide the add domain floating action button.
-                                        addDomainFAB.hide()
-
-                                        // Show and enable the delete menu item.
-                                        deleteMenuItem.isVisible = true
-
-                                        // Display the domain settings fragment.
-                                        supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commitNow()
-                                    }
-                                } else {  // The snackbar was dismissed without the undo button being pushed.
-                                    // Delete the selected domain.
-                                    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.
-                                    if (closeActivityAfterDismissingSnackbar)
-                                        NavUtils.navigateUpFromSameTask(activity)
-                                }
-                            }
-                        })
-
-                    // Show the Snackbar.
-                    undoDeleteSnackbar!!.show()
-                }
+                // Populate the domains list view.  For some reason, beginning with appcompat 1.7.0, this needs to be in a runnable instead of being called directly, or the system crashes.
+                populateDomainsListViewHandler.post(populateDomainsListViewRunnable)
             }
         }
 
-        // Consume the event.
-        return true
+        // Register the on back pressed callback.
+        onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
     }
 
     override fun onSaveInstanceState(outState: Bundle) {
@@ -660,9 +715,6 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             // Hide the add domain floating action button.
             addDomainFAB.hide()
 
-            // Show and enable the delete menu item.
-            deleteMenuItem.isVisible = true
-
             // Create an arguments bundle.
             val argumentsBundle = Bundle()
 
@@ -677,7 +729,9 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             domainSettingsFragment.arguments = argumentsBundle
 
             // Display the domain settings fragment.
-            supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commitNow()
+            supportFragmentManager.commitNow {
+                replace(R.id.domains_listview_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+            }
         }
     }
 
@@ -800,7 +854,7 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
         domainsListView!!.setSelection(domainsListViewPosition)
 
         // Display the domain settings in the second pane if operating in two pane mode and the database contains at least one domain.
-        if (twoPanedMode && domainsCursor.count > 0) {  // Two-paned mode is enabled and there is at least one domain.
+        if (twoPanedMode && (domainsCursor.count > 0)) {  // Two-paned mode is enabled and there is at least one domain.
             // Initialize the highlighted domain position tracker.
             var highlightedDomainPosition = 0
 
@@ -840,13 +894,21 @@ class DomainsActivity : AppCompatActivity(), AddDomainListener, DismissSnackbarI
             domainSettingsFragment.arguments = argumentsBundle
 
             // Display the domain settings fragment.
-            supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commit()
+            supportFragmentManager.commitNow {
+                replace(R.id.domain_settings_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+            }
 
-            // Enable the delete options menu items.
-            deleteMenuItem.isEnabled = true
+            // Enable the delete options menu item.
+            deleteMenuItemEnabled = true
+
+            // Update the options menu.
+            invalidateMenu()
         } else if (twoPanedMode) {  // Two-paned mode is enabled but there are no domains.
             // Disable the delete menu item.
-            deleteMenuItem.isEnabled = false
+            deleteMenuItemEnabled = false
+
+            // Update the options menu.
+            invalidateMenu()
         }
     }
 
index a1d8ecc78220aefd7b6a310dbdb0f62b4785befe..1e31f8f2d1c1d372e287448a31e4a480dc919913 100644 (file)
@@ -5598,7 +5598,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     // Check to see if the URL is `about:blank`.
                     if (currentUrl == "about:blank") {  // The WebView is blank.
                         // Display the hint in the URL edit text.
-                        urlEditText.setText("")
+                        urlEditText.text = null
 
                         // Request focus for the URL text box.
                         urlEditText.requestFocus()
@@ -6186,7 +6186,7 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
             if (!loadingNewIntent) {  // A new intent is not being loaded.
                 if ((urlString == null) || (urlString == "about:blank")) {  // The WebView is blank.
                     // Display the hint in the URL edit text.
-                    urlEditText.setText("")
+                    urlEditText.text = null
 
                     // Request focus for the URL text box.
                     urlEditText.requestFocus()
index cd91ecba4d062c2cefc24209bb73b69843b45823..73b7754b0df4e49bd7d951a33b5de3f4bb89e254 100644 (file)
@@ -70,7 +70,7 @@ class GetHeadersBackgroundTask {
 
         // Get the colon string.
         val colonString = application.getString(R.string.colon)
-        val newLineString = System.getProperty("line.separator")
+        val newLineString = System.lineSeparator()
 
         if (urlString.startsWith("content://")) {  // This is a content URL.
             // Attempt to read the content data.  Return an error if this fails.
index 978753530c549f11f77a2657f0637903f7e1a683..4c8da5684ac4532dffba39bbf9dda2f88e30c558 100644 (file)
@@ -45,7 +45,10 @@ import android.webkit.WebView
 import android.widget.TextView
 
 import androidx.activity.result.contract.ActivityResultContracts
+import androidx.core.view.MenuHost
+import androidx.core.view.MenuProvider
 import androidx.fragment.app.Fragment
+import androidx.lifecycle.Lifecycle
 
 import com.google.android.material.snackbar.Snackbar
 
@@ -214,12 +217,88 @@ class AboutVersionFragment : Fragment() {
 
         // Store the arguments in class variables.
         filterListsVersions = requireArguments().getStringArray(FILTERLISTS_VERSIONS)!!
-
-        // Enable the options menu for this fragment.
-        setHasOptionsMenu(true)
     }
 
     override fun onCreateView(layoutInflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
+        // Add an options menu.
+        (requireActivity() as MenuHost).addMenuProvider(object : MenuProvider {
+            override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
+                // Inflate the about version menu.
+                menuInflater.inflate(R.menu.about_version_options_menu, menu)
+            }
+
+            override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
+                // Run the appropriate commands.
+                when (menuItem.itemId) {
+                    R.id.copy -> {  // Copy.
+                        // Get the about version string.
+                        val aboutVersionString = getAboutVersionString()
+
+                        // Get a handle for the clipboard manager.
+                        val clipboardManager = (requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
+
+                        // Place the about version string in a clip data.
+                        val aboutVersionClipData = ClipData.newPlainText(getString(R.string.about), aboutVersionString)
+
+                        // Place the clip data on the clipboard.
+                        clipboardManager.setPrimaryClip(aboutVersionClipData)
+
+                        // Display a snackbar if the API <= 32 (Android 12L).  Beginning in Android 13 the OS displays a notification that covers up the snackbar.
+                        if (Build.VERSION.SDK_INT <= 32)
+                            Snackbar.make(aboutVersionLayout, R.string.version_info_copied, Snackbar.LENGTH_SHORT).show()
+
+                        // Consume the event.
+                        return true
+                    }
+
+                    R.id.share -> {  // Share.
+                        // Get the about version string.
+                        val aboutString = getAboutVersionString()
+
+                        // Create a share intent.
+                        val shareIntent = Intent(Intent.ACTION_SEND)
+
+                        // Add the about version string to the intent.
+                        shareIntent.putExtra(Intent.EXTRA_TEXT, aboutString)
+
+                        // Set the MIME type.
+                        shareIntent.type = "text/plain"
+
+                        // Set the intent to open in a new task.
+                        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+
+                        // Make it so.
+                        startActivity(Intent.createChooser(shareIntent, getString(R.string.share)))
+
+                        // Consume the event.
+                        return true
+                    }
+
+                    R.id.save_text -> {  // Save text.
+                        // Open the file picker.
+                        saveAboutVersionTextActivityResultLauncher.launch(getString(R.string.privacy_browser_version_txt, BuildConfig.VERSION_NAME))
+
+                        // Consume the event.
+                        return true
+                    }
+
+                    R.id.save_image -> {  // Save image.
+                        // Open the file picker.
+                        saveAboutVersionImageActivityResultLauncher.launch(getString(R.string.privacy_browser_version_png, BuildConfig.VERSION_NAME))
+
+                        // Consume the event.
+                        return true
+                    }
+
+                    else -> {  // The home button was selected.
+                        // Do not consume the event.
+                        return false
+                    }
+                }
+            }
+
+        }, viewLifecycleOwner, Lifecycle.State.RESUMED)
+
         // Inflate the layout.  Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
         aboutVersionLayout = layoutInflater.inflate(R.layout.about_version_scrollview, container, false)
 
@@ -575,84 +654,6 @@ class AboutVersionFragment : Fragment() {
         return aboutVersionLayout
     }
 
-    override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
-        // Inflate the about version menu.
-        menuInflater.inflate(R.menu.about_version_options_menu, menu)
-
-        // Run the default commands.
-        super.onCreateOptionsMenu(menu, menuInflater)
-    }
-
-    override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
-        // Run the appropriate commands.
-        when (menuItem.itemId) {
-            R.id.copy -> {  // Copy.
-                // Get the about version string.
-                val aboutVersionString = getAboutVersionString()
-
-                // Get a handle for the clipboard manager.
-                val clipboardManager = (requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
-
-                // Place the about version string in a clip data.
-                val aboutVersionClipData = ClipData.newPlainText(getString(R.string.about), aboutVersionString)
-
-                // Place the clip data on the clipboard.
-                clipboardManager.setPrimaryClip(aboutVersionClipData)
-
-                // Display a snackbar if the API <= 32 (Android 12L).  Beginning in Android 13 the OS displays a notification that covers up the snackbar.
-                if (Build.VERSION.SDK_INT <= 32)
-                    Snackbar.make(aboutVersionLayout, R.string.version_info_copied, Snackbar.LENGTH_SHORT).show()
-
-                // Consume the event.
-                return true
-            }
-
-            R.id.share -> {  // Share.
-                // Get the about version string.
-                val aboutString = getAboutVersionString()
-
-                // Create a share intent.
-                val shareIntent = Intent(Intent.ACTION_SEND)
-
-                // Add the about version string to the intent.
-                shareIntent.putExtra(Intent.EXTRA_TEXT, aboutString)
-
-                // Set the MIME type.
-                shareIntent.type = "text/plain"
-
-                // Set the intent to open in a new task.
-                shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-
-                // Make it so.
-                startActivity(Intent.createChooser(shareIntent, getString(R.string.share)))
-
-                // Consume the event.
-                return true
-            }
-
-            R.id.save_text -> {  // Save text.
-                // Open the file picker.
-                saveAboutVersionTextActivityResultLauncher.launch(getString(R.string.privacy_browser_version_txt, BuildConfig.VERSION_NAME))
-
-                // Consume the event.
-                return true
-            }
-
-            R.id.save_image -> {  // Save image.
-                // Open the file picker.
-                saveAboutVersionImageActivityResultLauncher.launch(getString(R.string.privacy_browser_version_png, BuildConfig.VERSION_NAME))
-
-                // Consume the event.
-                return true
-            }
-
-            else -> {  // The home button was selected.
-                // Run the parents class on return.
-                return super.onOptionsItemSelected(menuItem)
-            }
-        }
-    }
-
     override fun onSaveInstanceState(savedInstanceState: Bundle) {
         // Run the default commands.
         super.onSaveInstanceState(savedInstanceState)
index 96a475b5ff3df039a51d6022e4663e79782ef550..f43bca5a7a5f838febdab47b21af4e0b4f8fbe50 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright © 2016-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016-2023 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
index 00c3447e7681d996c1046caad5731e9f7e953c14..e59a9c446ca94d56b9a55e13305493e5495e6ff1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
index 558bba2c036780bff5ec09c58e0adf4b94bc2089..307480c843d808a5d9c0fa7024418dab77cc9f4a 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright © 2017-2020,2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2017-2020, 2022, 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
@@ -29,10 +29,12 @@ import android.widget.AdapterView.OnItemClickListener
 import android.widget.ListView
 
 import androidx.fragment.app.Fragment
+import androidx.fragment.app.commitNow
 
 import com.google.android.material.floatingactionbutton.FloatingActionButton
 
 import com.stoutner.privacybrowser.R
+import com.stoutner.privacybrowser.activities.DOMAIN_SETTINGS_FRAGMENT_TAG
 import com.stoutner.privacybrowser.activities.DomainsActivity
 
 class DomainsListFragment : Fragment() {
@@ -40,12 +42,12 @@ class DomainsListFragment : Fragment() {
     private lateinit var dismissSnackbarInterface: DismissSnackbarInterface
     private lateinit var saveDomainSettingsInterface: SaveDomainSettingsInterface
 
-    // Define the public dismiss snackbar interface.
+    // Define the dismiss snackbar interface.
     interface DismissSnackbarInterface {
         fun dismissSnackbar()
     }
 
-    // Define the public save domain interface.
+    // Define the save domain interface.
     interface SaveDomainSettingsInterface {
         fun saveDomainSettings(view: View)
     }
@@ -74,16 +76,16 @@ class DomainsListFragment : Fragment() {
             // Dismiss the snackbar if it is visible.
             dismissSnackbarInterface.dismissSnackbar()
 
-            // Save the current domain settings if operating in two-paned mode and a domain is currently selected.
-            if (DomainsActivity.twoPanedMode && DomainsActivity.deleteMenuItem.isEnabled) {
-                // Get a handle for the domain settings fragment.
-                val domainSettingsFragment = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container)!!
+            // Get a handle for the old domain settings fragment.
+            val oldDomainSettingsFragment = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container)
 
-                // Get a handle for the domain settings fragment view.
-                val domainSettingsFragmentView = domainSettingsFragment.requireView()
+            // Save the current domain settings if operating in two-paned mode and a domain is currently selected.
+            if (DomainsActivity.twoPanedMode && (oldDomainSettingsFragment != null)) {
+                // Get a handle for the old domain settings fragment view.
+                val oldDomainSettingsFragmentView = oldDomainSettingsFragment.requireView()
 
                 // Save the domain settings.
-                saveDomainSettingsInterface.saveDomainSettings(domainSettingsFragmentView)
+                saveDomainSettingsInterface.saveDomainSettings(oldDomainSettingsFragmentView)
             }
 
             // Store the new current domain database ID, converting it from long to int to match the format of the domains database.
@@ -103,22 +105,14 @@ class DomainsListFragment : Fragment() {
 
             // Check to see if the device is in two paned mode.
             if (DomainsActivity.twoPanedMode) {  // The device in in two-paned mode.
-                // Enable the delete menu item if the system is not waiting for a snackbar to be dismissed.
-                if (!DomainsActivity.dismissingSnackbar) {
-                    // Enable the delete menu item.
-                    DomainsActivity.deleteMenuItem.isEnabled = true
-                }
-
                 // Display the domain settings fragment.
-                supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commit()
+                supportFragmentManager.commitNow {
+                    replace(R.id.domain_settings_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                }
             } else { // The device in in single-paned mode
                 // Save the domains listview position.
                 DomainsActivity.domainsListViewPosition = domainsListView.firstVisiblePosition
 
-                // Show the delete menu item if the system is not waiting for a snackbar to be dismissed.
-                if (!DomainsActivity.dismissingSnackbar)
-                    DomainsActivity.deleteMenuItem.isVisible = true
-
                 // Get a handle for the add domain floating action button.
                 val addDomainFab = requireActivity().findViewById<FloatingActionButton>(R.id.add_domain_fab)
 
@@ -126,11 +120,13 @@ class DomainsListFragment : Fragment() {
                 addDomainFab.hide()
 
                 // Display the domain settings fragment.
-                supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit()
+                supportFragmentManager.commitNow {
+                    replace(R.id.domains_listview_fragment_container, domainSettingsFragment, DOMAIN_SETTINGS_FRAGMENT_TAG)
+                }
             }
         }
 
         // Return the domains list fragment.
         return domainsListFragmentView
     }
-}
\ No newline at end of file
+}
index b5d14b44c054863896066a1ecd7a9167946a9faf..957eb10bcfd55543598d2c7c845c2355b862b2b3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2016-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
index 2dae24194687477fb1da939cd13a21d48c795793..f1e27ec0f99b81ea79de0f4c5181f966018b3403 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright 2019-2020,2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2019-2020, 2022-2023 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
index 10f985bef6a2f6924800a394d508f42f60e4efa6..2e0edff8e097b980d0f7ca90b65991e490da068b 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright © 2017,2021-2022 Soren Stoutner <soren@stoutner.com>.
+  Copyright 2017, 2021-2022 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
@@ -40,4 +40,4 @@
         android:layout_height="match_parent"
         android:layout_width="0dp"
         android:layout_weight="3" />
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
index 7d6221a003f7fcaa2c5e0d623bbce03123d6ce56..f48069aff836f49d1358725cefdef5742881f0a8 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright © 2017,2019-2020,2022 Soren Stoutner <soren@stoutner.com>.
+  Copyright 2017, 2019-2020, 2022 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
@@ -29,4 +29,4 @@
     android:layout_width="match_parent"
     android:choiceMode="singleChoice"
     android:divider="@color/transparent"
-    android:dividerHeight="1dp" />
\ No newline at end of file
+    android:dividerHeight="1dp" />
index 5685e2f3f68f024bb19c2332d5c074e9a7329de1..1c0ac69d1e53a9b245d5d0d11cef5e1198e7aea9 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright © 2017,2020,2022 Soren Stoutner <soren@stoutner.com>.
+  Copyright 2017, 2020, 2022 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
@@ -27,4 +27,4 @@
     android:layout_height="match_parent"
     android:layout_width="match_parent"
     android:divider="@color/transparent"
-    android:dividerHeight="1dp" />
\ No newline at end of file
+    android:dividerHeight="1dp" />
index f16fa2b524b801411f3cae49fc06fedfce62a4bb..37427c85143c240d5b7ce60bb07d17f7a855b31b 100644 (file)
@@ -3,7 +3,7 @@
 <!--
   Copyright 2017, 2020, 2022, 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
index f56237fd82c1e3bc98c3c5b893f245a2ef6ece22..28ca9f778730d4f4f9a3509dbe07f55427a8c803 100644 (file)
@@ -26,7 +26,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:8.5.1'
+        classpath 'com.android.tools.build:gradle:8.5.2'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
 
         // NOTE: Do not place your application dependencies here; they belong