forked from upstream-mirrors/quik
Show confirmation dialog before deleting message.
This commit is contained in:
@@ -115,6 +115,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
override val sendIntent by lazy { send.clicks() }
|
override val sendIntent by lazy { send.clicks() }
|
||||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||||
override val backPressedIntent: 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] }
|
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
|
||||||
|
|
||||||
@@ -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 {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
menuInflater.inflate(R.menu.compose, menu)
|
menuInflater.inflate(R.menu.compose, menu)
|
||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
val sendIntent: Observable<Unit>
|
val sendIntent: Observable<Unit>
|
||||||
val viewQksmsPlusIntent: Subject<Unit>
|
val viewQksmsPlusIntent: Subject<Unit>
|
||||||
val backPressedIntent: Observable<Unit>
|
val backPressedIntent: Observable<Unit>
|
||||||
|
val confirmDeleteIntent: Observable<List<Long>>
|
||||||
|
|
||||||
fun clearSelection()
|
fun clearSelection()
|
||||||
fun showDetails(details: String)
|
fun showDetails(details: String)
|
||||||
@@ -71,5 +72,6 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
fun setDraft(draft: String)
|
fun setDraft(draft: String)
|
||||||
fun scrollToMessage(id: Long)
|
fun scrollToMessage(id: Long)
|
||||||
fun showQksmsPlusSnackbar(@StringRes message: Int)
|
fun showQksmsPlusSnackbar(@StringRes message: Int)
|
||||||
|
fun showDeleteDialog( messages: List<Long>)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -340,15 +340,15 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { view.showDetails(it) }
|
.subscribe { view.showDetails(it) }
|
||||||
|
|
||||||
// Delete the messages
|
// Show the delete message dialog
|
||||||
view.optionsItemIntent
|
view.optionsItemIntent
|
||||||
.filter { it == R.id.delete }
|
.filter { it == R.id.delete }
|
||||||
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
|
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
|
||||||
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
|
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
|
||||||
deleteMessages.execute(DeleteMessages.Params(messages, conversation.id))
|
view.showDeleteDialog(messages)
|
||||||
}
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { view.clearSelection() }
|
.subscribe()
|
||||||
|
|
||||||
// Forward the message
|
// Forward the message
|
||||||
view.optionsItemIntent
|
view.optionsItemIntent
|
||||||
@@ -728,6 +728,14 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe()
|
.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? {
|
private fun getVCard(contactData: Uri): String? {
|
||||||
|
|||||||
@@ -92,6 +92,10 @@
|
|||||||
<item quantity="one">Are you sure you would like to delete this conversation?</item>
|
<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>
|
<item quantity="other">Are you sure you would like to delete %d conversations?</item>
|
||||||
</plurals>
|
</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">
|
<string-array name="message_options">
|
||||||
<item>Copy text</item>
|
<item>Copy text</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user