Commit 806f6031 authored by Grisha Kruglov's avatar Grisha Kruglov Committed by Grisha Kruglov
Browse files

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

parent ad265be6
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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
        }
    }
}
+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))
    }
}