/*
- * 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>.
*
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
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() {
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.
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
// 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)
}
}
// 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() {