|
|
|
@ -10,6 +10,10 @@ import android.view.View
|
|
|
|
|
import android.widget.FrameLayout
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import kotlinx.android.synthetic.main.component_sync_tabs.view.*
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.cancel
|
|
|
|
|
import mozilla.components.browser.storage.sync.SyncedDeviceTabs
|
|
|
|
|
import mozilla.components.feature.syncedtabs.view.SyncedTabsView
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
@ -23,6 +27,7 @@ class SyncedTabsLayout @JvmOverloads constructor(
|
|
|
|
|
override var listener: SyncedTabsView.Listener? = null
|
|
|
|
|
|
|
|
|
|
private val adapter = SyncedTabsAdapter { listener?.onTabClicked(it) }
|
|
|
|
|
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
inflate(getContext(), R.layout.component_sync_tabs, this)
|
|
|
|
@ -34,6 +39,7 @@ class SyncedTabsLayout @JvmOverloads constructor(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onError(error: SyncedTabsView.ErrorType) {
|
|
|
|
|
coroutineScope.launch {
|
|
|
|
|
// We may still be displaying a "loading" spinner, hide it.
|
|
|
|
|
stopLoading()
|
|
|
|
|
|
|
|
|
@ -52,8 +58,10 @@ class SyncedTabsLayout @JvmOverloads constructor(
|
|
|
|
|
|
|
|
|
|
synced_tabs_pull_to_refresh.isEnabled = pullToRefreshEnableState(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun displaySyncedTabs(syncedTabs: List<SyncedDeviceTabs>) {
|
|
|
|
|
coroutineScope.launch {
|
|
|
|
|
synced_tabs_list.visibility = View.VISIBLE
|
|
|
|
|
sync_tabs_status.visibility = View.GONE
|
|
|
|
|
|
|
|
|
@ -71,6 +79,7 @@ class SyncedTabsLayout @JvmOverloads constructor(
|
|
|
|
|
|
|
|
|
|
adapter.submitList(allDeviceTabs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun startLoading() {
|
|
|
|
|
synced_tabs_list.visibility = View.VISIBLE
|
|
|
|
@ -83,6 +92,11 @@ class SyncedTabsLayout @JvmOverloads constructor(
|
|
|
|
|
synced_tabs_pull_to_refresh.isRefreshing = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow()
|
|
|
|
|
coroutineScope.cancel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|