Skip to content

Commit

Permalink
Show confirmation dialog before deleting message.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-git committed Aug 20, 2021
1 parent 4573656 commit 4a0e552
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val sendIntent by lazy { send.clicks() }
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()

private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }

Expand Down Expand Up @@ -349,6 +350,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
}
}

override fun showDeleteDialog(messages: List<Long>) {
val count = messages.size
android.app.AlertDialog.Builder(this)
.setTitle(R.string.dialog_delete_title)
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_chat, count, count))
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(messages) }
.setNegativeButton(R.string.button_cancel, null)
.show()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.compose, menu)
return super.onCreateOptionsMenu(menu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface ComposeView : QkView<ComposeState> {
val sendIntent: Observable<Unit>
val viewQksmsPlusIntent: Subject<Unit>
val backPressedIntent: Observable<Unit>
val confirmDeleteIntent: Observable<List<Long>>

fun clearSelection()
fun showDetails(details: String)
Expand All @@ -71,5 +72,6 @@ interface ComposeView : QkView<ComposeState> {
fun setDraft(draft: String)
fun scrollToMessage(id: Long)
fun showQksmsPlusSnackbar(@StringRes message: Int)
fun showDeleteDialog( messages: List<Long>)

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { view.showDetails(it) }

// Delete the messages
// Show the delete message dialog
view.optionsItemIntent
.filter { it == R.id.delete }
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
view.showDeleteDialog(messages)
}
.autoDisposable(view.scope())
.subscribe { view.clearSelection() }
.subscribe()

// Forward the message
view.optionsItemIntent
Expand Down Expand Up @@ -728,6 +728,14 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe()

// Delete the message
view.confirmDeleteIntent
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
}
.autoDisposable(view.scope())
.subscribe { view.clearSelection() }

}

private fun getVCard(contactData: Uri): String? {
Expand Down
4 changes: 4 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<item quantity="one">Are you sure you would like to delete this conversation?</item>
<item quantity="other">Are you sure you would like to delete %d conversations?</item>
</plurals>
<plurals name="dialog_delete_chat">
<item quantity="one">Are you sure you would like to delete this message?</item>
<item quantity="other">Are you sure you would like to delete %d messages?</item>
</plurals>

<string-array name="message_options">
<item>Copy text</item>
Expand Down

0 comments on commit 4a0e552

Please sign in to comment.