Skip to content

Commit

Permalink
filter character and expand/collapse medium fab
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 22, 2024
1 parent cd653cc commit d3be63a
Showing 5 changed files with 74 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 2 additions & 0 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
@@ -30,4 +30,6 @@
<string name="blood_type">Blood Type</string>
<string name="gender">Gender</string>
<string name="birth_date">Birthdate</string>
<string name="add">Add</string>
<string name="edit">Edit</string>
</resources>

0 comments on commit d3be63a

Please sign in to comment.