Add database settings

This commit is contained in:
J-Jamet
2019-09-24 11:52:01 +02:00
parent 9413987355
commit 9b891013b8
11 changed files with 241 additions and 52 deletions

View File

@@ -83,11 +83,16 @@ class MainPreferenceFragment : PreferenceFragmentCompat() {
}
}
findPreference<Preference>(getString(R.string.settings_database_change_credentials_key))?.apply {
findPreference<Preference>(getString(R.string.settings_database_security_key))?.apply {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
fragmentManager?.let { fragmentManager ->
AssignMasterKeyDialogFragment().show(fragmentManager, "passwordDialog")
}
mCallback?.onNestedPreferenceSelected(NestedSettingsFragment.Screen.DATABASE_SECURITY)
false
}
}
findPreference<Preference>(getString(R.string.settings_database_credentials_key))?.apply {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
mCallback?.onNestedPreferenceSelected(NestedSettingsFragment.Screen.DATABASE_MASTER_KEY)
false
}
}

View File

@@ -36,10 +36,7 @@ import androidx.biometric.BiometricManager
import androidx.preference.*
import com.kunzisoft.keepass.BuildConfig
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.KeyboardExplanationDialogFragment
import com.kunzisoft.keepass.activities.dialogs.ProFeatureDialogFragment
import com.kunzisoft.keepass.activities.dialogs.UnavailableFeatureDialogFragment
import com.kunzisoft.keepass.activities.dialogs.UnderDevelopmentFeatureDialogFragment
import com.kunzisoft.keepass.activities.dialogs.*
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
import com.kunzisoft.keepass.activities.stylish.Stylish
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
@@ -63,7 +60,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
private var mParallelismPref: InputKdfNumberPreference? = null
enum class Screen {
APPLICATION, FORM_FILLING, ADVANCED_UNLOCK, DATABASE, APPEARANCE
APPLICATION, FORM_FILLING, ADVANCED_UNLOCK, APPEARANCE, DATABASE, DATABASE_SECURITY, DATABASE_MASTER_KEY
}
override fun onResume() {
@@ -107,6 +104,12 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
Screen.DATABASE -> {
onCreateDatabasePreference(rootKey)
}
Screen.DATABASE_SECURITY -> {
onCreateDatabaseSecurityPreference(rootKey)
}
Screen.DATABASE_MASTER_KEY -> {
onCreateDatabaseMasterKeyPreference(rootKey)
}
}
}
@@ -379,6 +382,15 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
findPreference<InputNumberPreference>(getString(R.string.max_history_size_key))
?.summary = mDatabase.historyMaxSize.toString()
} else {
Log.e(javaClass.name, "Database isn't ready")
}
}
private fun onCreateDatabaseSecurityPreference(rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_database_security, rootKey)
if (mDatabase.loaded) {
// Encryption Algorithm
findPreference<DialogListExplanationPreference>(getString(R.string.encryption_algorithm_key))
?.summary = mDatabase.getEncryptionAlgorithmName(resources)
@@ -398,7 +410,23 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
// Parallelism
mParallelismPref = findPreference(getString(R.string.parallelism_key))
mParallelismPref?.summary = mDatabase.parallelism.toString()
} else {
Log.e(javaClass.name, "Database isn't ready")
}
}
private fun onCreateDatabaseMasterKeyPreference(rootKey: String?) {
setPreferencesFromResource(R.xml.preferences_database_master_key, rootKey)
if (mDatabase.loaded) {
findPreference<Preference>(getString(R.string.settings_database_change_credentials_key))?.apply {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
fragmentManager?.let { fragmentManager ->
AssignMasterKeyDialogFragment().show(fragmentManager, "passwordDialog")
}
false
}
}
} else {
Log.e(javaClass.name, "Database isn't ready")
}
@@ -543,8 +571,10 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
Screen.APPLICATION -> resources.getString(R.string.menu_app_settings)
Screen.FORM_FILLING -> resources.getString(R.string.menu_form_filling_settings)
Screen.ADVANCED_UNLOCK -> resources.getString(R.string.menu_advanced_unlock_settings)
Screen.DATABASE -> resources.getString(R.string.menu_database_settings)
Screen.APPEARANCE -> resources.getString(R.string.menu_appearance_settings)
Screen.DATABASE -> resources.getString(R.string.menu_database_settings)
Screen.DATABASE_SECURITY -> resources.getString(R.string.menu_security_settings)
Screen.DATABASE_MASTER_KEY -> resources.getString(R.string.menu_master_key_settings)
}
}
}

View File

@@ -0,0 +1,10 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="?attr/iconPreferenceColor"
android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z"/>
</vector>

View File

@@ -0,0 +1,10 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="?attr/iconPreferenceColor"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>

View File

@@ -148,17 +148,21 @@
<!-- Database Settings -->
<string name="settings_database_key" translatable="false">settings_database_key</string>
<string name="settings_database_change_credentials_key" translatable="false">settings_database_change_credentials_key</string>
<string name="settings_database_security_key" translatable="false">settings_database_security_key</string>
<string name="settings_database_credentials_key" translatable="false">settings_database_credentials_key</string>
<string name="database_general_key" translatable="false">database_general_key</string>
<string name="database_name_key" translatable="false">database_name_key</string>
<string name="database_description_key" translatable="false">database_description_key</string>
<string name="database_default_username_key" translatable="false">database_default_username_key</string>
<string name="database_custom_color_key" translatable="false">database_custom_color_key</string>
<string name="database_version_key" translatable="false">database_version_key</string>
<string name="database_history_key" translatable="false">database_history_key</string>
<string name="database_data_compression_key" translatable="false">database_data_compression_key</string>
<string name="recycle_bin_key" translatable="false">recycle_bin_key</string>
<string name="max_history_items_key" translatable="false">max_history_items_key</string>
<string name="max_history_size_key" translatable="false">max_history_size_key</string>
<string name="recycle_bin_key" translatable="false">recycle_bin_key</string>
<string name="encryption_algorithm_key" translatable="false">algorithm</string>
<string name="key_derivation_function_key" translatable="false">key_derivation_function_key</string>
@@ -166,6 +170,11 @@
<string name="memory_usage_key" translatable="false">memory_usage_key</string>
<string name="parallelism_key" translatable="false">parallelism_key</string>
<string name="settings_database_change_credentials_key" translatable="false">settings_database_change_credentials_key</string>
<string name="settings_database_recommend_changing_master_key_key" translatable="false">settings_database_recommend_changing_master_key_key</string>
<string name="settings_database_force_changing_master_key_key" translatable="false">settings_database_force_changing_master_key_key</string>
<string name="settings_database_force_changing_master_key_next_time_key" translatable="false">settings_database_force_changing_master_key_next_time_key</string>
<!--
*******************
Store settings

View File

@@ -25,6 +25,8 @@
<string name="add_entry">Add entry</string>
<string name="edit_entry">Edit entry</string>
<string name="add_group">Add group</string>
<string name="master_key">Master Key</string>
<string name="security">Security</string>
<string name="encryption">Encryption</string>
<string name="encryption_algorithm">Encryption algorithm</string>
<string name="key_derivation_function">Key derivation function</string>
@@ -150,6 +152,8 @@
<string name="menu_form_filling_settings">Form filling</string>
<string name="menu_advanced_unlock_settings">Advanced unlock</string>
<string name="menu_database_settings">Database settings</string>
<string name="menu_security_settings">Security settings</string>
<string name="menu_master_key_settings">Master Key settings</string>
<string name="menu_donate">Donate</string>
<string name="menu_edit">Edit</string>
<string name="menu_copy">Copy</string>
@@ -286,12 +290,19 @@
<string name="bytes">Bytes</string>
<string name="full_file_path_enable_title">File path</string>
<string name="full_file_path_enable_summary">View the full file path</string>
<string name="database_data_compression_title">Data compression</string>
<string name="recycle_bin_title">Use recycle bin</string>
<string name="recycle_bin_summary">Moves groups and entries to \"Recycle bin\" before deleting</string>
<string name="max_history_items_title">Max. history items</string>
<string name="max_history_items_summary">Limit number of history items per entry</string>
<string name="max_history_size_title">Max. history size</string>
<string name="max_history_size_summary">Limit history size per entry (in binary bytes)</string>
<string name="settings_database_recommend_changing_master_key_title">Recommend changing</string>
<string name="settings_database_recommend_changing_master_key_summary">Recommend changing the master key (days)</string>
<string name="settings_database_force_changing_master_key_title">Force changing</string>
<string name="settings_database_force_changing_master_key_summary">Force changing the master key (days)</string>
<string name="settings_database_force_changing_master_key_next_time_title">Force changing the next time</string>
<string name="settings_database_force_changing_master_key_next_time_summary">Force changing the master key the next time (once)</string>
<string name="monospace_font_fields_enable_title">Field font</string>
<string name="monospace_font_fields_enable_summary">Change font used in fields for better character visibility</string>
<string name="auto_open_file_uri_title">Open files by selecting</string>
@@ -306,10 +317,13 @@
<string name="open_link_database">Link of database file to open</string>
<string name="database_name_title">Database name</string>
<string name="database_description_title">Database description</string>
<string name="database_default_username_title">Default username</string>
<string name="database_custom_color_title">Custom database color</string>
<string name="database_version_title">Database version</string>
<string name="text_appearance">Text</string>
<string name="application_appearance">App</string>
<string name="other">Other</string>
<string name="compression">Compression</string>
<string name="recycle_bin">Recycle Bin</string>
<string name="keyboard">Keyboard</string>
<string name="magic_keyboard_title">Magikeyboard</string>

View File

@@ -51,9 +51,15 @@
android:icon="@drawable/prefs_data_usage_24dp"
android:persistent="false" />
<Preference
android:key="@string/settings_database_change_credentials_key"
android:title="@string/menu_change_key_settings"
android:icon="@drawable/prefs_key_white_24dp"
android:key="@string/settings_database_security_key"
android:title="@string/security"
android:icon="@drawable/prefs_security_24dp"
android:dependency="@string/settings_database_key"
android:persistent="false" />
<Preference
android:key="@string/settings_database_credentials_key"
android:title="@string/master_key"
android:icon="@drawable/prefs_key_24dp"
android:dependency="@string/settings_database_key"
android:persistent="false" />
</PreferenceCategory>

View File

@@ -17,7 +17,8 @@
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
@@ -36,6 +37,20 @@
android:title="@string/database_description_title"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<!-- TODO username preference -->
<com.kunzisoft.keepass.settings.preference.InputTextPreference
android:key="@string/database_default_username_key"
android:persistent="false"
android:title="@string/database_default_username_title"
android:enabled="false"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<!-- TODO custom color preference -->
<Preference
android:key="@string/database_custom_color_key"
android:persistent="false"
android:enabled="false"
android:title="@string/database_custom_color_title"/>
<Preference
android:key="@string/database_version_key"
android:persistent="false"
@@ -43,6 +58,17 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/compression">
<com.kunzisoft.keepass.settings.preference.DialogListExplanationPreference
android:key="@string/database_data_compression_key"
android:persistent="false"
android:enabled="false"
android:title="@string/database_data_compression_title"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/recycle_bin">
@@ -74,40 +100,4 @@
android:negativeButtonText="@string/entry_cancel"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/encryption">
<com.kunzisoft.keepass.settings.preference.DialogListExplanationPreference
android:key="@string/encryption_algorithm_key"
android:persistent="false"
android:title="@string/encryption_algorithm"/>
<com.kunzisoft.keepass.settings.preference.DialogListExplanationPreference
android:key="@string/key_derivation_function_key"
android:persistent="false"
android:title="@string/key_derivation_function"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/transform_rounds_key"
android:persistent="false"
android:title="@string/rounds"
custom:explanations="@string/rounds_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/memory_usage_key"
android:persistent="false"
android:title="@string/memory_usage"
custom:explanations="@string/memory_usage_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/parallelism_key"
android:persistent="false"
android:title="@string/parallelism"
custom:explanations="@string/parallelism_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 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/>.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:key="@string/settings_database_change_credentials_key"
android:title="@string/menu_change_key_settings"
android:icon="@drawable/prefs_autorenew_24dp"
android:persistent="false" />
<PreferenceCategory
android:title="@string/master_key">
<com.kunzisoft.keepass.settings.preference.InputTextPreference
android:key="@string/settings_database_recommend_changing_master_key_key"
android:title="@string/settings_database_recommend_changing_master_key_title"
android:enabled="false"
android:persistent="false" />
<com.kunzisoft.keepass.settings.preference.InputTextPreference
android:key="@string/settings_database_force_changing_master_key_key"
android:title="@string/settings_database_force_changing_master_key_title"
android:enabled="false"
android:persistent="false" />
<com.kunzisoft.keepass.settings.preference.InputTextPreference
android:key="@string/settings_database_force_changing_master_key_next_time_key"
android:title="@string/settings_database_force_changing_master_key_next_time_title"
android:enabled="false"
android:persistent="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 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/>.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:title="@string/encryption">
<com.kunzisoft.keepass.settings.preference.DialogListExplanationPreference
android:key="@string/encryption_algorithm_key"
android:persistent="false"
android:title="@string/encryption_algorithm"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/key_derivation_function">
<com.kunzisoft.keepass.settings.preference.DialogListExplanationPreference
android:key="@string/key_derivation_function_key"
android:persistent="false"
android:title="@string/key_derivation_function"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/transform_rounds_key"
android:persistent="false"
android:title="@string/rounds"
custom:explanations="@string/rounds_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/memory_usage_key"
android:persistent="false"
android:title="@string/memory_usage"
custom:explanations="@string/memory_usage_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
<com.kunzisoft.keepass.settings.preference.InputKdfNumberPreference
android:key="@string/parallelism_key"
android:persistent="false"
android:title="@string/parallelism"
custom:explanations="@string/parallelism_explanation"
android:positiveButtonText="@string/entry_save"
android:negativeButtonText="@string/entry_cancel"/>
</PreferenceCategory>
</PreferenceScreen>