From 4a0e552f738741a9d93314c9c8ab380660324226 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Fri, 20 Aug 2021 20:18:29 +0430 Subject: [PATCH] Show confirmation dialog before deleting message. --- .../moez/QKSMS/feature/compose/ComposeActivity.kt | 11 +++++++++++ .../com/moez/QKSMS/feature/compose/ComposeView.kt | 2 ++ .../moez/QKSMS/feature/compose/ComposeViewModel.kt | 14 +++++++++++--- presentation/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt index 3b42535b..0ceff0d3 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt @@ -115,6 +115,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView { override val sendIntent by lazy { send.clicks() } override val viewQksmsPlusIntent: Subject = PublishSubject.create() override val backPressedIntent: Subject = PublishSubject.create() + override val confirmDeleteIntent: Subject> = PublishSubject.create() 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) { + 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) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt index d8a78eec..166ae49a 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeView.kt @@ -55,6 +55,7 @@ interface ComposeView : QkView { val sendIntent: Observable val viewQksmsPlusIntent: Subject val backPressedIntent: Observable + val confirmDeleteIntent: Observable> fun clearSelection() fun showDetails(details: String) @@ -71,5 +72,6 @@ interface ComposeView : QkView { fun setDraft(draft: String) fun scrollToMessage(id: Long) fun showQksmsPlusSnackbar(@StringRes message: Int) + fun showDeleteDialog( messages: List) } \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt index ba601f2f..96047191 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt @@ -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 @@ -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? { diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 2c7e1b83..31cbb082 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -92,6 +92,10 @@ Are you sure you would like to delete this conversation? Are you sure you would like to delete %d conversations? + + Are you sure you would like to delete this message? + Are you sure you would like to delete %d messages? + Copy text