I'm trying to fetch data from Tmdb and i'm using room , dagger2 and networkboundresource class but the data not displayed and the logcat didn't show me any error .. i think i'm calling the wrong method in viewmodel or what
fun loadMovies(page: Int = 1): LiveData<Resource<List<Movie>>> {
return object : NetworkBoundResource<List<Movie>, MoviesResponse>(appExecutors) {
// ignore
override fun saveCallResult(item: MoviesResponse) {
}
override fun shouldFetch(data: List<Movie>?): Boolean {
return true
}
override fun loadFromDb(): LiveData<List<Movie>> {
return moviesDao.getAllMovies()
}
override fun createCall(): LiveData<GenericApiResponse<MoviesResponse>> {
return tmdbApi.getListMovies(page = page)
}
}.asLiveData()
and this my viewmodel
class MainViewModel
@Inject
constructor(
private val mainRepository: MainRepository
): ViewModel() {
fun getPopularMovies(){
mainRepository.loadMovies()
}
}
model class
@Entity(tableName = "Movies")
data class Movie(
@SerializedName("id")
@Expose
@ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true)
val id: Long,
@SerializedName("title")
@Expose
@ColumnInfo(name = "title")
val title: String,
@SerializedName("overview")
@Expose
@ColumnInfo(name = "overview")
val overview: String,
@SerializedName("poster_path")
@Expose
@ColumnInfo(name = "posterPath")
val posterPath: String,