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,145 +861,136 @@ private fun ReviewsCard(
} }
} }
val hasReviews = reviewsResponse.value?.results?.size?.let { it > 0 } ListContentCard(
val m = if (hasReviews == true) { modifier = modifier,
modifier.height(400.dp) header = {
} else { Column(
modifier.height(200.dp) verticalArrangement = Arrangement.spacedBy(9.dp)
} ) {
Text(
text = stringResource(R.string.reviews_title),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
LazyListContentCard( if (SessionManager.currentSession?.isAuthorized == true) {
modifier = m Row(
.fillMaxWidth(), modifier = Modifier
header = { .fillMaxWidth()
Text( .height(50.dp)
text = "Reviews", .padding(bottom = 4.dp),
style = MaterialTheme.typography.titleLarge, horizontalArrangement = Arrangement.spacedBy(8.dp)
color = MaterialTheme.colorScheme.onSurfaceVariant ) {
) var reviewTextState by remember { mutableStateOf("") }
},
footer = {
if (SessionManager.currentSession?.isAuthorized == true) {
Row(
modifier = Modifier
.fillMaxWidth()
.height(50.dp)
.padding(top = 4.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
var reviewTextState by remember { mutableStateOf("") }
RoundedTextField( RoundedTextField(
modifier = Modifier modifier = Modifier
.height(40.dp) .height(40.dp)
.align(Alignment.CenterVertically) .align(Alignment.CenterVertically)
.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
) )
val context = LocalContext.current val context = LocalContext.current
CircleBackgroundColorImage( CircleBackgroundColorImage(
modifier = Modifier modifier = Modifier
.align(Alignment.CenterVertically) .align(Alignment.CenterVertically)
.clickable ( .clickable(
onClick = { onClick = {
Toast.makeText(context, "TODO", Toast.LENGTH_SHORT).show() Toast.makeText(context, "TODO", Toast.LENGTH_SHORT).show()
} }
), ),
size = 40.dp, size = 40.dp,
backgroundColor = MaterialTheme.colorScheme.tertiary, backgroundColor = MaterialTheme.colorScheme.tertiary,
image = Icons.Filled.Send, image = Icons.Filled.Send,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.surfaceVariant), colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.surfaceVariant),
contentDescription = "" contentDescription = ""
) )
} }
} }
} }
) { },
val reviews = reviewsResponse.value?.results ?: emptyList() ) {
if (reviews.isNotEmpty()) { val reviews = reviewsResponse.value?.results ?: emptyList()
items(reviews.size) { i -> if (reviews.isNotEmpty()) {
val review = reviews[i] reviews.reversed().forEach { review ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(end = 16.dp),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
AvatarImage(
size = 50.dp,
author = review.authorDetails
)
Row( // todo - only show this for user's review
modifier = Modifier CircleBackgroundColorImage(
.fillMaxWidth() image = Icons.Filled.Delete,
.padding(end = 16.dp), size = 30.dp,
verticalAlignment = Alignment.Top, backgroundColor = MaterialTheme.colorScheme.error,
horizontalArrangement = Arrangement.spacedBy(16.dp) contentDescription = "",
) { imageSize = DpSize(width = 20.dp, height = 15.dp),
Column( colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.surfaceVariant)
verticalArrangement = Arrangement.spacedBy(8.dp), )
horizontalAlignment = Alignment.CenterHorizontally }
) {
AvatarImage(
size = 50.dp,
author = review.authorDetails
)
// todo - only show this for user's review Column(
CircleBackgroundColorImage( verticalArrangement = Arrangement.spacedBy(4.dp)
image = Icons.Filled.Delete, ) {
size = 30.dp, Text(
backgroundColor = MaterialTheme.colorScheme.error, text = review.author,
contentDescription = "", color = MaterialTheme.colorScheme.secondary,
imageSize = DpSize(width = 20.dp, height = 15.dp), fontWeight = FontWeight.Bold
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.surfaceVariant) )
)
}
Column( HtmlText(
verticalArrangement = Arrangement.spacedBy(4.dp) text = review.content,
) { color = MaterialTheme.colorScheme.onSurfaceVariant
Text( )
text = review.author,
color = MaterialTheme.colorScheme.secondary,
fontWeight = FontWeight.Bold
)
HtmlText( val createdAt = TmdbUtils.formatDate(review.createdAt)
text = review.content, val updatedAt = TmdbUtils.formatDate(review.updatedAt)
color = MaterialTheme.colorScheme.onSurfaceVariant var timestamp = stringResource(id = R.string.created_at_label, createdAt)
) if (updatedAt != createdAt) {
timestamp += "\n${stringResource(id = R.string.updated_at_label, updatedAt)}"
val createdAt = TmdbUtils.formatDate(review.createdAt) }
val updatedAt = TmdbUtils.formatDate(review.updatedAt) Text(
var timestamp = stringResource(id = R.string.created_at_label, createdAt) text = timestamp,
if (updatedAt != createdAt) { color = MaterialTheme.colorScheme.onSurfaceVariant,
timestamp += "\n${stringResource(id = R.string.updated_at_label, updatedAt)}" fontSize = 12.sp
} )
Text( }
text = timestamp, }
color = MaterialTheme.colorScheme.onSurfaceVariant, Divider(
fontSize = 12.sp color = MaterialTheme.colorScheme.secondary,
) modifier = Modifier.padding(horizontal = 50.dp, vertical = 6.dp)
} )
} }
Divider( } else {
color = MaterialTheme.colorScheme.secondary, Text(
modifier = Modifier.padding(horizontal = 50.dp, vertical = 6.dp) modifier = Modifier
) .fillMaxWidth()
} .wrapContentHeight()
} else { .padding(horizontal = 24.dp, vertical = 22.dp),
item { text = stringResource(R.string.no_reviews_label),
Text( color = MaterialTheme.colorScheme.tertiary,
modifier = Modifier textAlign = TextAlign.Center,
.fillMaxWidth() style = MaterialTheme.typography.headlineMedium
.wrapContentHeight() )
.padding(horizontal = 24.dp, vertical = 22.dp), }
text = stringResource(R.string.no_reviews_label), }
color = MaterialTheme.colorScheme.tertiary,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.headlineMedium
)
}
}
}
} }
private fun fetchMediaItem(id: Int, service: DetailService, mediaItem: MutableState<DetailedItem?>) { private fun fetchMediaItem(id: Int, service: DetailService, mediaItem: MutableState<DetailedItem?>) {

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>