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 c6354c5f authored by ekager's avatar ekager Committed by liuche
Browse files

For #13117 - Don't show add to collections button in private tabs tray

parent a1f622c2
......@@ -20,7 +20,8 @@ import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.ViewHolder
* multiple [RecyclerView.Adapter] in one [RecyclerView].
*/
class SaveToCollectionsButtonAdapter(
private val interactor: TabTrayInteractor
private val interactor: TabTrayInteractor,
private val isPrivate: Boolean = false
) : ListAdapter<Item, ViewHolder>(DiffCallback) {
init {
......@@ -38,14 +39,19 @@ class SaveToCollectionsButtonAdapter(
return
}
(payloads[0] as TabTrayView.TabChange).let {
holder.itemView.isVisible = it == TabTrayView.TabChange.NORMAL
when (val change = payloads[0]) {
is TabTrayView.TabChange -> {
holder.itemView.isVisible = change == TabTrayView.TabChange.NORMAL
}
is MultiselectModeChange -> {
holder.itemView.isVisible = change == MultiselectModeChange.NORMAL
}
}
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.itemView.isVisible =
interactor.onModeRequested() is TabTrayDialogFragmentState.Mode.Normal
holder.itemView.isVisible = !isPrivate &&
interactor.onModeRequested() is TabTrayDialogFragmentState.Mode.Normal
}
override fun getItemViewType(position: Int): Int {
......@@ -58,6 +64,10 @@ class SaveToCollectionsButtonAdapter(
override fun areContentsTheSame(oldItem: Item, newItem: Item) = true
}
enum class MultiselectModeChange {
MULTISELECT, NORMAL
}
/**
* An object to identify the data type.
*/
......
......@@ -41,6 +41,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange
/**
* View that contains and configures the BrowserAwesomeBar
......@@ -72,7 +73,7 @@ class TabTrayView(
private val bottomSheetCallback: BottomSheetBehavior.BottomSheetCallback
private var tabsTouchHelper: TabsTouchHelper
private val collectionsButtonAdapter = SaveToCollectionsButtonAdapter(interactor)
private val collectionsButtonAdapter = SaveToCollectionsButtonAdapter(interactor, isPrivate)
private var hasLoaded = false
......@@ -272,7 +273,7 @@ class TabTrayView(
val oldMode = mode
if (oldMode::class != state.mode::class) {
updateTabsForModeChanged()
updateTabsForMultiselectModeChanged(state.mode is TabTrayDialogFragmentState.Mode.MultiSelect)
if (view.context.settings().accessibilityServicesEnabled) {
view.announceForAccessibility(
if (state.mode == TabTrayDialogFragmentState.Mode.Normal) view.context.getString(
......@@ -419,13 +420,17 @@ class TabTrayView(
view.tab_layout.isVisible = !multiselect
}
private fun updateTabsForModeChanged() {
private fun updateTabsForMultiselectModeChanged(inMultiselectMode: Boolean) {
view.tabsTray.apply {
val tabs = view.context.components.core.store.state.getNormalOrPrivateTabs(
isPrivateModeSelected
)
collectionsButtonAdapter.notifyItemChanged(0)
collectionsButtonAdapter.notifyItemChanged(
0,
if (inMultiselectMode) MultiselectModeChange.MULTISELECT else MultiselectModeChange.NORMAL
)
tabsAdapter.notifyItemRangeChanged(0, tabs.size, true)
}
}
......
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