diff --git a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt index f3f882929..1f2fd9a91 100644 --- a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt +++ b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt @@ -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) { @@ -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 + } + } } diff --git a/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt b/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt new file mode 100644 index 000000000..7b69743b9 --- /dev/null +++ b/app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt @@ -0,0 +1,21 @@ +/* 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)) + } +}