From 502dc1257da3ffc1c33bb9c5b4c162ff837b64cf Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Fri, 15 Feb 2019 14:04:45 -0800 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/357 - Emits action on delete --- .../fenix/library/history/HistoryAdapter.kt | 16 +++++++++++++++- .../fenix/library/history/HistoryComponent.kt | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt index 6f76f4de2d..01f308391c 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt @@ -116,7 +116,19 @@ class HistoryAdapter( view: View, private val actionEmitter: Observer ) : RecyclerView.ViewHolder(view) { - private val button = view.findViewById(R.id.delete_history_button) + private lateinit var mode: HistoryState.Mode + + private val button = view.findViewById(R.id.delete_history_button).apply { + setOnClickListener { + val mode = mode + if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) { + actionEmitter.onNext(HistoryAction.Delete.Some(mode.selectedItems)) + } else { + actionEmitter.onNext(HistoryAction.Delete.All) + } + } + } + private val text = view.findViewById(R.id.delete_history_button_text).apply { val color = ContextCompat.getColor(context, R.color.photonRed60) val drawable = ContextCompat.getDrawable(context, R.drawable.ic_delete) @@ -125,6 +137,8 @@ class HistoryAdapter( } fun bind(mode: HistoryState.Mode) { + this.mode = mode + val text = if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) { text.context.resources.getString(R.string.delete_history_items, mode.selectedItems.size) } else { diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryComponent.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryComponent.kt index d9368a5534..e5b75055d2 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryComponent.kt @@ -81,6 +81,11 @@ sealed class HistoryAction : Action { object BackPressed : HistoryAction() data class AddItemForRemoval(val item: HistoryItem) : HistoryAction() data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction() + + sealed class Delete : HistoryAction() { + object All : Delete() + data class Some(val items: List) : Delete() + } } sealed class HistoryChange : Change {