Long.asDstWith -> GalleryDetailScreenDestination

This commit is contained in:
GG Bond authored and Vladimir Dostoyevskiy committed 2024-02-10 15:01:53 +08:00
1 parent e0b65184e2
commit 80e5f36c4e
8 files changed
+22 -27

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.GalleryDetailScreenDestination
import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination
import com.hippo.ehviewer.ui.destinations.HistoryScreenDestination
import com.hippo.ehviewer.ui.destinations.HomePageScreenDestination
@@ -113,7 +112,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.TokenArgs
import com.hippo.ehviewer.ui.screen.asDstWith
import com.hippo.ehviewer.ui.screen.navWithUrl
import com.hippo.ehviewer.ui.screen.navigate
import com.hippo.ehviewer.ui.settings.showNewVersion
@@ -329,7 +328,7 @@ class MainActivity : EhActivity() {
val result1 = GalleryDetailUrlParser.parse(text, false)
var launch: (() -> Unit)? = null
if (result1 != null) {
launch = { navController.navigate(GalleryDetailScreenDestination(TokenArgs(result1.gid, result1.token))) }
launch = { navController.navigate(result1.gid asDstWith result1.token) }
}
val result2 = GalleryPageUrlParser.parse(text, false)
if (result2 != null) {
@@ -454,7 +454,7 @@ fun DownloadsScreen(navigator: DestinationsNavigator) {
}
},
onThumbClick = {
navigator.navigate(info.galleryInfo.asDestination())
navigator.navigate(info.galleryInfo.asDst())
},
onLongClick = {
checkedInfoMap[info.gid] = info
@@ -279,7 +279,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
checkedInfoMap[info.gid] = info
}
} else {
navigator.navigate(info.asDestination())
navigator.navigate(info.asDst())
}
},
onLongClick = {
@@ -304,7 +304,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
checkedInfoMap[info.gid] = info
}
} else {
navigator.navigate(info.asDestination())
navigator.navigate(info.asDst())
}
},
onLongClick = {
@@ -343,7 +343,7 @@ fun FavouritesScreen(navigator: DestinationsNavigator) {
onClick(Icons.Default.Shuffle) {
val random = EhDB.randomLocalFav()
withUIContext {
navigator.navigate(random.asDestination())
navigator.navigate(random.asDst())
}
}
}
@@ -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.GalleryDetailScreenDestination
import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination
import com.hippo.ehviewer.ui.destinations.GalleryPreviewScreenDestination
import com.hippo.ehviewer.ui.getFavoriteIcon
@@ -471,7 +470,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa
val info = galleryDetail.newerVersions[selected]
withUIContext {
// Can't use GalleryInfoArgs as thumbKey is null
navigator.navigate(GalleryDetailScreenDestination(TokenArgs(info.gid, info.token!!)))
navigator.navigate(info.gid asDstWith info.token!!)
}
}
Spacer(modifier = Modifier.size(dimensionResource(id = R.dimen.keyline_margin)))
@@ -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.GalleryDetailScreenDestination
import com.hippo.ehviewer.ui.destinations.GalleryListScreenDestination
import com.hippo.ehviewer.ui.destinations.ProgressScreenDestination
import com.hippo.ehviewer.ui.doGalleryInfoAction
@@ -516,18 +515,11 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) {
abstract val destination: Direction
}
class GalleryDetailUrlSuggestion(
gid: Long,
token: String,
) : UrlSuggestion() {
override val destination = GalleryDetailScreenDestination(TokenArgs(gid, token))
class GalleryDetailUrlSuggestion(gid: Long, token: String) : UrlSuggestion() {
override val destination = gid asDstWith token
}
class GalleryPageUrlSuggestion(
gid: Long,
pToken: String,
page: Int,
) : UrlSuggestion() {
class GalleryPageUrlSuggestion(gid: Long, pToken: String, page: Int) : UrlSuggestion() {
override val destination = ProgressScreenDestination(gid, pToken, page)
}
@@ -698,7 +690,7 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) {
detailItemContent = { info ->
GalleryInfoListItem(
onClick = {
navigator.navigate(info.asDestination())
navigator.navigate(info.asDst())
},
onLongClick = {
coroutineScope.launch {
@@ -715,7 +707,7 @@ fun GalleryListScreen(lub: ListUrlBuilder, navigator: DestinationsNavigator) {
thumbItemContent = { info ->
GalleryInfoGridItem(
onClick = {
navigator.navigate(info.asDestination())
navigator.navigate(info.asDst())
},
onLongClick = {
coroutineScope.launch {
@@ -127,7 +127,7 @@ fun HistoryScreen(navigator: DestinationsNavigator) {
) {
GalleryInfoListItem(
onClick = {
navigator.navigate(info.asDestination())
navigator.navigate(info.asDst())
},
onLongClick = {
coroutineScope.launchIO {
@@ -18,7 +18,7 @@ private fun urlToDestination(url: String): Direction? {
val ret1 = GalleryListUrlParser.parse(url)
if (ret1 != null) return GalleryListScreenDestination(ret1)
val ret2 = GalleryDetailUrlParser.parse(url)
if (ret2 != null) return GalleryDetailScreenDestination(TokenArgs(ret2.gid, ret2.token))
if (ret2 != null) return ret2.gid asDstWith ret2.token
val ret3 = GalleryPageUrlParser.parse(url)
if (ret3 != null) return ProgressScreenDestination(ret3.gid, ret3.pToken, ret3.page)
return null
@@ -46,4 +46,10 @@ fun NavController.navWithUrl(url: String): Boolean {
@MainThread
fun NavController.navigate(direction: Direction) = navigate(direction.route)
fun BaseGalleryInfo.asDestination() = GalleryDetailScreenDestination(GalleryInfoArgs(this))
fun BaseGalleryInfo.asDst() = GalleryDetailScreenDestination(GalleryInfoArgs(this))
infix fun Long.asDstWith(token: String) = GalleryDetailScreenDestination(TokenArgs(this, token))
infix fun Long.asDstPageTo(page: Int) = this to page
infix fun Pair<Long, Int>.with(token: String) = GalleryDetailScreenDestination(TokenArgs(first, token, second))
@@ -25,7 +25,6 @@ import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.icons.EhIcons
import com.hippo.ehviewer.icons.big.SadAndroid
import com.hippo.ehviewer.ui.LockDrawer
import com.hippo.ehviewer.ui.destinations.GalleryDetailScreenDestination
import com.hippo.ehviewer.util.ExceptionUtils
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
@@ -48,7 +47,7 @@ fun ProgressScreen(gid: Long, token: String, page: Int, navigator: DestinationsN
}.onSuccess {
withUIContext {
navigator.popBackStack()
navigator.navigate(GalleryDetailScreenDestination(TokenArgs(gid, it, page)))
navigator.navigate(gid asDstPageTo page with it)
}
}.onFailure {
error = ExceptionUtils.getReadableString(it)