mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
fix: Credential allow action during orientation change #2253
This commit is contained in:
@@ -59,12 +59,17 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful to only waiting for the activity result and prevent any parallel action
|
||||||
|
*/
|
||||||
|
var credentialResultLaunched = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility activity result launcher,
|
* Utility activity result launcher,
|
||||||
* Used recursively, close each activity with return data
|
* Used recursively, close each activity with return data
|
||||||
*/
|
*/
|
||||||
protected var mCredentialActivityResultLauncher: DatabaseActivityResultLauncher =
|
protected var mCredentialActivityResultLauncher: CredentialActivityResultLauncher =
|
||||||
DatabaseActivityResultLauncher(
|
CredentialActivityResultLauncher(
|
||||||
registerForActivityResult(
|
registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
@@ -79,20 +84,15 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
/**
|
/**
|
||||||
* Custom ActivityResultLauncher to manage the database action
|
* Custom ActivityResultLauncher to manage the database action
|
||||||
*/
|
*/
|
||||||
protected class DatabaseActivityResultLauncher(
|
protected inner class CredentialActivityResultLauncher(
|
||||||
val builder: ActivityResultLauncher<Intent>
|
val builder: ActivityResultLauncher<Intent>
|
||||||
) : ActivityResultLauncher<Intent>() {
|
) : ActivityResultLauncher<Intent>() {
|
||||||
|
|
||||||
/**
|
|
||||||
* Useful to only waiting for the activity result and prevent any parallel action
|
|
||||||
*/
|
|
||||||
var allowAction = true
|
|
||||||
|
|
||||||
override fun launch(
|
override fun launch(
|
||||||
input: Intent?,
|
input: Intent?,
|
||||||
options: ActivityOptionsCompat?
|
options: ActivityOptionsCompat?
|
||||||
) {
|
) {
|
||||||
allowAction = false
|
credentialResultLaunched = true
|
||||||
builder.launch(input, options)
|
builder.launch(input, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +107,17 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
if (savedInstanceState != null
|
||||||
|
&& savedInstanceState.containsKey(CREDENTIAL_RESULT_LAUNCHER_KEY)
|
||||||
|
) {
|
||||||
|
credentialResultLaunched = savedInstanceState.getBoolean(CREDENTIAL_RESULT_LAUNCHER_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
mDatabaseViewModel.actionState.collect { uiState ->
|
mDatabaseViewModel.actionState.collect { uiState ->
|
||||||
if (mCredentialActivityResultLauncher.allowAction) {
|
if (credentialResultLaunched.not()) {
|
||||||
when (uiState) {
|
when (uiState) {
|
||||||
is DatabaseViewModel.ActionState.Wait -> {}
|
is DatabaseViewModel.ActionState.Wait -> {}
|
||||||
is DatabaseViewModel.ActionState.OnDatabaseReloaded -> {
|
is DatabaseViewModel.ActionState.OnDatabaseReloaded -> {
|
||||||
@@ -170,7 +177,7 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||||
mDatabaseViewModel.databaseState.collect { database ->
|
mDatabaseViewModel.databaseState.collect { database ->
|
||||||
if (mCredentialActivityResultLauncher.allowAction) {
|
if (credentialResultLaunched.not()) {
|
||||||
// Nullable function
|
// Nullable function
|
||||||
onUnknownDatabaseRetrieved(database)
|
onUnknownDatabaseRetrieved(database)
|
||||||
database?.let {
|
database?.let {
|
||||||
@@ -182,6 +189,11 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
outState.putBoolean(CREDENTIAL_RESULT_LAUNCHER_KEY, credentialResultLaunched)
|
||||||
|
super.onSaveInstanceState(outState)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nullable function to retrieve a database
|
* Nullable function to retrieve a database
|
||||||
*/
|
*/
|
||||||
@@ -288,4 +300,8 @@ abstract class DatabaseActivity : StylishActivity(), DatabaseRetrieval {
|
|||||||
protected open fun showDatabaseDialog(): Boolean {
|
protected open fun showDatabaseDialog(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CREDENTIAL_RESULT_LAUNCHER_KEY = "com.kunzisoft.keepass.CREDENTIAL_RESULT_LAUNCHER_KEY"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user