From 3ad4e8efe783e04805b1f0dfffaac28159acfb3f Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Thu, 29 Mar 2018 12:34:07 +0200 Subject: [PATCH] #67 Add warning dialog for storage setting --- .../dialogs/StorageAccessFrameworkDialog.java | 51 +++++++++++++++++++ .../settings/NestedSettingsFragment.java | 26 ++++++++-- .../main/res/layout/unavailable_feature.xml | 7 ++- app/src/main/res/values-fr/strings.xml | 3 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/keepassdroid/dialogs/StorageAccessFrameworkDialog.java diff --git a/app/src/main/java/com/keepassdroid/dialogs/StorageAccessFrameworkDialog.java b/app/src/main/java/com/keepassdroid/dialogs/StorageAccessFrameworkDialog.java new file mode 100644 index 000000000..27996567d --- /dev/null +++ b/app/src/main/java/com/keepassdroid/dialogs/StorageAccessFrameworkDialog.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 Brian Pellin, 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 2 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 . + * + */ +package com.keepassdroid.dialogs; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.app.AlertDialog; + +import com.kunzisoft.keepass.R; + +public class StorageAccessFrameworkDialog extends AlertDialog { + + public StorageAccessFrameworkDialog(@NonNull Context context) { + super(context); + } + + public StorageAccessFrameworkDialog(@NonNull Context context, int themeResId) { + super(context, themeResId); + } + + public StorageAccessFrameworkDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) { + super(context, cancelable, cancelListener); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + Context ctx = getContext(); + setMessage(ctx.getString(R.string.warning_disabling_storage_access_framework)); + + super.onCreate(savedInstanceState); + } +} diff --git a/app/src/main/java/com/keepassdroid/settings/NestedSettingsFragment.java b/app/src/main/java/com/keepassdroid/settings/NestedSettingsFragment.java index cb1269262..492b305fb 100644 --- a/app/src/main/java/com/keepassdroid/settings/NestedSettingsFragment.java +++ b/app/src/main/java/com/keepassdroid/settings/NestedSettingsFragment.java @@ -20,8 +20,8 @@ package com.keepassdroid.settings; import android.content.ActivityNotFoundException; -import android.content.Intent; import android.content.DialogInterface; +import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.os.Build; @@ -39,10 +39,11 @@ import android.util.Log; import android.view.autofill.AutofillManager; import android.widget.Toast; -import com.keepassdroid.database.Database; -import com.keepassdroid.dialogs.UnavailableFeatureDialogFragment; import com.keepassdroid.app.App; +import com.keepassdroid.database.Database; import com.keepassdroid.database.PwEncryptionAlgorithm; +import com.keepassdroid.dialogs.StorageAccessFrameworkDialog; +import com.keepassdroid.dialogs.UnavailableFeatureDialogFragment; import com.keepassdroid.fingerprint.FingerPrintHelper; import com.keepassdroid.stylish.Stylish; import com.kunzisoft.keepass.R; @@ -113,6 +114,25 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat return true; }); + SwitchPreference storageAccessFramework = (SwitchPreference) findPreference(getString(R.string.saf_key)); + storageAccessFramework.setOnPreferenceChangeListener((preference, newValue) -> { + Boolean value = (Boolean) newValue; + if (!value && getContext() != null) { + StorageAccessFrameworkDialog safDialog = new StorageAccessFrameworkDialog(getContext()); + safDialog.setButton(AlertDialog.BUTTON1, getText(android.R.string.ok), + (dialog, which) -> { + dialog.dismiss(); + }); + safDialog.setButton(AlertDialog.BUTTON2, getText(android.R.string.cancel), + (dialog, which) -> { + storageAccessFramework.setChecked(true); + dialog.dismiss(); + }); + safDialog.show(); + } + return true; + }); + Preference stylePreference = findPreference(getString(R.string.setting_style_key)); stylePreference.setOnPreferenceChangeListener((preference, newValue) -> { String styleString = (String) newValue; diff --git a/app/src/main/res/layout/unavailable_feature.xml b/app/src/main/res/layout/unavailable_feature.xml index d4d31314e..fbf43e3c9 100644 --- a/app/src/main/res/layout/unavailable_feature.xml +++ b/app/src/main/res/layout/unavailable_feature.xml @@ -8,8 +8,11 @@ android:paddingStart="20dp" android:paddingRight="20dp" android:paddingEnd="20dp" - android:paddingBottom="0dp" > + android:paddingBottom="0dp" + style="?alertDialogTheme"> + android:layout_height="wrap_content" + style="?android:attr/textAppearanceMedium" + android:textColor="?android:attr/textColorPrimary"/> \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9fdaadd9b..8e5682ef7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -142,7 +142,7 @@ Veuillez patienter… Protection Lecture seule - KeePassDroid n\'a pas la permission d\'écrire dans le répertoire de la base de données. Celle-ci sera ouverte en lecture seule. + KeePass DX n\'a pas la permission d\'écrire dans le répertoire de la base de données. Celle-ci sera ouverte en lecture seule. À partir d\'Android KitKat, certains appareils n\'autorisent plus les applications à écrire sur la carte SD. Historique de fichiers récents Mémoriser les fichiers récemment utilisés @@ -246,6 +246,7 @@ Ouvrir automatiquement un fichier à partir de l\'écran de sélection après une sélection dans le navigateur de fichiers Copie de mot de passe Autoriser la copie du mot de passe dans le presse-papiers. + ATTENTION : désactiver cette fonctionnalité peut engendrer une impossibilité d\'ouvrir ou sauvegarder les bases de données 5 secondes diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08c931478..f1182d984 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,6 +247,7 @@ Automatically open a file from the selection screen after a selection in the file browser Copy of password Allow the copy of the password to the clipboard. + WARNING : disabling this feature may result in an inability to open or save the databases 5 seconds