fix: Cancelable during save

This commit is contained in:
J-Jamet
2025-10-28 14:07:32 +01:00
parent 26daac4637
commit 3039efc67c
2 changed files with 24 additions and 31 deletions

View File

@@ -735,7 +735,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
// Close channels // Close channels
closeChallengeResponse() closeChallengeResponse()
// Restore previous message // Restore previous message
mProgressMessage = previousMessage mProgressMessage = previousMessage.apply {
cancelable = null
}
notifyProgressMessage() notifyProgressMessage()
} }
return response return response

View File

@@ -68,6 +68,27 @@ open class ProgressTaskDialogFragment : DialogFragment() {
isCancelable = false isCancelable = false
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
progressTaskViewModel.progressMessageState.collect { state ->
titleView?.text = state.title
messageView?.text = state.message
warningView?.apply {
state.warning?.let { warning ->
text = warning
visibility = View.VISIBLE
} ?: run {
visibility = View.GONE
}
}
cancelButton?.isVisible = state.cancelable != null
cancelButton?.setOnClickListener {
state.cancelable?.invoke()
}
}
}
}
return builder.create() return builder.create()
} }
} catch (e: Exception) { } catch (e: Exception) {
@@ -76,36 +97,6 @@ open class ProgressTaskDialogFragment : DialogFragment() {
return super.onCreateDialog(savedInstanceState) return super.onCreateDialog(savedInstanceState)
} }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
progressTaskViewModel.progressMessageState.collect { state ->
updateView(titleView, state.title)
updateView(messageView, state.message)
updateView(warningView, state.warning)
activity?.lifecycleScope?.launch {
cancelButton?.isVisible = state.cancelable != null
cancelButton?.setOnClickListener {
state.cancelable?.invoke()
}
}
}
}
}
}
private fun updateView(textView: TextView?, value: String?) {
activity?.lifecycleScope?.launch {
if (value == null) {
textView?.visibility = View.GONE
} else {
textView?.text = value
textView?.visibility = View.VISIBLE
}
}
}
companion object { companion object {
private val TAG = ProgressTaskDialogFragment::class.java.simpleName private val TAG = ProgressTaskDialogFragment::class.java.simpleName
const val PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment" const val PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment"