full size reviews card

This commit is contained in:
Owen LeJeune
2022-11-07 17:03:40 -05:00
parent 1d9888aeff
commit 3e2c23bb8e
4 changed files with 158 additions and 134 deletions

View File

@@ -129,6 +129,37 @@ fun LazyListContentCard(
} }
} }
@Composable
fun ListContentCard(
modifier: Modifier = Modifier,
header: @Composable (() -> Unit)? = null,
footer: @Composable (() -> Unit)? = null,
backgroundColor: Color = MaterialTheme.colorScheme.surfaceVariant,
content: @Composable ColumnScope.() -> Unit
) {
Card(
modifier = modifier,
shape = RoundedCornerShape(10.dp),
backgroundColor = backgroundColor,
elevation = 8.dp
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
header?.invoke()
Column(
content = content,
modifier = Modifier
.fillMaxWidth()
)
footer?.invoke()
}
}
}
@Composable @Composable
fun TwoLineImageTextCard( fun TwoLineImageTextCard(
title: String, title: String,

View File

@@ -572,10 +572,11 @@ fun FullScreenThumbnailVideoPlayer(
val context = LocalContext.current val context = LocalContext.current
Column( Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(6.dp) verticalArrangement = Arrangement.spacedBy(6.dp)
) { ) {
AsyncImage( AsyncImage(
modifier = modifier modifier = Modifier
.clickable( .clickable(
onClick = { onClick = {
val intent = Intent(Intent.ACTION_VIEW).apply { val intent = Intent(Intent.ACTION_VIEW).apply {

View File

@@ -848,7 +848,6 @@ private fun VideoGroup(results: List<Video>, type: Video.Type, title: String) {
} }
} }
@OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
private fun ReviewsCard( private fun ReviewsCard(
itemId: Int?, itemId: Int?,
@@ -862,30 +861,24 @@ private fun ReviewsCard(
} }
} }
val hasReviews = reviewsResponse.value?.results?.size?.let { it > 0 } ListContentCard(
val m = if (hasReviews == true) { modifier = modifier,
modifier.height(400.dp)
} else {
modifier.height(200.dp)
}
LazyListContentCard(
modifier = m
.fillMaxWidth(),
header = { header = {
Column(
verticalArrangement = Arrangement.spacedBy(9.dp)
) {
Text( Text(
text = "Reviews", text = stringResource(R.string.reviews_title),
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant color = MaterialTheme.colorScheme.onSurfaceVariant
) )
},
footer = {
if (SessionManager.currentSession?.isAuthorized == true) { if (SessionManager.currentSession?.isAuthorized == true) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(50.dp) .height(50.dp)
.padding(top = 4.dp), .padding(bottom = 4.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
var reviewTextState by remember { mutableStateOf("") } var reviewTextState by remember { mutableStateOf("") }
@@ -897,7 +890,7 @@ private fun ReviewsCard(
.weight(1f), .weight(1f),
value = reviewTextState, value = reviewTextState,
onValueChange = { reviewTextState = it }, onValueChange = { reviewTextState = it },
placeHolder = "Add a review", placeHolder = stringResource(R.string.add_a_review_hint),
backgroundColor = MaterialTheme.colorScheme.secondary, backgroundColor = MaterialTheme.colorScheme.secondary,
placeHolderTextColor = MaterialTheme.colorScheme.background, placeHolderTextColor = MaterialTheme.colorScheme.background,
textColor = MaterialTheme.colorScheme.onSecondary textColor = MaterialTheme.colorScheme.onSecondary
@@ -921,12 +914,11 @@ private fun ReviewsCard(
} }
} }
} }
},
) { ) {
val reviews = reviewsResponse.value?.results ?: emptyList() val reviews = reviewsResponse.value?.results ?: emptyList()
if (reviews.isNotEmpty()) { if (reviews.isNotEmpty()) {
items(reviews.size) { i -> reviews.reversed().forEach { review ->
val review = reviews[i]
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -987,7 +979,6 @@ private fun ReviewsCard(
) )
} }
} else { } else {
item {
Text( Text(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -1001,7 +992,6 @@ private fun ReviewsCard(
} }
} }
} }
}
private fun fetchMediaItem(id: Int, service: DetailService, mediaItem: MutableState<DetailedItem?>) { private fun fetchMediaItem(id: Int, service: DetailService, mediaItem: MutableState<DetailedItem?>) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {

View File

@@ -153,4 +153,6 @@
<string name="popular_today_header">Popular Today</string> <string name="popular_today_header">Popular Today</string>
<string name="preference_show_poster_titles_title">Show Poster Titles</string> <string name="preference_show_poster_titles_title">Show Poster Titles</string>
<string name="preference_show_poster_titles_subtitle">Show titles on home screen posters</string> <string name="preference_show_poster_titles_subtitle">Show titles on home screen posters</string>
<string name="reviews_title">Reviews</string>
<string name="add_a_review_hint">Add a review</string>
</resources> </resources>