diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumStateMachine.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumStateMachine.kt index 04fe857..dda4ece 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumStateMachine.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/MediumStateMachine.kt @@ -28,10 +28,6 @@ class MediumStateMachine( currentState = it } onEnter { state -> - Cache.getMedium(state.snapshot.query)?.let { - return@onEnter state.override { State.Success(query, it) } - } - val response = CatchResult.result { client.query(state.snapshot.query).execute().dataOrThrow() }.mapSuccess { @@ -40,14 +36,20 @@ class MediumStateMachine( } } + val cached = Cache.getMedium(state.snapshot.query) + state.override { response.asSuccess { crashlytics?.log(it) - if (retry <= 3) { - State.Loading(query, retry + 1) + if (cached != null) { + State.Success(query, cached) } else { - State.Error(query) + if (retry <= 3) { + State.Loading(query, retry + 1) + } else { + State.Error(query) + } } } } diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Medium.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Medium.kt index 563fba3..f052a61 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Medium.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Medium.kt @@ -383,6 +383,8 @@ open class Medium( val isYoutube: Boolean = site.contains("youtu.be", ignoreCase = true) || site.contains("youtube", ignoreCase = true) + val isDailymotion: Boolean = site.contains("dailymotion", ignoreCase = true) + private val youtubeVideoId: String? = run { val afterVi = thumbnail.substringAfter( delimiter = "vi/", @@ -395,9 +397,19 @@ open class Medium( afterVi.substringBefore('/', missingDelimiterValue = "").ifBlank { null } } - val youtubeVideo = (id ?: youtubeVideoId)?.let { + private val youtubeVideo = (id ?: youtubeVideoId)?.let { "https://youtube.com/watch?v=$it" } + + private val dailymotionVideo = id?.let { + "https://dailymotion.com/video/$it" + } + + val videoUrl = when { + isYoutube -> youtubeVideo + isDailymotion -> dailymotionVideo + else -> null + } } } } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/EditFAB.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/EditFAB.kt index f86c100..8619929 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/EditFAB.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/custom/EditFAB.kt @@ -47,14 +47,14 @@ fun EditFAB( ) ) { LabelFAB( - label = "Rating", + label = "Progress", onClick = { showOtherFABs = false - onRate() + onProgress() } ) { Icon( - imageVector = Icons.Default.Star, + imageVector = Icons.Default.Visibility, contentDescription = null ) } @@ -74,14 +74,14 @@ fun EditFAB( ) ) { LabelFAB( - label = "Progress", + label = "Rating", onClick = { showOtherFABs = false - onProgress() + onRate() } ) { Icon( - imageVector = Icons.Default.Visibility, + imageVector = Icons.Default.Star, contentDescription = null ) } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/MediumScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/MediumScreen.kt index adecb0f..dd08e88 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/MediumScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/MediumScreen.kt @@ -93,7 +93,9 @@ fun MediumScreen(component: MediumComponent) { bodyText = "" ), config = RatingConfig( - ratingOptionsCount = 5 + ratingOptionsCount = 5, + ratingOptionsSelected = userRating.takeIf { it > 0 }, + ratingZeroValid = true ) ) @@ -488,8 +490,7 @@ fun MediumScreen(component: MediumComponent) { Card( modifier = Modifier.fillParentMaxWidth().height(200.dp).padding(16.dp), onClick = { - Napier.e(t.id ?: t.website) - uriHandler.openUri(t.youtubeVideo ?: t.website) + uriHandler.openUri(t.videoUrl ?: t.website) } ) { Box(