Skip to content

Commit

Permalink
Merge pull request #74 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 15, 2024
2 parents 769ceb2 + 23b8f5d commit 0647d41
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 207 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 = 13
versionName = "1.0.12"
versionCode = 14
versionName = "1.0.13"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ data class Member(
val nickName: String = "",
val email: String = "",
val phoneNumber: String = "",
val gender: String = ""
val gender: String = "",
val forceDelete: Boolean = false
)

data class MemberPhoto(
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/application/moviesapp/ui/home/HomeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import com.application.moviesapp.ui.viewmodel.OnboardingViewModel
import com.application.moviesapp.ui.viewmodel.ProfileViewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
Expand Down Expand Up @@ -171,6 +172,7 @@ fun HomeApp(modifier: Modifier = Modifier,
val profileUiState by homeViewModel.profileInfoUiState.collectAsState()
val darkModeUiState by profileViewModel.isDarkMode.collectAsState(initial = SettingsPreference(false))

val userDetailUIState by onboardingViewModel.profileUIState.collectAsState()

var searchValue by remember {
mutableStateOf("")
Expand Down Expand Up @@ -244,6 +246,7 @@ fun HomeApp(modifier: Modifier = Modifier,
LaunchedEffect(key1 = Unit) {
permissionState.launchMultiplePermissionRequest()
onboardingViewModel.getProfilePhoto()
onboardingViewModel.getProfile()
}

val itemsListCategories = listOf(Categories.Movies, Categories.TV)
Expand Down Expand Up @@ -435,7 +438,14 @@ fun HomeApp(modifier: Modifier = Modifier,
else -> { }
}
} },
onMovieWithTvSeries = homeViewModel::getMovieWithTvSeries
onMovieWithTvSeries = homeViewModel::getMovieWithTvSeries,

userDetailUIState = userDetailUIState,
onForceDelete = {
homeViewModel.signOut()
(context as Activity).finish()
HomeActivity.startActivity(context as Activity)
}
)
}
composable(route = BottomNavigationScreens.Explore.route) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/application/moviesapp/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.application.moviesapp.ui.theme.MoviesAppTheme
import com.application.moviesapp.R
import com.application.moviesapp.data.api.request.Member
import com.application.moviesapp.data.common.Resource
import com.application.moviesapp.domain.model.MovieWithTvSeries
import com.application.moviesapp.ui.detail.DetailActivity
Expand All @@ -88,8 +89,23 @@ fun HomeScreen(modifier: Modifier = Modifier,
goToDownloadClick: () -> Unit = { },
goToMyListClick: (String, Int, Boolean) -> Unit = { _, _, _ -> },
onMovieWithTvSeries: () -> Unit = { },


userDetailUIState: Resource<Member> = Resource.Loading,
onForceDelete: () -> Unit = { }
) {


when (userDetailUIState) {
is Resource.Loading -> { }
is Resource.Failure -> { }
is Resource.Success -> {
if (userDetailUIState.data.forceDelete) {
onForceDelete()
}
}
}

val context = LocalContext.current

val coroutineScope = rememberCoroutineScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -42,6 +43,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
import coil.compose.AsyncImage
import coil.request.ImageRequest
Expand Down Expand Up @@ -108,8 +110,8 @@ fun ExploreScreen(modifier: Modifier = Modifier,
)
.pullRefresh(pullRefreshState)) {
Column {
if (moviesDiscoverFlow.itemCount == 0) {
Column(
when (moviesDiscoverFlow.loadState.refresh) {
is LoadState.Error -> Column(
modifier = modifier
.fillMaxSize()
.wrapContentSize(align = Alignment.Center),
Expand Down Expand Up @@ -146,48 +148,57 @@ fun ExploreScreen(modifier: Modifier = Modifier,
)
}
}
} else {
if (searchClicked) {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(top = 16.dp, start = 16.dp, end = 16.dp)
) {

items(count = movieSearchFlow.itemCount) { index ->
MovieImageCard(
imageUrl = movieSearchFlow[index]?.posterPath ?: "",
rating = movieSearchFlow[index]?.voteAverage.toString() ?: "",
movieId = movieSearchFlow[index]?.id
)
}
}
} else {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(top = 16.dp, start = 16.dp, end = 16.dp)
) {
is LoadState.Loading -> {
CircularProgressIndicator(modifier = modifier
.fillMaxSize()
.wrapContentSize(align = Alignment.Center))
}
is LoadState.NotLoading -> {
if (searchClicked) {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(top = 16.dp, start = 16.dp, end = 16.dp)
) {

if (categories == Categories.Movies) {
items(count = moviesDiscoverFlow.itemCount) { index ->
items(count = movieSearchFlow.itemCount) { index ->
MovieImageCard(
imageUrl = moviesDiscoverFlow[index]?.posterPath ?: "",
rating = moviesDiscoverFlow[index]?.voteAverage.toString() ?: "",
movieId = moviesDiscoverFlow[index]?.id
imageUrl = movieSearchFlow[index]?.posterPath ?: "",
rating = movieSearchFlow[index]?.voteAverage.toString() ?: "",
movieId = movieSearchFlow[index]?.id
)
}
} else {
items(count = tvSeriesDiscoverFlow.itemCount) { index ->
MovieImageCard(
imageUrl = tvSeriesDiscoverFlow[index]?.posterPath ?: "",
rating = tvSeriesDiscoverFlow[index]?.voteAverage.toString() ?: "",
movieId = tvSeriesDiscoverFlow[index]?.id
)
}
} else {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(top = 16.dp, start = 16.dp, end = 16.dp)
) {

if (categories == Categories.Movies) {
items(count = moviesDiscoverFlow.itemCount) { index ->
MovieImageCard(
imageUrl = moviesDiscoverFlow[index]?.posterPath ?: "",
rating = moviesDiscoverFlow[index]?.voteAverage.toString()
?: "",
movieId = moviesDiscoverFlow[index]?.id
)
}
} else {
items(count = tvSeriesDiscoverFlow.itemCount) { index ->
MovieImageCard(
imageUrl = tvSeriesDiscoverFlow[index]?.posterPath ?: "",
rating = tvSeriesDiscoverFlow[index]?.voteAverage.toString()
?: "",
movieId = tvSeriesDiscoverFlow[index]?.id
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
bottom = bottomPadding.calculateBottomPadding()
).pullRefresh(pullRefreshState)) {
Column {
if (moviesFlow.itemCount == 0) {
Column(modifier = modifier
when (moviesFlow.loadState.refresh) {
is LoadState.Error -> Column(modifier = modifier
.fillMaxSize()
.wrapContentSize(align = Alignment.Center),
verticalArrangement = Arrangement.spacedBy(8.dp)) {
Expand All @@ -132,28 +132,34 @@ fun NowPlayingMoviesScreen(modifier: Modifier = Modifier,
fontWeight = FontWeight.SemiBold)
}
}
} else {

if (searchClicked) {
LazyVerticalGrid(columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) {

items(movieSearchFlow.itemCount) { index ->
MovieImageCard(imageUrl = movieSearchFlow[index]?.posterPath ?: "", rating = movieSearchFlow[index]?.voteAverage.toString() ?: "", movieId = movieSearchFlow[index]?.id ?: 0)
is LoadState.Loading -> {
CircularProgressIndicator(modifier = modifier
.fillMaxSize()
.wrapContentSize(align = Alignment.Center))
}
is LoadState.NotLoading -> {

if (searchClicked) {
LazyVerticalGrid(columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) {

items(movieSearchFlow.itemCount) { index ->
MovieImageCard(imageUrl = movieSearchFlow[index]?.posterPath ?: "", rating = movieSearchFlow[index]?.voteAverage.toString() ?: "", movieId = movieSearchFlow[index]?.id ?: 0)
}
}
}
} else {
LazyVerticalGrid(columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) {

items(moviesFlow.itemCount) { index ->
MovieImageCard(imageUrl = moviesFlow[index]?.posterPath ?: "", rating = moviesFlow[index]?.voteAverage.toString() ?: "", movieId = moviesFlow[index]?.id ?: 0)
} else {
LazyVerticalGrid(columns = GridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = lazyGridState,
contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) {

items(moviesFlow.itemCount) { index ->
MovieImageCard(imageUrl = moviesFlow[index]?.posterPath ?: "", rating = moviesFlow[index]?.voteAverage.toString() ?: "", movieId = moviesFlow[index]?.id ?: 0)
}
}
}
}
Expand Down
Loading

0 comments on commit 0647d41

Please sign in to comment.