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:
@@ -1,8 +1,13 @@
|
|||||||
package com.kunzisoft.keepass.database
|
package com.kunzisoft.keepass.database
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
data class ProgressMessage(
|
data class ProgressMessage(
|
||||||
var title: String,
|
@StringRes
|
||||||
var message: String? = null,
|
var titleId: Int? = null,
|
||||||
var warning: String? = null,
|
@StringRes
|
||||||
|
var messageId: Int? = null,
|
||||||
|
@StringRes
|
||||||
|
var warningId: Int? = null,
|
||||||
var cancelable: (() -> Unit)? = null
|
var cancelable: (() -> Unit)? = null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import com.kunzisoft.keepass.R
|
|||||||
import com.kunzisoft.keepass.activities.GroupActivity
|
import com.kunzisoft.keepass.activities.GroupActivity
|
||||||
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.credentialprovider.activity.HardwareKeyActivity
|
|
||||||
import com.kunzisoft.keepass.database.ContextualDatabase
|
import com.kunzisoft.keepass.database.ContextualDatabase
|
||||||
import com.kunzisoft.keepass.database.MainCredential
|
import com.kunzisoft.keepass.database.MainCredential
|
||||||
import com.kunzisoft.keepass.database.ProgressMessage
|
import com.kunzisoft.keepass.database.ProgressMessage
|
||||||
@@ -62,6 +61,7 @@ import com.kunzisoft.keepass.database.element.node.Node
|
|||||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
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.credentialprovider.activity.HardwareKeyActivity
|
||||||
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
import com.kunzisoft.keepass.model.CipherEncryptDatabase
|
||||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
@@ -112,7 +112,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
private var mTaskRemovedRequested = false
|
private var mTaskRemovedRequested = false
|
||||||
private var mSaveState = false
|
private var mSaveState = false
|
||||||
|
|
||||||
private lateinit var mProgressMessage: ProgressMessage
|
private var mProgressMessage: ProgressMessage = ProgressMessage(R.string.database_opened)
|
||||||
|
|
||||||
override fun retrieveChannelId(): String {
|
override fun retrieveChannelId(): String {
|
||||||
return CHANNEL_DATABASE_ID
|
return CHANNEL_DATABASE_ID
|
||||||
@@ -305,13 +305,6 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
mResponseChallengeChannel = null
|
mResponseChallengeChannel = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
mProgressMessage = ProgressMessage(
|
|
||||||
title = getString(R.string.database_opened)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return mActionTaskBinder
|
return mActionTaskBinder
|
||||||
@@ -398,9 +391,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
TimeoutHelper.temporarilyDisableTimeout()
|
TimeoutHelper.temporarilyDisableTimeout()
|
||||||
|
|
||||||
sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply {
|
sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply {
|
||||||
putExtra(DATABASE_TASK_TITLE_KEY, mProgressMessage.title)
|
putExtra(DATABASE_TASK_TITLE_KEY, mProgressMessage.titleId)
|
||||||
putExtra(DATABASE_TASK_MESSAGE_KEY, mProgressMessage.message)
|
putExtra(DATABASE_TASK_MESSAGE_KEY, mProgressMessage.messageId)
|
||||||
putExtra(DATABASE_TASK_WARNING_KEY, mProgressMessage.warning)
|
putExtra(DATABASE_TASK_WARNING_KEY, mProgressMessage.warningId)
|
||||||
})
|
})
|
||||||
|
|
||||||
mActionTaskListeners.forEach { actionTaskListener ->
|
mActionTaskListeners.forEach { actionTaskListener ->
|
||||||
@@ -513,8 +506,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
R.drawable.notification_ic_database_action
|
R.drawable.notification_ic_database_action
|
||||||
|
|
||||||
// Title depending on action
|
// Title depending on action
|
||||||
mProgressMessage.title =
|
mProgressMessage.titleId =
|
||||||
getString(if (intentAction == null) {
|
if (intentAction == null) {
|
||||||
R.string.database_opened
|
R.string.database_opened
|
||||||
} else when (intentAction) {
|
} else when (intentAction) {
|
||||||
ACTION_DATABASE_CREATE_TASK -> R.string.creating_database
|
ACTION_DATABASE_CREATE_TASK -> R.string.creating_database
|
||||||
@@ -529,23 +522,24 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
else
|
else
|
||||||
R.string.command_execution
|
R.string.command_execution
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
// Updated later
|
// Updated later
|
||||||
mProgressMessage.message = null
|
mProgressMessage.messageId = null
|
||||||
|
|
||||||
// Warning if data is saved
|
// Warning if data is saved
|
||||||
mProgressMessage.warning =
|
mProgressMessage.warningId =
|
||||||
if (mSaveState)
|
if (mSaveState)
|
||||||
getString(R.string.do_not_kill_app)
|
R.string.do_not_kill_app
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
val notificationBuilder = buildNewNotification().apply {
|
val notificationBuilder = buildNewNotification().apply {
|
||||||
setSmallIcon(iconId)
|
setSmallIcon(iconId)
|
||||||
intent?.let {
|
val titleId = mProgressMessage.titleId?.let {
|
||||||
setContentTitle(intent.getStringExtra(DATABASE_TASK_TITLE_KEY))
|
intent?.getIntExtra(DATABASE_TASK_TITLE_KEY, it)
|
||||||
}
|
} ?: R.string.app_name
|
||||||
|
setContentTitle(getString(titleId))
|
||||||
setAutoCancel(false)
|
setAutoCancel(false)
|
||||||
setContentIntent(null)
|
setContentIntent(null)
|
||||||
}
|
}
|
||||||
@@ -666,8 +660,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMessage(@StringRes resId: Int) {
|
private fun updateMessage(resId: Int) {
|
||||||
mProgressMessage.message = getString(resId)
|
mProgressMessage.messageId = resId
|
||||||
notifyProgressMessage()
|
notifyProgressMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,7 +707,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
initializeChallengeResponse()
|
initializeChallengeResponse()
|
||||||
val previousMessage = mProgressMessage.copy()
|
val previousMessage = mProgressMessage.copy()
|
||||||
mProgressMessage.apply {
|
mProgressMessage.apply {
|
||||||
message = getString(R.string.waiting_challenge_request)
|
messageId = R.string.waiting_challenge_request
|
||||||
cancelable = {
|
cancelable = {
|
||||||
cancelChallengeResponse(R.string.error_cancel_by_user)
|
cancelChallengeResponse(R.string.error_cancel_by_user)
|
||||||
}
|
}
|
||||||
@@ -728,7 +722,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|
|||||||
)
|
)
|
||||||
// Wait the response
|
// Wait the response
|
||||||
mProgressMessage.apply {
|
mProgressMessage.apply {
|
||||||
message = getString(R.string.waiting_challenge_response)
|
messageId = R.string.waiting_challenge_response
|
||||||
}
|
}
|
||||||
notifyProgressMessage()
|
notifyProgressMessage()
|
||||||
response = mResponseChallengeChannel?.receive() ?: byteArrayOf()
|
response = mResponseChallengeChannel?.receive() ?: byteArrayOf()
|
||||||
|
|||||||
@@ -71,9 +71,12 @@ open class ProgressTaskDialogFragment : DialogFragment() {
|
|||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
progressTaskViewModel.progressMessageState.collect { state ->
|
progressTaskViewModel.progressMessageState.collect { state ->
|
||||||
updateView(titleView, state.title)
|
updateView(titleView,
|
||||||
updateView(messageView, state.message)
|
state.titleId?.let { title -> getString(title) })
|
||||||
updateView(warningView, state.warning)
|
updateView(messageView,
|
||||||
|
state.messageId?.let { message -> getString(message) })
|
||||||
|
updateView(warningView,
|
||||||
|
state.warningId?.let { warning -> getString(warning) })
|
||||||
cancelButton?.isVisible = state.cancelable != null
|
cancelButton?.isVisible = state.cancelable != null
|
||||||
cancelButton?.setOnClickListener {
|
cancelButton?.setOnClickListener {
|
||||||
state.cancelable?.invoke()
|
state.cancelable?.invoke()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
|
|
||||||
class ProgressTaskViewModel: ViewModel() {
|
class ProgressTaskViewModel: ViewModel() {
|
||||||
|
|
||||||
private val mProgressMessageState = MutableStateFlow(ProgressMessage(""))
|
private val mProgressMessageState = MutableStateFlow(ProgressMessage())
|
||||||
val progressMessageState: StateFlow<ProgressMessage> = mProgressMessageState
|
val progressMessageState: StateFlow<ProgressMessage> = mProgressMessageState
|
||||||
|
|
||||||
private val mProgressTaskState = MutableStateFlow<ProgressTaskState>(ProgressTaskState.Stop)
|
private val mProgressTaskState = MutableStateFlow<ProgressTaskState>(ProgressTaskState.Stop)
|
||||||
|
|||||||
Reference in New Issue
Block a user