Skip to content

Commit

Permalink
provide character information immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 26, 2024
1 parent 623122b commit 1a288e5
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 52 deletions.
22 changes: 16 additions & 6 deletions anilist/src/commonMain/graphql/AiringQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions anilist/src/commonMain/graphql/MediumQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions anilist/src/commonMain/graphql/SeasonQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions anilist/src/commonMain/graphql/TrendingQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}

Expand All @@ -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
)
}

Expand All @@ -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,
)
}

Expand Down Expand Up @@ -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
)
}

Expand All @@ -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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -71,7 +78,7 @@ fun CollapsingToolbar(
contentScale = ContentScale.Crop
)
),
alpha = 1F - state.collapsedFraction
alpha = imageAlpha
)
LargeTopAppBar(
navigationIcon = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1a288e5

Please sign in to comment.