From 1a288e59f98b100ab2400353a6e449523e241df6 Mon Sep 17 00:00:00 2001 From: DatLag Date: Fri, 26 Apr 2024 14:44:37 +0200 Subject: [PATCH] provide character information immediately --- .../commonMain/graphql/AiringQuery.graphql | 22 +++-- .../commonMain/graphql/MediumQuery.graphql | 22 +++-- .../commonMain/graphql/SeasonQuery.graphql | 22 +++-- .../commonMain/graphql/TrendingQuery.graphql | 22 +++-- .../datlag/aniflow/anilist/model/Character.kt | 96 ++++++++++++++----- .../screen/initial/home/HomeScreen.kt | 2 +- .../medium/component/CharacterSection.kt | 2 +- .../medium/component/CollapsingToolbar.kt | 9 +- .../screen/medium/component/TrailerSection.kt | 2 +- 9 files changed, 147 insertions(+), 52 deletions(-) diff --git a/anilist/src/commonMain/graphql/AiringQuery.graphql b/anilist/src/commonMain/graphql/AiringQuery.graphql index 0005d2d..bd48c7c 100644 --- a/anilist/src/commonMain/graphql/AiringQuery.graphql +++ b/anilist/src/commonMain/graphql/AiringQuery.graphql @@ -56,17 +56,27 @@ query AiringQuery( nodes { id, name { - first, + first middle - last, - full, - native, + last + full + native userPreferred }, image { - large, + large medium - } + }, + description(asHtml:$html) + gender, + dateOfBirth { + year + month + day + }, + bloodType, + isFavourite, + isFavouriteBlocked, } }, mediaListEntry { diff --git a/anilist/src/commonMain/graphql/MediumQuery.graphql b/anilist/src/commonMain/graphql/MediumQuery.graphql index 402c4a1..dc15e08 100644 --- a/anilist/src/commonMain/graphql/MediumQuery.graphql +++ b/anilist/src/commonMain/graphql/MediumQuery.graphql @@ -44,17 +44,27 @@ query MediumQuery($id: Int, $statusVersion: Int, $html: Boolean) { nodes { id, name { - first, + first middle - last, - full, - native, + last + full + native userPreferred }, image { - large, + large medium - } + }, + description(asHtml:$html) + gender, + dateOfBirth { + year + month + day + }, + bloodType, + isFavourite, + isFavouriteBlocked, } }, mediaListEntry { diff --git a/anilist/src/commonMain/graphql/SeasonQuery.graphql b/anilist/src/commonMain/graphql/SeasonQuery.graphql index 6f51e15..2b84cf0 100644 --- a/anilist/src/commonMain/graphql/SeasonQuery.graphql +++ b/anilist/src/commonMain/graphql/SeasonQuery.graphql @@ -56,17 +56,27 @@ query SeasonQuery( nodes { id, name { - first, + first middle - last, - full, - native, + last + full + native userPreferred }, image { - large, + large medium - } + }, + description(asHtml:$html) + gender, + dateOfBirth { + year + month + day + }, + bloodType, + isFavourite, + isFavouriteBlocked, } }, mediaListEntry { diff --git a/anilist/src/commonMain/graphql/TrendingQuery.graphql b/anilist/src/commonMain/graphql/TrendingQuery.graphql index a04587d..5891760 100644 --- a/anilist/src/commonMain/graphql/TrendingQuery.graphql +++ b/anilist/src/commonMain/graphql/TrendingQuery.graphql @@ -59,17 +59,27 @@ query TrendingQuery( nodes { id, name { - first, + first middle - last, - full, - native, + last + full + native userPreferred }, image { - large, + large medium - } + }, + description(asHtml:$html) + gender, + dateOfBirth { + year + month + day + }, + bloodType, + isFavourite, + isFavouriteBlocked, } }, mediaListEntry { diff --git a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Character.kt b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Character.kt index 7f486fa..401d7e4 100644 --- a/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Character.kt +++ b/anilist/src/commonMain/kotlin/dev/datlag/aniflow/anilist/model/Character.kt @@ -218,6 +218,54 @@ data class Character( year = birth.year ) } + + operator fun invoke(birth: TrendingQuery.DateOfBirth): BirthDate? { + if (birth.day == null && birth.month == null && birth.year == null) { + return null + } + + return BirthDate( + day = birth.day, + month = birth.month, + year = birth.year + ) + } + + operator fun invoke(birth: MediumQuery.DateOfBirth): BirthDate? { + if (birth.day == null && birth.month == null && birth.year == null) { + return null + } + + return BirthDate( + day = birth.day, + month = birth.month, + year = birth.year + ) + } + + operator fun invoke(birth: AiringQuery.DateOfBirth): BirthDate? { + if (birth.day == null && birth.month == null && birth.year == null) { + return null + } + + return BirthDate( + day = birth.day, + month = birth.month, + year = birth.year + ) + } + + operator fun invoke(birth: SeasonQuery.DateOfBirth): BirthDate? { + if (birth.day == null && birth.month == null && birth.year == null) { + return null + } + + return BirthDate( + day = birth.day, + month = birth.month, + year = birth.year + ) + } } } @@ -230,12 +278,12 @@ data class Character( id = character.id, name = name, image = image, - gender = null, - bloodType = null, - birthDate = null, - description = null, - isFavorite = false, - isFavoriteBlocked = true + gender = character.gender?.ifBlank { null }, + bloodType = character.bloodType?.ifBlank { null }, + birthDate = character.dateOfBirth?.let { BirthDate(it) }, + description = character.description?.ifBlank { null }, + isFavorite = character.isFavourite, + isFavoriteBlocked = character.isFavouriteBlocked ) } @@ -247,12 +295,12 @@ data class Character( id = character.id, name = name, image = image, - gender = null, - bloodType = null, - birthDate = null, - description = null, - isFavorite = false, - isFavoriteBlocked = true, + gender = character.gender?.ifBlank { null }, + bloodType = character.bloodType?.ifBlank { null }, + birthDate = character.dateOfBirth?.let { BirthDate(it) }, + description = character.description?.ifBlank { null }, + isFavorite = character.isFavourite, + isFavoriteBlocked = character.isFavouriteBlocked, ) } @@ -281,12 +329,12 @@ data class Character( id = character.id, name = name, image = image, - gender = null, - bloodType = null, - birthDate = null, - description = null, - isFavorite = false, - isFavoriteBlocked = true + gender = character.gender?.ifBlank { null }, + bloodType = character.bloodType?.ifBlank { null }, + birthDate = character.dateOfBirth?.let { BirthDate(it) }, + description = character.description?.ifBlank { null }, + isFavorite = character.isFavourite, + isFavoriteBlocked = character.isFavouriteBlocked ) } @@ -298,12 +346,12 @@ data class Character( id = character.id, name = name, image = image, - gender = null, - bloodType = null, - birthDate = null, - description = null, - isFavorite = false, - isFavoriteBlocked = true + gender = character.gender?.ifBlank { null }, + bloodType = character.bloodType?.ifBlank { null }, + birthDate = character.dateOfBirth?.let { BirthDate(it) }, + description = character.description?.ifBlank { null }, + isFavorite = character.isFavourite, + isFavoriteBlocked = character.isFavouriteBlocked ) } } diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreen.kt index 282f5c5..28ad0d2 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/initial/home/HomeScreen.kt @@ -68,7 +68,7 @@ private fun MainView(component: HomeComponent, modifier: Modifier = Modifier) { is TraceStateMachine.State.Success -> { val results = remember(traceState) { current.response.result.sortedByDescending { it.similarity } } - SideEffect { + LaunchedEffect(current) { results.maxByOrNull { it.similarity }?.aniList?.asMedium()?.let(component::details) } /*OptionDialog( diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CharacterSection.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CharacterSection.kt index ba32f06..7d21fa6 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CharacterSection.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CharacterSection.kt @@ -36,7 +36,7 @@ fun CharacterSection( ) LazyRow( modifier = Modifier.fillMaxWidth(), - contentPadding = PaddingValues(16.dp), + contentPadding = PaddingValues(top = 8.dp, start = 16.dp, end = 16.dp, bottom = 16.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterHorizontally) ) { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt index f6534ff..5c61099 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/CollapsingToolbar.kt @@ -34,6 +34,8 @@ import dev.datlag.aniflow.common.notPreferred import dev.datlag.aniflow.common.preferred import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle import kotlinx.coroutines.flow.StateFlow +import kotlin.math.max +import kotlin.math.min @OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class) @Composable @@ -55,6 +57,11 @@ fun CollapsingToolbar( val isCollapsed by remember(state) { derivedStateOf { state.collapsedFraction >= 0.99F } } + val imageAlpha by remember(state) { + derivedStateOf { + max(min(1F - state.collapsedFraction, 1F), 0F) + } + } AsyncImage( modifier = Modifier @@ -71,7 +78,7 @@ fun CollapsingToolbar( contentScale = ContentScale.Crop ) ), - alpha = 1F - state.collapsedFraction + alpha = imageAlpha ) LargeTopAppBar( navigationIcon = { diff --git a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TrailerSection.kt b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TrailerSection.kt index 90026ee..94f6e54 100644 --- a/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TrailerSection.kt +++ b/composeApp/src/commonMain/kotlin/dev/datlag/aniflow/ui/navigation/screen/medium/component/TrailerSection.kt @@ -41,7 +41,7 @@ fun TrailerSection( style = MaterialTheme.typography.headlineSmall ) Card( - modifier = Modifier.fillMaxWidth().height(200.dp).padding(16.dp), + modifier = Modifier.fillMaxWidth().height(200.dp).padding(top = 8.dp, start = 16.dp, end = 16.dp, bottom = 16.dp), onClick = { uriHandler.openUri(trailer?.videoUrl ?: trailer!!.website) }