diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index e25b603e..177b8862 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -22,7 +22,6 @@ import android.util.AttributeSet import android.view.View import android.widget.FrameLayout import android.widget.ProgressBar -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import ca.allanwang.kau.utils.ContextHelper import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.circularReveal @@ -104,14 +103,26 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( protected abstract val layoutRes: Int - override var swipeEnabled = true + @Volatile + override var swipeDisabledByAction = false set(value) { - if (field == value) - return field = value - refresh.post { refresh.isEnabled = value } + updateSwipeEnabler() } + @Volatile + override var swipeAllowedByPage: Boolean = true + set(value) { + field = value + updateSwipeEnabler() + } + + private fun updateSwipeEnabler() { + val swipeEnabled = swipeAllowedByPage && !swipeDisabledByAction + if (refresh.isEnabled == swipeEnabled) return + refresh.post { refresh.isEnabled = swipeEnabled } + } + /** * Sets up everything * Called by [bind] @@ -136,7 +147,6 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( refreshChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { r -> refresh.isRefreshing = r - refresh.isEnabled = true } progressChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { p -> |