mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-26 03:46:46 -08:00
Remove SAF setting and fix education when create button is gone
This commit is contained in:
1 parent
5bb9168c29
commit
f1fdb9fc84
28 files changed
+57
-185
No files matched your search
@@ -228,7 +228,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
|
||||
|
||||
private fun performedNextEducation(fileDatabaseSelectActivityEducation: FileDatabaseSelectActivityEducation) {
|
||||
// If no recent files
|
||||
if (createButtonView != null
|
||||
if (createButtonView != null && createButtonView!!.visibility == View.VISIBLE
|
||||
&& mFileDatabaseHistory != null
|
||||
&& !mFileDatabaseHistory!!.hasRecentFiles() && fileDatabaseSelectActivityEducation.checkAndPerformedCreateDatabaseEducation(
|
||||
createButtonView!!,
|
||||
|
||||
@@ -857,11 +857,9 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
private fun showWarnings() {
|
||||
// TODO Preferences
|
||||
if (Database.getInstance().isReadOnly) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (prefs.getBoolean(getString(R.string.show_read_only_warning), true)) {
|
||||
ReadOnlyDialog(this).show()
|
||||
if (PreferencesUtil.showReadOnlyWarning(this)) {
|
||||
ReadOnlyDialog().show(supportFragmentManager, "readOnlyDialog")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,33 +19,38 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.activities.dialogs
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.app.Dialog
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
|
||||
import android.support.v4.app.DialogFragment
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class ReadOnlyDialog(context: Context) : AlertDialog(context) {
|
||||
class ReadOnlyDialog : DialogFragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle) {
|
||||
val ctx = context
|
||||
var warning = ctx.getString(R.string.read_only_warning)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
warning = warning + "\n\n" + context.getString(R.string.read_only_kitkat_warning)
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
activity?.let { activity ->
|
||||
// Use the Builder class for convenient dialog construction
|
||||
val builder = android.support.v7.app.AlertDialog.Builder(activity)
|
||||
|
||||
var warning = getString(R.string.read_only_warning)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
warning = warning + "\n\n" + getString(R.string.read_only_kitkat_warning)
|
||||
}
|
||||
builder.setMessage(warning)
|
||||
|
||||
builder.setPositiveButton(getString(android.R.string.ok)) { _, _ -> dismiss() }
|
||||
builder.setNegativeButton(getString(R.string.beta_dontask)) { _, _ ->
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val edit = prefs.edit()
|
||||
edit.putBoolean(getString(R.string.show_read_only_warning), false)
|
||||
edit.apply()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
// Create the AlertDialog object and return it
|
||||
return builder.create()
|
||||
}
|
||||
setMessage(warning)
|
||||
|
||||
setButton(BUTTON_POSITIVE, ctx.getText(android.R.string.ok)) { _, _ -> dismiss() }
|
||||
setButton(BUTTON_NEGATIVE, ctx.getText(R.string.beta_dontask)) { _, _ ->
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||
val edit = prefs.edit()
|
||||
edit.putBoolean(ctx.getString(R.string.show_read_only_warning), false)
|
||||
edit.apply()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
return super.onCreateDialog(savedInstanceState)
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import android.support.v4.app.FragmentActivity
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.kunzisoft.keepass.activities.dialogs.BrowserDialogFragment
|
||||
import com.kunzisoft.keepass.fileselect.StorageAF
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
|
||||
class KeyFileHelper {
|
||||
@@ -56,9 +55,9 @@ class KeyFileHelper {
|
||||
|
||||
override fun onClick(v: View) {
|
||||
try {
|
||||
if (activity != null && StorageAF.useStorageFramework(activity!!)) {
|
||||
try {
|
||||
openActivityWithActionOpenDocument()
|
||||
} else {
|
||||
} catch(e: Exception) {
|
||||
openActivityWithActionGetContent()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -72,7 +71,7 @@ class KeyFileHelper {
|
||||
}
|
||||
|
||||
private fun openActivityWithActionOpenDocument() {
|
||||
val i = Intent(StorageAF.ACTION_OPEN_DOCUMENT)
|
||||
val i = Intent(ACTION_OPEN_DOCUMENT)
|
||||
i.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
i.type = "*/*"
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
@@ -193,18 +192,16 @@ class KeyFileHelper {
|
||||
if (data != null) {
|
||||
var uri = data.data
|
||||
if (uri != null) {
|
||||
if (StorageAF.useStorageFramework(activity!!)) {
|
||||
try {
|
||||
// try to persist read and write permissions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
activity?.contentResolver?.apply {
|
||||
takePersistableUriPermission(uri!!, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
takePersistableUriPermission(uri!!, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
}
|
||||
try {
|
||||
// try to persist read and write permissions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
activity?.contentResolver?.apply {
|
||||
takePersistableUriPermission(uri!!, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
takePersistableUriPermission(uri!!, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// nop
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// nop
|
||||
}
|
||||
if (requestCode == GET_CONTENT) {
|
||||
uri = UriUtil.translateUri(activity!!, uri)
|
||||
@@ -223,6 +220,17 @@ class KeyFileHelper {
|
||||
|
||||
private const val TAG = "KeyFileHelper"
|
||||
|
||||
private var ACTION_OPEN_DOCUMENT: String
|
||||
|
||||
init {
|
||||
ACTION_OPEN_DOCUMENT = try {
|
||||
val openDocument = Intent::class.java.getField("ACTION_OPEN_DOCUMENT")
|
||||
openDocument.get(null) as String
|
||||
} catch (e: Exception) {
|
||||
"android.intent.action.OPEN_DOCUMENT"
|
||||
}
|
||||
}
|
||||
|
||||
const val OPEN_INTENTS_FILE_BROWSE = "org.openintents.action.PICK_FILE"
|
||||
|
||||
private const val GET_CONTENT = 25745
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.fileselect
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.preference.PreferenceManager
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
object StorageAF {
|
||||
|
||||
var ACTION_OPEN_DOCUMENT: String
|
||||
|
||||
init {
|
||||
ACTION_OPEN_DOCUMENT = try {
|
||||
val openDocument = Intent::class.java.getField("ACTION_OPEN_DOCUMENT")
|
||||
openDocument.get(null) as String
|
||||
} catch (e: Exception) {
|
||||
"android.intent.action.OPEN_DOCUMENT"
|
||||
}
|
||||
}
|
||||
|
||||
fun useStorageFramework(context: Context): Boolean {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return false
|
||||
}
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.saf_key),
|
||||
context.resources.getBoolean(R.bool.settings_saf_default))
|
||||
}
|
||||
}
|
||||
@@ -132,23 +132,6 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
true
|
||||
}
|
||||
|
||||
val storageAccessFramework = findPreference(getString(R.string.saf_key)) as SwitchPreference
|
||||
storageAccessFramework.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (!(newValue as Boolean) && context != null) {
|
||||
val alertDialog = AlertDialog.Builder(context!!)
|
||||
.setMessage(getString(R.string.warning_disabling_storage_access_framework)).create()
|
||||
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getText(android.R.string.ok)
|
||||
) { dialog, _ -> dialog.dismiss() }
|
||||
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getText(android.R.string.cancel)
|
||||
) { dialog, _ ->
|
||||
storageAccessFramework.isChecked = true
|
||||
dialog.dismiss()
|
||||
}
|
||||
alertDialog.show()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
val fingerprintEnablePreference = findPreference(getString(R.string.fingerprint_enable_key)) as SwitchPreference
|
||||
// < M solve verifyError exception
|
||||
var fingerprintSupported = false
|
||||
|
||||
@@ -28,6 +28,11 @@ import java.util.*
|
||||
|
||||
object PreferencesUtil {
|
||||
|
||||
fun showReadOnlyWarning(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.show_read_only_warning), true)
|
||||
}
|
||||
|
||||
fun omitBackup(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.omitbackup_key),
|
||||
|
||||
@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.utils
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import com.kunzisoft.keepass.fileselect.StorageAF
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
@@ -58,7 +57,7 @@ object UriUtil {
|
||||
fun translateUri(ctx: Context, uri: Uri): Uri {
|
||||
var currentUri = uri
|
||||
// StorageAF provides nice URIs
|
||||
if (StorageAF.useStorageFramework(ctx) || hasWritableContentUri(currentUri)) {
|
||||
if (hasWritableContentUri(currentUri)) {
|
||||
return currentUri
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user