X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FViewHeadersActivity.kt;h=8e72b596b9cea383b7d6a0b509b71e03030e4060;hb=HEAD;hp=ce86183b021b79f83053a1f276a759ba59cb6390;hpb=cbeede13395a246b8a32adebbee3872031259f82;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt index ce86183b..8e72b596 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt @@ -1,7 +1,7 @@ /* - * Copyright 2017-2023 Soren Stoutner . + * Copyright 2017-2024 Soren Stoutner . * - * This file is part of Privacy Browser Android . + * This file is part of Privacy Browser Android . * * Privacy Browser Android is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,6 @@ import android.view.View import android.view.View.OnFocusChangeListener import android.view.WindowManager import android.view.inputmethod.InputMethodManager -import android.widget.Button import android.widget.EditText import android.widget.ProgressBar import android.widget.TextView @@ -46,7 +45,7 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.ActionBar import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar -import androidx.core.app.NavUtils +import androidx.constraintlayout.widget.ConstraintLayout import androidx.lifecycle.ViewModelProvider import androidx.preference.PreferenceManager import androidx.swiperefreshlayout.widget.SwipeRefreshLayout @@ -90,8 +89,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener private lateinit var urlEditText: EditText private lateinit var sslInformationTitleTextView: TextView private lateinit var sslInformationTextView: TextView - private lateinit var ciphersButton: Button - private lateinit var certificateButton: Button + private lateinit var sslButtonsConstraintLayout: ConstraintLayout private lateinit var requestHeadersTitleTextView: TextView private lateinit var requestHeadersTextView: TextView private lateinit var responseMessageTitleTextView: TextView @@ -105,23 +103,17 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener private val saveTextActivityResultLauncher = 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 = 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 = 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. @@ -159,9 +151,8 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false) // Disable screenshots if not allowed. - if (!allowScreenshots) { + if (!allowScreenshots) window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) - } // Run the default commands. super.onCreate(savedInstanceState) @@ -174,11 +165,10 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener val userAgent = intent.getStringExtra(USER_AGENT)!! // Set the content view. - if (bottomAppBar) { + if (bottomAppBar) setContentView(R.layout.view_headers_bottom_appbar) - } else { + else setContentView(R.layout.view_headers_top_appbar) - } // Get a handle for the toolbar. val toolbar = findViewById(R.id.toolbar) @@ -193,7 +183,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener actionBar.setCustomView(R.layout.view_headers_appbar_custom_view) // Instruct the action bar to display a custom layout. - actionBar.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM + actionBar.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM or ActionBar.DISPLAY_HOME_AS_UP // Get handles for the views. urlEditText = findViewById(R.id.url_edittext) @@ -201,8 +191,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener val swipeRefreshLayout = findViewById(R.id.swiperefreshlayout) sslInformationTitleTextView = findViewById(R.id.ssl_information_title_textview) sslInformationTextView = findViewById(R.id.ssl_information_textview) - ciphersButton = findViewById(R.id.ciphers_button) - certificateButton = findViewById(R.id.certificate_button) + sslButtonsConstraintLayout = findViewById(R.id.ssl_buttons_constraintlayout) requestHeadersTitleTextView = findViewById(R.id.request_headers_title_textview) requestHeadersTextView = findViewById(R.id.request_headers_textview) responseMessageTitleTextView = findViewById(R.id.response_message_title_textview) @@ -435,7 +424,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener } override fun onOptionsItemSelected(menuItem: MenuItem): Boolean { - // Run the appropriate commands. + // Run the commands that correlate to the selected menu item. when (menuItem.itemId) { R.id.copy_headers -> { // Copy the headers. // Get the headers string. @@ -452,7 +441,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener // 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(urlEditText, R.string.version_info_copied, Snackbar.LENGTH_SHORT).show() + Snackbar.make(urlEditText, R.string.headers_copied, Snackbar.LENGTH_SHORT).show() // Consume the event. return true @@ -510,18 +499,12 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener } else -> { // The home button was selected. - // Run the parents class on return. + // Do not consume the event. The system will process the home command. return super.onOptionsItemSelected(menuItem) } } } - // This method must be named `goBack()` and must have a View argument to match the default back arrow in the app bar or a crash occurs. - fun goBack(@Suppress("UNUSED_PARAMETER") view: View) { - // Go home. - NavUtils.navigateUpFromSameTask(this) - } - private fun getHeadersString(): String { // Initialize a headers string builder. val headersStringBuilder = StringBuilder() @@ -595,8 +578,7 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener // Hide the unused views. sslInformationTitleTextView.visibility = View.GONE sslInformationTextView.visibility = View.GONE - ciphersButton.visibility = View.GONE - certificateButton.visibility = View.GONE + sslButtonsConstraintLayout.visibility = View.GONE requestHeadersTitleTextView.visibility = View.GONE requestHeadersTextView.visibility = View.GONE responseMessageTitleTextView.visibility = View.GONE @@ -611,14 +593,12 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener // Hide the SSL information views. sslInformationTitleTextView.visibility = View.GONE sslInformationTextView.visibility = View.GONE - ciphersButton.visibility = View.GONE - certificateButton.visibility = View.GONE + sslButtonsConstraintLayout.visibility = View.GONE } else { // This is not an HTTP URL. // Show the SSL information views. sslInformationTitleTextView.visibility = View.VISIBLE sslInformationTextView.visibility = View.VISIBLE - ciphersButton.visibility = View.VISIBLE - certificateButton.visibility = View.VISIBLE + sslButtonsConstraintLayout.visibility = View.VISIBLE } // Show the other views.