Fix swipe-to-refresh

This commit is contained in:
FooIbar committed 2023-08-11 13:49:15 +08:00
1 parent f901bd2336
commit 4d09504abc
5 files changed
+42 -36

No files matched your search

@@ -326,14 +326,18 @@ class FavoritesScene : SearchBarScene() {
when (val state = it.refresh) {
is LoadState.Loading -> {
showSearchBar()
transition.showView(1)
if (!binding.refreshLayout.isRefreshing) {
transition.showView(1)
}
}
is LoadState.Error -> {
binding.refreshLayout.isRefreshing = false
binding.tip.text = ExceptionUtils.getReadableString(state.error)
transition.showView(2)
}
is LoadState.NotLoading -> {
delay(500)
binding.refreshLayout.isRefreshing = false
if (mAdapter?.itemCount == 0) {
binding.tip.text = empty
transition.showView(2)
@@ -51,7 +51,6 @@ class GalleryAdapter(
) : PagingDataAdapter<BaseGalleryInfo, GalleryHolder>(diffCallback) {
private val resources = recyclerView.context.resources
private val layoutManager: AutoStaggeredGridLayoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL)
private val mPaddingTopSB: Int = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar)
private var mListDecoration: ItemDecoration? = null
private var mGirdDecoration: MarginItemDecoration? = null
private var mType = TYPE_INVALID
@@ -142,16 +141,6 @@ class GalleryAdapter(
recyclerView.adapter = this
recyclerView.layoutManager = layoutManager
type = Settings.listMode
adjustPaddings()
}
private fun adjustPaddings() {
recyclerView.setPadding(
recyclerView.paddingLeft,
recyclerView.paddingTop + mPaddingTopSB,
recyclerView.paddingRight,
recyclerView.paddingBottom,
)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
@@ -368,9 +368,12 @@ class GalleryListScene : SearchBarScene() {
when (val state = it.refresh) {
is LoadState.Loading -> {
showSearchBar()
transition.showView(1)
if (!binding.refreshLayout.isRefreshing) {
transition.showView(1)
}
}
is LoadState.Error -> {
binding.refreshLayout.isRefreshing = false
binding.tip.text = ExceptionUtils.getReadableString(state.error)
transition.showView(2)
if (state.error.cause is CloudflareBypassException) {
@@ -386,6 +389,7 @@ class GalleryListScene : SearchBarScene() {
}
is LoadState.NotLoading -> {
delay(500)
binding.refreshLayout.isRefreshing = false
if (mAdapter?.itemCount == 0) {
if (mUrlBuilder.mode == MODE_SUBSCRIPTION) {
binding.tip.text = noWatch
+31 -23
View File
@@ -17,39 +17,47 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tip"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="228dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center_horizontal" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress"
style="@style/ProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout
android:id="@+id/refresh_layout"
<FrameLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:paddingTop="16dp"
app:fitsSystemWindowsInsets="top"
app:layout_behavior="@string/searchbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
<TextView
android:id="@+id/tip"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="228dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center_horizontal" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress"
style="@style/ProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/gallery_padding_top_search_bar"
android:clipChildren="false"
android:clipToPadding="false" />
app:fitsSystemWindowsInsets="top">
</androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.ThemedSwipeRefreshLayout>
</FrameLayout>
<com.hippo.ehviewer.ui.legacy.FastScroller
android:id="@+id/fast_scroller"
@@ -45,6 +45,7 @@
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/gallery_padding_top_search_bar"
android:clipChildren="false"
app:fitsSystemWindowsInsets="top">