Skip to content

Commit

Permalink
Merge pull request #78 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 17, 2024
2 parents 6092096 + d50285b commit 87ba3cb
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, MovieFavouriteDto.Result>() {
class MovieFavouritePagingSource(private val moviesApi: MoviesApi, private val searchText: String = ""): PagingSource<Int, MovieFavouriteDto.Result>() {
override fun getRefreshKey(state: PagingState<Int, MovieFavouriteDto.Result>): Int? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
Expand All @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, TvSeriesFavouriteDto.Result>() {
class TvSeriesFavouritePagingSource(private val moviesApi: MoviesApi, private val searchText: String = ""): PagingSource<Int, TvSeriesFavouriteDto.Result>() {
override fun getRefreshKey(state: PagingState<Int, TvSeriesFavouriteDto.Result>): Int? {
return state.anchorPosition?.let { anchorPosition ->
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
Expand All @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ interface MoviesRepository {

fun getTvSeriesBySearchPagingFlow(search: String = ""): Flow<PagingData<TvSeriesSearchDto.Result>>

fun getFavouriteMoviesPagingFlow(): Flow<PagingData<MovieFavouriteDto.Result>>
fun getFavouriteMoviesPagingFlow(searchText: String = ""): Flow<PagingData<MovieFavouriteDto.Result>>

fun getFavouriteTvSeriesPagingFlow(): Flow<PagingData<TvSeriesFavouriteDto.Result>>
fun getFavouriteTvSeriesPagingFlow(searchText: String = ""): Flow<PagingData<TvSeriesFavouriteDto.Result>>

suspend fun getMoviesUpcoming(): MovieUpcomingDto

Expand Down Expand Up @@ -182,17 +182,17 @@ class MoviesRepositoryImpl @Inject constructor(private val movies: MoviesApi,
}
).flow

override fun getFavouriteMoviesPagingFlow(): Flow<PagingData<MovieFavouriteDto.Result>> = Pager(
override fun getFavouriteMoviesPagingFlow(searchText: String): Flow<PagingData<MovieFavouriteDto.Result>> = Pager(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = {
MovieFavouritePagingSource(movies)
MovieFavouritePagingSource(movies, searchText)
}
).flow

override fun getFavouriteTvSeriesPagingFlow(): Flow<PagingData<TvSeriesFavouriteDto.Result>> = Pager(
override fun getFavouriteTvSeriesPagingFlow(searchText: String): Flow<PagingData<TvSeriesFavouriteDto.Result>> = Pager(
config = PagingConfig(pageSize = 20),
pagingSourceFactory = {
TvSeriesFavouritePagingSource(movies)
TvSeriesFavouritePagingSource(movies, searchText)
}
).flow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.map
import javax.inject.Inject

interface MovieFavouriteUseCase {
operator fun invoke(): Flow<PagingData<MovieFavourite>>
operator fun invoke(searchText: String = ""): Flow<PagingData<MovieFavourite>>
}

class GetMovieFavouriteInteractor @Inject constructor(private val repository: MoviesRepository): MovieFavouriteUseCase {
Expand All @@ -19,7 +19,7 @@ class GetMovieFavouriteInteractor @Inject constructor(private val repository: Mo
const val TAG = "GetMovieFavouriteInteractor"
}

override fun invoke(): Flow<PagingData<MovieFavourite>> = repository.getFavouriteMoviesPagingFlow().map {
override fun invoke(searchText: String): Flow<PagingData<MovieFavourite>> = repository.getFavouriteMoviesPagingFlow(searchText).map {
it.map { movie ->
movie.toMovie()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.map
import javax.inject.Inject

interface TvSeriesFavouriteUseCase {
operator fun invoke(): Flow<PagingData<TvSeriesFavourite>>
operator fun invoke(searchText: String = ""): Flow<PagingData<TvSeriesFavourite>>
}

class GetTvSeriesFavouriteInteractor @Inject constructor(private val repository: MoviesRepository): TvSeriesFavouriteUseCase {
Expand All @@ -22,7 +22,7 @@ class GetTvSeriesFavouriteInteractor @Inject constructor(private val repository:
const val TAG = "GetTvSeriesFavouriteInteractor"
}

override fun invoke(): Flow<PagingData<TvSeriesFavourite>> = repository.getFavouriteTvSeriesPagingFlow().map {
override fun invoke(searchText: String): Flow<PagingData<TvSeriesFavourite>> = repository.getFavouriteTvSeriesPagingFlow(searchText).map {
it.map { tvSeries -> tvSeries.toDomain() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -468,6 +468,7 @@ fun HomeApp(modifier: Modifier = Modifier,
tvSeriesFavouriteFlow = myListTvSeriesFlowState,
lazyGridState = myListScrollState,
lazyTvSeriesGridState = myListTvSeriesScrollState,
searchText = searchValue,
bottomPadding = paddingValues)
}
composable(route = BottomNavigationScreens.Download.route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fun MyListScreen(modifier: Modifier = Modifier,
tvSeriesFavouriteFlow: LazyPagingItems<TvSeriesFavourite>,
lazyGridState: LazyGridState = LazyGridState(),
lazyTvSeriesGridState: LazyGridState = LazyGridState(),
searchText: String = "",
bottomPadding: PaddingValues = PaddingValues()
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 87ba3cb

Please sign in to comment.