2020-07-15 01:20:42 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.tabhistory
|
|
|
|
|
|
|
|
import android.view.View
|
2020-07-30 23:44:41 +02:00
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import kotlinx.android.synthetic.main.tab_history_list_item.*
|
2020-07-31 02:16:40 +02:00
|
|
|
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
|
|
|
import org.mozilla.fenix.R
|
2020-07-30 18:59:37 +02:00
|
|
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
|
|
|
import org.mozilla.fenix.utils.view.ViewHolder
|
2020-07-15 01:20:42 +02:00
|
|
|
|
|
|
|
class TabHistoryViewHolder(
|
2020-07-30 18:59:37 +02:00
|
|
|
view: View,
|
2020-07-15 01:20:42 +02:00
|
|
|
private val interactor: TabHistoryViewInteractor
|
2020-07-30 18:59:37 +02:00
|
|
|
) : ViewHolder(view) {
|
|
|
|
|
|
|
|
private lateinit var item: TabHistoryItem
|
|
|
|
|
|
|
|
init {
|
2020-07-30 23:44:41 +02:00
|
|
|
history_layout.setOnClickListener { interactor.goToHistoryItem(item) }
|
2020-07-30 18:59:37 +02:00
|
|
|
}
|
2020-07-15 01:20:42 +02:00
|
|
|
|
|
|
|
fun bind(item: TabHistoryItem) {
|
2020-07-30 18:59:37 +02:00
|
|
|
this.item = item
|
2020-07-15 01:20:42 +02:00
|
|
|
|
2020-07-30 18:59:37 +02:00
|
|
|
history_layout.displayAs(LibrarySiteItemView.ItemType.SITE)
|
2020-07-30 23:44:41 +02:00
|
|
|
history_layout.overflowView.isVisible = false
|
2020-07-31 02:16:40 +02:00
|
|
|
history_layout.titleView.text = item.title
|
2020-07-30 18:59:37 +02:00
|
|
|
history_layout.urlView.text = item.url
|
|
|
|
history_layout.loadFavicon(item.url)
|
|
|
|
|
2020-07-31 02:16:40 +02:00
|
|
|
if (item.isSelected) {
|
2020-08-11 23:24:38 +02:00
|
|
|
history_layout.setBackgroundColor(
|
|
|
|
history_layout.context.getColorFromAttr(R.attr.tabHistoryItemSelectedBackground)
|
|
|
|
)
|
2020-07-15 01:20:42 +02:00
|
|
|
} else {
|
2020-07-31 02:16:40 +02:00
|
|
|
history_layout.background = null
|
2020-07-15 01:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|