diff --git a/app/src/main/java/hu/bbara/purefin/app/home/ui/HomeSections.kt b/app/src/main/java/hu/bbara/purefin/app/home/ui/HomeSections.kt index 41f48a4..2834be8 100644 --- a/app/src/main/java/hu/bbara/purefin/app/home/ui/HomeSections.kt +++ b/app/src/main/java/hu/bbara/purefin/app/home/ui/HomeSections.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import coil3.compose.AsyncImage import hu.bbara.purefin.app.home.HomePageViewModel +import hu.bbara.purefin.common.ui.PosterCard import hu.bbara.purefin.image.JellyfinImageHelper import hu.bbara.purefin.player.PlayerActivity import org.jellyfin.sdk.model.api.BaseItemKind @@ -47,14 +48,10 @@ import kotlin.math.nextUp @Composable fun ContinueWatchingSection( - items: List, - colors: HomeColors, - modifier: Modifier = Modifier + items: List, colors: HomeColors, modifier: Modifier = Modifier ) { SectionHeader( - title = "Continue Watching", - action = null, - colors = colors + title = "Continue Watching", action = null, colors = colors ) LazyRow( modifier = modifier.fillMaxWidth(), @@ -62,12 +59,9 @@ fun ContinueWatchingSection( horizontalArrangement = Arrangement.spacedBy(16.dp) ) { items( - items = items, - key = { it.id } - ) { item -> + items = items, key = { it.id }) { item -> ContinueWatchingCard( - item = item, - colors = colors + item = item, colors = colors ) } } @@ -104,18 +98,17 @@ fun ContinueWatchingCard( ) { AsyncImage( model = JellyfinImageHelper.toImageUrl( - url = "https://jellyfin.bbara.hu", - itemId = item.id, - type = ImageType.PRIMARY + url = "https://jellyfin.bbara.hu", itemId = item.id, type = ImageType.PRIMARY ), contentDescription = null, - modifier = Modifier.fillMaxSize() + modifier = Modifier + .fillMaxSize() .clickable { openItem(item) }, contentScale = ContentScale.Crop, - ) + ) Box( modifier = Modifier .matchParentSize() @@ -136,12 +129,11 @@ fun ContinueWatchingCard( ) } Button( - modifier = Modifier.align(Alignment.BottomEnd), - onClick = { + modifier = Modifier.align(Alignment.BottomEnd), onClick = { val intent = Intent(context, PlayerActivity::class.java) intent.putExtra("MEDIA_ID", item.id.toString()) context.startActivity(intent) - }) { + }) { Icon(imageVector = Icons.Outlined.PlayArrow, contentDescription = "Play") } } @@ -174,9 +166,7 @@ fun LibraryPosterSection( modifier: Modifier = Modifier ) { SectionHeader( - title = title, - action = action, - colors = colors + title = title, action = action, colors = colors ) LazyRow( modifier = modifier.fillMaxWidth(), @@ -184,9 +174,7 @@ fun LibraryPosterSection( horizontalArrangement = Arrangement.spacedBy(16.dp) ) { items( - items = items, - key = { it.id } - ) { item -> + items = items, key = { it.id }) { item -> PosterCard( item = item, colors = colors, @@ -195,52 +183,6 @@ fun LibraryPosterSection( } } -@Composable -fun PosterCard( - item: PosterItem, - colors: HomeColors, - modifier: Modifier = Modifier, - viewModel: HomePageViewModel = hiltViewModel() -) { - fun openItem(posterItem: PosterItem) - { - when (posterItem.type) { - BaseItemKind.MOVIE -> viewModel.onMovieSelected(posterItem.id.toString()) - BaseItemKind.SERIES -> viewModel.onSeriesSelected(posterItem.id.toString()) - BaseItemKind.EPISODE -> viewModel.onSelectEpisode(posterItem.id.toString()) - else -> {} - } - } - - Box( - modifier = modifier - .width(144.dp) - .aspectRatio(2f / 3f) - .shadow(10.dp, RoundedCornerShape(14.dp)) - .clip(RoundedCornerShape(14.dp)) - .background(colors.card) - .clickable(onClick = { openItem(item) }) - ) { - AsyncImage( - model = JellyfinImageHelper.toImageUrl(url = "https://jellyfin.bbara.hu", itemId = item.imageItemId, type = ImageType.PRIMARY), - contentDescription = null, - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Crop - ) - Text( - text = item.title, - color = colors.textPrimary, - fontSize = 13.sp, - fontWeight = FontWeight.Medium, - modifier = Modifier - .align(Alignment.BottomStart) - .padding(10.dp), - maxLines = 2, - overflow = TextOverflow.Ellipsis - ) - } -} - @Composable fun SectionHeader( title: String, @@ -257,10 +199,7 @@ fun SectionHeader( horizontalArrangement = Arrangement.SpaceBetween ) { Text( - text = title, - color = colors.textPrimary, - fontSize = 20.sp, - fontWeight = FontWeight.Bold + text = title, color = colors.textPrimary, fontSize = 20.sp, fontWeight = FontWeight.Bold ) if (action != null) { Text( @@ -268,8 +207,7 @@ fun SectionHeader( color = colors.primary, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, - modifier = Modifier.clickable { onActionClick() } - ) + modifier = Modifier.clickable { onActionClick() }) } } } diff --git a/app/src/main/java/hu/bbara/purefin/common/ui/PosterCard.kt b/app/src/main/java/hu/bbara/purefin/common/ui/PosterCard.kt new file mode 100644 index 0000000..edd9d60 --- /dev/null +++ b/app/src/main/java/hu/bbara/purefin/common/ui/PosterCard.kt @@ -0,0 +1,74 @@ +package hu.bbara.purefin.common.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel +import coil3.compose.AsyncImage +import hu.bbara.purefin.app.home.HomePageViewModel +import hu.bbara.purefin.app.home.ui.HomeColors +import hu.bbara.purefin.app.home.ui.PosterItem +import hu.bbara.purefin.image.JellyfinImageHelper +import org.jellyfin.sdk.model.api.BaseItemKind +import org.jellyfin.sdk.model.api.ImageType + +@Composable +fun PosterCard( + item: PosterItem, + colors: HomeColors, + modifier: Modifier = Modifier, + viewModel: HomePageViewModel = hiltViewModel() +) { + fun openItem(posterItem: PosterItem) { + when (posterItem.type) { + BaseItemKind.MOVIE -> viewModel.onMovieSelected(posterItem.id.toString()) + BaseItemKind.SERIES -> viewModel.onSeriesSelected(posterItem.id.toString()) + BaseItemKind.EPISODE -> viewModel.onSelectEpisode(posterItem.id.toString()) + else -> {} + } + } + Column( + modifier = Modifier + .width(144.dp) + ) { + + AsyncImage( + model = JellyfinImageHelper.toImageUrl( + url = "https://jellyfin.bbara.hu", + itemId = item.imageItemId, + type = ImageType.PRIMARY + ), + contentDescription = null, + modifier = Modifier + .aspectRatio(2f / 3f) + .shadow(10.dp, RoundedCornerShape(14.dp)) + .clip(RoundedCornerShape(14.dp)) + .background(colors.card) + .clickable(onClick = { openItem(item) }), + contentScale = ContentScale.Crop + ) + Text( + text = item.title, + color = colors.textPrimary, + fontSize = 13.sp, + fontWeight = FontWeight.Medium, + modifier = Modifier.padding(top = 8.dp, start = 4.dp, end = 4.dp, bottom = 8.dp), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } +} \ No newline at end of file