From d3be63a2f2fd7f9b542fab7c9ea798510bc49eb0 Mon Sep 17 00:00:00 2001 From: DatLag Date: Mon, 22 Apr 2024 16:26:02 +0200 Subject: [PATCH] filter character and expand/collapse medium fab --- .../datlag/aniflow/anilist/model/Character.kt | 16 ++-- .../datlag/aniflow/anilist/model/Medium.kt | 4 +- .../dev/datlag/aniflow/ui/custom/EditFAB.kt | 74 +++++++++++++------ .../navigation/screen/medium/MediumScreen.kt | 21 +++--- .../moko-resources/base/strings.xml | 2 + 5 files changed, 74 insertions(+), 43 deletions(-) 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 3133328..0c6a063 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 @@ -5,42 +5,42 @@ import dev.datlag.aniflow.anilist.MediumQuery import kotlinx.serialization.Serializable @Serializable -open class Character( +data class Character( /** * The id of the character */ - open val id: Int, + val id: Int, /** * The names of the character */ - open val name: Name, + val name: Name, /** * Character images */ - open val image: Image, + val image: Image, /** * The character's gender. * Usually Male, Female, or Non-binary but can be any string. */ - open val gender: String?, + val gender: String?, /** * The characters blood type */ - open val bloodType: String?, + val bloodType: String?, /** * The character's birthdate */ - open val birthDate: Character.BirthDate?, + val birthDate: Character.BirthDate?, /** * A general description of the character */ - open val description: String?, + val description: String?, ) { @Serializable 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 729fa2e..787f76d 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 @@ -250,7 +250,9 @@ open class Medium( coverImage = medium.coverImage, nextAiringEpisode = mediumQuery.nextAiringEpisode, ranking = mediumQuery.rankingsFilterNotNull()?.map(::Ranking)?.toSet() ?: emptySet(), - characters = mediumQuery.characters?.nodesFilterNotNull()?.mapNotNull(Character::invoke)?.toSet() ?: emptySet(), + characters = mediumQuery.characters?.nodesFilterNotNull()?.mapNotNull(Character::invoke)?.filterNot { + it.id == 36309 // Narrator + }?.toSet() ?: emptySet(), entry = mediumQuery.mediaListEntry?.let(::Entry), trailer = mediumQuery.trailer?.let { val site = it.site?.ifBlank { 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 409d989..210a93a 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 @@ -26,6 +26,7 @@ import dev.icerock.moko.resources.compose.stringResource fun EditFAB( displayAdd: Boolean = false, bsAvailable: Boolean = false, + expanded: Boolean = false, onBS: () -> Unit, onRate: () -> Unit, onProgress: () -> Unit @@ -52,6 +53,7 @@ fun EditFAB( ) { LabelFAB( label = "Progress", + expanded = expanded, onClick = { showOtherFABs = false onProgress() @@ -79,6 +81,7 @@ fun EditFAB( ) { LabelFAB( label = "Rating", + expanded = expanded, onClick = { showOtherFABs = false onRate() @@ -106,6 +109,7 @@ fun EditFAB( ) { LabelFAB( label = stringResource(SharedRes.strings.bs), + expanded = expanded, onClick = { showOtherFABs = false onBS() @@ -120,42 +124,64 @@ fun EditFAB( } } - FloatingActionButton( + ExtendedFloatingActionButton( onClick = { showOtherFABs = !showOtherFABs - } - ) { - val icon = if (displayAdd) { - Icons.Default.Add - } else { - Icons.Default.Edit - } + }, + expanded = expanded, + icon = { + val icon = if (displayAdd) { + Icons.Default.Add + } else { + Icons.Default.Edit + } - Icon( - imageVector = icon, - contentDescription = null - ) - } + Icon( + imageVector = icon, + contentDescription = null + ) + }, + text = { + val text = if (displayAdd) { + SharedRes.strings.add + } else { + SharedRes.strings.edit + } + + Text(text = stringResource(text)) + } + ) } } @Composable -private fun LabelFAB(label: String, onClick: () -> Unit, icon: @Composable () -> Unit) { +private fun LabelFAB( + label: String, + expanded: Boolean, + onClick: () -> Unit, + icon: @Composable () -> Unit +) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { - Surface( - onClick = onClick, - tonalElevation = 8.dp, - shadowElevation = 4.dp, - shape = RoundedCornerShape(4.dp) + AnimatedVisibility( + visible = expanded, + enter = fadeIn(), + exit = fadeOut() ) { - Text( - modifier = Modifier.padding(4.dp), - text = label, - maxLines = 1 - ) + Surface( + onClick = onClick, + tonalElevation = 8.dp, + shadowElevation = 4.dp, + shape = RoundedCornerShape(4.dp) + ) { + Text( + modifier = Modifier.padding(4.dp), + text = label, + maxLines = 1 + ) + } } SmallFloatingActionButton( 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 2c82c91..f5e511e 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 @@ -81,6 +81,10 @@ fun MediumScreen(component: MediumComponent) { val ratingState = rememberUseCaseState() val userRating by component.rating.collectAsStateWithLifecycle() val dialogState by component.dialog.subscribeAsState() + val listState = rememberLazyListState( + initialFirstVisibleItemIndex = StateSaver.List.mediaOverview, + initialFirstVisibleItemScrollOffset = StateSaver.List.mediaOverviewOffset + ) dialogState.child?.instance?.render() @@ -217,6 +221,7 @@ fun MediumScreen(component: MediumComponent) { EditFAB( displayAdd = !alreadyAdded, bsAvailable = component.bsAvailable, + expanded = listState.isScrollingUp(), onBS = { }, @@ -235,10 +240,6 @@ fun MediumScreen(component: MediumComponent) { CompositionLocalProvider( LocalPaddingValues provides LocalPadding().merge(it) ) { - val listState = rememberLazyListState( - initialFirstVisibleItemIndex = StateSaver.List.mediaOverview, - initialFirstVisibleItemScrollOffset = StateSaver.List.mediaOverviewOffset - ) val description by component.description.collectAsStateWithLifecycle() var descriptionExpandable by remember(description) { mutableStateOf(false) } var descriptionExpanded by remember(description) { mutableStateOf(false) } @@ -557,13 +558,13 @@ fun MediumScreen(component: MediumComponent) { } } } + } + } - DisposableEffect(listState) { - onDispose { - StateSaver.List.mediaOverview = listState.firstVisibleItemIndex - StateSaver.List.mediaOverviewOffset = listState.firstVisibleItemScrollOffset - } - } + DisposableEffect(listState) { + onDispose { + StateSaver.List.mediaOverview = listState.firstVisibleItemIndex + StateSaver.List.mediaOverviewOffset = listState.firstVisibleItemScrollOffset } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/moko-resources/base/strings.xml b/composeApp/src/commonMain/moko-resources/base/strings.xml index 26144f4..1b119cf 100644 --- a/composeApp/src/commonMain/moko-resources/base/strings.xml +++ b/composeApp/src/commonMain/moko-resources/base/strings.xml @@ -30,4 +30,6 @@ Blood Type Gender Birthdate + Add + Edit