For #18520: Add Empty Tab State To Browser Tray List

upstream-sync
Kate Glazko 3 years ago committed by Jonathan Almeida
parent d0f8b3a64d
commit ae157e5679

@ -5,6 +5,9 @@
package org.mozilla.fenix.tabstray.viewholders
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.TextView
import androidx.annotation.CallSuper
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
@ -23,10 +26,13 @@ abstract class BaseBrowserTabViewHolder(
) : AbstractTrayViewHolder(containerView) {
private val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
private val emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
abstract val emptyStringText: String
init {
trayList.interactor = interactor
trayList.tabsTrayStore = tabsTrayStore
emptyList.text = emptyStringText
}
@CallSuper
@ -36,11 +42,21 @@ abstract class BaseBrowserTabViewHolder(
) {
adapter.registerAdapterDataObserver(OneTimeAdapterObserver(adapter) {
trayList.scrollToPosition(currentTabIndex)
updateTrayVisibility(adapter.itemCount)
})
trayList.layoutManager = layoutManager
trayList.adapter = adapter
}
private fun updateTrayVisibility(size: Int) {
if (size == 0) {
trayList.visibility = GONE
emptyList.visibility = VISIBLE
} else {
trayList.visibility = VISIBLE
emptyList.visibility = GONE
}
}
}
/**

@ -37,6 +37,9 @@ class NormalBrowserTabViewHolder(
override val selectedItems: Set<Tab>
get() = store.state.mode.selectedTabs
override val emptyStringText: String
get() = itemView.resources.getString(R.string.no_open_tabs_description)
override fun bind(
adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>,
layoutManager: RecyclerView.LayoutManager

@ -23,6 +23,9 @@ class PrivateBrowserTabViewHolder(
interactor,
currentTabIndex
) {
override val emptyStringText: String
get() = itemView.resources.getString(R.string.no_private_tabs_description)
companion object {
const val LAYOUT_ID = R.layout.private_browser_tray_list
}

@ -32,23 +32,6 @@
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/topBar" />
<TextView
android:id="@+id/tab_tray_empty_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:paddingTop="80dp"
android:text="@string/no_open_tabs_description"
android:textColor="?secondaryText"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/info_banner" />
<View
android:id="@+id/topBar"
android:layout_width="match_parent"

@ -1,6 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<org.mozilla.fenix.tabstray.browser.NormalBrowserTrayList
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tray_list_item"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">
<org.mozilla.fenix.tabstray.browser.NormalBrowserTrayList
android:id="@+id/tray_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<TextView
android:id="@+id/tab_tray_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:paddingTop="80dp"
android:text="@string/no_open_tabs_description"
android:textColor="?secondaryText"
android:textSize="16sp"
android:visibility="visible" />
</FrameLayout>

@ -1,6 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<org.mozilla.fenix.tabstray.browser.PrivateBrowserTrayList
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tray_list_item"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">
<org.mozilla.fenix.tabstray.browser.PrivateBrowserTrayList
android:id="@+id/tray_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<TextView
android:id="@+id/tab_tray_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:paddingTop="80dp"
android:text="@string/no_open_tabs_description"
android:textColor="?secondaryText"
android:textSize="16sp"
android:visibility="visible" />
</FrameLayout>

@ -0,0 +1,79 @@
/* 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.viewholders
import android.view.LayoutInflater
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import io.mockk.mockk
import mozilla.components.concept.tabstray.Tabs
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
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.BrowserTabsAdapter
import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor
import org.mozilla.fenix.tabstray.browser.createTab
@RunWith(FenixRobolectricTestRunner::class)
class BaseBrowserTabViewHolderTest {
val store: TabsTrayStore = TabsTrayStore()
val interactor = mockk<TabsTrayInteractor>(relaxed = true)
val browserTrayInteractor = mockk<BrowserTrayInteractor>(relaxed = true)
val adapter = BrowserTabsAdapter(testContext, browserTrayInteractor, store)
@Test
fun `WHEN tabs inserted THEN show tray`() {
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 emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
viewHolder.bind(adapter, LinearLayoutManager(testContext))
adapter.updateTabs(
Tabs(
list = listOf(
createTab("tab1")
),
selectedIndex = 0
)
)
adapter.onTabsInserted(0, 1)
assertTrue(trayList.visibility == VISIBLE)
assertTrue(emptyList.visibility == GONE)
}
@Test
fun `WHEN no tabs THEN show empty view`() {
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 emptyList: TextView = itemView.findViewById(R.id.tab_tray_empty_view)
viewHolder.bind(adapter, LinearLayoutManager(testContext))
adapter.updateTabs(
Tabs(
list = emptyList(),
selectedIndex = 0
)
)
adapter.onTabsInserted(0, 0)
assertTrue(trayList.visibility == GONE)
assertTrue(emptyList.visibility == VISIBLE)
}
}
Loading…
Cancel
Save