Closed Rafelcf closed 1 month ago
Hey @Rafelcf I think your issue is not clear, could you please explain it well
Thanks, my question is: In PopuarMovies If I want it to only show me the movies in their original language "original_language" = EU Where and how to apply the filter? *.filter { it.original_language == "EU"}
Hey @Rafelcf sorry for the late reply but to filter out some movies, you can do that from the paging source e.g
LoadResult.Page(
data = trendingMoviesList.searches.filter {
it.originalLanguage == "en"
},
prevKey = if (nextPage == 1) null else nextPage - 1,
nextKey = if (trendingMoviesList.searches.isEmpty()) null else trendingMoviesList.page + 1
)
Full paging source example:
class TrendingMoviesSource(private val api: TMDBApi) :
PagingSource<Int, Movie>() {
override fun getRefreshKey(state: PagingState<Int, Movie>): Int? {
return state.anchorPosition
}
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Movie> {
return try {
val nextPage = params.key ?: 1
val trendingMoviesList = api.getTrendingTodayMovies(nextPage)
LoadResult.Page(
data = trendingMoviesList.searches.filter {
it.originalLanguage == "en"
},
prevKey = if (nextPage == 1) null else nextPage - 1,
nextKey = if (trendingMoviesList.searches.isEmpty()) null else trendingMoviesList.page + 1
)
} catch (exception: IOException) {
return LoadResult.Error(exception)
} catch (exception: HttpException) {
return LoadResult.Error(exception)
}
}
}
when filterList for example originalLanguage in popularmovies? and sortBy date