mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/357 - Emits action on delete
This commit is contained in:
parent
912d8dbb04
commit
502dc1257d
@ -116,7 +116,19 @@ class HistoryAdapter(
|
|||||||
view: View,
|
view: View,
|
||||||
private val actionEmitter: Observer<HistoryAction>
|
private val actionEmitter: Observer<HistoryAction>
|
||||||
) : RecyclerView.ViewHolder(view) {
|
) : RecyclerView.ViewHolder(view) {
|
||||||
private val button = view.findViewById<View>(R.id.delete_history_button)
|
private lateinit var mode: HistoryState.Mode
|
||||||
|
|
||||||
|
private val button = view.findViewById<View>(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<TextView>(R.id.delete_history_button_text).apply {
|
private val text = view.findViewById<TextView>(R.id.delete_history_button_text).apply {
|
||||||
val color = ContextCompat.getColor(context, R.color.photonRed60)
|
val color = ContextCompat.getColor(context, R.color.photonRed60)
|
||||||
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_delete)
|
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_delete)
|
||||||
@ -125,6 +137,8 @@ class HistoryAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun bind(mode: HistoryState.Mode) {
|
fun bind(mode: HistoryState.Mode) {
|
||||||
|
this.mode = mode
|
||||||
|
|
||||||
val text = if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) {
|
val text = if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) {
|
||||||
text.context.resources.getString(R.string.delete_history_items, mode.selectedItems.size)
|
text.context.resources.getString(R.string.delete_history_items, mode.selectedItems.size)
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,6 +81,11 @@ sealed class HistoryAction : Action {
|
|||||||
object BackPressed : HistoryAction()
|
object BackPressed : HistoryAction()
|
||||||
data class AddItemForRemoval(val item: HistoryItem) : HistoryAction()
|
data class AddItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||||
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction()
|
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||||
|
|
||||||
|
sealed class Delete : HistoryAction() {
|
||||||
|
object All : Delete()
|
||||||
|
data class Some(val items: List<HistoryItem>) : Delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class HistoryChange : Change {
|
sealed class HistoryChange : Change {
|
||||||
|
Loading…
Reference in New Issue
Block a user