Fixes #1828 - Adds an empty tab state
parent
0f367a018a
commit
146492bd59
|
@ -90,7 +90,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||||
private fun getCardTitle(): String? {
|
private fun getCardTitle(): String? {
|
||||||
return sessionType?.let {
|
return sessionType?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is SessionType.Current -> getString(R.string.tabs_header_title)
|
is SessionType.Current -> getString(R.string.tab_header_label)
|
||||||
is SessionType.Private -> getString(R.string.tabs_header_private_title)
|
is SessionType.Private -> getString(R.string.tabs_header_private_title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import io.reactivex.Observer
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.ArchiveTabsViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.ArchiveTabsViewHolder
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.DeleteTabsViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.DeleteTabsViewHolder
|
||||||
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.NoTabMessageViewHolder
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.PrivateBrowsingDescriptionViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.PrivateBrowsingDescriptionViewHolder
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabHeaderViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabHeaderViewHolder
|
||||||
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabViewHolder
|
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabViewHolder
|
||||||
|
@ -18,6 +19,7 @@ import java.lang.IllegalStateException
|
||||||
|
|
||||||
sealed class AdapterItem {
|
sealed class AdapterItem {
|
||||||
object TabHeader : AdapterItem()
|
object TabHeader : AdapterItem()
|
||||||
|
object NoTabMessage : AdapterItem()
|
||||||
data class TabItem(val tab: Tab) : AdapterItem()
|
data class TabItem(val tab: Tab) : AdapterItem()
|
||||||
object PrivateBrowsingDescription : AdapterItem()
|
object PrivateBrowsingDescription : AdapterItem()
|
||||||
object ArchiveTabs : AdapterItem()
|
object ArchiveTabs : AdapterItem()
|
||||||
|
@ -26,6 +28,7 @@ sealed class AdapterItem {
|
||||||
val viewType: Int
|
val viewType: Int
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
TabHeader -> TabHeaderViewHolder.LAYOUT_ID
|
TabHeader -> TabHeaderViewHolder.LAYOUT_ID
|
||||||
|
NoTabMessage -> NoTabMessageViewHolder.LAYOUT_ID
|
||||||
is TabItem -> TabViewHolder.LAYOUT_ID
|
is TabItem -> TabViewHolder.LAYOUT_ID
|
||||||
ArchiveTabs -> ArchiveTabsViewHolder.LAYOUT_ID
|
ArchiveTabs -> ArchiveTabsViewHolder.LAYOUT_ID
|
||||||
PrivateBrowsingDescription -> PrivateBrowsingDescriptionViewHolder.LAYOUT_ID
|
PrivateBrowsingDescription -> PrivateBrowsingDescriptionViewHolder.LAYOUT_ID
|
||||||
|
@ -51,6 +54,7 @@ class SessionControlAdapter(
|
||||||
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
TabHeaderViewHolder.LAYOUT_ID -> TabHeaderViewHolder(view, actionEmitter)
|
TabHeaderViewHolder.LAYOUT_ID -> TabHeaderViewHolder(view, actionEmitter)
|
||||||
|
NoTabMessageViewHolder.LAYOUT_ID -> NoTabMessageViewHolder(view)
|
||||||
TabViewHolder.LAYOUT_ID -> TabViewHolder(view, actionEmitter, job)
|
TabViewHolder.LAYOUT_ID -> TabViewHolder(view, actionEmitter, job)
|
||||||
ArchiveTabsViewHolder.LAYOUT_ID -> ArchiveTabsViewHolder(view, actionEmitter)
|
ArchiveTabsViewHolder.LAYOUT_ID -> ArchiveTabsViewHolder(view, actionEmitter)
|
||||||
PrivateBrowsingDescriptionViewHolder.LAYOUT_ID -> PrivateBrowsingDescriptionViewHolder(
|
PrivateBrowsingDescriptionViewHolder.LAYOUT_ID -> PrivateBrowsingDescriptionViewHolder(
|
||||||
|
|
|
@ -19,17 +19,18 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
@SuppressWarnings("ComplexMethod")
|
@SuppressWarnings("ComplexMethod")
|
||||||
private fun SessionControlState.toAdapterList(): List<AdapterItem> {
|
private fun SessionControlState.toAdapterList(): List<AdapterItem> {
|
||||||
val items = mutableListOf<AdapterItem>()
|
val items = mutableListOf<AdapterItem>()
|
||||||
|
items.add(AdapterItem.TabHeader)
|
||||||
|
|
||||||
if (tabs.isNotEmpty()) {
|
if (tabs.isNotEmpty()) {
|
||||||
items.add(AdapterItem.TabHeader)
|
|
||||||
tabs.reversed().map(AdapterItem::TabItem).forEach { items.add(it) }
|
tabs.reversed().map(AdapterItem::TabItem).forEach { items.add(it) }
|
||||||
if (mode == Mode.Private) {
|
if (mode == Mode.Private) {
|
||||||
items.add(AdapterItem.DeleteTabs)
|
items.add(AdapterItem.DeleteTabs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mode == Mode.Private) {
|
val item = if (mode == Mode.Private) AdapterItem.PrivateBrowsingDescription
|
||||||
items.add(AdapterItem.PrivateBrowsingDescription)
|
else AdapterItem.NoTabMessage
|
||||||
}
|
|
||||||
|
items.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* 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.home.sessioncontrol.viewholders
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
|
class NoTabMessageViewHolder(
|
||||||
|
view: View
|
||||||
|
) : RecyclerView.ViewHolder(view) {
|
||||||
|
companion object {
|
||||||
|
const val LAYOUT_ID = R.layout.no_tab_message
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ class TabHeaderViewHolder(
|
||||||
actionEmitter.onNext(TabAction.Add)
|
actionEmitter.onNext(TabAction.Add)
|
||||||
}
|
}
|
||||||
|
|
||||||
val headerTextResourceId = if (isPrivate) R.string.tabs_header_private_title else R.string.tabs_header_title
|
val headerTextResourceId = if (isPrivate) R.string.tabs_header_private_title else R.string.tab_header_label
|
||||||
header_text.text = context.getString(headerTextResourceId)
|
header_text.text = context.getString(headerTextResourceId)
|
||||||
tabs_overflow_button.increaseTapArea(overflowButtonIncreaseDps)
|
tabs_overflow_button.increaseTapArea(overflowButtonIncreaseDps)
|
||||||
tabs_overflow_button.setOnClickListener {
|
tabs_overflow_button.setOnClickListener {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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/. -->
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<stroke android:width="2dp" android:dashWidth="4dp" android:color="?neutral" android:dashGap="4dp" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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/. -->
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/no_tabs_wrapper"
|
||||||
|
android:background="@drawable/empty_session_control_background"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_tab_header"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableEnd="@drawable/ic_tabs"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:text="@string/no_open_tabs_header"
|
||||||
|
android:textAppearance="@style/HeaderTextStyle"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_tab_description"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="@string/no_open_tabs_description"
|
||||||
|
android:textColor="?primaryText"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="normal" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -46,7 +46,7 @@
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:text="@string/tabs_header_title"
|
android:text="@string/tab_header_label"
|
||||||
android:textAppearance="@style/HeaderTextStyle"
|
android:textAppearance="@style/HeaderTextStyle"
|
||||||
android:textColor="?primaryText"
|
android:textColor="?primaryText"
|
||||||
app:layout_constraintStart_toEndOf="@id/current_session_image"
|
app:layout_constraintStart_toEndOf="@id/current_session_image"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
android:id="@+id/header_text"
|
android:id="@+id/header_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/tabs_header_title"
|
android:text="@string/tab_header_label"
|
||||||
android:textAppearance="@style/HeaderTextStyle"
|
android:textAppearance="@style/HeaderTextStyle"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
|
@ -222,8 +222,8 @@
|
||||||
<string name="content_description_close_button">Close</string>
|
<string name="content_description_close_button">Close</string>
|
||||||
|
|
||||||
<!-- Sessions -->
|
<!-- Sessions -->
|
||||||
<!-- Title for the list of tabs in the current session -->
|
<!-- Title for the list of tabs -->
|
||||||
<string name="tabs_header_title">Current session</string>
|
<string name="tab_header_label">Open tabs</string>
|
||||||
<!-- Title for the list of tabs in the current private session -->
|
<!-- Title for the list of tabs in the current private session -->
|
||||||
<string name="tabs_header_private_title">Private session</string>
|
<string name="tabs_header_private_title">Private session</string>
|
||||||
<!-- Content description (not visible, for screen readers etc.): Add tab button. Adds a news tab when pressed -->
|
<!-- Content description (not visible, for screen readers etc.): Add tab button. Adds a news tab when pressed -->
|
||||||
|
@ -250,6 +250,11 @@
|
||||||
The first parameter is a digit that shows the cardinal number of how many additional tabs the session has. -->
|
The first parameter is a digit that shows the cardinal number of how many additional tabs the session has. -->
|
||||||
<string name="session_items_more">%1$d sites…</string>
|
<string name="session_items_more">%1$d sites…</string>
|
||||||
|
|
||||||
|
<!-- No Open Tabs Message Header -->
|
||||||
|
<string name="no_open_tabs_header">No tabs opened</string>
|
||||||
|
<!-- No Open Tabs Message Description -->
|
||||||
|
<string name="no_open_tabs_description">Your open tabs will be shown here.</string>
|
||||||
|
|
||||||
<!-- History -->
|
<!-- History -->
|
||||||
<!-- Text for the button to clear all history -->
|
<!-- Text for the button to clear all history -->
|
||||||
<string name="history_delete_all">Delete history</string>
|
<string name="history_delete_all">Delete history</string>
|
||||||
|
@ -393,4 +398,8 @@
|
||||||
<string name="tracking_protection_on">On</string>
|
<string name="tracking_protection_on">On</string>
|
||||||
<!-- Summary of tracking protection preference if tracking protection is set to off -->
|
<!-- Summary of tracking protection preference if tracking protection is set to off -->
|
||||||
<string name="tracking_protection_off">Off</string>
|
<string name="tracking_protection_off">Off</string>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- DEPRECATED -->
|
||||||
|
<string name="tabs_header_title">DEPRECATED</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue