diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt index 436f8b00..38b09657 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt @@ -1,15 +1,17 @@ package com.pitchedapps.frost.views import android.content.Context +import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.util.AttributeSet import android.view.View +import ca.allanwang.kau.utils.circularReveal +import ca.allanwang.kau.utils.fadeOut import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.fragments.RecyclerContentContract -import com.pitchedapps.frost.utils.L -import java.lang.ref.WeakReference +import com.pitchedapps.frost.utils.Prefs /** * Created by Allan Wang on 2017-05-29. @@ -27,12 +29,16 @@ class FrostRecyclerView @JvmOverloads constructor( override val currentUrl: String get() = parent.baseUrl - lateinit var recyclerContract: WeakReference<RecyclerContentContract> + lateinit var recyclerContract: RecyclerContentContract + + init { + layoutManager = LinearLayoutManager(context) + } override fun bind(container: FrostContentContainer): View { if (container !is RecyclerContentContract) throw IllegalStateException("FrostRecyclerView must bind to a container that is a RecyclerContentContract") - this.recyclerContract = WeakReference(container) + this.recyclerContract = container container.bind(this) return this } @@ -41,15 +47,15 @@ class FrostRecyclerView @JvmOverloads constructor( isNestedScrollingEnabled = true } + var onReloadClear: () -> Unit = {} + override fun reloadBase(animate: Boolean) { - val contract = recyclerContract.get() - if (contract == null) { - L.eThrow("Attempted to reload with invalid contract") - return - } - contract.reload({ parent.progressObservable.onNext(it) }) { + if (Prefs.animate) fadeOut(onFinish = onReloadClear) + parent.refreshObservable.onNext(true) + recyclerContract.reload({ parent.progressObservable.onNext(it) }) { parent.progressObservable.onNext(100) parent.refreshObservable.onNext(false) + if (Prefs.animate) post { circularReveal() } } } @@ -64,11 +70,12 @@ class FrostRecyclerView @JvmOverloads constructor( override fun onBackPressed() = false /** - * If webview is already at the top, refresh + * If recycler is already at the top, refresh * Otherwise scroll to top */ override fun onTabClicked() { - if (scrollY < 5) reloadBase(true) + val firstPosition = (layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() + if (firstPosition == 0) reloadBase(true) else scrollToTop() } @@ -77,12 +84,8 @@ class FrostRecyclerView @JvmOverloads constructor( smoothScrollToPosition(0) } + // nothing running in background; no need to listen override var active: Boolean = true - set(value) { - if (field == value) return - field = value - // todo - } override fun reloadTheme() { reloadThemeSelf() |