ListUrlBuilder.asDst

This commit is contained in:
GG Bond authored and Vladimir Dostoyevskiy committed 2024-02-10 15:01:53 +08:00
1 parent 80e5f36c4e
commit 028a7c2352
5 files changed
+35 -41

No files matched your search

@@ -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<Uri>(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))
}
}
}
@@ -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 {
@@ -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) }
@@ -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
@@ -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<Long, Int>.with(token: String) = GalleryDetailScreenDestination(TokenArgs(first, token, second))
fun ListUrlBuilder.asDst() = GalleryListScreenDestination(this)