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