2019-04-09 23:57:53 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-04-09 23:57:53 +02:00
|
|
|
|
|
|
|
package org.mozilla.fenix.library.history.viewholders
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import kotlinx.android.synthetic.main.delete_history_button.view.*
|
|
|
|
import org.mozilla.fenix.R
|
2019-07-11 23:39:06 +02:00
|
|
|
import org.mozilla.fenix.library.history.HistoryInteractor
|
2019-04-09 23:57:53 +02:00
|
|
|
import org.mozilla.fenix.library.history.HistoryState
|
|
|
|
|
|
|
|
class HistoryDeleteButtonViewHolder(
|
|
|
|
view: View,
|
2019-07-11 23:39:06 +02:00
|
|
|
historyInteractor: HistoryInteractor
|
2019-04-09 23:57:53 +02:00
|
|
|
) : RecyclerView.ViewHolder(view) {
|
|
|
|
private var mode: HistoryState.Mode? = null
|
2019-04-10 00:31:40 +02:00
|
|
|
private val buttonView = view.delete_history_button
|
2019-04-09 23:57:53 +02:00
|
|
|
|
|
|
|
init {
|
2019-04-10 00:31:40 +02:00
|
|
|
buttonView.setOnClickListener {
|
2019-04-09 23:57:53 +02:00
|
|
|
mode?.also {
|
2019-07-11 23:39:06 +02:00
|
|
|
when (it) {
|
|
|
|
is HistoryState.Mode.Normal -> historyInteractor.onDeleteAll()
|
|
|
|
is HistoryState.Mode.Editing -> historyInteractor.onDeleteSome(it.selectedItems)
|
|
|
|
}
|
2019-04-09 23:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 05:47:39 +02:00
|
|
|
|
2019-04-09 23:57:53 +02:00
|
|
|
fun bind(mode: HistoryState.Mode) {
|
2019-04-12 09:58:46 +02:00
|
|
|
this.mode = mode
|
2019-04-09 23:57:53 +02:00
|
|
|
|
2019-05-10 18:58:54 +02:00
|
|
|
buttonView.run {
|
2019-05-29 19:59:05 +02:00
|
|
|
val isDeleting = mode is HistoryState.Mode.Deleting
|
|
|
|
if (isDeleting || mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) {
|
2019-05-10 18:58:54 +02:00
|
|
|
isEnabled = false
|
|
|
|
alpha = DISABLED_ALPHA
|
|
|
|
} else {
|
|
|
|
isEnabled = true
|
|
|
|
alpha = 1f
|
|
|
|
}
|
2019-04-09 23:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-05-10 18:58:54 +02:00
|
|
|
const val DISABLED_ALPHA = 0.4f
|
2019-04-09 23:57:53 +02:00
|
|
|
const val LAYOUT_ID = R.layout.delete_history_button
|
|
|
|
}
|
2019-04-10 00:31:40 +02:00
|
|
|
}
|