mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-20 07:31:40 +02:00
Disable refresh if not at the top, resolves #1450
This commit is contained in:
parent
79efcadf89
commit
92aad9bf4c
@ -87,6 +87,9 @@ class LoginActivity : BaseActivity() {
|
|||||||
toolbar(toolbar)
|
toolbar(toolbar)
|
||||||
}
|
}
|
||||||
profileLoader = GlideApp.with(profile)
|
profileLoader = GlideApp.with(profile)
|
||||||
|
swipeRefresh.setOnChildScrollUpCallback { parent, child ->
|
||||||
|
web.canScrollVertically(-1)
|
||||||
|
}
|
||||||
launch {
|
launch {
|
||||||
for (refreshing in refreshChannel.uniqueOnly(this)) {
|
for (refreshing in refreshChannel.uniqueOnly(this)) {
|
||||||
if (refreshing) swipeRefresh.isEnabled = true
|
if (refreshing) swipeRefresh.isEnabled = true
|
||||||
|
@ -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
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
app:layout_scrollFlags="scroll|enterAlways"
|
app:layout_scrollFlags="scroll|enterAlways"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<com.pitchedapps.frost.views.SwipeRefreshLayout
|
||||||
android:id="@+id/swipe_refresh"
|
android:id="@+id/swipe_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@ -29,7 +29,7 @@
|
|||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true" />
|
android:focusableInTouchMode="true" />
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</com.pitchedapps.frost.views.SwipeRefreshLayout>
|
||||||
|
|
||||||
<include layout="@layout/view_main_fab" />
|
<include layout="@layout/view_main_fab" />
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.pitchedapps.frost.views.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/swipe_refresh"
|
android:id="@+id/swipe_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@ -36,4 +36,4 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</com.pitchedapps.frost.views.SwipeRefreshLayout>
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<com.pitchedapps.frost.views.SwipeRefreshLayout
|
||||||
android:id="@id/content_refresh"
|
android:id="@id/content_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
@ -19,7 +19,7 @@
|
|||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</com.pitchedapps.frost.views.SwipeRefreshLayout>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@id/content_progress"
|
android:id="@id/content_progress"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<com.pitchedapps.frost.views.SwipeRefreshLayout
|
||||||
android:id="@id/content_refresh"
|
android:id="@id/content_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
@ -19,7 +19,7 @@
|
|||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</com.pitchedapps.frost.views.SwipeRefreshLayout>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@id/content_progress"
|
android:id="@id/content_progress"
|
||||||
|
Loading…
Reference in New Issue
Block a user