From b8b6f5e400cd47b12dad148c348d3ca11ffe3790 Mon Sep 17 00:00:00 2001 From: sheikh-20 Date: Tue, 2 Jul 2024 11:57:49 +0530 Subject: [PATCH] search bar words issue fixed --- app/build.gradle.kts | 4 +- .../moviesapp/data/api/NetworkInterceptor.kt | 10 - .../application/moviesapp/ui/home/HomeApp.kt | 8 + .../moviesapp/ui/home/mylist/MyListScreen.kt | 394 ++++++++++-------- 4 files changed, 232 insertions(+), 184 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 30a701f..2919eda 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,8 +53,8 @@ android { applicationId = "com.application.moviesapp" minSdk = 24 targetSdk = 33 - versionCode = 26 - versionName = "1.0.25" + versionCode = 27 + versionName = "1.0.26" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/application/moviesapp/data/api/NetworkInterceptor.kt b/app/src/main/java/com/application/moviesapp/data/api/NetworkInterceptor.kt index 73764fc..1dcc6e5 100755 --- a/app/src/main/java/com/application/moviesapp/data/api/NetworkInterceptor.kt +++ b/app/src/main/java/com/application/moviesapp/data/api/NetworkInterceptor.kt @@ -12,11 +12,6 @@ class NetworkInterceptor @Inject constructor(@Named("movies_api_key") private va val request = chain.request().newBuilder() request.addHeader(name = "Authorization", value = "Bearer $apiKey") - try { - Thread.sleep(2_000L) // Introduce delay - } catch (e: InterruptedException) { - e.printStackTrace() - } return chain.proceed(request.build()) } } @@ -26,11 +21,6 @@ class YoutubeNetworkInterceptor @Inject constructor(@Named("youtube_api_key") pr val request = chain.request().url.newBuilder() request.addQueryParameter(name = "key", value = apiKey) - try { - Thread.sleep(2_000L) // Introduce delay - } catch (e: InterruptedException) { - e.printStackTrace() - } return chain.proceed(chain.request().newBuilder().url(request.build()).build()) } } diff --git a/app/src/main/java/com/application/moviesapp/ui/home/HomeApp.kt b/app/src/main/java/com/application/moviesapp/ui/home/HomeApp.kt index 693f45d..2ecabe6 100755 --- a/app/src/main/java/com/application/moviesapp/ui/home/HomeApp.kt +++ b/app/src/main/java/com/application/moviesapp/ui/home/HomeApp.kt @@ -927,6 +927,10 @@ private fun HomeTopAppbar(navController: NavHostController, } + LaunchedEffect(key1 = null) { + onDownloadSearch("") + } + AnimatedVisibility( visible = mylistHideTopAppBar, enter = slideInVertically(animationSpec = tween(durationMillis = 200)), @@ -992,6 +996,10 @@ private fun HomeTopAppbar(navController: NavHostController, } + LaunchedEffect(key1 = null) { + onDownloadSearch("") + } + AnimatedVisibility( visible = downloadHideTopAppBar, enter = slideInVertically(animationSpec = tween(durationMillis = 200)), diff --git a/app/src/main/java/com/application/moviesapp/ui/home/mylist/MyListScreen.kt b/app/src/main/java/com/application/moviesapp/ui/home/mylist/MyListScreen.kt index 6441ba8..5860e32 100755 --- a/app/src/main/java/com/application/moviesapp/ui/home/mylist/MyListScreen.kt +++ b/app/src/main/java/com/application/moviesapp/ui/home/mylist/MyListScreen.kt @@ -168,197 +168,247 @@ fun MyListScreen(modifier: Modifier = Modifier, HorizontalPager(count = tabsList.size, state = pager, modifier = modifier.fillMaxWidth()) { index -> when (index) { 0 -> { - when (moviesFavouriteFlow.loadState.refresh){ - is LoadState.Error -> Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center) - .padding(32.dp) - ) { - Image( - painter = painterResource(id = R.drawable.ic_empty_list), - contentDescription = null, + Column(modifier = modifier.fillMaxSize()) { + when (moviesFavouriteFlow.loadState.refresh){ + is LoadState.Error -> Column( + verticalArrangement = Arrangement.spacedBy(16.dp), modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - .size(200.dp), - contentScale = ContentScale.Crop, - ) - - Text( - text = stringResource(R.string.you_list_is_empty), - style = MaterialTheme.typography.titleLarge, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - - Text( - text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyLarge, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - } - is LoadState.Loading -> { - CircularProgressIndicator(modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center)) - } - is LoadState.NotLoading -> { - Column(modifier = modifier.fillMaxSize().wrapContentSize(align = Alignment.TopStart)) { - - if (moviesFavouriteFlow.itemCount == 0) { - Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center) - .padding(32.dp) - ) { - Image( - painter = painterResource(id = R.drawable.ic_empty_list), - contentDescription = null, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - .size(200.dp), - contentScale = ContentScale.Crop, - ) - - Text( - text = stringResource(R.string.you_list_is_empty), - style = MaterialTheme.typography.titleLarge, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - - Text( - text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyLarge, + .fillMaxSize() + .wrapContentSize(align = Alignment.Center) + .padding(32.dp) + ) { + Image( + painter = painterResource(id = R.drawable.ic_empty_list), + contentDescription = null, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .size(200.dp), + contentScale = ContentScale.Crop, + ) + + Text( + text = stringResource(R.string.you_list_is_empty), + style = MaterialTheme.typography.titleLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + + Text( + text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.bodyLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + } + is LoadState.Loading -> { + CircularProgressIndicator(modifier = modifier + .fillMaxSize() + .wrapContentSize(align = Alignment.Center)) + } + is LoadState.NotLoading -> { + Column(modifier = modifier + .fillMaxSize() + .wrapContentSize(align = Alignment.TopStart)) { + + if (moviesFavouriteFlow.itemCount == 0) { + Column( + verticalArrangement = Arrangement.spacedBy(16.dp), modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) + .fillMaxSize() + .wrapContentSize(align = Alignment.Center) + .padding(32.dp) + ) { + Image( + painter = painterResource(id = R.drawable.ic_empty_list), + contentDescription = null, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .size(200.dp), + contentScale = ContentScale.Crop, + ) + + Text( + text = stringResource(R.string.you_list_is_empty), + style = MaterialTheme.typography.titleLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + + Text( + text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.bodyLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + } } - } - 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(moviesFavouriteFlow.itemCount) { index -> - MovieImageCard(imageUrl = moviesFavouriteFlow[index]?.posterPath ?: "", rating = moviesFavouriteFlow[index]?.voteAverage.toString(), movieId = moviesFavouriteFlow[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(moviesFavouriteFlow.itemCount) { index -> + MovieImageCard(imageUrl = moviesFavouriteFlow[index]?.posterPath ?: "", rating = moviesFavouriteFlow[index]?.voteAverage.toString(), movieId = moviesFavouriteFlow[index]?.id ?: 0) + } } } } } } - } - } - 1 -> { - when (tvSeriesFavouriteFlow.loadState.refresh){ - is LoadState.Error -> Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center) - .padding(32.dp) - ) { - Image( - painter = painterResource(id = R.drawable.ic_empty_list), - contentDescription = null, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - .size(200.dp), - contentScale = ContentScale.Crop, - ) - Text( - text = stringResource(R.string.you_list_is_empty), - style = MaterialTheme.typography.titleLarge, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - - Text( - text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyLarge, - modifier = modifier + when (moviesFavouriteFlow.loadState.append) { + is LoadState.Loading -> { + CircularProgressIndicator(modifier = modifier .fillMaxWidth() .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - } - is LoadState.Loading -> { - CircularProgressIndicator(modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center)) + .padding(16.dp)) + } + is LoadState.NotLoading -> { } + is LoadState.Error -> { + Text(text = if (moviesFavouriteFlow.loadState.append.endOfPaginationReached) "You have reached the end" else "", + style = MaterialTheme.typography.displayMedium, + color = MaterialTheme.colorScheme.primary, + fontWeight = FontWeight.SemiBold, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .padding(16.dp), + textAlign = TextAlign.Center) + } } - is LoadState.NotLoading -> { - Column(modifier = modifier.fillMaxSize().wrapContentSize(align = Alignment.TopStart)) { - - if (tvSeriesFavouriteFlow.itemCount == 0) { - Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - modifier = modifier - .fillMaxSize() - .wrapContentSize(align = Alignment.Center) - .padding(32.dp) - ) { - Image( - painter = painterResource(id = R.drawable.ic_empty_list), - contentDescription = null, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - .size(200.dp), - contentScale = ContentScale.Crop, - ) - - Text( - text = stringResource(R.string.you_list_is_empty), - style = MaterialTheme.typography.titleLarge, - modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) - - Text( - text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyLarge, + } + } + 1 -> { + Column(modifier = modifier.fillMaxSize()) { + when (tvSeriesFavouriteFlow.loadState.refresh){ + is LoadState.Error -> Column( + verticalArrangement = Arrangement.spacedBy(16.dp), + modifier = modifier + .fillMaxSize() + .wrapContentSize(align = Alignment.Center) + .padding(32.dp) + ) { + Image( + painter = painterResource(id = R.drawable.ic_empty_list), + contentDescription = null, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .size(200.dp), + contentScale = ContentScale.Crop, + ) + + Text( + text = stringResource(R.string.you_list_is_empty), + style = MaterialTheme.typography.titleLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + + Text( + text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.bodyLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + } + is LoadState.Loading -> { + CircularProgressIndicator(modifier = modifier + .fillMaxSize() + .wrapContentSize(align = Alignment.Center)) + } + is LoadState.NotLoading -> { + Column(modifier = modifier + .fillMaxSize() + .wrapContentSize(align = Alignment.TopStart)) { + + if (tvSeriesFavouriteFlow.itemCount == 0) { + Column( + verticalArrangement = Arrangement.spacedBy(16.dp), modifier = modifier - .fillMaxWidth() - .wrapContentWidth(align = Alignment.CenterHorizontally) - ) + .fillMaxSize() + .wrapContentSize(align = Alignment.Center) + .padding(32.dp) + ) { + Image( + painter = painterResource(id = R.drawable.ic_empty_list), + contentDescription = null, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .size(200.dp), + contentScale = ContentScale.Crop, + ) + + Text( + text = stringResource(R.string.you_list_is_empty), + style = MaterialTheme.typography.titleLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + + Text( + text = stringResource(R.string.it_seems_you_haven_t_listed_any_movies_or_series), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.bodyLarge, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + ) + } } - } - else { - LazyVerticalGrid( - columns = GridCells.Fixed(2), - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - state = lazyTvSeriesGridState, - contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) { - - items(tvSeriesFavouriteFlow.itemCount) { index -> - MovieImageCard(imageUrl = tvSeriesFavouriteFlow[index]?.posterPath ?: "", rating = tvSeriesFavouriteFlow[index]?.voteAverage.toString(), movieId = tvSeriesFavouriteFlow[index]?.id ?: 0, isType = IS_TYPE.TvSeries) + else { + LazyVerticalGrid( + columns = GridCells.Fixed(2), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + state = lazyTvSeriesGridState, + contentPadding = PaddingValues(start = 16.dp, end = 16.dp)) { + + items(tvSeriesFavouriteFlow.itemCount) { index -> + MovieImageCard(imageUrl = tvSeriesFavouriteFlow[index]?.posterPath ?: "", rating = tvSeriesFavouriteFlow[index]?.voteAverage.toString(), movieId = tvSeriesFavouriteFlow[index]?.id ?: 0, isType = IS_TYPE.TvSeries) + } } } } } } + + when (tvSeriesFavouriteFlow.loadState.append) { + is LoadState.Loading -> { + CircularProgressIndicator(modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .padding(16.dp)) + } + is LoadState.NotLoading -> { } + is LoadState.Error -> { + Text(text = if (tvSeriesFavouriteFlow.loadState.append.endOfPaginationReached) "You have reached the end" else "", + style = MaterialTheme.typography.displayMedium, + color = MaterialTheme.colorScheme.primary, + fontWeight = FontWeight.SemiBold, + modifier = modifier + .fillMaxWidth() + .wrapContentWidth(align = Alignment.CenterHorizontally) + .padding(16.dp), + textAlign = TextAlign.Center) + } + } } } }