Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Issue #21686: Stop using internally stored tabs list in adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger authored and mergify[bot] committed Oct 9, 2021
1 parent abcc9df commit 4ad4940
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ class BrowserTabsAdapter(
* display itself.
*/
override fun onBindViewHolder(holder: AbstractBrowserTabViewHolder, position: Int, payloads: List<Any>) {
val tabs = tabs ?: return

if (tabs.list.isEmpty()) return
if (currentList.isEmpty()) return

if (payloads.isEmpty()) {
onBindViewHolder(holder, position)
return
}

if (position == tabs.selectedIndex) {
if (position == selectedIndex) {
if (payloads.contains(PAYLOAD_HIGHLIGHT_SELECTED_ITEM)) {
holder.updateSelectedTabIndicator(true)
} else if (payloads.contains(PAYLOAD_DONT_HIGHLIGHT_SELECTED_ITEM)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ abstract class TabsAdapter<T : TabViewHolder>(
delegate: Observable<TabsTray.Observer> = ObserverRegistry()
) : ListAdapter<Tab, T>(DiffCallback), TabsTray, Observable<TabsTray.Observer> by delegate {

protected var tabs: Tabs? = null
protected var selectedIndex: Int? = null
protected var styling: TabsTrayStyling = TabsTrayStyling()

@CallSuper
override fun updateTabs(tabs: Tabs) {
this.tabs = tabs
this.selectedIndex = tabs.selectedIndex

submitList(tabs.list)

Expand All @@ -44,13 +44,10 @@ abstract class TabsAdapter<T : TabViewHolder>(

@CallSuper
override fun onBindViewHolder(holder: T, position: Int) {
val tabs = tabs ?: return

holder.bind(tabs.list[position], isTabSelected(tabs, position), styling, this)
holder.bind(getItem(position), selectedIndex == position, styling, this)
}

final override fun isTabSelected(tabs: Tabs, position: Int): Boolean =
tabs.selectedIndex == position
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false

private object DiffCallback : DiffUtil.ItemCallback<Tab>() {
override fun areItemsTheSame(oldItem: Tab, newItem: Tab): Boolean {
Expand Down

0 comments on commit 4ad4940

Please sign in to comment.