From cc94bed7722cc184ab0ffe6981e5394b9cf0fe02 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:48:05 +0800 Subject: [PATCH] Fix error message when no hits found --- .../client/parser/GalleryListParser.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.kt index ee2d437f5..d6ca9f5cf 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.kt @@ -6,20 +6,22 @@ import com.hippo.ehviewer.client.data.GalleryInfo.Companion.LOCAL_FAVORITED import com.hippo.ehviewer.client.data.GalleryInfo.Companion.NOT_FAVORITED object GalleryListParser { - suspend fun parse(body: String) = parseGalleryInfoList(body).apply { - galleryInfoList.onEach { - if (it.favoriteSlot == NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) { - it.favoriteSlot = LOCAL_FAVORITED + suspend fun parse(body: String) = runCatching { + parseGalleryInfoList(body).apply { + galleryInfoList.onEach { + if (it.favoriteSlot == NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) { + it.favoriteSlot = LOCAL_FAVORITED + } + it.generateSLang() } - it.generateSLang() } - } + }.getOrDefault(GalleryListResult()) } class GalleryListResult( - val prev: String?, - val next: String?, - val galleryInfoList: ArrayList, + val prev: String? = null, + val next: String? = null, + val galleryInfoList: ArrayList = arrayListOf(), ) private external fun parseGalleryInfoList(e: String): GalleryListResult