1
0
Fork 0

Fixes #1828 - Adds an empty tab state

master
Jeff Boek 2019-04-19 11:56:12 -07:00
parent 0f367a018a
commit 146492bd59
10 changed files with 85 additions and 10 deletions

View File

@ -90,7 +90,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
private fun getCardTitle(): String? {
return sessionType?.let {
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)
}
}

View File

@ -11,6 +11,7 @@ import io.reactivex.Observer
import kotlinx.coroutines.Job
import org.mozilla.fenix.home.sessioncontrol.viewholders.ArchiveTabsViewHolder
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.TabHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabViewHolder
@ -18,6 +19,7 @@ import java.lang.IllegalStateException
sealed class AdapterItem {
object TabHeader : AdapterItem()
object NoTabMessage : AdapterItem()
data class TabItem(val tab: Tab) : AdapterItem()
object PrivateBrowsingDescription : AdapterItem()
object ArchiveTabs : AdapterItem()
@ -26,6 +28,7 @@ sealed class AdapterItem {
val viewType: Int
get() = when (this) {
TabHeader -> TabHeaderViewHolder.LAYOUT_ID
NoTabMessage -> NoTabMessageViewHolder.LAYOUT_ID
is TabItem -> TabViewHolder.LAYOUT_ID
ArchiveTabs -> ArchiveTabsViewHolder.LAYOUT_ID
PrivateBrowsingDescription -> PrivateBrowsingDescriptionViewHolder.LAYOUT_ID
@ -51,6 +54,7 @@ class SessionControlAdapter(
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return when (viewType) {
TabHeaderViewHolder.LAYOUT_ID -> TabHeaderViewHolder(view, actionEmitter)
NoTabMessageViewHolder.LAYOUT_ID -> NoTabMessageViewHolder(view)
TabViewHolder.LAYOUT_ID -> TabViewHolder(view, actionEmitter, job)
ArchiveTabsViewHolder.LAYOUT_ID -> ArchiveTabsViewHolder(view, actionEmitter)
PrivateBrowsingDescriptionViewHolder.LAYOUT_ID -> PrivateBrowsingDescriptionViewHolder(

View File

@ -19,17 +19,18 @@ import androidx.recyclerview.widget.ItemTouchHelper
@SuppressWarnings("ComplexMethod")
private fun SessionControlState.toAdapterList(): List<AdapterItem> {
val items = mutableListOf<AdapterItem>()
items.add(AdapterItem.TabHeader)
if (tabs.isNotEmpty()) {
items.add(AdapterItem.TabHeader)
tabs.reversed().map(AdapterItem::TabItem).forEach { items.add(it) }
if (mode == Mode.Private) {
items.add(AdapterItem.DeleteTabs)
}
} else {
if (mode == Mode.Private) {
items.add(AdapterItem.PrivateBrowsingDescription)
}
val item = if (mode == Mode.Private) AdapterItem.PrivateBrowsingDescription
else AdapterItem.NoTabMessage
items.add(item)
}
return items

View File

@ -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
}
}

View File

@ -28,7 +28,7 @@ class TabHeaderViewHolder(
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)
tabs_overflow_button.increaseTapArea(overflowButtonIncreaseDps)
tabs_overflow_button.setOnClickListener {

View File

@ -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>

View File

@ -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>

View File

@ -46,7 +46,7 @@
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp"
android:text="@string/tabs_header_title"
android:text="@string/tab_header_label"
android:textAppearance="@style/HeaderTextStyle"
android:textColor="?primaryText"
app:layout_constraintStart_toEndOf="@id/current_session_image"

View File

@ -14,7 +14,7 @@
android:id="@+id/header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tabs_header_title"
android:text="@string/tab_header_label"
android:textAppearance="@style/HeaderTextStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -222,8 +222,8 @@
<string name="content_description_close_button">Close</string>
<!-- Sessions -->
<!-- Title for the list of tabs in the current session -->
<string name="tabs_header_title">Current session</string>
<!-- Title for the list of tabs -->
<string name="tab_header_label">Open tabs</string>
<!-- Title for the list of tabs in the current private session -->
<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 -->
@ -250,6 +250,11 @@
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>
<!-- 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 -->
<!-- Text for the button to clear all history -->
<string name="history_delete_all">Delete history</string>
@ -393,4 +398,8 @@
<string name="tracking_protection_on">On</string>
<!-- Summary of tracking protection preference if tracking protection is set to off -->
<string name="tracking_protection_off">Off</string>
<!-- DEPRECATED -->
<string name="tabs_header_title">DEPRECATED</string>
</resources>