For #13427 - Disable the "selected tab" decoration when in Multiselect

Selecting a tab while in Multiselect would add a different decoration to the one
already set for the last tab opened and this would confuse users.
Let's avoid this.
This commit is contained in:
Mugurell 2020-11-04 17:53:23 +02:00 committed by Christian Sadilek
parent d1345e8f93
commit f2191bdbb5
2 changed files with 18 additions and 5 deletions

View File

@ -59,13 +59,22 @@ class FenixTabsAdapter(
override fun onBindViewHolder(
holder: TabViewHolder,
position: Int,
payloads: MutableList<Any>
payloads: List<Any>
) {
if (payloads.isNullOrEmpty()) {
onBindViewHolder(holder, position)
return
}
// Having non-empty payloads means we have to make a partial update.
// This currently only happens when changing between the Normal and MultiSelect modes
// when we want to either show the last opened tab as selected (default) or hide this ui decorator.
if (mode is TabTrayDialogFragmentState.Mode.Normal) {
super.onBindViewHolder(holder, position, listOf(PAYLOAD_HIGHLIGHT_SELECTED_ITEM))
} else {
super.onBindViewHolder(holder, position, listOf(PAYLOAD_DONT_HIGHLIGHT_SELECTED_ITEM))
}
holder.tab?.let { showCheckedIfSelected(it, holder.itemView) }
}
@ -133,6 +142,11 @@ class FenixTabsAdapter(
tabsList = recyclerView
}
override fun isTabSelected(tabs: Tabs, position: Int): Boolean {
return mode is TabTrayDialogFragmentState.Mode.Normal &&
tabs.selectedIndex == position
}
private fun showCheckedIfSelected(tab: Tab, view: View) {
val shouldBeChecked =
mode is TabTrayDialogFragmentState.Mode.MultiSelect && selectedItems.contains(tab)

View File

@ -227,10 +227,9 @@ class TabTrayViewHolder(
.take(MAX_URI_LENGTH)
}
@VisibleForTesting
internal fun updateSelectedTabIndicator(isSelected: Boolean) {
override fun updateSelectedTabIndicator(showAsSelected: Boolean) {
if (itemView.context.settings().gridTabView) {
itemView.tab_tray_grid_item.background = if (isSelected) {
itemView.tab_tray_grid_item.background = if (showAsSelected) {
AppCompatResources.getDrawable(itemView.context, R.drawable.tab_tray_grid_item_selected_border)
} else {
null
@ -238,7 +237,7 @@ class TabTrayViewHolder(
return
}
val color = if (isSelected) {
val color = if (showAsSelected) {
R.color.tab_tray_item_selected_background_normal_theme
} else {
R.color.tab_tray_item_background_normal_theme