From d85e8733c032d0056bb82bd5437039bf925c5e1f Mon Sep 17 00:00:00 2001 From: sheikh-20 Date: Mon, 17 Jun 2024 19:28:11 +0530 Subject: [PATCH] my list search integrated --- .../data/remote/MovieFavouritePagingSource.kt | 4 ++-- .../data/remote/TvSeriesFavouritePagingSource.kt | 4 ++-- .../moviesapp/data/repository/MoviesRepository.kt | 12 ++++++------ .../domain/usecase/MovieFavouriteUseCase.kt | 4 ++-- .../domain/usecase/TvSeriesFavouriteUseCase.kt | 4 ++-- .../com/application/moviesapp/ui/home/HomeApp.kt | 5 +++-- .../moviesapp/ui/home/mylist/MyListScreen.kt | 1 + .../moviesapp/ui/viewmodel/MyListViewModel.kt | 4 ++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/application/moviesapp/data/remote/MovieFavouritePagingSource.kt b/app/src/main/java/com/application/moviesapp/data/remote/MovieFavouritePagingSource.kt index 714ad82..627afd3 100755 --- a/app/src/main/java/com/application/moviesapp/data/remote/MovieFavouritePagingSource.kt +++ b/app/src/main/java/com/application/moviesapp/data/remote/MovieFavouritePagingSource.kt @@ -5,7 +5,7 @@ import androidx.paging.PagingState import com.application.moviesapp.data.api.MoviesApi import com.application.moviesapp.data.api.response.MovieNowPlayingDto -class MovieFavouritePagingSource(private val moviesApi: MoviesApi): PagingSource() { +class MovieFavouritePagingSource(private val moviesApi: MoviesApi, private val searchText: String = ""): PagingSource() { override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { anchorPosition -> state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) @@ -28,7 +28,7 @@ class MovieFavouritePagingSource(private val moviesApi: MoviesApi): PagingSource } LoadResult.Page( - data = movies?.results?.map { it ?: MovieFavouriteDto.Result(null, null, null, null, null, null, null, null, null, null, null, null, null, null)} ?: listOf(), + data = movies?.results?.filter { it?.title?.contains(searchText, ignoreCase = true) == true }?.map { it ?: MovieFavouriteDto.Result(null, null, null, null, null, null, null, null, null, null, null, null, null, null)} ?: listOf(), prevKey = if (page == 1) null else page.minus(1), nextKey = if (movies?.results?.isEmpty() == true) null else page.plus(1), ) diff --git a/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouritePagingSource.kt b/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouritePagingSource.kt index 7644cad..2c44233 100644 --- a/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouritePagingSource.kt +++ b/app/src/main/java/com/application/moviesapp/data/remote/TvSeriesFavouritePagingSource.kt @@ -4,7 +4,7 @@ import androidx.paging.PagingSource import androidx.paging.PagingState import com.application.moviesapp.data.api.MoviesApi -class TvSeriesFavouritePagingSource(private val moviesApi: MoviesApi): PagingSource() { +class TvSeriesFavouritePagingSource(private val moviesApi: MoviesApi, private val searchText: String = ""): PagingSource() { override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { anchorPosition -> state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) @@ -27,7 +27,7 @@ class TvSeriesFavouritePagingSource(private val moviesApi: MoviesApi): PagingSou } LoadResult.Page( - data = movies?.results?.map { it ?: TvSeriesFavouriteDto.Result(null, null, null, null, null, null, null, null, null, null, null, null, null, null)} ?: listOf(), + data = movies?.results?.filter { it?.name?.contains(searchText, ignoreCase = true) == true }?.map { it ?: TvSeriesFavouriteDto.Result(null, null, null, null, null, null, null, null, null, null, null, null, null, null)} ?: listOf(), prevKey = if (page == 1) null else page.minus(1), nextKey = if (movies?.results?.isEmpty() == true) null else page.plus(1), ) diff --git a/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt b/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt index 8e87364..f0c1728 100755 --- a/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt +++ b/app/src/main/java/com/application/moviesapp/data/repository/MoviesRepository.kt @@ -72,9 +72,9 @@ interface MoviesRepository { fun getTvSeriesBySearchPagingFlow(search: String = ""): Flow> - fun getFavouriteMoviesPagingFlow(): Flow> + fun getFavouriteMoviesPagingFlow(searchText: String = ""): Flow> - fun getFavouriteTvSeriesPagingFlow(): Flow> + fun getFavouriteTvSeriesPagingFlow(searchText: String = ""): Flow> suspend fun getMoviesUpcoming(): MovieUpcomingDto @@ -182,17 +182,17 @@ class MoviesRepositoryImpl @Inject constructor(private val movies: MoviesApi, } ).flow - override fun getFavouriteMoviesPagingFlow(): Flow> = Pager( + override fun getFavouriteMoviesPagingFlow(searchText: String): Flow> = Pager( config = PagingConfig(pageSize = 20), pagingSourceFactory = { - MovieFavouritePagingSource(movies) + MovieFavouritePagingSource(movies, searchText) } ).flow - override fun getFavouriteTvSeriesPagingFlow(): Flow> = Pager( + override fun getFavouriteTvSeriesPagingFlow(searchText: String): Flow> = Pager( config = PagingConfig(pageSize = 20), pagingSourceFactory = { - TvSeriesFavouritePagingSource(movies) + TvSeriesFavouritePagingSource(movies, searchText) } ).flow diff --git a/app/src/main/java/com/application/moviesapp/domain/usecase/MovieFavouriteUseCase.kt b/app/src/main/java/com/application/moviesapp/domain/usecase/MovieFavouriteUseCase.kt index fa7d436..6ea0cc2 100755 --- a/app/src/main/java/com/application/moviesapp/domain/usecase/MovieFavouriteUseCase.kt +++ b/app/src/main/java/com/application/moviesapp/domain/usecase/MovieFavouriteUseCase.kt @@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.map import javax.inject.Inject interface MovieFavouriteUseCase { - operator fun invoke(): Flow> + operator fun invoke(searchText: String = ""): Flow> } class GetMovieFavouriteInteractor @Inject constructor(private val repository: MoviesRepository): MovieFavouriteUseCase { @@ -19,7 +19,7 @@ class GetMovieFavouriteInteractor @Inject constructor(private val repository: Mo const val TAG = "GetMovieFavouriteInteractor" } - override fun invoke(): Flow> = repository.getFavouriteMoviesPagingFlow().map { + override fun invoke(searchText: String): Flow> = repository.getFavouriteMoviesPagingFlow(searchText).map { it.map { movie -> movie.toMovie() } diff --git a/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesFavouriteUseCase.kt b/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesFavouriteUseCase.kt index b51348f..ccd8b8d 100644 --- a/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesFavouriteUseCase.kt +++ b/app/src/main/java/com/application/moviesapp/domain/usecase/TvSeriesFavouriteUseCase.kt @@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.map import javax.inject.Inject interface TvSeriesFavouriteUseCase { - operator fun invoke(): Flow> + operator fun invoke(searchText: String = ""): Flow> } class GetTvSeriesFavouriteInteractor @Inject constructor(private val repository: MoviesRepository): TvSeriesFavouriteUseCase { @@ -22,7 +22,7 @@ class GetTvSeriesFavouriteInteractor @Inject constructor(private val repository: const val TAG = "GetTvSeriesFavouriteInteractor" } - override fun invoke(): Flow> = repository.getFavouriteTvSeriesPagingFlow().map { + override fun invoke(searchText: String): Flow> = repository.getFavouriteTvSeriesPagingFlow(searchText).map { it.map { tvSeries -> tvSeries.toDomain() } } } \ No newline at end of file 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 03c82ef..7bcbd54 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 @@ -190,8 +190,8 @@ fun HomeApp(modifier: Modifier = Modifier, val moviesSearchFlowState = exploreViewModel.getMovieBySearch(searchUiState.search).collectAsLazyPagingItems() - val myListMoviesFlowState = myListViewModel.getMovieFavouritePagingFlow.collectAsLazyPagingItems() - val myListTvSeriesFlowState = myListViewModel.getTvSeriesFavouritePagingFlow.collectAsLazyPagingItems() + val myListMoviesFlowState = myListViewModel.getMovieFavouritePagingFlow(searchValue).collectAsLazyPagingItems() + val myListTvSeriesFlowState = myListViewModel.getTvSeriesFavouritePagingFlow(searchValue).collectAsLazyPagingItems() val coroutineScope = rememberCoroutineScope() var showBottomSheet by remember { mutableStateOf(BottomSheet.Default) } @@ -468,6 +468,7 @@ fun HomeApp(modifier: Modifier = Modifier, tvSeriesFavouriteFlow = myListTvSeriesFlowState, lazyGridState = myListScrollState, lazyTvSeriesGridState = myListTvSeriesScrollState, + searchText = searchValue, bottomPadding = paddingValues) } composable(route = BottomNavigationScreens.Download.route) { 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 c9dbac3..8d6203f 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 @@ -86,6 +86,7 @@ fun MyListScreen(modifier: Modifier = Modifier, tvSeriesFavouriteFlow: LazyPagingItems, lazyGridState: LazyGridState = LazyGridState(), lazyTvSeriesGridState: LazyGridState = LazyGridState(), + searchText: String = "", bottomPadding: PaddingValues = PaddingValues() ) { diff --git a/app/src/main/java/com/application/moviesapp/ui/viewmodel/MyListViewModel.kt b/app/src/main/java/com/application/moviesapp/ui/viewmodel/MyListViewModel.kt index 90d646f..9dd1cd6 100755 --- a/app/src/main/java/com/application/moviesapp/ui/viewmodel/MyListViewModel.kt +++ b/app/src/main/java/com/application/moviesapp/ui/viewmodel/MyListViewModel.kt @@ -17,7 +17,7 @@ import javax.inject.Inject @HiltViewModel class MyListViewModel @Inject constructor(private val useCase: MovieFavouriteUseCase, private val tvSeriesFavouriteUseCase: TvSeriesFavouriteUseCase): ViewModel() { - val getMovieFavouritePagingFlow = useCase().cachedIn(viewModelScope) + fun getMovieFavouritePagingFlow(searchText: String = "") = useCase(searchText).cachedIn(viewModelScope) - val getTvSeriesFavouritePagingFlow = tvSeriesFavouriteUseCase().cachedIn(viewModelScope) + fun getTvSeriesFavouritePagingFlow(searchText: String = "") = tvSeriesFavouriteUseCase(searchText).cachedIn(viewModelScope) } \ No newline at end of file