1
0
Fork 0

For #12433 - Allow synced tabs pull-to-refresh for non-critical account errors

master
Grisha Kruglov 2020-07-09 14:49:56 -07:00 committed by Grisha Kruglov
parent ad265be672
commit 806f6031ae
2 changed files with 38 additions and 1 deletions

View File

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

View File

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