Show confirmation when deleting conversation

This commit is contained in:
Moez Bhatti
2018-02-28 00:04:07 -05:00
parent b4563e1b9b
commit 8aace11ab6
7 changed files with 47 additions and 4 deletions
@@ -19,12 +19,14 @@
package presentation.feature.conversationinfo package presentation.feature.conversationinfo
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import com.jakewharton.rxbinding2.view.clicks import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent import common.di.appComponent
import io.reactivex.subjects.PublishSubject
import kotlinx.android.synthetic.main.conversation_info_activity.* import kotlinx.android.synthetic.main.conversation_info_activity.*
import presentation.common.base.QkThemedActivity import presentation.common.base.QkThemedActivity
import javax.inject.Inject import javax.inject.Inject
@@ -35,6 +37,7 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
override val notificationsIntent by lazy { notifications.clicks() } override val notificationsIntent by lazy { notifications.clicks() }
override val archiveIntent by lazy { archive.clicks() } override val archiveIntent by lazy { archive.clicks() }
override val deleteIntent by lazy { delete.clicks() } override val deleteIntent by lazy { delete.clicks() }
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter @Inject lateinit var recipientAdapter: ConversationRecipientAdapter
@@ -65,10 +68,19 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
recipientAdapter.data = state.recipients recipientAdapter.data = state.recipients
archive.title = getString(when(state.archived) { archive.title = getString(when (state.archived) {
true -> R.string.info_unarchive true -> R.string.info_unarchive
false -> R.string.info_archive false -> R.string.info_archive
}) })
} }
override fun showDeleteDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
.setPositiveButton(R.string.button_delete, { _, _ -> confirmDeleteIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
} }
@@ -26,5 +26,8 @@ interface ConversationInfoView : QkView<ConversationInfoState> {
val notificationsIntent: Observable<Unit> val notificationsIntent: Observable<Unit>
val archiveIntent: Observable<Unit> val archiveIntent: Observable<Unit>
val deleteIntent: Observable<Unit> val deleteIntent: Observable<Unit>
val confirmDeleteIntent: Observable<Unit>
fun showDeleteDialog()
} }
@@ -102,8 +102,13 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
} }
} }
// Delete the conversation // Show the delete confirmation dialog
view.deleteIntent view.deleteIntent
.autoDisposable(view.scope())
.subscribe { view.showDeleteDialog() }
// Delete the conversation
view.confirmDeleteIntent
.withLatestFrom(conversation, { _, conversation -> conversation }) .withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe { conversation -> deleteConversation.execute(conversation.id) } .subscribe { conversation -> deleteConversation.execute(conversation.id) }
@@ -80,6 +80,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
override val conversationClickIntent by lazy { conversationsAdapter.clicks } override val conversationClickIntent by lazy { conversationsAdapter.clicks }
override val conversationLongClickIntent by lazy { conversationsAdapter.longClicks } override val conversationLongClickIntent by lazy { conversationsAdapter.longClicks }
override val conversationMenuItemIntent by lazy { menuItemAdapter.menuItemClicks } override val conversationMenuItemIntent by lazy { menuItemAdapter.menuItemClicks }
override val confirmDeleteIntent: Subject<Unit> = PublishSubject.create()
override val swipeConversationIntent by lazy { itemTouchCallback.swipes } override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
override val undoSwipeConversationIntent: Subject<Unit> = PublishSubject.create() override val undoSwipeConversationIntent: Subject<Unit> = PublishSubject.create()
@@ -269,6 +270,15 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
toolbarSearch.text = null toolbarSearch.text = null
} }
override fun showDeleteDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
.setPositiveButton(R.string.button_delete, { _, _ -> confirmDeleteIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean { override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main, menu) menuInflater.inflate(R.menu.main, menu)
return super.onCreateOptionsMenu(menu) return super.onCreateOptionsMenu(menu)
@@ -32,10 +32,12 @@ interface MainView : QkView<MainState> {
val conversationClickIntent: Observable<Long> val conversationClickIntent: Observable<Long>
val conversationLongClickIntent: Observable<Long> val conversationLongClickIntent: Observable<Long>
val conversationMenuItemIntent: Subject<Int> val conversationMenuItemIntent: Subject<Int>
val confirmDeleteIntent: Subject<Unit>
val swipeConversationIntent: Observable<Int> val swipeConversationIntent: Observable<Int>
val undoSwipeConversationIntent: Subject<Unit> val undoSwipeConversationIntent: Subject<Unit>
fun clearSearch() fun clearSearch()
fun showDeleteDialog()
} }
@@ -206,12 +206,18 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
when (actionId) { when (actionId) {
menuArchive.actionId -> markArchived.execute(threadId) menuArchive.actionId -> markArchived.execute(threadId)
menuUnarchive.actionId -> markUnarchived.execute(threadId) menuUnarchive.actionId -> markUnarchived.execute(threadId)
menuDelete.actionId -> deleteConversation.execute(threadId) menuDelete.actionId -> view.showDeleteDialog()
} }
}) })
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe() .subscribe()
// Delete the conversation
view.confirmDeleteIntent
.withLatestFrom(view.conversationLongClickIntent, { _, threadId -> threadId })
.autoDisposable(view.scope())
.subscribe { threadId -> deleteConversation.execute(threadId) }
val swipedConversation = view.swipeConversationIntent val swipedConversation = view.swipeConversationIntent
.withLatestFrom(conversations.toObservable(), { position, conversations -> conversations[position] }) .withLatestFrom(conversations.toObservable(), { position, conversations -> conversations[position] })
.map { pair -> pair.conversation } .map { pair -> pair.conversation }
+6 -1
View File
@@ -64,6 +64,9 @@
<string name="scheduled_empty_text">Your scheduled messages will appear here</string> <string name="scheduled_empty_text">Your scheduled messages will appear here</string>
<string name="blocked_empty_text">Your blocked senders will appear here</string> <string name="blocked_empty_text">Your blocked senders will appear here</string>
<string name="dialog_delete_title">Delete</string>
<string name="dialog_delete_message">Are you sure you would like to delete this conversation?</string>
<string name="info_title">Details</string> <string name="info_title">Details</string>
<string name="info_notifications">Notifications</string> <string name="info_notifications">Notifications</string>
<string name="info_archive">Archive</string> <string name="info_archive">Archive</string>
@@ -127,8 +130,10 @@
<string name="notification_reply">Reply</string> <string name="notification_reply">Reply</string>
<string name="notification_read">Mark read</string> <string name="notification_read">Mark read</string>
<string name="button_undo">Undo</string> <string name="button_yes">Yes</string>
<string name="button_cancel">Cancel</string> <string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string>
<string name="button_undo">Undo</string>
<string name="button_more">More</string> <string name="button_more">More</string>
<string name="toast_copied">Copied</string> <string name="toast_copied">Copied</string>