1
0
Fork 0

For #12287: Show devices with no tabs in Synced Tabs list

master
Jonathan Almeida 2020-08-18 01:15:08 -04:00 committed by Jonathan Almeida
parent f614c0b18d
commit b54b743d83
5 changed files with 29 additions and 24 deletions

View File

@ -7,16 +7,16 @@ package org.mozilla.fenix.sync.ext
import mozilla.components.browser.storage.sync.SyncedDeviceTabs import mozilla.components.browser.storage.sync.SyncedDeviceTabs
import org.mozilla.fenix.sync.SyncedTabsAdapter.AdapterItem import org.mozilla.fenix.sync.SyncedTabsAdapter.AdapterItem
fun List<SyncedDeviceTabs>.toAdapterList( /**
): MutableList<AdapterItem> { * Converts a list of [SyncedDeviceTabs] into a list of [AdapterItem].
val allDeviceTabs = mutableListOf<AdapterItem>() */
fun List<SyncedDeviceTabs>.toAdapterList() = asSequence().flatMap { (device, tabs) ->
forEach { (device, tabs) -> val deviceTabs = if (tabs.isEmpty()) {
if (tabs.isNotEmpty()) { sequenceOf(AdapterItem.NoTabs(device))
allDeviceTabs.add(AdapterItem.Device(device)) } else {
tabs.mapTo(allDeviceTabs) { AdapterItem.Tab(it) } tabs.asSequence().map { AdapterItem.Tab(it) }
}
} }
return allDeviceTabs sequenceOf(AdapterItem.Device(device)) + deviceTabs
} }.toList()

View File

@ -8,6 +8,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?android:attr/selectableItemBackground"> android:background="?android:attr/selectableItemBackground">
<TextView <TextView
@ -42,16 +43,4 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/synced_tab_item_title" /> app:layout_constraintTop_toBottomOf="@+id/synced_tab_item_title" />
<View
android:id="@+id/synced_tab_item_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="7dp"
android:background="?syncedTabsSeparator"
android:importantForAccessibility="no"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/synced_tab_item_url" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -4,6 +4,18 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:paddingBottom="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginTop="16dp"
android:singleLine="true"
android:text="@string/synced_tabs_no_open_tabs"
android:textAlignment="viewStart"
android:textColor="?secondaryText"
android:textSize="12sp" />
</FrameLayout> </FrameLayout>

View File

@ -1455,6 +1455,8 @@
<string name="synced_tabs_sign_in_message">View a list of tabs from your other devices.</string> <string name="synced_tabs_sign_in_message">View a list of tabs from your other devices.</string>
<!-- Text displayed on a button in the synced tabs screen to link users to sign in when a user is not signed in to Firefox Sync --> <!-- Text displayed on a button in the synced tabs screen to link users to sign in when a user is not signed in to Firefox Sync -->
<string name="synced_tabs_sign_in_button">Sign in to sync</string> <string name="synced_tabs_sign_in_button">Sign in to sync</string>
<!-- The text displayed when a synced device has no tabs to show in the list of Synced Tabs. -->
<string name="synced_tabs_no_open_tabs">No open tabs</string>
<!-- Top Sites --> <!-- Top Sites -->
<!-- Title text displayed in the dialog when top sites limit is reached. --> <!-- Title text displayed in the dialog when top sites limit is reached. -->

View File

@ -87,6 +87,8 @@ class SyncedTabsAdapterKtTest {
val syncedDeviceList = listOf(noTabDevice) val syncedDeviceList = listOf(noTabDevice)
val adapterData = syncedDeviceList.toAdapterList() val adapterData = syncedDeviceList.toAdapterList()
assertEquals(0, adapterData.count()) assertEquals(2, adapterData.count())
assertTrue(adapterData[0] is SyncedTabsAdapter.AdapterItem.Device)
assertTrue(adapterData[1] is SyncedTabsAdapter.AdapterItem.NoTabs)
} }
} }