X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FAboutVersionFragment.kt;h=7dfeda99553fd10c2e77d6ba3122417cbd014c2c;hb=HEAD;hp=ceb060b796c38e51a768379208f35edfa66f0216;hpb=f95501b3f5d609aac90ef75acad30b7d19448c3d;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt index ceb060b7..163e41d1 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 Soren Stoutner . + * Copyright 2016-2024 Soren Stoutner . * * This file is part of 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. - 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() {