mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-02 03:40:16 +00:00
Issue #21686: Move submitList calls into TabsAdapter
Co-authored-by: Roger Yang <royang@mozilla.com>
This commit is contained in:
parent
7e0146d08d
commit
aa1bd6b7e4
@ -105,10 +105,6 @@ class InactiveTabsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
||||||
override fun onTabsChanged(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsInserted(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsMoved(fromPosition: Int, toPosition: Int) = Unit
|
|
||||||
override fun onTabsRemoved(position: Int, count: Int) = Unit
|
|
||||||
|
|
||||||
private object DiffCallback : DiffUtil.ItemCallback<Item>() {
|
private object DiffCallback : DiffUtil.ItemCallback<Item>() {
|
||||||
override fun areItemsTheSame(oldItem: Item, newItem: Item): Boolean {
|
override fun areItemsTheSame(oldItem: Item, newItem: Item): Boolean {
|
||||||
|
@ -109,10 +109,6 @@ class TabGroupAdapter(
|
|||||||
* Not implemented; handled by nested [RecyclerView].
|
* Not implemented; handled by nested [RecyclerView].
|
||||||
*/
|
*/
|
||||||
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
||||||
override fun onTabsChanged(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsInserted(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsMoved(fromPosition: Int, toPosition: Int) = Unit
|
|
||||||
override fun onTabsRemoved(position: Int, count: Int) = Unit
|
|
||||||
|
|
||||||
private object DiffCallback : DiffUtil.ItemCallback<Group>() {
|
private object DiffCallback : DiffUtil.ItemCallback<Group>() {
|
||||||
override fun areItemsTheSame(oldItem: Group, newItem: Group) = oldItem.title == newItem.title
|
override fun areItemsTheSame(oldItem: Group, newItem: Group) = oldItem.title == newItem.title
|
||||||
|
@ -46,19 +46,10 @@ class TabSorter(
|
|||||||
// Normal tabs.
|
// Normal tabs.
|
||||||
val totalNormalTabs = (normalTabs + remainderTabs)
|
val totalNormalTabs = (normalTabs + remainderTabs)
|
||||||
val selectedTabIndex = totalNormalTabs.findSelectedIndex(selectedTabId)
|
val selectedTabIndex = totalNormalTabs.findSelectedIndex(selectedTabId)
|
||||||
|
|
||||||
// N.B: For regular tabs, we cannot use submitList alone, because the `TabsAdapter` needs to have a reference
|
|
||||||
// to the new tabs in it. We considered moving the call within `updateTabs` but this would have the side-effect
|
|
||||||
// of notifying the adapter twice for private tabs which shared the `TabsAdapter`.
|
|
||||||
concatAdapter.browserAdapter.updateTabs(Tabs(totalNormalTabs, selectedTabIndex))
|
concatAdapter.browserAdapter.updateTabs(Tabs(totalNormalTabs, selectedTabIndex))
|
||||||
concatAdapter.browserAdapter.submitList(totalNormalTabs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
|
||||||
override fun onTabsChanged(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsInserted(position: Int, count: Int) = Unit
|
|
||||||
override fun onTabsMoved(fromPosition: Int, toPosition: Int) = Unit
|
|
||||||
override fun onTabsRemoved(position: Int, count: Int) = Unit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Tab>.findSelectedIndex(tabId: String?): Int {
|
private fun List<Tab>.findSelectedIndex(tabId: String?): Int {
|
||||||
|
@ -37,6 +37,8 @@ abstract class TabsAdapter<T : TabViewHolder>(
|
|||||||
override fun updateTabs(tabs: Tabs) {
|
override fun updateTabs(tabs: Tabs) {
|
||||||
this.tabs = tabs
|
this.tabs = tabs
|
||||||
|
|
||||||
|
submitList(tabs.list)
|
||||||
|
|
||||||
notifyObservers { onTabsUpdated() }
|
notifyObservers { onTabsUpdated() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,23 +49,9 @@ abstract class TabsAdapter<T : TabViewHolder>(
|
|||||||
holder.bind(tabs.list[position], isTabSelected(tabs, position), styling, this)
|
holder.bind(tabs.list[position], isTabSelected(tabs, position), styling, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = tabs?.list?.size ?: 0
|
|
||||||
|
|
||||||
final override fun isTabSelected(tabs: Tabs, position: Int): Boolean =
|
final override fun isTabSelected(tabs: Tabs, position: Int): Boolean =
|
||||||
tabs.selectedIndex == position
|
tabs.selectedIndex == position
|
||||||
|
|
||||||
final override fun onTabsChanged(position: Int, count: Int) =
|
|
||||||
notifyItemRangeChanged(position, count)
|
|
||||||
|
|
||||||
final override fun onTabsInserted(position: Int, count: Int) =
|
|
||||||
notifyItemRangeInserted(position, count)
|
|
||||||
|
|
||||||
final override fun onTabsMoved(fromPosition: Int, toPosition: Int) =
|
|
||||||
notifyItemMoved(fromPosition, toPosition)
|
|
||||||
|
|
||||||
final override fun onTabsRemoved(position: Int, count: Int) =
|
|
||||||
notifyItemRangeRemoved(position, count)
|
|
||||||
|
|
||||||
private object DiffCallback : DiffUtil.ItemCallback<Tab>() {
|
private object DiffCallback : DiffUtil.ItemCallback<Tab>() {
|
||||||
override fun areItemsTheSame(oldItem: Tab, newItem: Tab): Boolean {
|
override fun areItemsTheSame(oldItem: Tab, newItem: Tab): Boolean {
|
||||||
return oldItem.id == newItem.id
|
return oldItem.id == newItem.id
|
||||||
|
@ -51,7 +51,6 @@ class AbstractBrowserPageViewHolderTest {
|
|||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
adapter.onTabsInserted(0, 1)
|
|
||||||
|
|
||||||
assertTrue(trayList.visibility == VISIBLE)
|
assertTrue(trayList.visibility == VISIBLE)
|
||||||
assertTrue(emptyList.visibility == GONE)
|
assertTrue(emptyList.visibility == GONE)
|
||||||
@ -74,7 +73,6 @@ class AbstractBrowserPageViewHolderTest {
|
|||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
adapter.onTabsInserted(0, 0)
|
|
||||||
|
|
||||||
assertTrue(trayList.visibility == GONE)
|
assertTrue(trayList.visibility == GONE)
|
||||||
assertTrue(emptyList.visibility == VISIBLE)
|
assertTrue(emptyList.visibility == VISIBLE)
|
||||||
|
Loading…
Reference in New Issue
Block a user