Add setting updates for dialog thread

This commit is contained in:
J-Jamet
2019-10-18 13:44:28 +02:00
parent 2e58c2f1b3
commit 9d160db281
18 changed files with 492 additions and 392 deletions

View File

@@ -22,9 +22,11 @@ package com.kunzisoft.keepass.crypto.keyDerivation
import com.kunzisoft.keepass.database.ObjectNameResource import com.kunzisoft.keepass.database.ObjectNameResource
import java.io.IOException import java.io.IOException
import java.io.Serializable
import java.util.UUID import java.util.UUID
abstract class KdfEngine : ObjectNameResource { // TODO Parcelable
abstract class KdfEngine : ObjectNameResource, Serializable {
var uuid: UUID? = null var uuid: UUID? = null

View File

@@ -9,6 +9,7 @@ import android.os.Bundle
import android.os.IBinder import android.os.IBinder
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
import com.kunzisoft.keepass.database.element.* import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK
@@ -19,7 +20,18 @@ import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Compa
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_NODES_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_NODES_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_MOVE_NODES_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_MOVE_NODES_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COLOR_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COMPRESSION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DESCRIPTION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ENCRYPTION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ITERATIONS_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_NAME_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_PARALLELISM_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENTRY_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENTRY_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_GROUP_TASK import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_GROUP_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.getBundleFromListNodes import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.getBundleFromListNodes
@@ -172,6 +184,12 @@ class ProgressDialogThread(private val activity: FragmentActivity,
} }
} }
/*
----
Main methods
----
*/
fun startDatabaseCreate(databaseUri: Uri, fun startDatabaseCreate(databaseUri: Uri,
masterPasswordChecked: Boolean, masterPasswordChecked: Boolean,
masterPassword: String?, masterPassword: String?,
@@ -187,10 +205,6 @@ class ProgressDialogThread(private val activity: FragmentActivity,
, ACTION_DATABASE_CREATE_TASK) , ACTION_DATABASE_CREATE_TASK)
} }
fun startDatabaseSave() {
start(null, ACTION_DATABASE_SAVE_TASK)
}
fun startDatabaseLoad(databaseUri: Uri, fun startDatabaseLoad(databaseUri: Uri,
masterPassword: String?, masterPassword: String?,
keyFile: Uri?, keyFile: Uri?,
@@ -222,6 +236,12 @@ class ProgressDialogThread(private val activity: FragmentActivity,
, ACTION_DATABASE_ASSIGN_PASSWORD_TASK) , ACTION_DATABASE_ASSIGN_PASSWORD_TASK)
} }
/*
----
Nodes Actions
----
*/
fun startDatabaseCreateGroup(newGroup: GroupVersioned, fun startDatabaseCreateGroup(newGroup: GroupVersioned,
parent: GroupVersioned, parent: GroupVersioned,
save: Boolean) { save: Boolean) {
@@ -313,4 +333,124 @@ class ProgressDialogThread(private val activity: FragmentActivity,
save: Boolean) { save: Boolean) {
startDatabaseActionListNodes(ACTION_DATABASE_DELETE_NODES_TASK, nodesToDelete, null, save) startDatabaseActionListNodes(ACTION_DATABASE_DELETE_NODES_TASK, nodesToDelete, null, save)
} }
/*
-----------------
Main Settings
-----------------
*/
fun startDatabaseSaveName(oldName: String,
newName: String) {
start(Bundle().apply {
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldName)
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newName)
}
, ACTION_DATABASE_SAVE_NAME_TASK)
}
fun startDatabaseSaveDescription(oldDescription: String,
newDescription: String) {
start(Bundle().apply {
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldDescription)
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newDescription)
}
, ACTION_DATABASE_SAVE_DESCRIPTION_TASK)
}
fun startDatabaseSaveDefaultUsername(oldDefaultUsername: String,
newDefaultUsername: String) {
start(Bundle().apply {
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldDefaultUsername)
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newDefaultUsername)
}
, ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK)
}
fun startDatabaseSaveColor(oldColor: String,
newColor: String) {
start(Bundle().apply {
putString(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldColor)
putString(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newColor)
}
, ACTION_DATABASE_SAVE_COLOR_TASK)
}
fun startDatabaseSaveCompression(oldCompression: PwCompressionAlgorithm,
newCompression: PwCompressionAlgorithm) {
start(Bundle().apply {
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression)
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newCompression)
}
, ACTION_DATABASE_SAVE_COMPRESSION_TASK)
}
fun startDatabaseSaveMaxHistoryItems(oldMaxHistoryItems: Int,
newMaxHistoryItems: Int) {
start(Bundle().apply {
putInt(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMaxHistoryItems)
putInt(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMaxHistoryItems)
}
, ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK)
}
fun startDatabaseSaveMaxHistorySize(oldMaxHistorySize: Long,
newMaxHistorySize: Long) {
start(Bundle().apply {
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMaxHistorySize)
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMaxHistorySize)
}
, ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK)
}
/*
-------------------
Security Settings
-------------------
*/
fun startDatabaseSaveEncryption(oldEncryption: PwEncryptionAlgorithm,
newEncryption: PwEncryptionAlgorithm) {
start(Bundle().apply {
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldEncryption)
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newEncryption)
}
, ACTION_DATABASE_SAVE_ENCRYPTION_TASK)
}
fun startDatabaseSaveKeyDerivation(oldKeyDerivation: KdfEngine,
newKeyDerivation: KdfEngine) {
start(Bundle().apply {
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldKeyDerivation)
putSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newKeyDerivation)
}
, ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK)
}
fun startDatabaseSaveIterations(oldIterations: Long,
newIterations: Long) {
start(Bundle().apply {
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldIterations)
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newIterations)
}
, ACTION_DATABASE_SAVE_ITERATIONS_TASK)
}
fun startDatabaseSaveMemoryUsage(oldMemoryUsage: Long,
newMemoryUsage: Long) {
start(Bundle().apply {
putLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldMemoryUsage)
putLong(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newMemoryUsage)
}
, ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK)
}
fun startDatabaseSaveParallelism(oldParallelism: Int,
newParallelism: Int) {
start(Bundle().apply {
putInt(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldParallelism)
putInt(DatabaseTaskNotificationService.NEW_ELEMENT_KEY, newParallelism)
}
, ACTION_DATABASE_SAVE_PARALLELISM_TASK)
}
} }

View File

@@ -74,17 +74,8 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
val titleId: Int = when (intentAction) { val titleId: Int = when (intentAction) {
ACTION_DATABASE_CREATE_TASK -> R.string.creating_database ACTION_DATABASE_CREATE_TASK -> R.string.creating_database
ACTION_DATABASE_SAVE_TASK,
ACTION_DATABASE_ASSIGN_PASSWORD_TASK,
ACTION_DATABASE_CREATE_GROUP_TASK,
ACTION_DATABASE_UPDATE_GROUP_TASK,
ACTION_DATABASE_CREATE_ENTRY_TASK,
ACTION_DATABASE_UPDATE_ENTRY_TASK,
ACTION_DATABASE_COPY_NODES_TASK,
ACTION_DATABASE_MOVE_NODES_TASK,
ACTION_DATABASE_DELETE_NODES_TASK -> R.string.saving_database
ACTION_DATABASE_LOAD_TASK -> R.string.loading_database ACTION_DATABASE_LOAD_TASK -> R.string.loading_database
else -> R.string.loading_database else -> R.string.saving_database
} }
val messageId: Int? = when (intentAction) { val messageId: Int? = when (intentAction) {
ACTION_DATABASE_LOAD_TASK -> null ACTION_DATABASE_LOAD_TASK -> null
@@ -98,7 +89,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
val actionRunnable: ActionRunnable? = when (intentAction) { val actionRunnable: ActionRunnable? = when (intentAction) {
ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent) ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent)
ACTION_DATABASE_SAVE_TASK -> buildDatabaseSaveActionTask()
ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent) ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent)
ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent) ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent)
ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent) ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent)
@@ -108,22 +98,22 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
ACTION_DATABASE_COPY_NODES_TASK -> buildDatabaseCopyNodesActionTask(intent) ACTION_DATABASE_COPY_NODES_TASK -> buildDatabaseCopyNodesActionTask(intent)
ACTION_DATABASE_MOVE_NODES_TASK -> buildDatabaseMoveNodesActionTask(intent) ACTION_DATABASE_MOVE_NODES_TASK -> buildDatabaseMoveNodesActionTask(intent)
ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent) ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent)
ACTION_DATABASE_SAVE_NAME_TASK,
ACTION_DATABASE_SAVE_DESCRIPTION_TASK,
ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK,
ACTION_DATABASE_SAVE_COLOR_TASK,
ACTION_DATABASE_SAVE_COMPRESSION_TASK,
ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK,
ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK,
ACTION_DATABASE_SAVE_ENCRYPTION_TASK,
ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK,
ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK,
ACTION_DATABASE_SAVE_PARALLELISM_TASK,
ACTION_DATABASE_SAVE_ITERATIONS_TASK -> buildDatabaseSaveElementActionTask(intent)
else -> null else -> null
} }
when (intentAction) { actionRunnable?.let { actionRunnableNotNull ->
ACTION_DATABASE_CREATE_TASK,
ACTION_DATABASE_SAVE_TASK,
ACTION_DATABASE_LOAD_TASK,
ACTION_DATABASE_ASSIGN_PASSWORD_TASK,
ACTION_DATABASE_CREATE_GROUP_TASK,
ACTION_DATABASE_UPDATE_GROUP_TASK,
ACTION_DATABASE_CREATE_ENTRY_TASK,
ACTION_DATABASE_UPDATE_ENTRY_TASK,
ACTION_DATABASE_COPY_NODES_TASK,
ACTION_DATABASE_MOVE_NODES_TASK,
ACTION_DATABASE_DELETE_NODES_TASK -> {
// Assign elements for updates // Assign elements for updates
mTitleId = titleId mTitleId = titleId
mMessageId = messageId mMessageId = messageId
@@ -147,7 +137,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
}, { result -> }, { result ->
mActionTaskListeners.forEach { actionTaskListener -> mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onStopAction(intentAction, result) actionTaskListener.onStopAction(intentAction!!, result)
} }
sendBroadcast(Intent(DATABASE_STOP_TASK_ACTION)) sendBroadcast(Intent(DATABASE_STOP_TASK_ACTION))
@@ -155,12 +145,8 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
stopSelf() stopSelf()
} }
) )
actionRunnable?.let { actionRunnableNotNull ->
actionRunnableAsyncTask?.execute({ actionRunnableNotNull }) actionRunnableAsyncTask?.execute({ actionRunnableNotNull })
} }
}
else -> {}
}
return START_REDELIVER_INTENT return START_REDELIVER_INTENT
} }
@@ -221,12 +207,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
} }
} }
private fun buildDatabaseSaveActionTask(): ActionRunnable? {
return SaveDatabaseActionRunnable(this,
Database.getInstance(),
true)
}
private fun buildDatabaseLoadActionTask(intent: Intent): ActionRunnable? { private fun buildDatabaseLoadActionTask(intent: Intent): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY) if (intent.hasExtra(DATABASE_URI_KEY)
@@ -288,6 +268,16 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
} }
} }
private inner class AfterActionNodeRunnable : AfterActionNodeFinishRunnable() {
override fun onActionNodeFinish(actionNodeValues: ActionNodeValues) {
// TODO Encapsulate
val bundle = actionNodeValues.result.data ?: Bundle()
bundle.putBundle(OLD_NODES_KEY, getBundleFromListNodes(actionNodeValues.oldNodes))
bundle.putBundle(NEW_NODES_KEY, getBundleFromListNodes(actionNodeValues.newNodes))
actionNodeValues.result.data = bundle
}
}
private fun buildDatabaseCreateGroupActionTask(intent: Intent): ActionRunnable? { private fun buildDatabaseCreateGroupActionTask(intent: Intent): ActionRunnable? {
return if (intent.hasExtra(GROUP_KEY) return if (intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(PARENT_ID_KEY) && intent.hasExtra(PARENT_ID_KEY)
@@ -366,16 +356,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
} }
} }
private inner class AfterActionNodeRunnable : AfterActionNodeFinishRunnable() {
override fun onActionNodeFinish(actionNodeValues: ActionNodeValues) {
// TODO Encapsulate
val bundle = actionNodeValues.result.data ?: Bundle()
bundle.putBundle(OLD_NODES_KEY, getBundleFromListNodes(actionNodeValues.oldNodes))
bundle.putBundle(NEW_NODES_KEY, getBundleFromListNodes(actionNodeValues.newNodes))
actionNodeValues.result.data = bundle
}
}
private fun buildDatabaseCopyNodesActionTask(intent: Intent): ActionRunnable? { private fun buildDatabaseCopyNodesActionTask(intent: Intent): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY) return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY) && intent.hasExtra(ENTRIES_ID_KEY)
@@ -435,6 +415,17 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
} }
} }
private fun buildDatabaseSaveElementActionTask(intent: Intent): ActionRunnable? {
return SaveDatabaseActionRunnable(this,
Database.getInstance(),
true,
object: ActionRunnable() {
override fun onFinishRun(result: Result) {
result.data = intent.extras
}
})
}
private class ActionRunnableAsyncTask(private val progressTaskUpdater: ProgressTaskUpdater, private class ActionRunnableAsyncTask(private val progressTaskUpdater: ProgressTaskUpdater,
private val onPreExecute: () -> Unit, private val onPreExecute: () -> Unit,
private val onPostExecute: (result: ActionRunnable.Result) -> Unit) private val onPostExecute: (result: ActionRunnable.Result) -> Unit)
@@ -471,7 +462,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
const val DATABASE_TASK_WARNING_KEY = "DATABASE_TASK_WARNING_KEY" const val DATABASE_TASK_WARNING_KEY = "DATABASE_TASK_WARNING_KEY"
const val ACTION_DATABASE_CREATE_TASK = "ACTION_DATABASE_CREATE_TASK" const val ACTION_DATABASE_CREATE_TASK = "ACTION_DATABASE_CREATE_TASK"
const val ACTION_DATABASE_SAVE_TASK = "ACTION_DATABASE_SAVE_TASK"
const val ACTION_DATABASE_LOAD_TASK = "ACTION_DATABASE_LOAD_TASK" const val ACTION_DATABASE_LOAD_TASK = "ACTION_DATABASE_LOAD_TASK"
const val ACTION_DATABASE_ASSIGN_PASSWORD_TASK = "ACTION_DATABASE_ASSIGN_PASSWORD_TASK" const val ACTION_DATABASE_ASSIGN_PASSWORD_TASK = "ACTION_DATABASE_ASSIGN_PASSWORD_TASK"
const val ACTION_DATABASE_CREATE_GROUP_TASK = "ACTION_DATABASE_CREATE_GROUP_TASK" const val ACTION_DATABASE_CREATE_GROUP_TASK = "ACTION_DATABASE_CREATE_GROUP_TASK"
@@ -481,6 +471,18 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
const val ACTION_DATABASE_COPY_NODES_TASK = "ACTION_DATABASE_COPY_NODES_TASK" const val ACTION_DATABASE_COPY_NODES_TASK = "ACTION_DATABASE_COPY_NODES_TASK"
const val ACTION_DATABASE_MOVE_NODES_TASK = "ACTION_DATABASE_MOVE_NODES_TASK" const val ACTION_DATABASE_MOVE_NODES_TASK = "ACTION_DATABASE_MOVE_NODES_TASK"
const val ACTION_DATABASE_DELETE_NODES_TASK = "ACTION_DATABASE_DELETE_NODES_TASK" const val ACTION_DATABASE_DELETE_NODES_TASK = "ACTION_DATABASE_DELETE_NODES_TASK"
const val ACTION_DATABASE_SAVE_NAME_TASK = "ACTION_DATABASE_SAVE_NAME_TASK"
const val ACTION_DATABASE_SAVE_DESCRIPTION_TASK = "ACTION_DATABASE_SAVE_DESCRIPTION_TASK"
const val ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK = "ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK"
const val ACTION_DATABASE_SAVE_COLOR_TASK = "ACTION_DATABASE_SAVE_COLOR_TASK"
const val ACTION_DATABASE_SAVE_COMPRESSION_TASK = "ACTION_DATABASE_SAVE_COMPRESSION_TASK"
const val ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK = "ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK"
const val ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK = "ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK"
const val ACTION_DATABASE_SAVE_ENCRYPTION_TASK = "ACTION_DATABASE_SAVE_ENCRYPTION_TASK"
const val ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK = "ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK"
const val ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK = "ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK"
const val ACTION_DATABASE_SAVE_PARALLELISM_TASK = "ACTION_DATABASE_SAVE_PARALLELISM_TASK"
const val ACTION_DATABASE_SAVE_ITERATIONS_TASK = "ACTION_DATABASE_SAVE_ITERATIONS_TASK"
const val DATABASE_URI_KEY = "DATABASE_URI_KEY" const val DATABASE_URI_KEY = "DATABASE_URI_KEY"
const val MASTER_PASSWORD_CHECKED_KEY = "MASTER_PASSWORD_CHECKED_KEY" const val MASTER_PASSWORD_CHECKED_KEY = "MASTER_PASSWORD_CHECKED_KEY"
@@ -500,6 +502,8 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
const val SAVE_DATABASE_KEY = "SAVE_DATABASE_KEY" const val SAVE_DATABASE_KEY = "SAVE_DATABASE_KEY"
const val OLD_NODES_KEY = "OLD_NODES_KEY" const val OLD_NODES_KEY = "OLD_NODES_KEY"
const val NEW_NODES_KEY = "NEW_NODES_KEY" const val NEW_NODES_KEY = "NEW_NODES_KEY"
const val OLD_ELEMENT_KEY = "OLD_ELEMENT_KEY" // Warning type of this thing change every time
const val NEW_ELEMENT_KEY = "NEW_ELEMENT_KEY" // Warning type of this thing change every time
fun getListNodesFromBundle(database: Database, bundle: Bundle): List<NodeVersioned> { fun getListNodesFromBundle(database: Database, bundle: Bundle): List<NodeVersioned> {
val nodesAction = ArrayList<NodeVersioned>() val nodesAction = ArrayList<NodeVersioned>()

View File

@@ -47,13 +47,30 @@ import com.kunzisoft.keepass.activities.stylish.Stylish
import com.kunzisoft.keepass.app.database.CipherDatabaseAction import com.kunzisoft.keepass.app.database.CipherDatabaseAction
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.biometric.BiometricUnlockDatabaseHelper import com.kunzisoft.keepass.biometric.BiometricUnlockDatabaseHelper
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.PwCompressionAlgorithm import com.kunzisoft.keepass.database.element.PwCompressionAlgorithm
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
import com.kunzisoft.keepass.education.Education import com.kunzisoft.keepass.education.Education
import com.kunzisoft.keepass.icons.IconPackChooser import com.kunzisoft.keepass.icons.IconPackChooser
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COLOR_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_COMPRESSION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_DESCRIPTION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ENCRYPTION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_ITERATIONS_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_NAME_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_PARALLELISM_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.NEW_ELEMENT_KEY
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.OLD_ELEMENT_KEY
import com.kunzisoft.keepass.settings.preference.* import com.kunzisoft.keepass.settings.preference.*
import com.kunzisoft.keepass.settings.preference.DialogColorPreference.Companion.DISABLE_COLOR import com.kunzisoft.keepass.settings.preference.DialogColorPreference.Companion.DISABLE_COLOR
import com.kunzisoft.keepass.settings.preferencedialogfragment.* import com.kunzisoft.keepass.settings.preferencedialogfragment.*
import com.kunzisoft.keepass.tasks.ActionRunnable
class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener { class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener {
@@ -62,7 +79,15 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
private var mCount = 0 private var mCount = 0
private var dbNamePref: InputTextPreference? = null
private var dbDescriptionPref: InputTextPreference? = null
private var dbDefaultUsername: InputTextPreference? = null
private var dbCustomColorPref: DialogColorPreference? = null private var dbCustomColorPref: DialogColorPreference? = null
private var dbDataCompressionPref: Preference? = null
private var dbMaxHistoryItemsPref: InputNumberPreference? = null
private var dbMaxHistorySizePref: InputNumberPreference? = null
private var mEncryptionAlgorithmPref: DialogListExplanationPreference? = null
private var mKeyDerivationPref: DialogListExplanationPreference? = null
private var mRoundPref: InputKdfNumberPreference? = null private var mRoundPref: InputKdfNumberPreference? = null
private var mMemoryPref: InputKdfNumberPreference? = null private var mMemoryPref: InputKdfNumberPreference? = null
private var mParallelismPref: InputKdfNumberPreference? = null private var mParallelismPref: InputKdfNumberPreference? = null
@@ -349,7 +374,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
val dbGeneralPrefCategory: PreferenceCategory? = findPreference(getString(R.string.database_category_general_key)) val dbGeneralPrefCategory: PreferenceCategory? = findPreference(getString(R.string.database_category_general_key))
// Database name // Database name
val dbNamePref: InputTextPreference? = findPreference(getString(R.string.database_name_key)) dbNamePref = findPreference(getString(R.string.database_name_key))
if (mDatabase.allowName) { if (mDatabase.allowName) {
dbNamePref?.summary = mDatabase.name dbNamePref?.summary = mDatabase.name
} else { } else {
@@ -357,7 +382,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
} }
// Database description // Database description
val dbDescriptionPref: InputTextPreference? = findPreference(getString(R.string.database_description_key)) dbDescriptionPref = findPreference(getString(R.string.database_description_key))
if (mDatabase.allowDescription) { if (mDatabase.allowDescription) {
dbDescriptionPref?.summary = mDatabase.description dbDescriptionPref?.summary = mDatabase.description
} else { } else {
@@ -365,7 +390,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
} }
// Database default username // Database default username
val dbDefaultUsername: InputTextPreference? = findPreference(getString(R.string.database_default_username_key)) dbDefaultUsername = findPreference(getString(R.string.database_default_username_key))
if (mDatabase.allowDefaultUsername) { if (mDatabase.allowDefaultUsername) {
dbDefaultUsername?.summary = mDatabase.defaultUsername dbDefaultUsername?.summary = mDatabase.defaultUsername
} else { } else {
@@ -397,9 +422,9 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
val dbCompressionPrefCategory: PreferenceCategory? = findPreference(getString(R.string.database_category_compression_key)) val dbCompressionPrefCategory: PreferenceCategory? = findPreference(getString(R.string.database_category_compression_key))
// Database compression // Database compression
val databaseDataCompressionPref = findPreference<Preference>(getString(R.string.database_data_compression_key)) dbDataCompressionPref = findPreference(getString(R.string.database_data_compression_key))
if (mDatabase.allowDataCompression) { if (mDatabase.allowDataCompression) {
databaseDataCompressionPref?.summary = (mDatabase.compressionAlgorithm dbDataCompressionPref?.summary = (mDatabase.compressionAlgorithm
?: PwCompressionAlgorithm.None).getName(resources) ?: PwCompressionAlgorithm.None).getName(resources)
} else { } else {
dbCompressionPrefCategory?.isVisible = false dbCompressionPrefCategory?.isVisible = false
@@ -421,12 +446,14 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
?.isVisible = mDatabase.manageHistory == true ?.isVisible = mDatabase.manageHistory == true
// Max history items // Max history items
findPreference<InputNumberPreference>(getString(R.string.max_history_items_key)) dbMaxHistoryItemsPref = findPreference<InputNumberPreference>(getString(R.string.max_history_items_key))?.apply {
?.summary = mDatabase.historyMaxItems.toString() summary = mDatabase.historyMaxItems.toString()
}
// Max history size // Max history size
findPreference<InputNumberPreference>(getString(R.string.max_history_size_key)) dbMaxHistorySizePref = findPreference<InputNumberPreference>(getString(R.string.max_history_size_key))?.apply {
?.summary = mDatabase.historyMaxSize.toString() summary = mDatabase.historyMaxSize.toString()
}
} else { } else {
Log.e(javaClass.name, "Database isn't ready") Log.e(javaClass.name, "Database isn't ready")
@@ -438,24 +465,29 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
if (mDatabase.loaded) { if (mDatabase.loaded) {
// Encryption Algorithm // Encryption Algorithm
findPreference<DialogListExplanationPreference>(getString(R.string.encryption_algorithm_key)) mEncryptionAlgorithmPref = findPreference<DialogListExplanationPreference>(getString(R.string.encryption_algorithm_key))?.apply {
?.summary = mDatabase.getEncryptionAlgorithmName(resources) summary = mDatabase.getEncryptionAlgorithmName(resources)
}
// Key derivation function // Key derivation function
findPreference<DialogListExplanationPreference>(getString(R.string.key_derivation_function_key)) mKeyDerivationPref = findPreference<DialogListExplanationPreference>(getString(R.string.key_derivation_function_key))?.apply {
?.summary = mDatabase.getKeyDerivationName(resources) summary = mDatabase.getKeyDerivationName(resources)
}
// Round encryption // Round encryption
mRoundPref = findPreference(getString(R.string.transform_rounds_key)) mRoundPref = findPreference<InputKdfNumberPreference>(getString(R.string.transform_rounds_key))?.apply {
mRoundPref?.summary = mDatabase.numberKeyEncryptionRounds.toString() summary = mDatabase.numberKeyEncryptionRounds.toString()
}
// Memory Usage // Memory Usage
mMemoryPref = findPreference(getString(R.string.memory_usage_key)) mMemoryPref = findPreference<InputKdfNumberPreference>(getString(R.string.memory_usage_key))?.apply {
mMemoryPref?.summary = mDatabase.memoryUsage.toString() summary = mDatabase.memoryUsage.toString()
}
// Parallelism // Parallelism
mParallelismPref = findPreference(getString(R.string.parallelism_key)) mParallelismPref = findPreference<InputKdfNumberPreference>(getString(R.string.parallelism_key))?.apply {
mParallelismPref?.summary = mDatabase.parallelism.toString() summary = mDatabase.parallelism.toString()
}
} else { } else {
Log.e(javaClass.name, "Database isn't ready") Log.e(javaClass.name, "Database isn't ready")
} }
@@ -551,6 +583,178 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
return view return view
} }
fun onProgressDialogThreadResult(actionTask: String,
result: ActionRunnable.Result) {
result.data?.let { data ->
if (data.containsKey(OLD_ELEMENT_KEY)
&& data.containsKey(NEW_ELEMENT_KEY)) {
when (actionTask) {
/*
--------
Main preferences
--------
*/
ACTION_DATABASE_SAVE_NAME_TASK -> {
val oldName = data.getString(OLD_ELEMENT_KEY)!!
val newName = data.getString(NEW_ELEMENT_KEY)!!
val nameToShow =
if (result.isSuccess) {
newName
} else {
mDatabase.name = oldName
oldName
}
dbNamePref?.summary = nameToShow
}
ACTION_DATABASE_SAVE_DESCRIPTION_TASK -> {
val oldDescription = data.getString(OLD_ELEMENT_KEY)!!
val newDescription = data.getString(NEW_ELEMENT_KEY)!!
val descriptionToShow =
if (result.isSuccess) {
newDescription
} else {
mDatabase.description = oldDescription
oldDescription
}
dbDescriptionPref?.summary = descriptionToShow
}
ACTION_DATABASE_SAVE_DEFAULT_USERNAME_TASK -> {
val oldDefaultUsername = data.getString(OLD_ELEMENT_KEY)!!
val newDefaultUsername = data.getString(NEW_ELEMENT_KEY)!!
val defaultUsernameToShow =
if (result.isSuccess) {
newDefaultUsername
} else {
mDatabase.defaultUsername = oldDefaultUsername
oldDefaultUsername
}
dbDefaultUsername?.summary = defaultUsernameToShow
}
ACTION_DATABASE_SAVE_COLOR_TASK -> {
val oldColor = data.getString(OLD_ELEMENT_KEY)!!
val newColor = data.getString(NEW_ELEMENT_KEY)!!
val defaultColorToShow =
if (result.isSuccess) {
newColor
} else {
mDatabase.customColor = oldColor
oldColor
}
dbCustomColorPref?.summary = defaultColorToShow
}
ACTION_DATABASE_SAVE_COMPRESSION_TASK -> {
val oldCompression = data.getSerializable(OLD_ELEMENT_KEY) as PwCompressionAlgorithm
val newCompression = data.getSerializable(NEW_ELEMENT_KEY) as PwCompressionAlgorithm
val algorithmToShow =
if (result.isSuccess) {
newCompression
} else {
mDatabase.compressionAlgorithm = oldCompression
oldCompression
}
dbDataCompressionPref?.summary = algorithmToShow.getName(resources)
}
ACTION_DATABASE_SAVE_MAX_HISTORY_ITEMS_TASK -> {
val oldMaxHistoryItems = data.getInt(OLD_ELEMENT_KEY)
val newMaxHistoryItems = data.getInt(NEW_ELEMENT_KEY)
val maxHistoryItemsToShow =
if (result.isSuccess) {
newMaxHistoryItems
} else {
mDatabase.historyMaxItems = oldMaxHistoryItems
oldMaxHistoryItems
}
dbMaxHistoryItemsPref?.summary = maxHistoryItemsToShow.toString()
}
ACTION_DATABASE_SAVE_MAX_HISTORY_SIZE_TASK -> {
val oldMaxHistorySize = data.getLong(OLD_ELEMENT_KEY)
val newMaxHistorySize = data.getLong(NEW_ELEMENT_KEY)
val maxHistorySizeToShow =
if (result.isSuccess) {
newMaxHistorySize
} else {
mDatabase.historyMaxSize = oldMaxHistorySize
oldMaxHistorySize
}
dbMaxHistorySizePref?.summary = maxHistorySizeToShow.toString()
}
/*
--------
Security
--------
*/
ACTION_DATABASE_SAVE_ENCRYPTION_TASK -> {
val oldEncryption = data.getSerializable(OLD_ELEMENT_KEY) as PwEncryptionAlgorithm
val newEncryption = data.getSerializable(NEW_ELEMENT_KEY) as PwEncryptionAlgorithm
val algorithmToShow =
if (result.isSuccess) {
newEncryption
} else {
mDatabase.encryptionAlgorithm = oldEncryption
oldEncryption
}
mEncryptionAlgorithmPref?.summary = algorithmToShow.getName(resources)
}
ACTION_DATABASE_SAVE_KEY_DERIVATION_TASK -> {
val oldKeyDerivationEngine = data.getSerializable(OLD_ELEMENT_KEY) as KdfEngine
val newKeyDerivationEngine = data.getSerializable(NEW_ELEMENT_KEY) as KdfEngine
val kdfEngineToShow =
if (result.isSuccess) {
newKeyDerivationEngine
} else {
mDatabase.kdfEngine = oldKeyDerivationEngine
oldKeyDerivationEngine
}
mKeyDerivationPref?.summary = kdfEngineToShow.getName(resources)
mRoundPref?.summary = kdfEngineToShow.defaultKeyRounds.toString()
// Disable memory and parallelism if not available
mMemoryPref?.summary = kdfEngineToShow.defaultMemoryUsage.toString()
mParallelismPref?.summary = kdfEngineToShow.defaultParallelism.toString()
}
ACTION_DATABASE_SAVE_ITERATIONS_TASK -> {
val oldIterations = data.getLong(OLD_ELEMENT_KEY)
val newIterations = data.getLong(NEW_ELEMENT_KEY)
val roundsToShow =
if (result.isSuccess) {
newIterations
} else {
mDatabase.numberKeyEncryptionRounds = oldIterations
oldIterations
}
mRoundPref?.summary = roundsToShow.toString()
}
ACTION_DATABASE_SAVE_MEMORY_USAGE_TASK -> {
val oldMemoryUsage = data.getLong(OLD_ELEMENT_KEY)
val newMemoryUsage = data.getLong(NEW_ELEMENT_KEY)
val memoryToShow =
if (result.isSuccess) {
newMemoryUsage
} else {
mDatabase.memoryUsage = oldMemoryUsage
oldMemoryUsage
}
mMemoryPref?.summary = memoryToShow.toString()
}
ACTION_DATABASE_SAVE_PARALLELISM_TASK -> {
val oldParallelism = data.getInt(OLD_ELEMENT_KEY)
val newParallelism = data.getInt(NEW_ELEMENT_KEY)
val parallelismToShow =
if (result.isSuccess) {
newParallelism
} else {
mDatabase.parallelism = oldParallelism
oldParallelism
}
mParallelismPref?.summary = parallelismToShow.toString()
}
}
}
}
}
override fun onDisplayPreferenceDialog(preference: Preference?) { override fun onDisplayPreferenceDialog(preference: Preference?) {
var otherDialogFragment = false var otherDialogFragment = false
@@ -559,6 +763,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
preference?.let { preference -> preference?.let { preference ->
var dialogFragment: DialogFragment? = null var dialogFragment: DialogFragment? = null
when { when {
// Main Preferences
preference.key == getString(R.string.database_name_key) -> { preference.key == getString(R.string.database_name_key) -> {
dialogFragment = DatabaseNamePreferenceDialogFragmentCompat.newInstance(preference.key) dialogFragment = DatabaseNamePreferenceDialogFragmentCompat.newInstance(preference.key)
} }
@@ -582,6 +787,8 @@ class NestedSettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferen
preference.key == getString(R.string.max_history_size_key) -> { preference.key == getString(R.string.max_history_size_key) -> {
dialogFragment = MaxHistorySizePreferenceDialogFragmentCompat.newInstance(preference.key) dialogFragment = MaxHistorySizePreferenceDialogFragmentCompat.newInstance(preference.key)
} }
// Security
preference.key == getString(R.string.encryption_algorithm_key) -> { preference.key == getString(R.string.encryption_algorithm_key) -> {
dialogFragment = DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.newInstance(preference.key) dialogFragment = DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.newInstance(preference.key)
} }

View File

@@ -26,7 +26,6 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
@@ -36,8 +35,6 @@ import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
import com.kunzisoft.keepass.activities.lock.LockingActivity import com.kunzisoft.keepass.activities.lock.LockingActivity
import com.kunzisoft.keepass.database.action.ProgressDialogThread import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK
import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE_TASK
import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.timeout.TimeoutHelper
open class SettingsActivity open class SettingsActivity
@@ -94,18 +91,10 @@ open class SettingsActivity
backupManager = BackupManager(this) backupManager = BackupManager(this)
progressDialogThread = ProgressDialogThread(this) { actionTask, result -> progressDialogThread = ProgressDialogThread(this) { actionTask, result ->
when (actionTask) { // Call result in fragment
ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> { (supportFragmentManager
// Nothing here .findFragmentByTag(TAG_NESTED) as NestedSettingsFragment?)
} ?.onProgressDialogThreadResult(actionTask, result)
ACTION_DATABASE_SAVE_TASK -> {
if (!result.isSuccess) {
// TODO Log.e(TAG, result.message)
Toast.makeText(this, result.message, Toast.LENGTH_SHORT).show()
}
// TODO actionAfterSaveDatabase?.onFinishRun(result)
}
}
} }
} }
@@ -135,7 +124,10 @@ open class SettingsActivity
super.onStop() super.onStop()
} }
override fun onAssignKeyDialogPositiveClick(masterPasswordChecked: Boolean, masterPassword: String?, keyFileChecked: Boolean, keyFile: Uri?) { override fun onAssignKeyDialogPositiveClick(masterPasswordChecked: Boolean,
masterPassword: String?,
keyFileChecked: Boolean,
keyFile: Uri?) {
Database.getInstance().let { database -> Database.getInstance().let { database ->
// Show the progress dialog now or after dialog confirmation // Show the progress dialog now or after dialog confirmation
if (database.validatePasswordEncoding(masterPassword, keyFileChecked)) { if (database.validatePasswordEncoding(masterPassword, keyFileChecked)) {
@@ -161,7 +153,10 @@ open class SettingsActivity
} }
} }
override fun onAssignKeyDialogNegativeClick(masterPasswordChecked: Boolean, masterPassword: String?, keyFileChecked: Boolean, keyFile: Uri?) { override fun onAssignKeyDialogNegativeClick(masterPasswordChecked: Boolean,
masterPassword: String?,
keyFileChecked: Boolean,
keyFile: Uri?) {
} }

View File

@@ -36,7 +36,6 @@ import com.kunzisoft.androidclearchroma.colormode.ColorMode
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment
import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment.* import com.kunzisoft.androidclearchroma.fragment.ChromaColorFragment.*
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
import java.lang.Exception import java.lang.Exception
class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -88,16 +87,15 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
} }
val oldColor = database.customColor val oldColor = database.customColor
database.customColor = newColor database.customColor = newColor
progressDialogThread?.startDatabaseSaveColor(oldColor, newColor)
actionInUIThreadAfterSaveDatabase = AfterColorSave(newColor, oldColor)
} }
super.onDialogClosed(true) onDialogClosed(true)
dismiss() dismiss()
} }
alertDialogBuilder.setNegativeButton(android.R.string.cancel) { _, _ -> alertDialogBuilder.setNegativeButton(android.R.string.cancel) { _, _ ->
super.onDialogClosed(false) onDialogClosed(false)
dismiss() dismiss()
} }
@@ -112,6 +110,10 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
return dialog return dialog
} }
override fun onDialogClosed(positiveResult: Boolean) {
// Nothing here
}
/** /**
* Set new dimensions to dialog * Set new dimensions to dialog
* @param ad dialog * @param ad dialog
@@ -134,22 +136,6 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
return rootView 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?.customColor = mOldColor
mOldColor
}
preference.summary = defaultColorToShow
}
}
companion object { companion object {
private const val TAG_FRAGMENT_COLORS = "TAG_FRAGMENT_COLORS" private const val TAG_FRAGMENT_COLORS = "TAG_FRAGMENT_COLORS"

View File

@@ -26,7 +26,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.PwCompressionAlgorithm import com.kunzisoft.keepass.database.element.PwCompressionAlgorithm
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseDataCompressionPreferenceDialogFragmentCompat class DatabaseDataCompressionPreferenceDialogFragmentCompat
: DatabaseSavePreferenceDialogFragmentCompat(), : DatabaseSavePreferenceDialogFragmentCompat(),
@@ -60,39 +59,21 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
if (positiveResult) { if (positiveResult) {
database?.let { database -> database?.let { database ->
if (compressionSelected != null) { if (compressionSelected != null) {
val newAlgorithm = compressionSelected val newCompression = compressionSelected
val oldAlgorithm = database.compressionAlgorithm val oldCompression = database.compressionAlgorithm
database.compressionAlgorithm = newAlgorithm database.compressionAlgorithm = newCompression
if (oldAlgorithm != null && newAlgorithm != null) if (oldCompression != null && newCompression != null)
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newAlgorithm, oldAlgorithm) progressDialogThread?.startDatabaseSaveCompression(oldCompression, newCompression)
} }
} }
} }
super.onDialogClosed(positiveResult)
} }
override fun onItemSelected(item: PwCompressionAlgorithm) { override fun onItemSelected(item: PwCompressionAlgorithm) {
this.compressionSelected = item this.compressionSelected = item
} }
private inner class AfterDescriptionSave(private val mNewAlgorithm: PwCompressionAlgorithm,
private val mOldAlgorithm: PwCompressionAlgorithm)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val algorithmToShow =
if (result.isSuccess) {
mNewAlgorithm
} else {
database?.compressionAlgorithm = mOldAlgorithm
mOldAlgorithm
}
preference.summary = algorithmToShow.getName(settingsResources)
}
}
companion object { companion object {
fun newInstance(key: String): DatabaseDataCompressionPreferenceDialogFragmentCompat { fun newInstance(key: String): DatabaseDataCompressionPreferenceDialogFragmentCompat {

View File

@@ -21,7 +21,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -38,27 +37,9 @@ class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePrefer
val oldDefaultUsername = database.defaultUsername val oldDefaultUsername = database.defaultUsername
database.defaultUsername = newDefaultUsername database.defaultUsername = newDefaultUsername
actionInUIThreadAfterSaveDatabase = AfterDefaultUsernameSave(newDefaultUsername, oldDefaultUsername) progressDialogThread?.startDatabaseSaveDefaultUsername(oldDefaultUsername, newDefaultUsername)
} }
} }
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 { companion object {

View File

@@ -21,7 +21,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -38,27 +37,9 @@ class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreference
val oldDescription = database.description val oldDescription = database.description
database.description = newDescription database.description = newDescription
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newDescription, oldDescription) progressDialogThread?.startDatabaseSaveDescription(oldDescription, newDescription)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterDescriptionSave(private val mNewDescription: String,
private val mOldDescription: String)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val descriptionToShow =
if (result.isSuccess) {
mNewDescription
} else {
database?.description = mOldDescription
mOldDescription
}
preference.summary = descriptionToShow
}
} }
companion object { companion object {

View File

@@ -26,7 +26,6 @@ import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm import com.kunzisoft.keepass.database.element.PwEncryptionAlgorithm
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
: DatabaseSavePreferenceDialogFragmentCompat(), : DatabaseSavePreferenceDialogFragmentCompat(),
@@ -66,35 +65,17 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
database.encryptionAlgorithm = newAlgorithm database.encryptionAlgorithm = newAlgorithm
if (oldAlgorithm != null && newAlgorithm != null) if (oldAlgorithm != null && newAlgorithm != null)
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newAlgorithm, oldAlgorithm) progressDialogThread?.startDatabaseSaveEncryption(oldAlgorithm, newAlgorithm)
} }
} }
} }
} }
super.onDialogClosed(positiveResult)
} }
override fun onItemSelected(item: PwEncryptionAlgorithm) { override fun onItemSelected(item: PwEncryptionAlgorithm) {
this.algorithmSelected = item this.algorithmSelected = item
} }
private inner class AfterDescriptionSave(private val mNewAlgorithm: PwEncryptionAlgorithm,
private val mOldAlgorithm: PwEncryptionAlgorithm)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val algorithmToShow =
if (result.isSuccess) {
mNewAlgorithm
} else {
database?.encryptionAlgorithm = mOldAlgorithm
mOldAlgorithm
}
preference.summary = algorithmToShow.getName(settingsResources)
}
}
companion object { companion object {
fun newInstance(key: String): DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat { fun newInstance(key: String): DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat {

View File

@@ -27,7 +27,6 @@ import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseKeyDerivationPreferenceDialogFragmentCompat class DatabaseKeyDerivationPreferenceDialogFragmentCompat
: DatabaseSavePreferenceDialogFragmentCompat(), : DatabaseSavePreferenceDialogFragmentCompat(),
@@ -67,13 +66,11 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
val oldKdfEngine = database.kdfEngine val oldKdfEngine = database.kdfEngine
if (newKdfEngine != null && oldKdfEngine != null) { if (newKdfEngine != null && oldKdfEngine != null) {
database.kdfEngine = newKdfEngine database.kdfEngine = newKdfEngine
actionInUIThreadAfterSaveDatabase = AfterDescriptionSave(newKdfEngine, oldKdfEngine) progressDialogThread?.startDatabaseSaveKeyDerivation(oldKdfEngine, newKdfEngine)
} }
} }
} }
} }
super.onDialogClosed(positiveResult)
} }
fun setRoundPreference(preference: Preference?) { fun setRoundPreference(preference: Preference?) {
@@ -92,27 +89,6 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
kdfEngineSelected = item kdfEngineSelected = item
} }
private inner class AfterDescriptionSave(private val mNewKdfEngine: KdfEngine,
private val mOldKdfEngine: KdfEngine)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val kdfEngineToShow =
if (result.isSuccess) {
mNewKdfEngine
} else {
database?.kdfEngine = mOldKdfEngine
mOldKdfEngine
}
preference.summary = kdfEngineToShow.getName(settingsResources)
roundPreference?.summary = kdfEngineToShow.defaultKeyRounds.toString()
// Disable memory and parallelism if not available
memoryPreference?.summary = kdfEngineToShow.defaultMemoryUsage.toString()
parallelismPreference?.summary = kdfEngineToShow.defaultParallelism.toString()
}
}
companion object { companion object {
fun newInstance(key: String): DatabaseKeyDerivationPreferenceDialogFragmentCompat { fun newInstance(key: String): DatabaseKeyDerivationPreferenceDialogFragmentCompat {

View File

@@ -21,7 +21,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -38,27 +37,9 @@ class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogF
val oldName = database.name val oldName = database.name
database.name = newName database.name = newName
actionInUIThreadAfterSaveDatabase = AfterNameSave(newName, oldName) progressDialogThread?.startDatabaseSaveName(oldName, newName)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterNameSave(private val mNewName: String,
private val mOldName: String)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val nameToShow =
if (result.isSuccess) {
mNewName
} else {
database?.name = mOldName
mOldName
}
preference.summary = nameToShow
}
} }
companion object { companion object {

View File

@@ -19,20 +19,17 @@
*/ */
package com.kunzisoft.keepass.settings.preferencedialogfragment package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.content.res.Resources import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.View import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.settings.SettingsActivity import com.kunzisoft.keepass.settings.SettingsActivity
import com.kunzisoft.keepass.tasks.ActionRunnable
abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialogFragmentCompat() { abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialogFragmentCompat() {
protected var database: Database? = null protected var database: Database? = null
var actionInUIThreadAfterSaveDatabase: ActionRunnable? = null protected var progressDialogThread: ProgressDialogThread? = null
protected lateinit var settingsResources: Resources
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -40,33 +37,15 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialo
this.database = Database.getInstance() this.database = Database.getInstance()
} }
override fun onBindDialogView(view: View) { override fun onAttach(context: Context) {
super.onBindDialogView(view) super.onAttach(context)
// Attach dialog thread to start action
activity?.resources?.let { settingsResources = it } if (context is SettingsActivity) {
progressDialogThread = context.progressDialogThread
} }
override fun onDialogClosed(positiveResult: Boolean) {
if (positiveResult) {
registerActionFinish()
(activity as SettingsActivity?)?.progressDialogThread?.startDatabaseSave()
}
}
fun registerActionFinish() {
// TODO remove receiver
// Register a database task receiver to stop loading dialog when service finish the task
/*
when (intent?.action) {
DATABASE_STOP_TASK_ACTION -> {
actionInUIThreadAfterSaveDatabase?.onFinishRun(result)
}
}
*/
} }
companion object { companion object {
private const val TAG = "DbSavePrefDialog" private const val TAG = "DbSavePrefDialog"
} }
} }

View File

@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
class MaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class MaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -57,27 +56,9 @@ class MaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDial
val oldMaxHistoryItems = database.historyMaxItems val oldMaxHistoryItems = database.historyMaxItems
database.historyMaxItems = maxHistoryItems database.historyMaxItems = maxHistoryItems
actionInUIThreadAfterSaveDatabase = AfterMaxHistoryItemsSave(maxHistoryItems, oldMaxHistoryItems) progressDialogThread?.startDatabaseSaveMaxHistoryItems(oldMaxHistoryItems, maxHistoryItems)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterMaxHistoryItemsSave(private val mNewMaxHistoryItems: Int,
private val mOldMaxHistoryItems: Int)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val maxHistoryItemsToShow =
if (result.isSuccess) {
mNewMaxHistoryItems
} else {
database?.historyMaxItems = mOldMaxHistoryItems
mOldMaxHistoryItems
}
preference.summary = maxHistoryItemsToShow.toString()
}
} }
companion object { companion object {

View File

@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
class MaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class MaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -57,27 +56,9 @@ class MaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialo
val oldMaxHistorySize = database.historyMaxSize val oldMaxHistorySize = database.historyMaxSize
database.historyMaxSize = maxHistorySize database.historyMaxSize = maxHistorySize
actionInUIThreadAfterSaveDatabase = AfterMaxHistorySizeSave(maxHistorySize, oldMaxHistorySize) progressDialogThread?.startDatabaseSaveMaxHistorySize(oldMaxHistorySize, maxHistorySize)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterMaxHistorySizeSave(private val mNewMaxHistorySize: Long,
private val mOldMaxHistorySize: Long)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val maxHistorySizeToShow =
if (result.isSuccess) {
mNewMaxHistorySize
} else {
database?.historyMaxSize = mOldMaxHistorySize
mOldMaxHistorySize
}
preference.summary = maxHistorySizeToShow.toString()
}
} }
companion object { companion object {

View File

@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
class MemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class MemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -49,27 +48,9 @@ class MemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFr
val oldMemoryUsage = database.memoryUsage val oldMemoryUsage = database.memoryUsage
database.memoryUsage = memoryUsage database.memoryUsage = memoryUsage
actionInUIThreadAfterSaveDatabase = AfterMemorySave(memoryUsage, oldMemoryUsage) progressDialogThread?.startDatabaseSaveMemoryUsage(oldMemoryUsage, memoryUsage)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterMemorySave(private val mNewMemory: Long,
private val mOldMemory: Long)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val memoryToShow =
if (result.isSuccess) {
mNewMemory
} else {
database?.memoryUsage = mOldMemory
mOldMemory
}
preference.summary = memoryToShow.toString()
}
} }
companion object { companion object {

View File

@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.settings.preferencedialogfragment
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
class ParallelismPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class ParallelismPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -49,27 +48,9 @@ class ParallelismPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFr
val oldParallelism = database.parallelism val oldParallelism = database.parallelism
database.parallelism = parallelism database.parallelism = parallelism
actionInUIThreadAfterSaveDatabase = AfterParallelismSave(parallelism, oldParallelism) progressDialogThread?.startDatabaseSaveParallelism(oldParallelism, parallelism)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterParallelismSave(private val mNewParallelism: Int,
private val mOldParallelism: Int)
: ActionRunnable() {
override fun onFinishRun(result: Result) {
val parallelismToShow =
if (result.isSuccess) {
mNewParallelism
} else {
database?.parallelism = mOldParallelism
mOldParallelism
}
preference.summary = parallelismToShow.toString()
}
} }
companion object { companion object {

View File

@@ -23,7 +23,6 @@ import android.os.Bundle
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.tasks.ActionRunnable
class RoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() { class RoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat() {
@@ -55,26 +54,9 @@ class RoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmen
database.numberKeyEncryptionRounds = Long.MAX_VALUE database.numberKeyEncryptionRounds = Long.MAX_VALUE
} }
actionInUIThreadAfterSaveDatabase = AfterRoundSave(rounds, oldRounds) progressDialogThread?.startDatabaseSaveIterations(oldRounds, rounds)
} }
} }
super.onDialogClosed(positiveResult)
}
private inner class AfterRoundSave(private val mNewRounds: Long,
private val mOldRounds: Long) : ActionRunnable() {
override fun onFinishRun(result: Result) {
val roundsToShow =
if (result.isSuccess) {
mNewRounds
} else {
database?.numberKeyEncryptionRounds = mOldRounds
mOldRounds
}
preference.summary = roundsToShow.toString()
}
} }
companion object { companion object {