/*
- * Copyright 2017-2023 Soren Stoutner <soren@stoutner.com>.
+ * 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
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.constraintlayout.widget.ConstraintLayout
-import androidx.core.app.NavUtils
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
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.
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)
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<Toolbar>(R.id.toolbar)
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)
}
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.
}
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()