GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit d306e37a authored by Tiger Oakes's avatar Tiger Oakes Committed by liuche
Browse files

For #12887: Use ListAdapter to diff history

parent bc9000ce
......@@ -67,6 +67,8 @@ class LibrarySiteItemView @JvmOverloads constructor(
val overflowView: ImageButton get() = overflow_menu
private var iconUrl: String? = null
init {
LayoutInflater.from(context).inflate(R.layout.library_site_item, this, true)
......@@ -94,6 +96,9 @@ class LibrarySiteItemView @JvmOverloads constructor(
}
fun loadFavicon(url: String) {
if (iconUrl == url) return
iconUrl = url
context.components.core.icons.loadIntoView(favicon, url)
}
......
......@@ -6,7 +6,8 @@ package org.mozilla.fenix.tabhistory
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import org.mozilla.fenix.R
data class TabHistoryItem(
......@@ -18,23 +19,23 @@ data class TabHistoryItem(
class TabHistoryAdapter(
private val interactor: TabHistoryViewInteractor
) : RecyclerView.Adapter<TabHistoryViewHolder>() {
var historyList: List<TabHistoryItem> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
) : ListAdapter<TabHistoryItem, TabHistoryViewHolder>(DiffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TabHistoryViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.history_list_item, parent, false)
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.history_list_item, parent, false)
return TabHistoryViewHolder(view, interactor)
}
override fun onBindViewHolder(holder: TabHistoryViewHolder, position: Int) {
holder.bind(historyList[position])
holder.bind(getItem(position))
}
override fun getItemCount(): Int = historyList.size
internal object DiffCallback : DiffUtil.ItemCallback<TabHistoryItem>() {
override fun areItemsTheSame(oldItem: TabHistoryItem, newItem: TabHistoryItem) =
oldItem.url == newItem.url
override fun areContentsTheSame(oldItem: TabHistoryItem, newItem: TabHistoryItem) =
oldItem == newItem
}
}
......@@ -24,19 +24,16 @@ interface TabHistoryViewInteractor {
}
class TabHistoryView(
private val container: ViewGroup,
container: ViewGroup,
private val expandDialog: () -> Unit,
interactor: TabHistoryViewInteractor
) : LayoutContainer {
override val containerView: View?
get() = container
val view: View = LayoutInflater.from(container.context)
override val containerView: View = LayoutInflater.from(container.context)
.inflate(R.layout.component_tabhistory, container, true)
private val adapter = TabHistoryAdapter(interactor)
private val layoutManager = object : LinearLayoutManager(view.context) {
private val layoutManager = object : LinearLayoutManager(containerView.context) {
override fun onLayoutCompleted(state: RecyclerView.State?) {
super.onLayoutCompleted(state)
currentIndex?.let { index ->
......@@ -60,6 +57,7 @@ class TabHistoryView(
init {
tabHistoryRecyclerView.adapter = adapter
tabHistoryRecyclerView.layoutManager = layoutManager
tabHistoryRecyclerView.itemAnimator = null
}
fun updateState(state: BrowserState) {
......@@ -73,7 +71,7 @@ class TabHistoryView(
isSelected = index == historyState.currentIndex
)
}
adapter.historyList = items
adapter.submitList(items)
}
}
}
......@@ -7,28 +7,34 @@ package org.mozilla.fenix.tabhistory
import android.view.View
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.history_list_item.view.*
import kotlinx.android.synthetic.main.history_list_item.*
import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.utils.view.ViewHolder
class TabHistoryViewHolder(
private val view: View,
view: View,
private val interactor: TabHistoryViewInteractor
) : RecyclerView.ViewHolder(view) {
) : ViewHolder(view) {
private lateinit var item: TabHistoryItem
init {
itemView.setOnClickListener { interactor.goToHistoryItem(item) }
}
fun bind(item: TabHistoryItem) {
view.history_layout.overflowView.isVisible = false
view.history_layout.urlView.text = item.url
view.history_layout.loadFavicon(item.url)
this.item = item
view.history_layout.titleView.text = if (item.isSelected) {
history_layout.displayAs(LibrarySiteItemView.ItemType.SITE)
history_layout.urlView.text = item.url
history_layout.loadFavicon(item.url)
history_layout.titleView.text = if (item.isSelected) {
buildSpannedString {
bold { append(item.title) }
}
} else {
item.title
}
view.setOnClickListener { interactor.goToHistoryItem(item) }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment