Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Fix swipe disable logic and disable for messenger
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanWang committed Jan 13, 2021
1 parent ce9e44a commit 5aec10c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ class LoginActivity : BaseActivity() {
profileLoader = GlideApp.with(profile)
launch {
for (refreshing in refreshChannel.uniqueOnly(this)) {
if (refreshing) swipeRefresh.isEnabled = true
swipeRefresh.isRefreshing = refreshing
if (!refreshing) swipeRefresh.isEnabled = false
}
}
launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ interface FrostContentParent : DynamicUiContract {

var baseEnum: FbItem?

val swipeEnabled: Boolean get() = swipeAllowedByPage && !swipeDisabledByAction

/**
* Temporary disable swiping based on action
*/
var swipeDisabledByAction: Boolean

/**
* Toggle state for allowing swipes
* Allowed on any thread
* Decides if swipe should be allowed for the current page
*/
var swipeEnabled: Boolean
var swipeAllowedByPage: Boolean

/**
* Binds the container to self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,4 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
}
}

/**
* Alias for adding on refresh listener
*/
interface OnRefreshListener : SwipeRefreshLayout.OnRefreshListener
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FrostJSI(val web: FrostWebView) {
fun longClick(start: Boolean) {
activity?.contentBinding?.viewpager?.enableSwipe = !start
if (web.frostWebClient.urlSupportsRefresh) {
web.parent.swipeEnabled = !start
web.parent.swipeDisabledByAction = start
}
}

Expand All @@ -109,7 +109,7 @@ class FrostJSI(val web: FrostWebView) {
if (!web.frostWebClient.urlSupportsRefresh) {
return
}
web.parent.swipeEnabled = !disable
web.parent.swipeDisabledByAction = disable
if (disable) {
// locked onto an input field; ensure content is visible
(context as? MainActivityContract)?.collapseAppBar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
override fun doUpdateVisitedHistory(view: WebView, url: String?, isReload: Boolean) {
super.doUpdateVisitedHistory(view, url, isReload)
urlSupportsRefresh = urlSupportsRefresh(url)
web.parent.swipeEnabled = urlSupportsRefresh
web.parent.swipeAllowedByPage = urlSupportsRefresh
view.jsInject(
JsAssets.AUTO_RESIZE_TEXTAREA.maybe(prefs.autoExpandTextBox),
prefs = prefs
Expand Down

0 comments on commit 5aec10c

Please sign in to comment.