mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Merge branch 'feature/Color_Preference' into develop
This commit is contained in:
@@ -6,6 +6,7 @@ apply plugin: 'kotlin-kapt'
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '28.0.3'
|
||||
ndkVersion "20.0.5594570"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.kunzisoft.keepass"
|
||||
@@ -99,6 +100,8 @@ dependencies {
|
||||
implementation "com.madgag.spongycastle:prov:$spongycastleVersion"
|
||||
// Time
|
||||
implementation 'joda-time:joda-time:2.9.9'
|
||||
// Color
|
||||
implementation 'com.github.Kunzisoft:AndroidClearChroma:2.3'
|
||||
// Education
|
||||
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.12.0'
|
||||
// Apache Commons Collections
|
||||
|
||||
@@ -177,7 +177,7 @@ class EntryEditActivity : LockingHideActivity(),
|
||||
// Set info in view
|
||||
entryEditContentsView?.apply {
|
||||
title = newEntry.title
|
||||
username = newEntry.username
|
||||
username = if (newEntry.username.isEmpty()) mDatabase?.defaultUsername ?:"" else newEntry.username
|
||||
url = newEntry.url
|
||||
password = newEntry.password
|
||||
notes = newEntry.notes
|
||||
|
||||
@@ -67,15 +67,23 @@ class Database {
|
||||
return pwDatabaseV3?.iconFactory ?: pwDatabaseV4?.iconFactory ?: PwIconFactory()
|
||||
}
|
||||
|
||||
val name: String
|
||||
var name: String
|
||||
get() {
|
||||
return pwDatabaseV4?.name ?: ""
|
||||
}
|
||||
set(name) {
|
||||
pwDatabaseV4?.name = name
|
||||
pwDatabaseV4?.nameChanged = PwDate()
|
||||
}
|
||||
|
||||
val description: String
|
||||
var description: String
|
||||
get() {
|
||||
return pwDatabaseV4?.description ?: ""
|
||||
}
|
||||
set(description) {
|
||||
pwDatabaseV4?.description = description
|
||||
pwDatabaseV4?.descriptionChanged = PwDate()
|
||||
}
|
||||
|
||||
var defaultUsername: String
|
||||
get() {
|
||||
@@ -86,23 +94,55 @@ class Database {
|
||||
pwDatabaseV4?.defaultUserNameChanged = PwDate()
|
||||
}
|
||||
|
||||
// with format "#000000"
|
||||
var color: String
|
||||
get() {
|
||||
return pwDatabaseV4?.color ?: ""
|
||||
}
|
||||
set(value) {
|
||||
// TODO Check color string
|
||||
pwDatabaseV4?.color = value
|
||||
}
|
||||
|
||||
val availableCompressionAlgorithms: List<PwCompressionAlgorithm>
|
||||
get() = pwDatabaseV4?.availableCompressionAlgorithms ?: ArrayList()
|
||||
|
||||
val compressionAlgorithm: PwCompressionAlgorithm?
|
||||
var compressionAlgorithm: PwCompressionAlgorithm?
|
||||
get() = pwDatabaseV4?.compressionAlgorithm
|
||||
set(value) {
|
||||
value?.let {
|
||||
pwDatabaseV4?.compressionAlgorithm = it
|
||||
}
|
||||
// TODO Compression
|
||||
}
|
||||
|
||||
val availableEncryptionAlgorithms: List<PwEncryptionAlgorithm>
|
||||
get() = pwDatabaseV3?.availableEncryptionAlgorithms ?: pwDatabaseV4?.availableEncryptionAlgorithms ?: ArrayList()
|
||||
|
||||
val encryptionAlgorithm: PwEncryptionAlgorithm?
|
||||
var encryptionAlgorithm: PwEncryptionAlgorithm?
|
||||
get() = pwDatabaseV3?.encryptionAlgorithm ?: pwDatabaseV4?.encryptionAlgorithm
|
||||
set(algorithm) {
|
||||
algorithm?.let {
|
||||
pwDatabaseV4?.encryptionAlgorithm = algorithm
|
||||
pwDatabaseV4?.setDataEngine(algorithm.cipherEngine)
|
||||
pwDatabaseV4?.dataCipher = algorithm.dataCipher
|
||||
}
|
||||
}
|
||||
|
||||
val availableKdfEngines: List<KdfEngine>
|
||||
get() = pwDatabaseV3?.kdfAvailableList ?: pwDatabaseV4?.kdfAvailableList ?: ArrayList()
|
||||
|
||||
val kdfEngine: KdfEngine?
|
||||
var kdfEngine: KdfEngine?
|
||||
get() = pwDatabaseV3?.kdfEngine ?: pwDatabaseV4?.kdfEngine
|
||||
set(kdfEngine) {
|
||||
kdfEngine?.let {
|
||||
if (pwDatabaseV4?.kdfParameters?.uuid != kdfEngine.defaultParameters.uuid)
|
||||
pwDatabaseV4?.kdfParameters = kdfEngine.defaultParameters
|
||||
numberKeyEncryptionRounds = kdfEngine.defaultKeyRounds
|
||||
memoryUsage = kdfEngine.defaultMemoryUsage
|
||||
parallelism = kdfEngine.defaultParallelism
|
||||
}
|
||||
}
|
||||
|
||||
var numberKeyEncryptionRounds: Long
|
||||
get() = pwDatabaseV3?.numberKeyEncryptionRounds ?: pwDatabaseV4?.numberKeyEncryptionRounds ?: 0
|
||||
@@ -444,36 +484,25 @@ class Database {
|
||||
return false
|
||||
}
|
||||
|
||||
fun assignName(name: String) {
|
||||
pwDatabaseV4?.name = name
|
||||
pwDatabaseV4?.nameChanged = PwDate()
|
||||
}
|
||||
|
||||
fun containsDescription(): Boolean {
|
||||
pwDatabaseV4?.let { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
fun assignDescription(description: String) {
|
||||
pwDatabaseV4?.description = description
|
||||
pwDatabaseV4?.descriptionChanged = PwDate()
|
||||
fun containsDefaultUsername(): Boolean {
|
||||
pwDatabaseV4?.let { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
fun assignCompressionAlgorithm(algorithm: PwCompressionAlgorithm) {
|
||||
pwDatabaseV4?.compressionAlgorithm = algorithm
|
||||
// TODO Compression
|
||||
fun containsCustomColor(): Boolean {
|
||||
pwDatabaseV4?.let { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
fun allowEncryptionAlgorithmModification(): Boolean {
|
||||
return availableEncryptionAlgorithms.size > 1
|
||||
}
|
||||
|
||||
fun assignEncryptionAlgorithm(algorithm: PwEncryptionAlgorithm) {
|
||||
pwDatabaseV4?.encryptionAlgorithm = algorithm
|
||||
pwDatabaseV4?.setDataEngine(algorithm.cipherEngine)
|
||||
pwDatabaseV4?.dataCipher = algorithm.dataCipher
|
||||
}
|
||||
|
||||
fun getEncryptionAlgorithmName(resources: Resources): String {
|
||||
return pwDatabaseV3?.encryptionAlgorithm?.getName(resources) ?: pwDatabaseV4?.encryptionAlgorithm?.getName(resources) ?: ""
|
||||
}
|
||||
@@ -482,14 +511,6 @@ class Database {
|
||||
return availableKdfEngines.size > 1
|
||||
}
|
||||
|
||||
fun assignKdfEngine(kdfEngine: KdfEngine) {
|
||||
if (pwDatabaseV4?.kdfParameters?.uuid != kdfEngine.defaultParameters.uuid)
|
||||
pwDatabaseV4?.kdfParameters = kdfEngine.defaultParameters
|
||||
numberKeyEncryptionRounds = kdfEngine.defaultKeyRounds
|
||||
memoryUsage = kdfEngine.defaultMemoryUsage
|
||||
parallelism = kdfEngine.defaultParallelism
|
||||
}
|
||||
|
||||
fun getKeyDerivationName(resources: Resources): String {
|
||||
return kdfEngine?.getName(resources) ?: ""
|
||||
}
|
||||
|
||||
@@ -358,7 +358,6 @@ class ImporterV4(private val streamDir: File,
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemDbDefaultUserChanged, ignoreCase = true)) {
|
||||
mDatabase.defaultUserNameChanged = readPwTime(xpp)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemDbColor, ignoreCase = true)) {
|
||||
// TODO: Add support to interpret the color if we want to allow changing the database color
|
||||
mDatabase.color = readString(xpp)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemDbMntncHistoryDays, ignoreCase = true)) {
|
||||
mDatabase.maintenanceHistoryDays = readUInt(xpp, DEFAULT_HISTORY_DAYS)
|
||||
|
||||
@@ -22,18 +22,23 @@ package com.kunzisoft.keepass.settings
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.autofill.AutofillManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.*
|
||||
import com.kunzisoft.androidclearchroma.ChromaUtil
|
||||
import com.kunzisoft.keepass.BuildConfig
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
@@ -41,12 +46,13 @@ import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.activities.stylish.Stylish
|
||||
import com.kunzisoft.keepass.app.database.CipherDatabaseAction
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.education.Education
|
||||
import com.kunzisoft.keepass.biometric.BiometricUnlockDatabaseHelper
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.PwCompressionAlgorithm
|
||||
import com.kunzisoft.keepass.education.Education
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser
|
||||
import com.kunzisoft.keepass.settings.preference.*
|
||||
import com.kunzisoft.keepass.settings.preference.DialogColorPreference.Companion.DISABLE_COLOR
|
||||
import com.kunzisoft.keepass.settings.preferencedialogfragment.*
|
||||
|
||||
class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener {
|
||||
@@ -56,6 +62,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
|
||||
private var mCount = 0
|
||||
|
||||
private var databaseCustomColorPref: DialogColorPreference? = null
|
||||
private var mRoundPref: InputKdfNumberPreference? = null
|
||||
private var mMemoryPref: InputKdfNumberPreference? = null
|
||||
private var mParallelismPref: InputKdfNumberPreference? = null
|
||||
@@ -341,7 +348,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
|
||||
val dbGeneralPrefCategory: PreferenceCategory? = findPreference(getString(R.string.database_general_key))
|
||||
|
||||
// Db name
|
||||
// Database name
|
||||
val dbNamePref: InputTextPreference? = findPreference(getString(R.string.database_name_key))
|
||||
if (mDatabase.containsName()) {
|
||||
dbNamePref?.summary = mDatabase.name
|
||||
@@ -357,6 +364,30 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
dbGeneralPrefCategory?.removePreference(dbDescriptionPref)
|
||||
}
|
||||
|
||||
// Database default username
|
||||
val dbDefaultUsername: InputTextPreference? = findPreference(getString(R.string.database_default_username_key))
|
||||
if (mDatabase.containsDefaultUsername()) {
|
||||
dbDefaultUsername?.summary = mDatabase.defaultUsername
|
||||
} else {
|
||||
dbGeneralPrefCategory?.removePreference(dbDefaultUsername)
|
||||
}
|
||||
|
||||
// Database custom color
|
||||
databaseCustomColorPref = findPreference(getString(R.string.database_custom_color_key))
|
||||
if (mDatabase.containsCustomColor()) {
|
||||
databaseCustomColorPref?.apply {
|
||||
try {
|
||||
color = Color.parseColor(mDatabase.color)
|
||||
summary = mDatabase.color
|
||||
} catch (e: Exception) {
|
||||
color = DISABLE_COLOR
|
||||
summary = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dbGeneralPrefCategory?.removePreference(databaseCustomColorPref)
|
||||
}
|
||||
|
||||
// Database compression
|
||||
findPreference<Preference>(getString(R.string.database_data_compression_key))
|
||||
?.summary = (mDatabase.compressionAlgorithm ?: PwCompressionAlgorithm.None).getName(resources)
|
||||
@@ -488,6 +519,27 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
}
|
||||
}
|
||||
|
||||
private val colorSelectedListener: ((Boolean, Int)-> Unit)? = { enable, color ->
|
||||
databaseCustomColorPref?.summary = ChromaUtil.getFormattedColorString(color, false)
|
||||
if (enable) {
|
||||
databaseCustomColorPref?.color = color
|
||||
} else {
|
||||
databaseCustomColorPref?.color = DISABLE_COLOR
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = super.onCreateView(inflater, container, savedInstanceState)
|
||||
|
||||
try {
|
||||
// To reassign color listener after orientation change
|
||||
val chromaDialog = fragmentManager?.findFragmentByTag(TAG_PREF_FRAGMENT) as DatabaseColorPreferenceDialogFragmentCompat?
|
||||
chromaDialog?.onColorSelectedListener = colorSelectedListener
|
||||
} catch (e: Exception) {}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onDisplayPreferenceDialog(preference: Preference?) {
|
||||
|
||||
var otherDialogFragment = false
|
||||
@@ -502,6 +554,14 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
preference.key == getString(R.string.database_description_key) -> {
|
||||
dialogFragment = DatabaseDescriptionPreferenceDialogFragmentCompat.newInstance(preference.key)
|
||||
}
|
||||
preference.key == getString(R.string.database_default_username_key) -> {
|
||||
dialogFragment = DatabaseDefaultUsernamePreferenceDialogFragmentCompat.newInstance(preference.key)
|
||||
}
|
||||
preference.key == getString(R.string.database_custom_color_key) -> {
|
||||
dialogFragment = DatabaseColorPreferenceDialogFragmentCompat.newInstance(preference.key).apply {
|
||||
onColorSelectedListener = colorSelectedListener
|
||||
}
|
||||
}
|
||||
preference.key == getString(R.string.database_data_compression_key) -> {
|
||||
dialogFragment = DatabaseDataCompressionPreferenceDialogFragmentCompat.newInstance(preference.key)
|
||||
}
|
||||
@@ -536,7 +596,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
|
||||
if (dialogFragment != null && !mDatabaseReadOnly) {
|
||||
dialogFragment.setTargetFragment(this, 0)
|
||||
dialogFragment.show(fragmentManager, null)
|
||||
dialogFragment.show(fragmentManager, TAG_PREF_FRAGMENT)
|
||||
}
|
||||
// Could not be handled here. Try with the super method.
|
||||
else if (otherDialogFragment) {
|
||||
@@ -560,6 +620,8 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
|
||||
|
||||
private const val TAG_KEY = "NESTED_KEY"
|
||||
|
||||
private const val TAG_PREF_FRAGMENT = "TAG_PREF_FRAGMENT"
|
||||
|
||||
private const val REQUEST_CODE_AUTOFILL = 5201
|
||||
|
||||
@JvmOverloads
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kunzisoft.keepass.settings.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import androidx.annotation.ColorInt
|
||||
import com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class DialogColorPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.dialogPreferenceStyle,
|
||||
defStyleRes: Int = defStyleAttr)
|
||||
: ChromaPreferenceCompat(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
override fun setSummary(summary: CharSequence?) {
|
||||
if (color == DISABLE_COLOR)
|
||||
super.setSummary("")
|
||||
else
|
||||
super.setSummary(summary)
|
||||
}
|
||||
|
||||
override fun getDialogLayoutResource(): Int {
|
||||
return R.layout.pref_dialog_input_color
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@ColorInt
|
||||
const val DISABLE_COLOR: Int = Color.TRANSPARENT
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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.settings.preferencedialogfragment
|
||||
|
||||
import android.app.Dialog
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.widget.CompoundButton
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.kunzisoft.androidclearchroma.ChromaUtil
|
||||
import com.kunzisoft.androidclearchroma.IndicatorMode
|
||||
import com.kunzisoft.androidclearchroma.colormode.ColorMode
|
||||
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment
|
||||
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment.*
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import java.lang.Exception
|
||||
|
||||
class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
|
||||
|
||||
private lateinit var rootView: View
|
||||
private lateinit var enableSwitchView: CompoundButton
|
||||
private var chromaColorFragment: ChromaColorFragment? = null
|
||||
|
||||
var onColorSelectedListener: ((enable: Boolean, color: Int) -> Unit)? = null
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
||||
val alertDialogBuilder = AlertDialog.Builder(activity!!)
|
||||
|
||||
rootView = activity!!.layoutInflater.inflate(R.layout.pref_dialog_input_color, null)
|
||||
enableSwitchView = rootView.findViewById(R.id.switch_element)
|
||||
|
||||
val fragmentManager = childFragmentManager
|
||||
chromaColorFragment = fragmentManager.findFragmentByTag(TAG_FRAGMENT_COLORS) as ChromaColorFragment?
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
|
||||
database?.let { database ->
|
||||
val initColor = try {
|
||||
enableSwitchView.isChecked = true
|
||||
Color.parseColor(database.color)
|
||||
} catch (e: Exception) {
|
||||
enableSwitchView.isChecked = false
|
||||
DEFAULT_COLOR
|
||||
}
|
||||
arguments?.putInt(ARG_INITIAL_COLOR, initColor)
|
||||
}
|
||||
|
||||
if (chromaColorFragment == null) {
|
||||
chromaColorFragment = newInstance(arguments)
|
||||
fragmentTransaction.add(com.kunzisoft.androidclearchroma.R.id.color_dialog_container, chromaColorFragment!!, TAG_FRAGMENT_COLORS).commit()
|
||||
}
|
||||
|
||||
alertDialogBuilder.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
val currentColor = chromaColorFragment!!.currentColor
|
||||
val customColorEnable = enableSwitchView.isChecked
|
||||
|
||||
onColorSelectedListener?.invoke(customColorEnable, currentColor)
|
||||
|
||||
database?.let { database ->
|
||||
val newColor = if (customColorEnable) {
|
||||
ChromaUtil.getFormattedColorString(currentColor, false)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
val oldColor = database.color
|
||||
database.color = newColor
|
||||
|
||||
actionInUIThreadAfterSaveDatabase = AfterColorSave(newColor, oldColor)
|
||||
}
|
||||
|
||||
super.onDialogClosed(true)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
alertDialogBuilder.setNegativeButton(android.R.string.cancel) { _, _ ->
|
||||
super.onDialogClosed(false)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
alertDialogBuilder.setView(rootView)
|
||||
|
||||
val dialog = alertDialogBuilder.create()
|
||||
// request a window without the title
|
||||
dialog.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
|
||||
dialog.setOnShowListener { measureLayout(it as Dialog) }
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new dimensions to dialog
|
||||
* @param ad dialog
|
||||
*/
|
||||
private fun measureLayout(ad: Dialog) {
|
||||
val typedValue = TypedValue()
|
||||
resources.getValue(com.kunzisoft.androidclearchroma.R.dimen.chroma_dialog_height_multiplier, typedValue, true)
|
||||
val heightMultiplier = typedValue.float
|
||||
val height = (ad.context.resources.displayMetrics.heightPixels * heightMultiplier).toInt()
|
||||
|
||||
resources.getValue(com.kunzisoft.androidclearchroma.R.dimen.chroma_dialog_width_multiplier, typedValue, true)
|
||||
val widthMultiplier = typedValue.float
|
||||
val width = (ad.context.resources.displayMetrics.widthPixels * widthMultiplier).toInt()
|
||||
|
||||
ad.window?.setLayout(width, height)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
return rootView
|
||||
}
|
||||
|
||||
private inner class AfterColorSave(private val mNewColor: String,
|
||||
private val mOldColor: String)
|
||||
: ActionRunnable() {
|
||||
|
||||
override fun onFinishRun(result: Result) {
|
||||
val defaultColorToShow =
|
||||
if (result.isSuccess) {
|
||||
mNewColor
|
||||
} else {
|
||||
database?.color = mOldColor
|
||||
mOldColor
|
||||
}
|
||||
preference.summary = defaultColorToShow
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG_FRAGMENT_COLORS = "TAG_FRAGMENT_COLORS"
|
||||
|
||||
@ColorInt
|
||||
const val DEFAULT_COLOR: Int = Color.WHITE
|
||||
|
||||
fun newInstance(key: String): DatabaseColorPreferenceDialogFragmentCompat {
|
||||
val fragment = DatabaseColorPreferenceDialogFragmentCompat()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString(ARG_KEY, key)
|
||||
bundle.putInt(ARG_INITIAL_COLOR, Color.BLACK)
|
||||
bundle.putInt(ARG_COLOR_MODE, ColorMode.RGB.ordinal)
|
||||
bundle.putInt(ARG_INDICATOR_MODE, IndicatorMode.HEX.ordinal)
|
||||
fragment.arguments = bundle
|
||||
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,9 +62,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
if (compressionSelected != null) {
|
||||
val newAlgorithm = compressionSelected
|
||||
val oldAlgorithm = database.compressionAlgorithm
|
||||
newAlgorithm?.let {
|
||||
database.assignCompressionAlgorithm(it)
|
||||
}
|
||||
database.compressionAlgorithm = newAlgorithm
|
||||
|
||||
if (oldAlgorithm != null && newAlgorithm != null)
|
||||
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newAlgorithm, oldAlgorithm)
|
||||
@@ -88,7 +86,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
|
||||
if (result.isSuccess) {
|
||||
mNewAlgorithm
|
||||
} else {
|
||||
database?.assignCompressionAlgorithm(mOldAlgorithm)
|
||||
database?.compressionAlgorithm = mOldAlgorithm
|
||||
mOldAlgorithm
|
||||
}
|
||||
preference.summary = algorithmToShow.getName(settingsResources)
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.settings.preferencedialogfragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
|
||||
class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
|
||||
inputText = database?.defaultUsername?: ""
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
database?.let { database ->
|
||||
if (positiveResult) {
|
||||
val newDefaultUsername = inputText
|
||||
val oldDefaultUsername = database.defaultUsername
|
||||
database.defaultUsername = newDefaultUsername
|
||||
|
||||
actionInUIThreadAfterSaveDatabase = AfterDefaultUsernameSave(newDefaultUsername, oldDefaultUsername)
|
||||
}
|
||||
}
|
||||
|
||||
super.onDialogClosed(positiveResult)
|
||||
}
|
||||
|
||||
private inner class AfterDefaultUsernameSave(private val mNewDefaultUsername: String,
|
||||
private val mOldDefaultUsername: String)
|
||||
: ActionRunnable() {
|
||||
|
||||
override fun onFinishRun(result: Result) {
|
||||
val defaultUsernameToShow =
|
||||
if (result.isSuccess) {
|
||||
mNewDefaultUsername
|
||||
} else {
|
||||
database?.defaultUsername = mOldDefaultUsername
|
||||
mOldDefaultUsername
|
||||
}
|
||||
preference.summary = defaultUsernameToShow
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(key: String): DatabaseDefaultUsernamePreferenceDialogFragmentCompat {
|
||||
val fragment = DatabaseDefaultUsernamePreferenceDialogFragmentCompat()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString(ARG_KEY, key)
|
||||
fragment.arguments = bundle
|
||||
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,14 @@ class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreference
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
if (database != null && positiveResult) {
|
||||
val newDescription = inputText
|
||||
val oldDescription = database!!.description
|
||||
database?.assignDescription(newDescription)
|
||||
database?.let { database ->
|
||||
if (positiveResult) {
|
||||
val newDescription = inputText
|
||||
val oldDescription = database.description
|
||||
database.description = newDescription
|
||||
|
||||
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newDescription, oldDescription)
|
||||
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newDescription, oldDescription)
|
||||
}
|
||||
}
|
||||
|
||||
super.onDialogClosed(positiveResult)
|
||||
@@ -52,7 +54,7 @@ class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreference
|
||||
if (result.isSuccess) {
|
||||
mNewDescription
|
||||
} else {
|
||||
database?.assignDescription(mOldDescription)
|
||||
database?.description = mOldDescription
|
||||
mOldDescription
|
||||
}
|
||||
preference.summary = descriptionToShow
|
||||
|
||||
@@ -63,9 +63,7 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
|
||||
if (algorithmSelected != null) {
|
||||
val newAlgorithm = algorithmSelected
|
||||
val oldAlgorithm = database.encryptionAlgorithm
|
||||
newAlgorithm?.let {
|
||||
database.assignEncryptionAlgorithm(it)
|
||||
}
|
||||
database.encryptionAlgorithm = newAlgorithm
|
||||
|
||||
if (oldAlgorithm != null && newAlgorithm != null)
|
||||
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newAlgorithm, oldAlgorithm)
|
||||
@@ -90,7 +88,7 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
|
||||
if (result.isSuccess) {
|
||||
mNewAlgorithm
|
||||
} else {
|
||||
database?.assignEncryptionAlgorithm(mOldAlgorithm)
|
||||
database?.encryptionAlgorithm = mOldAlgorithm
|
||||
mOldAlgorithm
|
||||
}
|
||||
preference.summary = algorithmToShow.getName(settingsResources)
|
||||
|
||||
@@ -66,7 +66,7 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
|
||||
val newKdfEngine = kdfEngineSelected
|
||||
val oldKdfEngine = database.kdfEngine
|
||||
if (newKdfEngine != null && oldKdfEngine != null) {
|
||||
database.assignKdfEngine(newKdfEngine)
|
||||
database.kdfEngine = newKdfEngine
|
||||
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newKdfEngine, oldKdfEngine)
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
|
||||
if (result.isSuccess) {
|
||||
mNewKdfEngine
|
||||
} else {
|
||||
database?.assignKdfEngine(mOldKdfEngine)
|
||||
database?.kdfEngine = mOldKdfEngine
|
||||
mOldKdfEngine
|
||||
}
|
||||
preference.summary = kdfEngineToShow.getName(settingsResources)
|
||||
|
||||
@@ -36,7 +36,7 @@ class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogF
|
||||
database?.let { database ->
|
||||
val newName = inputText
|
||||
val oldName = database.name
|
||||
database.assignName(newName)
|
||||
database.name = newName
|
||||
|
||||
actionInUIThreadAfterSaveDatabase = AfterNameSave(newName, oldName)
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogF
|
||||
if (result.isSuccess) {
|
||||
mNewName
|
||||
} else {
|
||||
database?.assignName(mOldName)
|
||||
database?.name = mOldName
|
||||
mOldName
|
||||
}
|
||||
preference.summary = nameToShow
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.kunzisoft.keepass.settings.preferencedialogfragment
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
@@ -36,10 +37,14 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialo
|
||||
|
||||
protected lateinit var settingsResources: Resources
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
this.database = Database.getInstance()
|
||||
}
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
|
||||
activity?.resources?.let { settingsResources = it }
|
||||
}
|
||||
|
||||
48
app/src/main/res/layout/pref_dialog_input_color.xml
Normal file
48
app/src/main/res/layout/pref_dialog_input_color.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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/>.
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/edit"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAutofill="noExcludeDescendants"
|
||||
tools:targetApi="o">
|
||||
<FrameLayout
|
||||
android:id="@+id/color_dialog_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switch_element"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp"
|
||||
android:text="@string/enable"
|
||||
android:background="@drawable/background_button_small"
|
||||
android:textColor="?attr/textColorInverse"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:minHeight="48dp"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -38,7 +38,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
|
||||
<androidx.appcompat.widget.AppCompatCheckBox
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switch_element"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
|
||||
<androidx.appcompat.widget.AppCompatCheckBox
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switch_element"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -36,20 +36,22 @@
|
||||
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
|
||||
<com.kunzisoft.keepass.settings.preference.DialogColorPreference
|
||||
xmlns:chroma="http://schemas.android.com/apk/res-auto"
|
||||
android:key="@string/database_custom_color_key"
|
||||
android:persistent="false"
|
||||
android:enabled="false"
|
||||
android:title="@string/database_custom_color_title"/>
|
||||
android:title="@string/database_custom_color_title"
|
||||
android:summary="[color]"
|
||||
chroma:chromaShapePreview="ROUNDED_SQUARE"
|
||||
chroma:chromaColorMode="RGB"
|
||||
chroma:chromaIndicatorMode="HEX" />
|
||||
<Preference
|
||||
android:key="@string/database_version_key"
|
||||
android:persistent="false"
|
||||
|
||||
@@ -19,5 +19,6 @@ allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user