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

Set up image placeholders #132

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ kotlin {

sourceSets["desktopMain"].dependencies {
implementation(libs.ktor.java)
implementation(libs.coroutines.swing)
runtimeOnly(libs.coroutines.swing)
implementation(compose.desktop.currentOs)
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import coil3.compose.AsyncImage
import com.vickbt.composeApp.domain.models.Actor
import com.vickbt.composeApp.ui.theme.TextSecondary
import com.vickbt.composeApp.utils.loadImage
import com.vickbt.shared.resources.Res
import com.vickbt.shared.resources.ic_person
import org.jetbrains.compose.resources.painterResource

@Composable
fun ItemMovieCast(modifier: Modifier = Modifier, actor: Actor) {
Expand All @@ -33,6 +36,7 @@ fun ItemMovieCast(modifier: Modifier = Modifier, actor: Actor) {
model = actor.profilePath?.loadImage(),
contentDescription = "Cast",
contentScale = ContentScale.Crop,
error = painterResource(Res.drawable.ic_person)
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ import com.vickbt.composeApp.utils.getRating
import com.vickbt.composeApp.utils.getReleaseDate
import com.vickbt.composeApp.utils.loadImage
import com.vickbt.shared.resources.Res
import com.vickbt.shared.resources.ic_theatre
import com.vickbt.shared.resources.unknown_movie
import io.ktor.http.Url
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

@Composable
Expand Down Expand Up @@ -82,6 +84,7 @@ fun MovieCardLandscape(
contentDescription = null,
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
error = painterResource(Res.drawable.ic_theatre)
)
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.CachePolicy
import coil3.request.ImageRequest
import com.kmpalette.loader.NetworkLoader
import com.kmpalette.loader.rememberNetworkLoader
import com.kmpalette.rememberDominantColorState
Expand All @@ -40,10 +43,12 @@ import com.vickbt.composeApp.ui.components.ratingbar.StepSize
import com.vickbt.composeApp.utils.getRating
import com.vickbt.composeApp.utils.loadImage
import com.vickbt.shared.resources.Res
import com.vickbt.shared.resources.ic_theatre
import com.vickbt.shared.resources.unknown_movie
import io.ktor.http.Url
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

@Composable
Expand All @@ -60,6 +65,13 @@ fun MovieCardPager(
coroutineContext = Dispatchers.IO
)

val imageRequest = ImageRequest.Builder(LocalPlatformContext.current)
.data(movie.backdropPath?.loadImage())
.dispatcher(Dispatchers.IO)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.build()

movie.backdropPath?.loadImage()?.let {
LaunchedEffect(it) {
dominantColorState.updateFrom(Url(it))
Expand All @@ -73,10 +85,11 @@ fun MovieCardPager(
modifier = Modifier
.fillMaxSize()
.align(Alignment.Center),
model = movie.backdropPath?.loadImage(),
model = imageRequest,
contentDescription = null,
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
error = painterResource(Res.drawable.ic_theatre)
)
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
Expand All @@ -25,7 +25,9 @@ import coil3.compose.AsyncImage
import com.vickbt.composeApp.domain.models.Movie
import com.vickbt.composeApp.utils.loadImage
import com.vickbt.shared.resources.Res
import com.vickbt.shared.resources.ic_theatre
import com.vickbt.shared.resources.unknown_movie
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

@Composable
Expand All @@ -35,31 +37,31 @@ fun MovieCardPortraitCompact(
onItemClick: (Movie) -> Unit
) {
Column(
modifier = modifier,
modifier = modifier.width(150.dp),
verticalArrangement = Arrangement.spacedBy(3.dp)
) {
Card(
modifier = Modifier
.width(150.dp)
.fillMaxHeight()
.fillMaxWidth()
.height(220.dp)
.clickable { onItemClick(movie) },
elevation = CardDefaults.cardElevation(8.dp),
shape = RoundedCornerShape(4.dp)
) {
AsyncImage(
modifier = Modifier
.fillMaxWidth()
.height(220.dp)
.sizeIn(minHeight = 30.dp),
.fillMaxHeight(),
model = movie.posterPath?.loadImage(),
contentDescription = "Trending movie poster",
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
error = painterResource(Res.drawable.ic_theatre)
)
}

Text(
modifier = Modifier.width(145.dp),
modifier = Modifier.wrapContentWidth(),
text = movie.title ?: stringResource(Res.string.unknown_movie),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
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 Down Expand Up @@ -94,13 +95,14 @@ fun HomeScreen(
rememberPagerState(pageCount = { nowPlayingMovies.size })

HorizontalPager(
modifier = Modifier.fillMaxWidth().padding(vertical = 12.dp),
modifier = Modifier.fillMaxWidth().height(280.dp)
.padding(vertical = 12.dp),
state = pagerState,
contentPadding = PaddingValues(horizontal = 16.dp),
pageSpacing = 8.dp
) { currentPage ->
MovieCardPager(
modifier = Modifier.fillMaxWidth().height(280.dp),
modifier = Modifier.fillMaxWidth().fillMaxHeight(),
networkLoader = networkLoader,
movie = nowPlayingMovies[currentPage]
) { movie ->
Expand Down Expand Up @@ -132,13 +134,14 @@ fun HomeScreen(
LazyRow(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
.height(250.dp),
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
items(trendingMovies.itemCount) { index ->
trendingMovies[index]?.let {
MovieCardPortraitCompact(
modifier = Modifier.fillMaxHeight(),
movie = it,
onItemClick = { movie ->
navigator.navigate("/details/${movie.id}")
Expand All @@ -162,16 +165,16 @@ fun HomeScreen(
)

LazyRow(
modifier = Modifier.height(245.dp),
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(14.dp),
modifier = Modifier.wrapContentHeight()
) {
items(upcomingMovies.itemCount) { index ->
upcomingMovies[index]?.let {
MovieCardLandscape(
modifier = Modifier
.width(300.dp)
.height(245.dp),
.fillMaxHeight(),
movie = it,
networkLoader = networkLoader,
onClickItem = { movie ->
Expand Down
Loading