Loading app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt +17 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,8 @@ class SyncedTabsLayout @JvmOverloads constructor( synced_tabs_list.visibility = View.GONE sync_tabs_status.visibility = View.VISIBLE synced_tabs_pull_to_refresh.isEnabled = false synced_tabs_pull_to_refresh.isEnabled = pullToRefreshEnableState(error) } override fun displaySyncedTabs(syncedTabs: List<SyncedDeviceTabs>) { Loading Loading @@ -78,4 +79,19 @@ class SyncedTabsLayout @JvmOverloads constructor( override fun stopLoading() { synced_tabs_pull_to_refresh.isRefreshing = false } companion object { internal fun pullToRefreshEnableState(error: SyncedTabsView.ErrorType) = when (error) { // Disable "pull-to-refresh" when we clearly can't sync tabs, and user needs to take an // action within the app. SyncedTabsView.ErrorType.SYNC_UNAVAILABLE, SyncedTabsView.ErrorType.SYNC_NEEDS_REAUTHENTICATION -> false // Enable "pull-to-refresh" when an external event (e.g. connecting a desktop client, // or enabling tabs sync, or connecting to a network) may resolve our problem. SyncedTabsView.ErrorType.SYNC_ENGINE_UNAVAILABLE, SyncedTabsView.ErrorType.MULTIPLE_DEVICES_UNAVAILABLE, SyncedTabsView.ErrorType.NO_TABS_AVAILABLE -> true } } } app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line /* 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.sync import mozilla.components.feature.syncedtabs.view.SyncedTabsView.ErrorType import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse import org.junit.Test class SyncedTabsLayoutTest { @Test fun `pull to refresh state`() { assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.MULTIPLE_DEVICES_UNAVAILABLE)) assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_ENGINE_UNAVAILABLE)) assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.NO_TABS_AVAILABLE)) assertFalse(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_NEEDS_REAUTHENTICATION)) assertFalse(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_UNAVAILABLE)) } } Loading
app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt +17 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,8 @@ class SyncedTabsLayout @JvmOverloads constructor( synced_tabs_list.visibility = View.GONE sync_tabs_status.visibility = View.VISIBLE synced_tabs_pull_to_refresh.isEnabled = false synced_tabs_pull_to_refresh.isEnabled = pullToRefreshEnableState(error) } override fun displaySyncedTabs(syncedTabs: List<SyncedDeviceTabs>) { Loading Loading @@ -78,4 +79,19 @@ class SyncedTabsLayout @JvmOverloads constructor( override fun stopLoading() { synced_tabs_pull_to_refresh.isRefreshing = false } companion object { internal fun pullToRefreshEnableState(error: SyncedTabsView.ErrorType) = when (error) { // Disable "pull-to-refresh" when we clearly can't sync tabs, and user needs to take an // action within the app. SyncedTabsView.ErrorType.SYNC_UNAVAILABLE, SyncedTabsView.ErrorType.SYNC_NEEDS_REAUTHENTICATION -> false // Enable "pull-to-refresh" when an external event (e.g. connecting a desktop client, // or enabling tabs sync, or connecting to a network) may resolve our problem. SyncedTabsView.ErrorType.SYNC_ENGINE_UNAVAILABLE, SyncedTabsView.ErrorType.MULTIPLE_DEVICES_UNAVAILABLE, SyncedTabsView.ErrorType.NO_TABS_AVAILABLE -> true } } }
app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line /* 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.sync import mozilla.components.feature.syncedtabs.view.SyncedTabsView.ErrorType import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse import org.junit.Test class SyncedTabsLayoutTest { @Test fun `pull to refresh state`() { assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.MULTIPLE_DEVICES_UNAVAILABLE)) assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_ENGINE_UNAVAILABLE)) assertTrue(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.NO_TABS_AVAILABLE)) assertFalse(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_NEEDS_REAUTHENTICATION)) assertFalse(SyncedTabsLayout.pullToRefreshEnableState(ErrorType.SYNC_UNAVAILABLE)) } }