This file contains hidden or 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 MovieListViewModel : BaseViewModel() { | |
private val movieRepo: MovieRepo by inject() | |
fun fetchList(category: MovieCategory): Listing<MovieModel> = movieRepo.fetchMovieList(category) | |
} |
This file contains hidden or 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 MovieListViewModel : BaseViewModel() { | |
private val movieRepo: MovieRepo by inject() | |
private val movieCategoryEvent = BehaviorSubject.create<MovieCategory>() | |
private val fetchDataSource: Observable<Listing<MovieModel>> = movieCategoryEvent | |
.map { movieRepo.fetchMovieList(it) } | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.cache() |
This file contains hidden or 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 MovieRepo { | |
fun fetchMovieList(category: MovieCategory, pageSize: Int = DEFAULT_PAGE_SIZE): Listing<MovieModel> | |
} | |
class MovieRepoImpl : MovieRepo, KoinComponent { | |
override fun fetchMovieList( | |
category: MovieCategory, | |
pageSize: Int | |
): Listing<MovieModel> { |
This file contains hidden or 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
data class Listing<T>( | |
// the paged list for UI to observer | |
val pagedList: Observable<PagedList<T>>, | |
// the network request status for pull-to-refresh or first time refresh | |
val refreshState: Observable<NetworkState>? = null, | |
// the network request state to show load more progress or error | |
val loadMoreState: Observable<NetworkState>? = null, | |
// refresh the whole data set and fetch it from scratch | |
val refresh: () -> Unit = {} | |
) |
This file contains hidden or 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 MovieRepo { | |
fun fetchMovieList(category: MovieCategory, pageSize: Int = DEFAULT_PAGE_SIZE): Observable<PagedList<MovieModel>> | |
} | |
class MovieRepoImpl : MovieRepo, KoinComponent { | |
override fun fetchMovieList( | |
category: MovieCategory, | |
pageSize: Int | |
): Observable<PagedList<MovieModel>> { |
This file contains hidden or 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 MovieListDataSourceFactory(private val category: MovieCategory): DataSource.Factory<Int, MovieModel>() { | |
val initLoadState = BehaviorSubject.createDefault(NetworkState.IDLE) | |
val loadMoreState = BehaviorSubject.createDefault(NetworkState.IDLE) | |
var dataSource: MovieListDataSource? = null | |
override fun create(): DataSource<Int, MovieModel> { | |
dataSource = MovieListDataSource(category, initLoadState, loadMoreState) | |
return dataSource!! | |
} |
This file contains hidden or 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 MovieListDataSource( | |
private val category: MovieCategory, | |
private val initLoadState: BehaviorSubject<NetworkState>, | |
private val loadMoreState: BehaviorSubject<NetworkState> | |
) : PageKeyedDataSource<Int, MovieModel>(), KoinComponent { | |
private val api: MovieApiService by inject() | |
private var currentPage: Int = -1 | |
override fun loadInitial( |
This file contains hidden or 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
data class MovieModel( | |
val id: String, | |
val posterPath: String?, | |
val title: String?, | |
val voteAverage: Float?, | |
val voteCount: Int?, | |
val releaseDate: String?, | |
val genreList: List<Genre>?, | |
val runtime: Int? | |
) |
This file contains hidden or 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 MovieDataSource : DataSource() { | |
private val api: MovieApiService by inject() | |
fun getMovieList(): PagedList<MovieListResponse> { | |
return api.fetchMovieList() | |
} | |
} | |
class MoviePagedListAdapter: PagedListAdapter() { | |
val pagedList: PagedList<MovieListResponse> |
This file contains hidden or 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
2020-08-10 17:14:36.131 V/MixpanelAPI.DecideUpdts: No unseen notifications exist, none will be returned. | |
2020-08-10 17:14:36.131 V/MixpanelAPI.API: No notification available, will not show. | |
2020-08-10 17:14:36.764 V/MixpanelAPI.Messages: Flushing queue due to scheduled or forced flush (Thread 3793) | |
2020-08-10 17:14:36.764 V/MixpanelAPI.Messages: Average send frequency approximately 46 seconds. (Thread 3793) | |
2020-08-10 17:14:36.765 V/MixpanelAPI.Message: ConnectivityManager says we are online | |
2020-08-10 17:14:36.776 V/MixpanelAPI.DChecker: Querying decide server, url: https://decide.mixpanel.com/decide?version=1&lib=android&token=9647a9aa05aa740f3ffe6a12fa0fd68d&distinct_id=3023941919721&properties=%7B%22%24android_lib_version%22%3A%225.8.4%22%2C%22%24android_app_version%22%3A%222.21.0-beta.1%2Be40d1e27%22%2C%22%24android_version%22%3A%229%22%2C%22%24android_app_release%22%3A232002101%2C%22%24android_device_model%22%3A%22HTC_U-3u%22%7D | |
2020-08-10 17:14:36.777 V/MixpanelAPI.Message: ConnectivityManager says we |