From 4d09504abc2b1f58c34b4ca4dd27cf4bf8e69e83 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:04:31 +0800 Subject: [PATCH] Fix swipe-to-refresh --- .../hippo/ehviewer/ui/scene/FavoritesScene.kt | 6 ++- .../hippo/ehviewer/ui/scene/GalleryAdapter.kt | 11 ---- .../ehviewer/ui/scene/GalleryListScene.kt | 6 ++- app/src/main/res/layout/scene_favorites.xml | 54 +++++++++++-------- .../main/res/layout/scene_gallery_list.xml | 1 + 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt index d573efbd9..1e5e9434c 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt @@ -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) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt index ae24b1141..296361819 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt @@ -51,7 +51,6 @@ class GalleryAdapter( ) : PagingDataAdapter(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) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt index 7e460d1a3..12dac6b86 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt @@ -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 diff --git a/app/src/main/res/layout/scene_favorites.xml b/app/src/main/res/layout/scene_favorites.xml index 220b20094..39a43b4d5 100644 --- a/app/src/main/res/layout/scene_favorites.xml +++ b/app/src/main/res/layout/scene_favorites.xml @@ -17,39 +17,47 @@ - - - - - - + + + + + app:fitsSystemWindowsInsets="top"> - + + + +