Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Media Details Clickable #246

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 62 additions & 12 deletions media/src/main/kotlin/com/imashnake/animite/media/MediaPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand All @@ -32,10 +33,13 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SuggestionChip
import androidx.compose.material3.SuggestionChipDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -88,6 +92,7 @@ import androidx.core.net.toUri
// TODO: Need to use WindowInsets to get device corner radius if available.
private const val DEVICE_CORNER_RADIUS = 30

@OptIn(ExperimentalMaterial3Api::class)
@Composable
@Suppress(
"CognitiveComplexMethod",
Expand All @@ -102,6 +107,11 @@ fun MediaPage(

val media = viewModel.uiState

var showSheet by remember { mutableStateOf(false) }
val sheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = false,
)

MaterialTheme(colorScheme = rememberColorSchemeFor(media.color)) {
TranslucentStatusBarLayout(
scrollState = scrollState,
Expand Down Expand Up @@ -144,14 +154,16 @@ fun MediaPage(
modifier = Modifier
.skipToLookaheadSize()
.padding(
start = LocalPaddings.current.large
start = LocalPaddings.current.large / 2
+ dimensionResource(coreR.dimen.media_card_width)
+ LocalPaddings.current.large,
end = LocalPaddings.current.large
end = LocalPaddings.current.large / 2
)
.landscapeCutoutPadding()
.height(dimensionResource(R.dimen.media_details_height)),
onClick = { },
.height(
dimensionResource(R.dimen.media_details_height) + LocalPaddings.current.medium / 2
),
onClick = { showSheet = true },
textModifier = Modifier.sharedBounds(
rememberSharedContentState(
SharedContentKey(
Expand Down Expand Up @@ -221,7 +233,7 @@ fun MediaPage(
)
}
},
contentModifier = Modifier.padding(top = LocalPaddings.current.medium)
contentModifier = Modifier.padding(top = LocalPaddings.current.medium / 2)
)

// TODO: https://developer.android.com/jetpack/compose/animation/quick-guide#concurrent-animations
Expand Down Expand Up @@ -271,6 +283,30 @@ fun MediaPage(
}
}
}

if (showSheet)
ModalBottomSheet(
modifier = Modifier
.fillMaxHeight()
.padding(horizontal = LocalPaddings.current.medium),
sheetState = sheetState,
onDismissRequest = { showSheet = false },
) {
Column(
modifier = Modifier.padding(horizontal = LocalPaddings.current.large),
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.medium)
) {
Text(
text = media.title.orEmpty(),
color = MaterialTheme.colorScheme.onBackground,
style = MaterialTheme.typography.titleLarge,
)

MediaDescription(
html = media.description.orEmpty(),
)
}
}
}
}
}
Expand Down Expand Up @@ -305,7 +341,13 @@ fun MediaDetails(
modifier: Modifier = Modifier,
textModifier: Modifier = Modifier
) {
Column(modifier.clickable { onClick() }) {
Column(
modifier = modifier
.clip(RoundedCornerShape(LocalPaddings.current.small))
.clickable { onClick() }
.padding(horizontal = LocalPaddings.current.large / 2)
.padding(top = LocalPaddings.current.medium / 2)
) {
Box(Modifier.fillMaxWidth()) {
Text(
text = title,
Expand All @@ -318,16 +360,24 @@ fun MediaDetails(
}

NestedScrollableContent { contentModifier ->
Text(
text = AnnotatedString.fromHtml(description),
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.74f),
style = MaterialTheme.typography.bodyMedium,
modifier = contentModifier,
)
MediaDescription(description, contentModifier)
}
}
}

@Composable
fun MediaDescription(
html: String,
modifier: Modifier = Modifier,
) {
Text(
text = AnnotatedString.fromHtml(html),
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.74f),
style = MaterialTheme.typography.bodyMedium,
modifier = modifier,
)
}

@Composable
fun MediaGenres(
genres: List<String>,
Expand Down
Loading