]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt
Fix some files not being displayed in the file picker. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / AboutVersionFragment.kt
index ceb060b796c38e51a768379208f35edfa66f0216..163e41d104cf4b6e9187c2586ece84196e973804 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -41,11 +41,11 @@ import android.view.MenuInflater
 import android.view.MenuItem
 import android.view.View
 import android.view.ViewGroup
+import android.webkit.WebView
 import android.widget.TextView
 
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.fragment.app.Fragment
-import androidx.webkit.WebViewCompat
 
 import com.google.android.material.snackbar.Snackbar
 
@@ -71,7 +71,8 @@ import java.text.NumberFormat
 import kotlin.text.StringBuilder
 
 // Define the class constants.
-private const val FILTERLISTS_VERSIONS = "filterlists_versions"
+private const val FILTERLISTS_VERSIONS = "A"
+private const val SCROLL_Y = "B"
 private const val MEBIBYTE = 1048576
 
 class AboutVersionFragment : Fragment() {
@@ -161,23 +162,17 @@ class AboutVersionFragment : Fragment() {
     private val saveAboutVersionTextActivityResultLauncher = registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { fileUri ->
         // Only save the file if the URI is not null, which happens if the user exited the file picker by pressing back.
         if (fileUri != null) {
-            // Initialize the file name string from the file URI last path segment.
-            var fileNameString = fileUri.lastPathSegment
+            // Get a cursor from the content resolver.
+            val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!!
 
-            // Query the exact file name if the API >= 26.
-            if (Build.VERSION.SDK_INT >= 26) {
-                // Get a cursor from the content resolver.
-                val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!!
+            // Move to the first row.
+            contentResolverCursor.moveToFirst()
 
-                // Move to the first row.
-                contentResolverCursor.moveToFirst()
+            // Get the file name from the cursor.
+            val fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
 
-                // Get the file name from the cursor.
-                fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
-
-                // Close the cursor.
-                contentResolverCursor.close()
-            }
+            // Close the cursor.
+            contentResolverCursor.close()
 
             try {
                 // Get the about version string.
@@ -306,8 +301,8 @@ class AboutVersionFragment : Fragment() {
         val serialNumberLabel = getString(R.string.serial_number)
         val signatureAlgorithmLabel = getString(R.string.signature_algorithm)
 
-        // Get the current WebView package info.  This can be replaced by the direct call once the minimum API >= 26.  <https://developer.android.com/reference/android/webkit/WebView#getCurrentWebViewPackage()>
-        val webViewPackageInfo = WebViewCompat.getCurrentWebViewPackage(requireContext())!!
+        // Get the current WebView package info.
+        val webViewPackageInfo = WebView.getCurrentWebViewPackage()!!
 
         // Get the device's information and store it in strings.
         val brand = Build.BRAND
@@ -572,8 +567,7 @@ class AboutVersionFragment : Fragment() {
         // Scroll the tab if the saved instance state is not null.
         if (savedInstanceState != null) {
             aboutVersionLayout.post {
-                aboutVersionLayout.scrollX = savedInstanceState.getInt("scroll_x")
-                aboutVersionLayout.scrollY = savedInstanceState.getInt("scroll_y")
+                aboutVersionLayout.scrollY = savedInstanceState.getInt(SCROLL_Y)
             }
         }
 
@@ -663,9 +657,8 @@ class AboutVersionFragment : Fragment() {
         // Run the default commands.
         super.onSaveInstanceState(savedInstanceState)
 
-        // Save the scroll positions.
-        savedInstanceState.putInt("scroll_x", aboutVersionLayout.scrollX)
-        savedInstanceState.putInt("scroll_y", aboutVersionLayout.scrollY)
+        // Save the scroll position.
+        savedInstanceState.putInt(SCROLL_Y, aboutVersionLayout.scrollY)
     }
 
     override fun onPause() {