From 028a7c2352870a64834984bfa7ee6437f6161b3c Mon Sep 17 00:00:00 2001 From: GG Bond Date: Sat, 10 Feb 2024 13:08:44 +0800 Subject: [PATCH] ListUrlBuilder.asDst --- .../com/hippo/ehviewer/ui/MainActivity.kt | 15 +++--- .../ui/screen/GalleryCommentsScreen.kt | 3 +- .../ehviewer/ui/screen/GalleryDetailScreen.kt | 47 ++++++++----------- .../ehviewer/ui/screen/GalleryListScreen.kt | 6 +-- .../com/hippo/ehviewer/ui/screen/MainNav.kt | 5 +- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt index a32465555..2b34aeb1d 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt @@ -103,7 +103,6 @@ import com.hippo.ehviewer.image.Image.Companion.decodeBitmap import com.hippo.ehviewer.ui.destinations.DownloadScreenDestination import com.hippo.ehviewer.ui.destinations.DownloadsScreenDestination import com.hippo.ehviewer.ui.destinations.FavouritesScreenDestination -import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination import com.hippo.ehviewer.ui.destinations.HistoryScreenDestination import com.hippo.ehviewer.ui.destinations.HomePageScreenDestination import com.hippo.ehviewer.ui.destinations.ProgressScreenDestination @@ -112,6 +111,7 @@ import com.hippo.ehviewer.ui.destinations.SignInScreenDestination import com.hippo.ehviewer.ui.destinations.SubscriptionScreenDestination import com.hippo.ehviewer.ui.destinations.ToplistScreenDestination import com.hippo.ehviewer.ui.destinations.WhatshotScreenDestination +import com.hippo.ehviewer.ui.screen.asDst import com.hippo.ehviewer.ui.screen.asDstWith import com.hippo.ehviewer.ui.screen.navWithUrl import com.hippo.ehviewer.ui.screen.navigate @@ -269,18 +269,19 @@ class MainActivity : EhActivity() { val type = intent.type if ("text/plain" == type) { val keyword = intent.getStringExtra(Intent.EXTRA_TEXT) - navController.navigate(GalleryListScreenDestination(ListUrlBuilder(mKeyword = keyword))) + navController.navigate(ListUrlBuilder(mKeyword = keyword).asDst()) } else if (type != null && type.startsWith("image/")) { val uri = intent.getParcelableExtraCompat(Intent.EXTRA_STREAM) if (null != uri) { val temp = saveImageToTempFile(uri) if (null != temp) { - val builder = ListUrlBuilder( - mode = ListUrlBuilder.MODE_IMAGE_SEARCH, - imagePath = temp.path, - isUseSimilarityScan = true, + navController.navigate( + ListUrlBuilder( + mode = ListUrlBuilder.MODE_IMAGE_SEARCH, + imagePath = temp.path, + isUseSimilarityScan = true, + ).asDst(), ) - navController.navigate(GalleryListScreenDestination(builder)) } } } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryCommentsScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryCommentsScreen.kt index d0507f679..ae560ad7e 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryCommentsScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryCommentsScreen.kt @@ -84,7 +84,6 @@ import com.hippo.ehviewer.dao.Filter import com.hippo.ehviewer.dao.FilterMode import com.hippo.ehviewer.ui.LockDrawer import com.hippo.ehviewer.ui.MainActivity -import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination import com.hippo.ehviewer.ui.jumpToReaderByPage import com.hippo.ehviewer.ui.legacy.CoilImageGetter import com.hippo.ehviewer.ui.main.GalleryCommentCard @@ -366,7 +365,7 @@ fun GalleryCommentsScreen(gid: Long, navigator: DestinationsNavigator) { mode = ListUrlBuilder.MODE_UPLOADER, mKeyword = item.user, ) - navigator.navigate(GalleryListScreenDestination(lub)) + navigator.navigate(lub.asDst()) }, onCardClick = { coroutineScope.launch { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt index 0abdb56cd..72e65801a 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt @@ -121,7 +121,6 @@ import com.hippo.ehviewer.ui.LockDrawer import com.hippo.ehviewer.ui.MainActivity import com.hippo.ehviewer.ui.confirmRemoveDownload import com.hippo.ehviewer.ui.destinations.GalleryCommentsScreenDestination -import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination import com.hippo.ehviewer.ui.destinations.GalleryPreviewScreenDestination import com.hippo.ehviewer.ui.getFavoriteIcon import com.hippo.ehviewer.ui.jumpToReaderByPage @@ -542,30 +541,24 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa val artist = galleryDetail.tags.getArtist() if (null != keyword) { navigator.navigate( - GalleryListScreenDestination( - ListUrlBuilder( - mode = ListUrlBuilder.MODE_NORMAL, - mKeyword = "\"" + keyword + "\"", - ), - ), + ListUrlBuilder( + mode = ListUrlBuilder.MODE_NORMAL, + mKeyword = "\"" + keyword + "\"", + ).asDst(), ) } else if (artist != null) { navigator.navigate( - GalleryListScreenDestination( - ListUrlBuilder( - mode = ListUrlBuilder.MODE_TAG, - mKeyword = "artist:$artist", - ), - ), + ListUrlBuilder( + mode = ListUrlBuilder.MODE_TAG, + mKeyword = "artist:$artist", + ).asDst(), ) } else if (null != galleryDetail.uploader) { navigator.navigate( - GalleryListScreenDestination( - ListUrlBuilder( - mode = ListUrlBuilder.MODE_UPLOADER, - mKeyword = galleryDetail.uploader, - ), - ), + ListUrlBuilder( + mode = ListUrlBuilder.MODE_UPLOADER, + mKeyword = galleryDetail.uploader, + ).asDst(), ) } }, @@ -576,12 +569,10 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa onClick = { val key = galleryDetail.thumbKey.orEmpty() navigator.navigate( - GalleryListScreenDestination( - ListUrlBuilder( - mode = ListUrlBuilder.MODE_NORMAL, - hash = key.substringAfterLast('/').substringBefore('-'), - ), - ), + ListUrlBuilder( + mode = ListUrlBuilder.MODE_NORMAL, + hash = key.substringAfterLast('/').substringBefore('-'), + ).asDst(), ) }, ) @@ -716,7 +707,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa val lub = ListUrlBuilder() lub.mode = ListUrlBuilder.MODE_TAG lub.keyword = it - navigator.navigate(GalleryListScreenDestination(lub)) + navigator.navigate(lub.asDst()) }, onTagLongClick = { translated, tag -> val index = tag.indexOf(':') @@ -796,7 +787,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa return } val lub = ListUrlBuilder(category = category) - navigator.navigate(GalleryListScreenDestination(lub)) + navigator.navigate(lub.asDst()) } fun onUploaderChipClick(galleryInfo: GalleryInfo) { val uploader = galleryInfo.uploader @@ -807,7 +798,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa val lub = ListUrlBuilder() lub.mode = ListUrlBuilder.MODE_UPLOADER lub.keyword = uploader - navigator.navigate(GalleryListScreenDestination(lub)) + navigator.navigate(lub.asDst()) } var showBottomSheet by remember { mutableStateOf(false) } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt index 7fc36f9d8..ea72e9c4b 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt @@ -113,7 +113,6 @@ import com.hippo.ehviewer.icons.filled.GoTo import com.hippo.ehviewer.image.Image.Companion.decodeBitmap import com.hippo.ehviewer.ui.LocalSideSheetState import com.hippo.ehviewer.ui.MainActivity -import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination import com.hippo.ehviewer.ui.destinations.ProgressScreenDestination import com.hippo.ehviewer.ui.doGalleryInfoAction import com.hippo.ehviewer.ui.main.AdvancedSearchOption @@ -447,7 +446,8 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) { ListItem( modifier = Modifier.clickable { if (urlBuilder.mode == MODE_WHATS_HOT) { - navigator.navigate(GalleryListScreenDestination(ListUrlBuilder(item))) + val builder = ListUrlBuilder(item) + navigator.navigate(builder.asDst()) } else { urlBuilder = ListUrlBuilder(item) data.refresh() @@ -562,7 +562,7 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) { MODE_TOPLIST, MODE_WHATS_HOT -> { // Wait for search view to hide delay(300) - withUIContext { navigator.navigate(GalleryListScreenDestination(builder)) } + withUIContext { navigator.navigate(builder.asDst()) } } else -> { urlBuilder = builder diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/MainNav.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/MainNav.kt index d2e77664a..b9b75a252 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/MainNav.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/MainNav.kt @@ -3,6 +3,7 @@ package com.hippo.ehviewer.ui.screen import androidx.annotation.MainThread import androidx.navigation.NavController import com.hippo.ehviewer.client.data.BaseGalleryInfo +import com.hippo.ehviewer.client.data.ListUrlBuilder import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser import com.hippo.ehviewer.client.parser.GalleryListUrlParser import com.hippo.ehviewer.client.parser.GalleryPageUrlParser @@ -16,7 +17,7 @@ import com.ramcosta.composedestinations.spec.Direction private fun urlToDestination(url: String): Direction? { if (url.isEmpty()) return null val ret1 = GalleryListUrlParser.parse(url) - if (ret1 != null) return GalleryListScreenDestination(ret1) + if (ret1 != null) return ret1.asDst() val ret2 = GalleryDetailUrlParser.parse(url) if (ret2 != null) return ret2.gid asDstWith ret2.token val ret3 = GalleryPageUrlParser.parse(url) @@ -53,3 +54,5 @@ infix fun Long.asDstWith(token: String) = GalleryDetailScreenDestination(TokenAr infix fun Long.asDstPageTo(page: Int) = this to page infix fun Pair.with(token: String) = GalleryDetailScreenDestination(TokenArgs(first, token, second)) + +fun ListUrlBuilder.asDst() = GalleryListScreenDestination(this)