From 92aad9bf4cd6ec5c1568420e9a2514bd4861438b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 11:54:38 -0700 Subject: Disable refresh if not at the top, resolves #1450 --- .../pitchedapps/frost/activities/LoginActivity.kt | 3 + .../pitchedapps/frost/views/SwipeRefreshLayout.kt | 78 ++++++++++++++++++++++ app/src/main/res/layout/activity_debug.xml | 4 +- app/src/main/res/layout/login_webview.xml | 4 +- .../main/res/layout/view_content_base_recycler.xml | 4 +- app/src/main/res/layout/view_content_base_web.xml | 4 +- 6 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt (limited to 'app/src') 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 ed207896..42a0f6bb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -87,6 +87,9 @@ class LoginActivity : BaseActivity() { toolbar(toolbar) } profileLoader = GlideApp.with(profile) + swipeRefresh.setOnChildScrollUpCallback { parent, child -> + web.canScrollVertically(-1) + } launch { for (refreshing in refreshChannel.uniqueOnly(this)) { if (refreshing) swipeRefresh.isEnabled = true diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt new file mode 100644 index 00000000..0ab11fc6 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt @@ -0,0 +1,78 @@ +package com.pitchedapps.frost.views + +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import android.view.View +import android.view.ViewConfiguration +import android.webkit.WebView +import android.widget.ListView +import androidx.core.widget.ListViewCompat +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnChildScrollUpCallback +import com.pitchedapps.frost.utils.L + +/** + * Variant that forbids refreshing if child layout is not at the top + * Inspired by https://github.com/slapperwan/gh4a/blob/master/app/src/main/java/com/gh4a/widget/SwipeRefreshLayout.java + * + */ +class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + SwipeRefreshLayout(context, attrs) { + + private var preventRefresh: Boolean = false + private var downY: Float = -1f + private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop + + /** + * Copy of [canChildScrollUp], with additional support if necessary + */ + private val canChildScrollUp = OnChildScrollUpCallback { parent, child -> + when (child) { + is WebView -> child.canScrollVertically(-1).apply { + L.d { "Webview can scroll up $this" } + } + is ListView -> ListViewCompat.canScrollList(child, -1) + // Supports webviews as well + else -> child?.canScrollVertically(-1) ?: false + } + } + + init { + setOnChildScrollUpCallback(canChildScrollUp) + } + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + if (ev.action != MotionEvent.ACTION_DOWN && preventRefresh) { + return false + } + when (ev.action) { + MotionEvent.ACTION_DOWN -> { + downY = ev.y + preventRefresh = canChildScrollUp() + } + MotionEvent.ACTION_MOVE -> { + if (downY - ev.y > touchSlop) { + preventRefresh = true + return false + } + } + } + return super.onInterceptTouchEvent(ev) + } + + override fun onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) { + if (preventRefresh) { + /* + * Ignoring offsetInWindow since + * 1. It doesn't seem to matter in the typical use case + * 2. It isn't being transferred to the underlying array used by the super class + */ + dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null) + } else { + super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed) + } + } + + interface OnRefreshListener : SwipeRefreshLayout.OnRefreshListener +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 55553f42..c3818749 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -16,7 +16,7 @@ app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/AppTheme.PopupOverlay" /> - - + diff --git a/app/src/main/res/layout/login_webview.xml b/app/src/main/res/layout/login_webview.xml index 8816383a..48d48589 100644 --- a/app/src/main/res/layout/login_webview.xml +++ b/app/src/main/res/layout/login_webview.xml @@ -1,5 +1,5 @@ - @@ -36,4 +36,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/view_content_base_recycler.xml b/app/src/main/res/layout/view_content_base_recycler.xml index 05b14215..ce33ce13 100644 --- a/app/src/main/res/layout/view_content_base_recycler.xml +++ b/app/src/main/res/layout/view_content_base_recycler.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - @@ -19,7 +19,7 @@ android:focusableInTouchMode="true" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + - @@ -19,7 +19,7 @@ android:focusableInTouchMode="true" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + Date: Mon, 1 Jul 2019 11:55:55 -0700 Subject: Update changelog --- app/src/main/play/en-US/whatsnew | 11 +++-------- app/src/main/res/xml/frost_changelog.xml | 7 +++++++ docs/Changelog.md | 4 ++++ 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'app/src') diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 009f4196..cd43de9e 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -1,9 +1,4 @@ -v2.3.0 +v2.3.1 -* Converted internals of Facebook data storage; auto migration will only work from 2.2.x to 2.3.x -* Added notification widget -* Update theme -* Update translations -* Add fingerprint unlock screen -* Fix messenger redirect -* Lots of internal updates \ No newline at end of file +* Hide all story panels if enabled +* Prevent swipe to refresh if not at the very top \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 94c4fcdf..c059c532 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -6,6 +6,13 @@ --> + + + + + + + diff --git a/docs/Changelog.md b/docs/Changelog.md index c54156d4..c581c0e1 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## v2.3.1 +* Hide all story panels if enabled +* Prevent swipe to refresh if not at the very top + ## v2.3.0 * Converted internals of Facebook data storage; auto migration will only work from 2.2.x to 2.3.x * Added notification widget -- cgit v1.2.3 From 42caa8a566c9416fc9f956e346b6001b5d7b549a Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 11:57:38 -0700 Subject: Support setting own child scroll callback --- .../main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt | 4 ---- .../main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt | 8 +++++++- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'app/src') 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 42a0f6bb..0fb24f7e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -41,7 +41,6 @@ import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp -import com.pitchedapps.frost.glide.transform import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Showcase import com.pitchedapps.frost.utils.frostEvent @@ -87,9 +86,6 @@ class LoginActivity : BaseActivity() { toolbar(toolbar) } profileLoader = GlideApp.with(profile) - swipeRefresh.setOnChildScrollUpCallback { parent, child -> - web.canScrollVertically(-1) - } launch { for (refreshing in refreshChannel.uniqueOnly(this)) { if (refreshing) swipeRefresh.isEnabled = true 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 0ab11fc6..451f3948 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt @@ -24,11 +24,13 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr private var downY: Float = -1f private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop + private var nestedCanChildScrollUp: OnChildScrollUpCallback? = null + /** * Copy of [canChildScrollUp], with additional support if necessary */ private val canChildScrollUp = OnChildScrollUpCallback { parent, child -> - when (child) { + nestedCanChildScrollUp?.canChildScrollUp(parent, child) ?: when (child) { is WebView -> child.canScrollVertically(-1).apply { L.d { "Webview can scroll up $this" } } @@ -42,6 +44,10 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr setOnChildScrollUpCallback(canChildScrollUp) } + override fun setOnChildScrollUpCallback(callback: OnChildScrollUpCallback?) { + this.nestedCanChildScrollUp = callback + } + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { if (ev.action != MotionEvent.ACTION_DOWN && preventRefresh) { return false -- cgit v1.2.3 From 70b42ba365d00f7ec19abe1050c51aee9931045b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 1 Jul 2019 11:58:10 -0700 Subject: Update interface alias comment --- app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/src') 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 451f3948..2154ce2d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt @@ -80,5 +80,8 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr } } + /** + * Alias for adding on refresh listener + */ interface OnRefreshListener : SwipeRefreshLayout.OnRefreshListener } \ No newline at end of file -- cgit v1.2.3