From 5aeded7a24b320caabbf1e440b51c58436380726 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:24:27 +0800 Subject: [PATCH] Don't show load state indicator when no hits found --- .../main/kotlin/com/hippo/ehviewer/client/EhEngine.kt | 3 ++- .../ehviewer/client/exception/NoHitsFoundException.kt | 5 +++++ .../kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt | 10 ++++++++-- app/src/main/rust/src/parser/list.rs | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 app/src/main/kotlin/com/hippo/ehviewer/client/exception/NoHitsFoundException.kt diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt index 83a3ab8e2..9c26a8fb2 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt @@ -29,6 +29,7 @@ import com.hippo.ehviewer.client.data.FavListUrlBuilder import com.hippo.ehviewer.client.data.GalleryInfo import com.hippo.ehviewer.client.exception.EhException import com.hippo.ehviewer.client.exception.InsufficientFundsException +import com.hippo.ehviewer.client.exception.NoHitsFoundException import com.hippo.ehviewer.client.exception.NotLoggedInException import com.hippo.ehviewer.client.exception.ParseException import com.hippo.ehviewer.client.parser.ArchiveParser @@ -130,7 +131,7 @@ fun rethrowExactly(status: HttpStatusCode, body: Either, e: if (e is ParseException || e is SerializationException) { body.onLeft { if ("<" !in it) throw EhException(it) } when (val message = e.cause?.message) { - "No hits found!" -> throw EhException(R.string.gallery_list_empty_hit) + "No hits found!" -> throw NoHitsFoundException() "No watched tags!" -> throw EhException(R.string.gallery_list_empty_hit_subscription) "Not logged in!" -> throw NotLoggedInException() is String -> if (message.startsWith("Your IP address")) throw EhException(message) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/exception/NoHitsFoundException.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/exception/NoHitsFoundException.kt new file mode 100644 index 000000000..425190c79 --- /dev/null +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/exception/NoHitsFoundException.kt @@ -0,0 +1,5 @@ +package com.hippo.ehviewer.client.exception + +import com.hippo.ehviewer.R + +class NoHitsFoundException : EhException(R.string.gallery_list_empty_hit) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt index e4e40b79c..1e257aac4 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt @@ -53,6 +53,7 @@ import androidx.paging.compose.itemKey import com.hippo.ehviewer.R import com.hippo.ehviewer.Settings import com.hippo.ehviewer.client.data.BaseGalleryInfo +import com.hippo.ehviewer.client.exception.NoHitsFoundException import com.hippo.ehviewer.collectAsState import com.hippo.ehviewer.icons.EhIcons import com.hippo.ehviewer.icons.big.SadAndroid @@ -116,6 +117,11 @@ fun GalleryList( } }, ) { + val showLoadStateIndicator = when (val state = data.loadState.append) { + LoadState.Loading -> true + is LoadState.Error -> state.error !is NoHitsFoundException + is LoadState.NotLoading -> false + } if (listMode == 0) { val columnWidth by collectDetailSizeAsState() FastScrollLazyVerticalGrid( @@ -136,7 +142,7 @@ fun GalleryList( detailItemContent(info) } } - if (data.loadState.append !is LoadState.NotLoading) { + if (showLoadStateIndicator) { item(span = { GridItemSpan(maxLineSpan) }) { LoadStateIndicator(state = data.loadState.append) { data.retry() @@ -165,7 +171,7 @@ fun GalleryList( thumbItemContent(info) } } - if (data.loadState.append !is LoadState.NotLoading) { + if (showLoadStateIndicator) { item(span = StaggeredGridItemSpan.FullLine) { LoadStateIndicator(state = data.loadState.append) { data.retry() diff --git a/app/src/main/rust/src/parser/list.rs b/app/src/main/rust/src/parser/list.rs index e57b7d1bf..195173f51 100644 --- a/app/src/main/rust/src/parser/list.rs +++ b/app/src/main/rust/src/parser/list.rs @@ -201,7 +201,7 @@ pub fn parse_info_list(dom: &VDom, parser: &Parser, str: &str) -> ResultYou do not have any watched tags") { bail!("No watched tags!") } - if str.contains("No hits found

") || str.contains("No unfiltered results found") { + if str.contains("No hits found

") || str.contains("No unfiltered results") { bail!("No hits found!") } let f = || {