From 09750fce34d891e8f2a057b1a721fa4f5c489d6e Mon Sep 17 00:00:00 2001 From: Mehedi Hassan Piash Date: Sun, 17 Nov 2024 17:54:58 +0600 Subject: [PATCH] - Fixing deleting fav not reflecting ui immediately --- .../ui/component/{ExistAlertDiaglog.kt => AlertDialog.kt} | 0 .../ui/screens/favorite/movie/FavoriteMovie.kt | 5 ++++- .../ui/screens/favorite/tvseries/FavoriteTvSeries.kt | 5 ++++- .../ui/screens/movies/movie_detail/MovieDetail.kt | 2 +- .../ui/screens/tvseries/tv_series_detail/TvSeriesDetail.kt | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) rename app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/component/{ExistAlertDiaglog.kt => AlertDialog.kt} (100%) diff --git a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/component/ExistAlertDiaglog.kt b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/component/AlertDialog.kt similarity index 100% rename from app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/component/ExistAlertDiaglog.kt rename to app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/component/AlertDialog.kt diff --git a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/movie/FavoriteMovie.kt b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/movie/FavoriteMovie.kt index b3d3e85..c7c98cc 100644 --- a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/movie/FavoriteMovie.kt +++ b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/movie/FavoriteMovie.kt @@ -19,6 +19,7 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -77,6 +78,9 @@ fun FavoriteMovieItemView( viewModel: FavoriteMovieViewModel, ) { val openDialog = remember { mutableStateOf(false) } + SideEffect { + viewModel.favoriteMoviesFromDB() + } Column(modifier = Modifier.padding(start = 5.dp, end = 5.dp, top = 0.dp, bottom = 10.dp).cornerRadius(10)) { Box { CoilImage( @@ -140,7 +144,6 @@ fun FavoriteMovieItemView( }, { viewModel.removeMovieFromDB(item.id) - viewModel.favoriteMoviesFromDB() openDialog.value = false }) } diff --git a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/tvseries/FavoriteTvSeries.kt b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/tvseries/FavoriteTvSeries.kt index 08e8145..1f0eb9f 100644 --- a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/tvseries/FavoriteTvSeries.kt +++ b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/favorite/tvseries/FavoriteTvSeries.kt @@ -19,6 +19,7 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -74,6 +75,9 @@ fun FavoriteTvSeries(navController: NavController) { @Composable fun FavoriteTvSeriesItemView(item: TvSeriesDetail, navController: NavController, viewModel: FavoriteTvSeriesViewModel) { val openDialog = remember { mutableStateOf(false) } + SideEffect { + viewModel.favoriteTvSeriesFromDB() + } Column(modifier = Modifier.padding(start = 5.dp, end = 5.dp, top = 0.dp, bottom = 10.dp).cornerRadius(10)) { Box { CoilImage( @@ -137,7 +141,6 @@ fun FavoriteTvSeriesItemView(item: TvSeriesDetail, navController: NavController, }, { viewModel.removeTvSeriesFromDB(item.id) - viewModel.favoriteTvSeriesFromDB() openDialog.value = false }) } diff --git a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/movies/movie_detail/MovieDetail.kt b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/movies/movie_detail/MovieDetail.kt index fc2bef3..0ee885b 100644 --- a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/movies/movie_detail/MovieDetail.kt +++ b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/movies/movie_detail/MovieDetail.kt @@ -137,7 +137,7 @@ fun MovieDetail(navController: NavController, movieId: Int) { .clip(CircleShape) .background(Color.White.copy(alpha = 0.8f)) ) { - movieFromDb?.let { detail -> + movieFromDb?.let { Icon( imageVector = Icons.Filled.Favorite, contentDescription = "Favorite", diff --git a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/tvseries/tv_series_detail/TvSeriesDetail.kt b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/tvseries/tv_series_detail/TvSeriesDetail.kt index 4a15d76..1914837 100644 --- a/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/tvseries/tv_series_detail/TvSeriesDetail.kt +++ b/app/src/main/java/com/piashcse/hilt_mvvm_compose_movie/ui/screens/tvseries/tv_series_detail/TvSeriesDetail.kt @@ -134,7 +134,7 @@ fun TvSeriesDetail(navController: NavController, tvSeriesId: Int) { .clip(CircleShape) .background(Color.White.copy(alpha = 0.8f)) ) { - tvSeriesFromDb?.let { detail -> + tvSeriesFromDb?.let { Icon( imageVector = Icons.Filled.Favorite, contentDescription = "Favorite",