Issue #19002: Use a single BrowserTrayList for normal/private list

We now have a BrowserTrayList.
 - Renamed from `BaseBrowserTrayList`.
 - Removed the abstract `configuration` and used a `lateinit var`
 instead.
 - Removed `NormalBrowserTrayList` and `PrivateBrowserTrayList`.
upstream-sync
Jonathan Almeida 3 years ago committed by Jonathan Almeida
parent bd753d3f94
commit a95a26b2c6

@ -22,7 +22,7 @@ import org.mozilla.fenix.tabstray.TabsTrayState.Mode
import org.mozilla.fenix.tabstray.TabsTrayStore
/**
* For interacting with UI that is specifically for [BaseBrowserTrayList] and other browser
* For interacting with UI that is specifically for [BrowserTrayList] and other browser
* tab tray views.
*/
interface BrowserTrayInteractor : SelectionInteractor<Tab>, UserInteractionHandler {

@ -14,7 +14,7 @@ import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.ext.filterFromConfig
abstract class BaseBrowserTrayList @JvmOverloads constructor(
class BrowserTrayList @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
@ -25,13 +25,7 @@ abstract class BaseBrowserTrayList @JvmOverloads constructor(
*/
enum class BrowserTabType { NORMAL, PRIVATE }
/**
* A configuration for classes that extend [BaseBrowserTrayList].
*/
data class Configuration(val browserTabType: BrowserTabType)
abstract val configuration: Configuration
lateinit var browserTabType: BrowserTabType
lateinit var interactor: TabsTrayInteractor
lateinit var tabsTrayStore: TabsTrayStore
@ -56,7 +50,7 @@ abstract class BaseBrowserTrayList @JvmOverloads constructor(
context.components.core.store,
selectTabUseCase,
removeTabUseCase,
{ it.filterFromConfig(configuration) },
{ it.filterFromConfig(browserTabType) },
{ }
)
}

@ -1,19 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tabstray.browser
import android.content.Context
import android.util.AttributeSet
/**
* A browser tabs list that displays normal tabs.
*/
class NormalBrowserTrayList @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BaseBrowserTrayList(context, attrs, defStyleAttr) {
override val configuration: Configuration = Configuration(BrowserTabType.NORMAL)
}

@ -1,19 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.tabstray.browser
import android.content.Context
import android.util.AttributeSet
/**
* A browser tabs list that displays private tabs.
*/
class PrivateBrowserTrayList @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BaseBrowserTrayList(context, attrs, defStyleAttr) {
override val configuration: Configuration = Configuration(BrowserTabType.PRIVATE)
}

@ -6,11 +6,11 @@ package org.mozilla.fenix.tabstray.ext
import mozilla.components.browser.state.state.TabSessionState
import org.mozilla.fenix.tabstray.Page
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList.BrowserTabType.PRIVATE
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList.Configuration
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType.PRIVATE
fun TabSessionState.filterFromConfig(configuration: Configuration): Boolean {
val isPrivate = configuration.browserTabType == PRIVATE
fun TabSessionState.filterFromConfig(type: BrowserTabType): Boolean {
val isPrivate = type == PRIVATE
return content.private == isPrivate
}

@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList
import org.mozilla.fenix.tabstray.browser.BrowserTrayList
/**
* A shared view holder for browser tabs tray list.
@ -25,7 +25,7 @@ abstract class BaseBrowserTabViewHolder(
private val currentTabIndex: Int
) : AbstractTrayViewHolder(containerView) {
private val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
protected val trayList: BrowserTrayList = itemView.findViewById(R.id.tray_list_item)
private val emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
abstract val emptyStringText: String

@ -11,6 +11,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.selection.SelectionHolder
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType.NORMAL
import org.mozilla.fenix.tabstray.browser.BrowserTabsAdapter
/**
@ -28,6 +29,10 @@ class NormalBrowserTabViewHolder(
currentTabIndex
), SelectionHolder<Tab> {
init {
trayList.browserTabType = NORMAL
}
/**
* Holds the list of selected tabs.
*

@ -8,6 +8,7 @@ import android.view.View
import org.mozilla.fenix.R
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType.PRIVATE
/**
* View holder for the private tabs tray list.
@ -23,6 +24,11 @@ class PrivateBrowserTabViewHolder(
interactor,
currentTabIndex
) {
init {
trayList.browserTabType = PRIVATE
}
override val emptyStringText: String
get() = itemView.resources.getString(R.string.no_private_tabs_description)

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.mozilla.fenix.tabstray.browser.NormalBrowserTrayList
<org.mozilla.fenix.tabstray.browser.BrowserTrayList
android:id="@+id/tray_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.mozilla.fenix.tabstray.browser.PrivateBrowserTrayList
<org.mozilla.fenix.tabstray.browser.BrowserTrayList
android:id="@+id/tray_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"

@ -4,7 +4,6 @@
package org.mozilla.fenix.tabstray.browser
import android.content.Context
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.support.test.robolectric.testContext
@ -14,11 +13,11 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.tabstray.TabsTrayStore
@RunWith(FenixRobolectricTestRunner::class)
class BaseBrowserTrayListTest {
class BrowserTrayListTest {
@Test
fun `WHEN recyclerview detaches from window THEN notify adapter`() {
val trayList = TestBaseBrowserTrayList(testContext)
val trayList = BrowserTrayList(testContext)
val adapter = mockk<BrowserTabsAdapter>(relaxed = true)
trayList.adapter = adapter
@ -28,8 +27,4 @@ class BaseBrowserTrayListTest {
verify { adapter.onDetachedFromRecyclerView(trayList) }
}
class TestBaseBrowserTrayList(context: Context) : BaseBrowserTrayList(context) {
override val configuration = Configuration(BrowserTabType.PRIVATE)
}
}

@ -11,9 +11,8 @@ import mozilla.components.browser.state.state.TabSessionState
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList.BrowserTabType.NORMAL
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList.BrowserTabType.PRIVATE
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList.Configuration
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType.NORMAL
import org.mozilla.fenix.tabstray.browser.BrowserTrayList.BrowserTabType.PRIVATE
class TabSessionStateKtTest {
@ -21,7 +20,7 @@ class TabSessionStateKtTest {
fun `WHEN configuration is private THEN return true`() {
val contentState = mockk<ContentState>()
val state = TabSessionState(content = contentState)
val config = Configuration(PRIVATE)
val config = PRIVATE
every { contentState.private } returns true
@ -32,7 +31,7 @@ class TabSessionStateKtTest {
fun `WHEN configuration is normal THEN return false`() {
val contentState = mockk<ContentState>()
val state = TabSessionState(content = contentState)
val config = Configuration(NORMAL)
val config = NORMAL
every { contentState.private } returns false
@ -43,13 +42,13 @@ class TabSessionStateKtTest {
fun `WHEN configuration does not match THEN return false`() {
val contentState = mockk<ContentState>()
val state = TabSessionState(content = contentState)
val config = Configuration(NORMAL)
val config = NORMAL
every { contentState.private } returns true
assertFalse(state.filterFromConfig(config))
val config2 = Configuration(PRIVATE)
val config2 = PRIVATE
every { contentState.private } returns false

@ -19,7 +19,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList
import org.mozilla.fenix.tabstray.browser.BrowserTrayList
import org.mozilla.fenix.tabstray.browser.BrowserTabsAdapter
import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor
import org.mozilla.fenix.tabstray.browser.createTab
@ -36,7 +36,7 @@ class BaseBrowserTabViewHolderTest {
val itemView =
LayoutInflater.from(testContext).inflate(R.layout.normal_browser_tray_list, null)
val viewHolder = NormalBrowserTabViewHolder(itemView, store, interactor, 5)
val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
val trayList: BrowserTrayList = itemView.findViewById(R.id.tray_list_item)
val emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
viewHolder.bind(adapter, LinearLayoutManager(testContext))
@ -60,7 +60,7 @@ class BaseBrowserTabViewHolderTest {
val itemView =
LayoutInflater.from(testContext).inflate(R.layout.normal_browser_tray_list, null)
val viewHolder = NormalBrowserTabViewHolder(itemView, store, interactor, 5)
val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
val trayList: BrowserTrayList = itemView.findViewById(R.id.tray_list_item)
val emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
viewHolder.bind(adapter, LinearLayoutManager(testContext))

Loading…
Cancel
Save