aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-01-12 23:07:02 -0800
committerAllan Wang <me@allanwang.ca>2021-01-12 23:07:02 -0800
commit5aec10ce0fe191d78399869074c7e118256848ea (patch)
treeaff3d79f003ef1200a36b810a336d6947e69114d
parentce9e44a742638eaaad5833f39d394535ddfd67a2 (diff)
downloadfrost-5aec10ce0fe191d78399869074c7e118256848ea.tar.gz
frost-5aec10ce0fe191d78399869074c7e118256848ea.tar.bz2
frost-5aec10ce0fe191d78399869074c7e118256848ea.zip
Fix swipe disable logic and disable for messenger
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt22
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt2
6 files changed, 28 insertions, 19 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
index 601516de..5cbbfafe 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
@@ -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 {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
index 8a6e57af..b8d0d86f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
@@ -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
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 ->
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt
index 9e9c2340..f02adcf0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt
@@ -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
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
index 40a048af..4e8e8cee 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -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
}
}
@@ -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()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
index 99473a11..8ec5f975 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -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