mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
fix: Duplicate UUIDs dialog and state flow
This commit is contained in:
19 files changed
+136
-140
No files matched your search
@@ -36,6 +36,7 @@ import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
@@ -46,7 +47,6 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.DuplicateUuidDialog
|
||||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
|
||||
import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
@@ -258,6 +258,38 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
onDatabaseFileLoaded(databaseFile?.databaseUri, keyFileUri, hardwareKey)
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
mDatabaseFileViewModel.databaseFileState.collect { databaseFileState ->
|
||||
when (databaseFileState) {
|
||||
is DatabaseFileViewModel.DatabaseFileState.Loading -> {}
|
||||
is DatabaseFileViewModel.DatabaseFileState.ShowLoadDatabaseDuplicateUuidMessage -> {
|
||||
AlertDialog.Builder(this@MainCredentialActivity).apply {
|
||||
val message = getString(R.string.contains_duplicate_uuid) +
|
||||
"\n\n" + getString(R.string.contains_duplicate_uuid_procedure)
|
||||
setMessage(message)
|
||||
setPositiveButton(getString(android.R.string.ok)) { _, _ ->
|
||||
databaseFileState.databaseUri?.let { databaseFileUri ->
|
||||
mDatabaseViewModel.loadDatabase(
|
||||
databaseUri = databaseFileUri,
|
||||
mainCredential = databaseFileState.mainCredential,
|
||||
readOnly = databaseFileState.readOnly,
|
||||
allowUserVerification = databaseFileState.allowUserVerification,
|
||||
cipherEncryptDatabase = databaseFileState.cipherEncryptDatabase,
|
||||
fixDuplicateUuid = true
|
||||
)
|
||||
}
|
||||
}
|
||||
setNegativeButton(getString(android.R.string.cancel)) { _, _ -> }
|
||||
create().show()
|
||||
}
|
||||
mDatabaseFileViewModel.actionPerformed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@@ -357,35 +389,14 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
when (result.exception) {
|
||||
is DuplicateUuidDatabaseException -> {
|
||||
// Relaunch loading if we need to fix UUID
|
||||
showLoadDatabaseDuplicateUuidMessage {
|
||||
|
||||
var databaseUri: Uri? = null
|
||||
var mainCredential = MainCredential()
|
||||
var readOnly = true
|
||||
var allowUserVerification = true
|
||||
var cipherEncryptDatabase: CipherEncryptDatabase? = null
|
||||
|
||||
result.data?.let { resultData ->
|
||||
databaseUri = resultData.getParcelableCompat(DATABASE_URI_KEY)
|
||||
mainCredential =
|
||||
resultData.getParcelableCompat(MAIN_CREDENTIAL_KEY)
|
||||
?: mainCredential
|
||||
readOnly = resultData.getBoolean(READ_ONLY_KEY)
|
||||
allowUserVerification = resultData.getBoolean(USER_VERIFICATION_KEY)
|
||||
cipherEncryptDatabase =
|
||||
resultData.getParcelableCompat(CIPHER_DATABASE_KEY)
|
||||
}
|
||||
|
||||
databaseUri?.let { databaseFileUri ->
|
||||
showProgressDialogAndLoadDatabase(
|
||||
databaseFileUri,
|
||||
mainCredential,
|
||||
readOnly,
|
||||
allowUserVerification,
|
||||
cipherEncryptDatabase,
|
||||
true
|
||||
)
|
||||
}
|
||||
result.data?.let { resultData ->
|
||||
mDatabaseFileViewModel.showLoadDatabaseDuplicateUuidMessage(
|
||||
databaseUri = resultData.getParcelableCompat(DATABASE_URI_KEY),
|
||||
mainCredential = resultData.getParcelableCompat(MAIN_CREDENTIAL_KEY) ?: MainCredential(),
|
||||
readOnly = resultData.getBoolean(READ_ONLY_KEY),
|
||||
allowUserVerification = resultData.getBoolean(USER_VERIFICATION_KEY),
|
||||
cipherEncryptDatabase = resultData.getParcelableCompat(CIPHER_DATABASE_KEY)
|
||||
)
|
||||
}
|
||||
}
|
||||
is FileNotFoundDatabaseException -> {
|
||||
@@ -399,7 +410,7 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
}
|
||||
}
|
||||
coordinatorLayout.showActionErrorIfNeeded(result)
|
||||
result.data?.clear()
|
||||
result.clear()
|
||||
}
|
||||
|
||||
private fun getUriFromIntent(intent: Intent?) {
|
||||
@@ -577,8 +588,10 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearCredentialsViews(clearKeyFile: Boolean = !mRememberKeyFile,
|
||||
clearHardwareKey: Boolean = !mRememberHardwareKey) {
|
||||
private fun clearCredentialsViews(
|
||||
clearKeyFile: Boolean = !mRememberKeyFile,
|
||||
clearHardwareKey: Boolean = !mRememberHardwareKey
|
||||
) {
|
||||
mainCredentialView?.populatePasswordTextView(null)
|
||||
if (clearKeyFile) {
|
||||
mainCredentialView?.populateKeyFileView(null)
|
||||
@@ -619,42 +632,17 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
} else {
|
||||
databaseFileUri?.let { databaseUri ->
|
||||
// Show the progress dialog and load the database
|
||||
showProgressDialogAndLoadDatabase(
|
||||
databaseUri,
|
||||
mainCredential ?: MainCredential(),
|
||||
mReadOnly,
|
||||
mUserVerificationAllowed,
|
||||
cipherEncryptDatabase,
|
||||
false
|
||||
mDatabaseViewModel.loadDatabase(
|
||||
databaseUri = databaseUri,
|
||||
mainCredential = mainCredential ?: MainCredential(),
|
||||
readOnly = mReadOnly,
|
||||
allowUserVerification = mUserVerificationAllowed,
|
||||
cipherEncryptDatabase = cipherEncryptDatabase
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showProgressDialogAndLoadDatabase(
|
||||
databaseUri: Uri,
|
||||
mainCredential: MainCredential,
|
||||
readOnly: Boolean,
|
||||
allowUserVerification: Boolean,
|
||||
cipherEncryptDatabase: CipherEncryptDatabase?,
|
||||
fixDuplicateUUID: Boolean
|
||||
) {
|
||||
mDatabaseViewModel.loadDatabase(
|
||||
databaseUri,
|
||||
mainCredential,
|
||||
readOnly,
|
||||
allowUserVerification,
|
||||
cipherEncryptDatabase,
|
||||
fixDuplicateUUID
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLoadDatabaseDuplicateUuidMessage(loadDatabaseWithFix: (() -> Unit)? = null) {
|
||||
DuplicateUuidDialog().apply {
|
||||
positiveAction = loadDatabaseWithFix
|
||||
}.show(supportFragmentManager, "duplicateUUIDDialog")
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
val inflater = menuInflater
|
||||
// Read menu
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
* KeePassDX 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.
|
||||
*
|
||||
* KeePassDX 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 KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.activities.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class DuplicateUuidDialog : DialogFragment() {
|
||||
|
||||
var positiveAction: (() -> Unit)? = null
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
activity?.let { activity ->
|
||||
// Use the Builder class for convenient dialog construction
|
||||
val builder = AlertDialog.Builder(activity).apply {
|
||||
val message = getString(R.string.contains_duplicate_uuid) +
|
||||
"\n\n" + getString(R.string.contains_duplicate_uuid_procedure)
|
||||
setMessage(message)
|
||||
setPositiveButton(getString(android.R.string.ok)) { _, _ ->
|
||||
positiveAction?.invoke()
|
||||
dismiss()
|
||||
}
|
||||
setNegativeButton(getString(android.R.string.cancel)) { _, _ -> dismiss() }
|
||||
}
|
||||
// Create the AlertDialog object and return it
|
||||
return builder.create()
|
||||
}
|
||||
return super.onCreateDialog(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
this.dismiss()
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -31,6 +31,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
@@ -45,7 +46,7 @@ class AutofillLauncherViewModel(application: Application): CredentialLauncherVie
|
||||
private var mSwitchToMagikeyboard: Boolean = false
|
||||
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
fun initialize() {
|
||||
mLockDatabaseAfterSelection = PreferencesUtil.isAutofillCloseDatabaseEnable(getApplication())
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import com.kunzisoft.keepass.model.SearchInfo
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
abstract class CredentialLauncherViewModel(application: Application): AndroidViewModel(application) {
|
||||
@@ -25,7 +26,7 @@ abstract class CredentialLauncherViewModel(application: Application): AndroidVie
|
||||
protected var isResultLauncherRegistered: Boolean = false
|
||||
private var mSelectionResult: ActivityResult? = null
|
||||
protected val mCredentialUiState = MutableStateFlow<CredentialState>(CredentialState.Loading)
|
||||
val credentialUiState: StateFlow<CredentialState> = mCredentialUiState
|
||||
val credentialUiState: StateFlow<CredentialState> = mCredentialUiState.asStateFlow()
|
||||
|
||||
fun showError(error: Throwable) {
|
||||
Log.e(TAG, "Error on credential provider launch", error)
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
@@ -33,7 +34,7 @@ class EntrySelectionViewModel(application: Application): CredentialLauncherViewM
|
||||
private var searchShareForMagikeyboard: Boolean = false
|
||||
private var mLockDatabaseAfterSelection: Boolean = false
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
fun initialize() {
|
||||
searchShareForMagikeyboard = getApplication<Application>().isKeyboardActivatedInSettings()
|
||||
|
||||
+2
-1
@@ -12,11 +12,12 @@ import com.kunzisoft.keepass.database.ContextualDatabase
|
||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class HardwareKeyLauncherViewModel(application: Application): CredentialLauncherViewModel(application) {
|
||||
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
override suspend fun launchAction(
|
||||
intent: Intent,
|
||||
|
||||
+2
-1
@@ -50,6 +50,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
@@ -69,7 +70,7 @@ class PasskeyLauncherViewModel(application: Application): CredentialLauncherView
|
||||
private var mBackupState: Boolean = false
|
||||
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
fun initialize(userVerified: Boolean) {
|
||||
mLockDatabaseAfterSelection = PreferencesUtil.isPasskeyCloseDatabaseEnable(getApplication())
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
@@ -55,7 +56,7 @@ class PasswordLauncherViewModel(application: Application): CredentialLauncherVie
|
||||
private var mLockDatabaseAfterSelection: Boolean = false
|
||||
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
fun initialize() {
|
||||
mLockDatabaseAfterSelection = PreferencesUtil.isPasskeyCloseDatabaseEnable(getApplication())
|
||||
|
||||
+2
-1
@@ -13,13 +13,14 @@ import com.kunzisoft.keepass.credentialprovider.passkey.util.PrivilegedAllowList
|
||||
import com.kunzisoft.keepass.utils.AppUtil.getInstalledBrowsersWithSignatures
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
class PasskeysPrivilegedAppsViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||
val uiState: StateFlow<UiState> = _uiState
|
||||
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
||||
|
||||
fun retrievePrivilegedAppsToSelect() {
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -4,12 +4,13 @@ import androidx.lifecycle.ViewModel
|
||||
import com.kunzisoft.keepass.database.ProgressMessage
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
class ProgressTaskViewModel: ViewModel() {
|
||||
|
||||
private val mProgressTaskState = MutableStateFlow<ProgressTaskState>(ProgressTaskState.Hide)
|
||||
val progressTaskState: StateFlow<ProgressTaskState> = mProgressTaskState
|
||||
val progressTaskState: StateFlow<ProgressTaskState> = mProgressTaskState.asStateFlow()
|
||||
|
||||
fun show(value: ProgressMessage) {
|
||||
mProgressTaskState.update { currentState ->
|
||||
|
||||
@@ -7,10 +7,15 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.kunzisoft.keepass.app.App
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.database.MainCredential
|
||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||
import com.kunzisoft.keepass.model.DatabaseFile
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.utils.IOActionTask
|
||||
import com.kunzisoft.keepass.utils.parseUri
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class DatabaseFileViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
@@ -23,6 +28,9 @@ class DatabaseFileViewModel(application: Application) : AndroidViewModel(applica
|
||||
private val mIsDefaultDatabase = MutableLiveData<Boolean>()
|
||||
val isDefaultDatabase: LiveData<Boolean> = mIsDefaultDatabase
|
||||
|
||||
private val mDatabaseFileState = MutableStateFlow<DatabaseFileState>(DatabaseFileState.Loading)
|
||||
val databaseFileState: StateFlow<DatabaseFileState> = mDatabaseFileState.asStateFlow()
|
||||
|
||||
fun checkIfIsDefaultDatabase(databaseUri: Uri) {
|
||||
IOActionTask(
|
||||
{
|
||||
@@ -46,6 +54,26 @@ class DatabaseFileViewModel(application: Application) : AndroidViewModel(applica
|
||||
).execute()
|
||||
}
|
||||
|
||||
fun showLoadDatabaseDuplicateUuidMessage(
|
||||
databaseUri: Uri?,
|
||||
mainCredential: MainCredential,
|
||||
readOnly: Boolean,
|
||||
allowUserVerification: Boolean,
|
||||
cipherEncryptDatabase: CipherEncryptDatabase?
|
||||
) {
|
||||
mDatabaseFileState.value = DatabaseFileState.ShowLoadDatabaseDuplicateUuidMessage(
|
||||
databaseUri = databaseUri,
|
||||
mainCredential = mainCredential,
|
||||
readOnly = readOnly,
|
||||
allowUserVerification = allowUserVerification,
|
||||
cipherEncryptDatabase = cipherEncryptDatabase
|
||||
)
|
||||
}
|
||||
|
||||
fun actionPerformed() {
|
||||
mDatabaseFileState.value = DatabaseFileState.Loading
|
||||
}
|
||||
|
||||
private val mDatabaseFileLoaded = MutableLiveData<DatabaseFile>()
|
||||
val databaseFileLoaded: LiveData<DatabaseFile> = mDatabaseFileLoaded
|
||||
|
||||
@@ -56,4 +84,15 @@ class DatabaseFileViewModel(application: Application) : AndroidViewModel(applica
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DatabaseFileState {
|
||||
object Loading : DatabaseFileState()
|
||||
data class ShowLoadDatabaseDuplicateUuidMessage(
|
||||
var databaseUri: Uri? = null,
|
||||
var mainCredential: MainCredential = MainCredential(),
|
||||
var readOnly: Boolean = true,
|
||||
var allowUserVerification: Boolean = true,
|
||||
var cipherEncryptDatabase: CipherEncryptDatabase? = null
|
||||
) : DatabaseFileState()
|
||||
}
|
||||
}
|
||||
@@ -22,18 +22,19 @@ import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.util.UUID
|
||||
|
||||
class DatabaseViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private val mDatabaseState = MutableStateFlow<ContextualDatabase?>(null)
|
||||
val databaseState: StateFlow<ContextualDatabase?> = mDatabaseState
|
||||
val databaseState: StateFlow<ContextualDatabase?> = mDatabaseState.asStateFlow()
|
||||
|
||||
val database: ContextualDatabase?
|
||||
get() = databaseState.value
|
||||
|
||||
private val mActionState = MutableStateFlow<ActionState>(ActionState.Wait)
|
||||
val actionState: StateFlow<ActionState> = mActionState
|
||||
val actionState: StateFlow<ActionState> = mActionState.asStateFlow()
|
||||
|
||||
private var mDatabaseTaskProvider: DatabaseTaskProvider = DatabaseTaskProvider(
|
||||
context = application
|
||||
@@ -107,7 +108,7 @@ class DatabaseViewModel(application: Application): AndroidViewModel(application)
|
||||
readOnly: Boolean,
|
||||
allowUserVerification: Boolean,
|
||||
cipherEncryptDatabase: CipherEncryptDatabase?,
|
||||
fixDuplicateUuid: Boolean
|
||||
fixDuplicateUuid: Boolean = false
|
||||
) {
|
||||
mDatabaseTaskProvider.startDatabaseLoad(
|
||||
databaseUri,
|
||||
|
||||
@@ -24,6 +24,7 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -88,7 +89,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
||||
}
|
||||
|
||||
private val _uiState = MutableStateFlow(DeviceUnlockState())
|
||||
val uiState: StateFlow<DeviceUnlockState> = _uiState
|
||||
val uiState: StateFlow<DeviceUnlockState> = _uiState.asStateFlow()
|
||||
|
||||
init {
|
||||
AppLifecycleObserver.appJustLaunched
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.utils.IOActionTask
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.util.UUID
|
||||
|
||||
|
||||
@@ -92,7 +93,7 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
private val _onBinaryPreviewLoaded = SingleLiveEvent<AttachmentPosition>()
|
||||
|
||||
private val mEntryEditState = MutableStateFlow<EntryEditState>(EntryEditState.Loading)
|
||||
val entryEditState: StateFlow<EntryEditState> = mEntryEditState
|
||||
val entryEditState: StateFlow<EntryEditState> = mEntryEditState.asStateFlow()
|
||||
|
||||
val entryLoaded: Boolean
|
||||
get() = templatesEntry.value != null
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.kunzisoft.keepass.timeout.ClipboardHelper
|
||||
import com.kunzisoft.keepass.utils.IOActionTask
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.util.UUID
|
||||
|
||||
|
||||
@@ -78,7 +79,7 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
|
||||
private val _historySelected = SingleLiveEvent<EntryHistory>()
|
||||
|
||||
private val mEntryState = MutableStateFlow<EntryState>(EntryState.Loading)
|
||||
val entryState: StateFlow<EntryState> = mEntryState
|
||||
val entryState: StateFlow<EntryState> = mEntryState.asStateFlow()
|
||||
|
||||
fun loadDatabase(database: ContextualDatabase?) {
|
||||
loadEntry(database, mainEntryId, historyPosition)
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
||||
import com.kunzisoft.keepass.database.MainCredential
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/**
|
||||
* ViewModel for the Main Credential Dialog
|
||||
@@ -13,7 +14,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
class MainCredentialViewModel: ViewModel() {
|
||||
|
||||
private val mUiState = MutableStateFlow<UIState>(UIState.Loading)
|
||||
val uiState: StateFlow<UIState> = mUiState
|
||||
val uiState: StateFlow<UIState> = mUiState.asStateFlow()
|
||||
|
||||
fun validateMainCredential(
|
||||
databaseUri: Uri,
|
||||
|
||||
@@ -5,11 +5,12 @@ import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class SettingsViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private val mSettingsState = MutableStateFlow<SettingsState>(SettingsState.Wait)
|
||||
val settingsState: StateFlow<SettingsState> = mSettingsState
|
||||
val settingsState: StateFlow<SettingsState> = mSettingsState.asStateFlow()
|
||||
|
||||
|
||||
var dialogFragment: DialogFragment? = null
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.kunzisoft.keepass.database.exception.InvalidCredentialsDatabaseExcept
|
||||
import com.kunzisoft.keepass.utils.clear
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/**
|
||||
* ViewModel for the User Verification
|
||||
@@ -14,7 +15,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
class UserVerificationViewModel: ViewModel() {
|
||||
|
||||
private val mUVState = MutableStateFlow<UVState>(UVState.Loading)
|
||||
val userVerificationState: StateFlow<UVState> = mUVState
|
||||
val userVerificationState: StateFlow<UVState> = mUVState.asStateFlow()
|
||||
|
||||
var dataToVerify: UserVerificationData? = null
|
||||
|
||||
|
||||
@@ -78,10 +78,19 @@ abstract class ActionRunnable: Runnable {
|
||||
/**
|
||||
* Class to manage result from ActionRunnable
|
||||
*/
|
||||
data class Result(var isSuccess: Boolean = true,
|
||||
var message: String? = null,
|
||||
var exception: DatabaseException? = null,
|
||||
var data: Bundle? = null)
|
||||
data class Result(
|
||||
var isSuccess: Boolean = true,
|
||||
var message: String? = null,
|
||||
var exception: DatabaseException? = null,
|
||||
var data: Bundle? = null
|
||||
) {
|
||||
fun clear() {
|
||||
message = null
|
||||
exception = null
|
||||
data?.clear()
|
||||
data = null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ActionRunnable"
|
||||
|
||||
Reference in new issue
Block a user