Skip to content

Commit

Permalink
Merge pull request #66 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 9, 2024
2 parents 8560b49 + 9e0251a commit 9574c7f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ android {
applicationId = "com.application.moviesapp"
minSdk = 24
targetSdk = 33
versionCode = 7
versionName = "1.0.6"
versionCode = 8
versionName = "1.0.7"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ import timber.log.Timber
@Composable
fun CastDetailScreen(modifier: Modifier = Modifier,
paddingValues: PaddingValues = PaddingValues(),
castDetailUIState: Resource<CastDetailWithImages> = Resource.Loading
castDetailUIState: Resource<CastDetailWithImages> = Resource.Loading,
onImageClick: (Pair<String, List<String?>?>) -> Unit = { _ -> }
) {

val scrollState = rememberScrollState()
Expand Down Expand Up @@ -247,7 +248,7 @@ fun CastDetailScreen(modifier: Modifier = Modifier,
contentPadding = PaddingValues(horizontal = 16.dp),
) {
items(castDetailUIState.data.images.profiles?.size ?: 0) { index ->
CastImageCard(imageUrl = castDetailUIState.data.images.profiles?.get(index)?.filePath ?: "")
CastImageCard(imageUrl = castDetailUIState.data.images.profiles?.get(index)?.filePath ?: "", onImageClick = onImageClick, imageList = castDetailUIState.data.images.profiles?.map { it?.filePath ?: ""})
}
}
}
Expand Down Expand Up @@ -351,11 +352,11 @@ private fun TvSeriesImageCard(modifier: Modifier = Modifier, imageUrl: String =

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun CastImageCard(modifier: Modifier = Modifier, imageUrl: String = "", personId: Int? = null) {
private fun CastImageCard(modifier: Modifier = Modifier, imageUrl: String = "", onImageClick: (Pair<String, List<String?>?>) -> Unit = { }, imageList: List<String?>? = emptyList()) {

val context = LocalContext.current

Card(shape = RoundedCornerShape(10), onClick = { }) {
Card(shape = RoundedCornerShape(10), onClick = { onImageClick(Pair(imageUrl, imageList)) }) {
Box {
AsyncImage(
model = ImageRequest.Builder(context = LocalContext.current)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,100 @@
package com.application.moviesapp.ui.detail

import android.app.Activity
import android.content.res.Configuration
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
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.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.PlayCircle
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.application.moviesapp.R
import com.application.moviesapp.ui.theme.MoviesAppTheme
import com.application.moviesapp.ui.utility.toImageUrl
import kotlinx.coroutines.launch

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CastScreen(modifier: Modifier = Modifier, paddingValues: PaddingValues = PaddingValues()) {
Column(modifier = modifier
.fillMaxSize()
.padding(top = paddingValues.calculateTopPadding(), start = 16.dp, end = 16.dp)) {
Text(text = "Cast screen")
fun CastScreen(modifier: Modifier = Modifier,
paddingValues: PaddingValues = PaddingValues(),
selectedImage: Pair<String, List<String?>?> = Pair("", emptyList())) {

val filteredImage = selectedImage.second?.indexOf(selectedImage.first)
val pagerState = rememberPagerState { selectedImage.second?.size ?: 0 }

val coroutineScope = rememberCoroutineScope()

LaunchedEffect(key1 = Unit) {
coroutineScope.launch {
pagerState.animateScrollToPage(page = filteredImage ?: 0)
}
}


Box(modifier = modifier
.fillMaxSize()) {

HorizontalPager(state = pagerState) { index ->
AsyncImage(
model = ImageRequest.Builder(context = LocalContext.current)
.data(selectedImage.second?.get(index)?.toImageUrl)
.crossfade(true)
.build(),
error = painterResource(id = R.drawable.ic_broken_image),
placeholder = painterResource(id = R.drawable.ic_image_placeholder),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier.fillMaxSize(),
)
}

Row(modifier = modifier
.fillMaxSize()
.wrapContentSize(align = Alignment.BottomCenter)
.padding(16.dp)
.background(color = Color(0x66FFFFFF), shape = RoundedCornerShape(50))) {
Text(text = "${pagerState.currentPage.inc()} / ${selectedImage.second?.size}", color = Color.White, style = MaterialTheme.typography.bodySmall, modifier = modifier.padding(horizontal = 16.dp, vertical = 8.dp))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ fun DetailScreen(modifier: Modifier = Modifier,

items(count = tvSeriesUIState.data.cast?.size ?: 0) { index ->

Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Row(modifier = modifier.clickable(onClick = { onCastClick(tvSeriesUIState.data.cast?.get(index)?.id ?: return@clickable) }, interactionSource = remember { MutableInteractionSource() }, indication = null), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
AsyncImage(model = ImageRequest.Builder(context = LocalContext.current)
.data(tvSeriesUIState.data.cast?.get(index)?.profilePath?.toImageUrl ?: "")
.crossfade(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.application.moviesapp.ui.detail

import android.app.Activity
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -9,13 +10,16 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.Cast
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -95,6 +99,8 @@ fun DetailScreenApp(modifier: Modifier = Modifier,
)
}

var selectedImage by remember { mutableStateOf(Pair<String, List<String?>?>("", emptyList())) }

Scaffold(
topBar = { DetailTopAppbar(navController = navController) },
snackbarHost = { SnackbarHost(snackbarHostState) }
Expand Down Expand Up @@ -129,14 +135,19 @@ fun DetailScreenApp(modifier: Modifier = Modifier,
composable(route = DetailScreen.CastDetail.name) {
CastDetailScreen(
modifier = modifier,
castDetailUIState = castDetailUIState
castDetailUIState = castDetailUIState,
onImageClick = {
selectedImage = it
navController.navigate(DetailScreen.Cast.name)
}
)
}

composable(route = DetailScreen.Cast.name) {
CastScreen(
modifier = modifier,
paddingValues = paddingValues
paddingValues = paddingValues,
selectedImage = selectedImage
)
}
}
Expand Down Expand Up @@ -183,13 +194,8 @@ private fun DetailTopAppbar(modifier: Modifier = Modifier, navController: NavHos
TopAppBar(
title = { },
navigationIcon = {
IconButton(onClick = { (context as Activity).finish() }) {
Icon(imageVector = Icons.Rounded.ArrowBack, contentDescription = null, tint = Color.White)
}
},
actions = {
IconButton(onClick = {}) {
Icon(imageVector = Icons.Rounded.Cast, contentDescription = null, tint = Color.White)
IconButton(onClick = { navController.navigateUp() }, modifier = modifier.padding(16.dp).background(color = Color(0xAABEBEBE), shape = RoundedCornerShape(50)).size(30.dp)) {
Icon(imageVector = Icons.Rounded.Close, contentDescription = null, tint = Color.White)
}
},
colors = TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent))
Expand Down

0 comments on commit 9574c7f

Please sign in to comment.