mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix progress message
This commit is contained in:
@@ -47,6 +47,7 @@ import com.kunzisoft.keepass.database.exception.InvalidCredentialsDatabaseExcept
|
|||||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||||
import com.kunzisoft.keepass.hardware.HardwareKeyResponseHelper
|
import com.kunzisoft.keepass.hardware.HardwareKeyResponseHelper
|
||||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||||
|
import com.kunzisoft.keepass.model.ProgressMessage
|
||||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
||||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK
|
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_ASSIGN_PASSWORD_TASK
|
||||||
@@ -176,19 +177,13 @@ class DatabaseTaskProvider {
|
|||||||
|
|
||||||
private val actionTaskListener = object: DatabaseTaskNotificationService.ActionTaskListener {
|
private val actionTaskListener = object: DatabaseTaskNotificationService.ActionTaskListener {
|
||||||
override fun onStartAction(database: Database,
|
override fun onStartAction(database: Database,
|
||||||
titleId: Int?,
|
progressMessage: ProgressMessage) {
|
||||||
messageId: Int?,
|
startDialog(progressMessage)
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)?) {
|
|
||||||
startDialog(titleId, messageId, warningId, cancelable)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpdateAction(database: Database,
|
override fun onUpdateAction(database: Database,
|
||||||
titleId: Int?,
|
progressMessage: ProgressMessage) {
|
||||||
messageId: Int?,
|
updateDialog(progressMessage)
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)?) {
|
|
||||||
updateDialog(titleId, messageId, warningId, cancelable)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopAction(database: Database,
|
override fun onStopAction(database: Database,
|
||||||
@@ -242,10 +237,7 @@ class DatabaseTaskProvider {
|
|||||||
|
|
||||||
private var requestChallengeListener: DatabaseTaskNotificationService.RequestChallengeListener? = null
|
private var requestChallengeListener: DatabaseTaskNotificationService.RequestChallengeListener? = null
|
||||||
|
|
||||||
private fun startDialog(titleId: Int?,
|
private fun startDialog(progressMessage: ProgressMessage) {
|
||||||
messageId: Int?,
|
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)?) {
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
activity.lifecycleScope.launch {
|
activity.lifecycleScope.launch {
|
||||||
if (progressTaskDialogFragment == null) {
|
if (progressTaskDialogFragment == null) {
|
||||||
@@ -259,26 +251,17 @@ class DatabaseTaskProvider {
|
|||||||
PROGRESS_TASK_DIALOG_TAG
|
PROGRESS_TASK_DIALOG_TAG
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
updateDialog(titleId, messageId, warningId, cancelable)
|
updateDialog(progressMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDialog(titleId: Int?,
|
private fun updateDialog(progressMessage: ProgressMessage) {
|
||||||
messageId: Int?,
|
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)?) {
|
|
||||||
progressTaskDialogFragment?.apply {
|
progressTaskDialogFragment?.apply {
|
||||||
titleId?.let {
|
updateTitle(progressMessage.titleId)
|
||||||
updateTitle(it)
|
updateMessage(progressMessage.messageId)
|
||||||
}
|
updateWarning(progressMessage.warningId)
|
||||||
messageId?.let {
|
setCancellable(progressMessage.cancelable)
|
||||||
updateMessage(it)
|
|
||||||
}
|
|
||||||
warningId?.let {
|
|
||||||
updateWarning(it)
|
|
||||||
}
|
|
||||||
setCancellable(cancelable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.kunzisoft.keepass.model
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
|
data class ProgressMessage(
|
||||||
|
@StringRes
|
||||||
|
var titleId: Int,
|
||||||
|
@StringRes
|
||||||
|
var messageId: Int? = null,
|
||||||
|
@StringRes
|
||||||
|
var warningId: Int? = null,
|
||||||
|
var cancelable: (() -> Unit)? = null
|
||||||
|
)
|
||||||
@@ -45,6 +45,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
|
|||||||
import com.kunzisoft.keepass.database.element.node.Type
|
import com.kunzisoft.keepass.database.element.node.Type
|
||||||
import com.kunzisoft.keepass.hardware.HardwareKey
|
import com.kunzisoft.keepass.hardware.HardwareKey
|
||||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||||
|
import com.kunzisoft.keepass.model.ProgressMessage
|
||||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||||
@@ -79,10 +80,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
private var mCreationState = false
|
private var mCreationState = false
|
||||||
|
|
||||||
private var mIconId: Int = R.drawable.notification_ic_database_load
|
private var mIconId: Int = R.drawable.notification_ic_database_load
|
||||||
private var mTitleId: Int = R.string.database_opened
|
private var mProgressMessage: ProgressMessage = ProgressMessage(R.string.database_opened)
|
||||||
private var mMessageId: Int? = null
|
|
||||||
private var mWarningId: Int? = null
|
|
||||||
private var mCancelable: (() -> Unit)? = null
|
|
||||||
|
|
||||||
override fun retrieveChannelId(): String {
|
override fun retrieveChannelId(): String {
|
||||||
return CHANNEL_DATABASE_ID
|
return CHANNEL_DATABASE_ID
|
||||||
@@ -154,15 +152,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
|
|
||||||
interface ActionTaskListener {
|
interface ActionTaskListener {
|
||||||
fun onStartAction(database: Database,
|
fun onStartAction(database: Database,
|
||||||
titleId: Int?,
|
progressMessage: ProgressMessage)
|
||||||
messageId: Int?,
|
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)? = null)
|
|
||||||
fun onUpdateAction(database: Database,
|
fun onUpdateAction(database: Database,
|
||||||
titleId: Int?,
|
progressMessage: ProgressMessage)
|
||||||
messageId: Int?,
|
|
||||||
warningId: Int?,
|
|
||||||
cancelable: (() -> Unit)? = null)
|
|
||||||
fun onStopAction(database: Database,
|
fun onStopAction(database: Database,
|
||||||
actionTask: String,
|
actionTask: String,
|
||||||
result: ActionRunnable.Result)
|
result: ActionRunnable.Result)
|
||||||
@@ -239,7 +231,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
if (mActionRunning) {
|
if (mActionRunning) {
|
||||||
mActionTaskListeners.forEach { actionTaskListener ->
|
mActionTaskListeners.forEach { actionTaskListener ->
|
||||||
actionTaskListener.onStartAction(
|
actionTaskListener.onStartAction(
|
||||||
database, mTitleId, mMessageId, mWarningId, mCancelable
|
database, mProgressMessage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,14 +346,14 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
mActionRunning = true
|
mActionRunning = true
|
||||||
|
|
||||||
sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply {
|
sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply {
|
||||||
putExtra(DATABASE_TASK_TITLE_KEY, mTitleId)
|
putExtra(DATABASE_TASK_TITLE_KEY, mProgressMessage.titleId)
|
||||||
putExtra(DATABASE_TASK_MESSAGE_KEY, mMessageId)
|
putExtra(DATABASE_TASK_MESSAGE_KEY, mProgressMessage.messageId)
|
||||||
putExtra(DATABASE_TASK_WARNING_KEY, mWarningId)
|
putExtra(DATABASE_TASK_WARNING_KEY, mProgressMessage.warningId)
|
||||||
})
|
})
|
||||||
|
|
||||||
mActionTaskListeners.forEach { actionTaskListener ->
|
mActionTaskListeners.forEach { actionTaskListener ->
|
||||||
actionTaskListener.onStartAction(
|
actionTaskListener.onStartAction(
|
||||||
database, mTitleId, mMessageId, mWarningId, mCancelable
|
database, mProgressMessage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +443,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
else
|
else
|
||||||
R.drawable.notification_ic_database_load
|
R.drawable.notification_ic_database_load
|
||||||
|
|
||||||
mTitleId = when {
|
mProgressMessage.titleId = when {
|
||||||
saveAction -> {
|
saveAction -> {
|
||||||
R.string.saving_database
|
R.string.saving_database
|
||||||
}
|
}
|
||||||
@@ -476,14 +468,14 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mMessageId = when (intentAction) {
|
mProgressMessage.messageId = when (intentAction) {
|
||||||
ACTION_DATABASE_LOAD_TASK,
|
ACTION_DATABASE_LOAD_TASK,
|
||||||
ACTION_DATABASE_MERGE_TASK,
|
ACTION_DATABASE_MERGE_TASK,
|
||||||
ACTION_DATABASE_RELOAD_TASK -> null
|
ACTION_DATABASE_RELOAD_TASK -> null
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
mWarningId =
|
mProgressMessage.warningId =
|
||||||
if (!saveAction
|
if (!saveAction
|
||||||
|| intentAction == ACTION_DATABASE_LOAD_TASK
|
|| intentAction == ACTION_DATABASE_LOAD_TASK
|
||||||
|| intentAction == ACTION_DATABASE_MERGE_TASK
|
|| intentAction == ACTION_DATABASE_MERGE_TASK
|
||||||
@@ -495,7 +487,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
val notificationBuilder = buildNewNotification().apply {
|
val notificationBuilder = buildNewNotification().apply {
|
||||||
setSmallIcon(mIconId)
|
setSmallIcon(mIconId)
|
||||||
intent?.let {
|
intent?.let {
|
||||||
setContentTitle(getString(intent.getIntExtra(DATABASE_TASK_TITLE_KEY, mTitleId)))
|
setContentTitle(getString(
|
||||||
|
intent.getIntExtra(DATABASE_TASK_TITLE_KEY, mProgressMessage.titleId))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
setAutoCancel(false)
|
setAutoCancel(false)
|
||||||
setContentIntent(null)
|
setContentIntent(null)
|
||||||
@@ -601,17 +595,26 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateMessage(resId: Int) {
|
private fun notifyProgressMessage() {
|
||||||
mMessageId = resId
|
|
||||||
mDatabase?.let { database ->
|
mDatabase?.let { database ->
|
||||||
mActionTaskListeners.forEach { actionTaskListener ->
|
mActionTaskListeners.forEach { actionTaskListener ->
|
||||||
actionTaskListener.onUpdateAction(
|
actionTaskListener.onUpdateAction(
|
||||||
database, mTitleId, mMessageId, mWarningId, mCancelable
|
database, mProgressMessage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun updateMessage(progressMessage: ProgressMessage) {
|
||||||
|
mProgressMessage = progressMessage
|
||||||
|
notifyProgressMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateMessage(resId: Int) {
|
||||||
|
mProgressMessage.messageId = resId
|
||||||
|
notifyProgressMessage()
|
||||||
|
}
|
||||||
|
|
||||||
override fun actionOnLock() {
|
override fun actionOnLock() {
|
||||||
if (!TimeoutHelper.temporarilyDisableLock) {
|
if (!TimeoutHelper.temporarilyDisableLock) {
|
||||||
closeDatabase(mDatabase)
|
closeDatabase(mDatabase)
|
||||||
@@ -636,24 +639,28 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
runBlocking {
|
runBlocking {
|
||||||
// Initialize the channels
|
// Initialize the channels
|
||||||
initializeChallengeResponse()
|
initializeChallengeResponse()
|
||||||
val previousMessageId = mMessageId
|
val previousMessage = mProgressMessage.copy()
|
||||||
mCancelable = {
|
mProgressMessage.apply {
|
||||||
cancelChallengeResponse(R.string.error_cancel_by_user)
|
messageId = R.string.waiting_challenge_request
|
||||||
|
cancelable = {
|
||||||
|
cancelChallengeResponse(R.string.error_cancel_by_user)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Send the request
|
// Send the request
|
||||||
updateMessage(R.string.waiting_challenge_request)
|
updateMessage(mProgressMessage)
|
||||||
val challengeResponseRequestListener = mRequestChallengeListenerChannel?.receive()
|
val challengeResponseRequestListener = mRequestChallengeListenerChannel?.receive()
|
||||||
challengeResponseRequestListener?.onChallengeResponseRequested(hardwareKey, seed)
|
challengeResponseRequestListener?.onChallengeResponseRequested(hardwareKey, seed)
|
||||||
// Wait the response
|
// Wait the response
|
||||||
updateMessage(R.string.waiting_challenge_response)
|
mProgressMessage.apply {
|
||||||
|
messageId = R.string.waiting_challenge_response
|
||||||
|
}
|
||||||
|
updateMessage(mProgressMessage)
|
||||||
response = mResponseChallengeChannel?.receive() ?: byteArrayOf()
|
response = mResponseChallengeChannel?.receive() ?: byteArrayOf()
|
||||||
// Close channels
|
// Close channels
|
||||||
closeChallengeResponse()
|
closeChallengeResponse()
|
||||||
// Restore previous message
|
// Restore previous message
|
||||||
mCancelable = null
|
mProgressMessage.cancelable = null
|
||||||
previousMessageId?.let {
|
updateMessage(previousMessage)
|
||||||
updateMessage(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,18 +110,18 @@ open class ProgressTaskDialogFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateTitle(@StringRes resId: Int) {
|
fun updateTitle(@StringRes resId: Int?) {
|
||||||
this.title = resId
|
this.title = resId ?: UNDEFINED
|
||||||
updateView(titleView, title)
|
updateView(titleView, title)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateMessage(@StringRes resId: Int) {
|
fun updateMessage(@StringRes resId: Int?) {
|
||||||
this.message = resId
|
this.message = resId ?: UNDEFINED
|
||||||
updateView(messageView, message)
|
updateView(messageView, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateWarning(@StringRes resId: Int) {
|
fun updateWarning(@StringRes resId: Int?) {
|
||||||
this.warning = resId
|
this.warning = resId ?: UNDEFINED
|
||||||
updateView(warningView, warning)
|
updateView(warningView, warning)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
package com.kunzisoft.keepass.tasks
|
package com.kunzisoft.keepass.tasks
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import com.kunzisoft.keepass.model.ProgressMessage
|
||||||
|
|
||||||
interface ProgressTaskUpdater {
|
interface ProgressTaskUpdater {
|
||||||
|
fun updateMessage(progressMessage: ProgressMessage)
|
||||||
fun updateMessage(@StringRes resId: Int)
|
fun updateMessage(@StringRes resId: Int)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user