2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00
This commit is contained in:
Jeff Boek 2019-02-15 14:04:45 -08:00
parent 912d8dbb04
commit 502dc1257d
2 changed files with 20 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {