This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MoviePagingAdapter : | |
PagingDataAdapter<id.ryolatech.paging3movieapi.data.bean.Movie, MoviePagingAdapter.ViewHolder>(listItemCallback) { | |
class ViewHolder(private val binding: ItemMovieBinding) : | |
RecyclerView.ViewHolder(binding.root) { | |
init { | |
binding.root.setOnClickListener { | |
} | |
} | |
fun bind(movie: id.ryolatech.paging3movieapi.data.bean.Movie) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'com.android.application' | |
id 'kotlin-android' | |
id 'kotlin-parcelize' | |
id 'kotlin-kapt' | |
id 'androidx.navigation.safeargs.kotlin' | |
} | |
apply from: '../shared_dependencies.gradle' | |
android { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
apply from: 'config.gradle' | |
buildscript { | |
ext.kotlin_version = "1.5.0" | |
ext.pagingVersion = "3.0.0" | |
ext.retrofit_version = "2.9.0" | |
ext.Interceptor_version = "4.8.0" | |
ext.hilt_version = '2.28-alpha' | |
ext.hilt_jetpack_version = '1.0.0-alpha02' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val adapter: MoviePagingAdapter by lazy { | |
MoviePagingAdapter() | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
initObservers() | |
} | |
fun initObservers() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MoviePagingAdapter : | |
PagingDataAdapter<Movie, MoviePagingAdapter.MyViewHolder>(listItemCallback) { | |
var onItemClick: ((Movie) -> Unit)? = null | |
companion object { | |
val listItemCallback = object : DiffUtil.ItemCallback<Movie>() { | |
override fun areItemsTheSame(oldItem: Movie, newItem: Movie): Boolean { | |
return oldItem.id == newItem.id | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FavoriteMovieViewModel ( | |
private val movieUseCase: MovieUseCase | |
) : ViewModel() { | |
val favMoviesasFlow = movieUseCase.getPagingFavoriteMovieFlow() | |
val favMoviesasLiveData = movieUseCase.getPagingFavoriteMovieLiveData() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface MovieRepository { | |
fun getPagingFavoriteMovieLiveData(): LiveData<PagingData<Movie>> | |
fun getPagingFavoriteMovieFlow(): Flow<PagingData<Movie>> | |
} | |
class MovieRepositoryImpl ( | |
private val movieLocalDataSource: MovieLocalDataSource | |
) : MovieRepository { | |
override fun getPagingFavoriteMovieLiveData(): LiveData<PagingData<Movie>> = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MovieLocalDataSource( | |
private val movieDao: MovieDao | |
) { | |
fun getFavMoviesasFlow() = Pager( | |
config = PagingConfig( | |
10 | |
) | |
) | |
{ movieDao.getAllFavMovie() } | |
.flow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Class Entity | |
*/ | |
@Parcelize | |
@Entity(tableName = "popular_movies") | |
data class Movie( | |
@PrimaryKey | |
@SerializedName("id") | |
val id: Int, | |
@SerializedName("overview") |
NewerOlder