Migrate feed to adapter delegates

This commit is contained in:
Koitharu
2020-11-23 19:16:02 +02:00
parent 12c8cdfd70
commit b9f35f34ad
21 changed files with 237 additions and 158 deletions

View File

@@ -32,12 +32,13 @@ class LocalListFragment : MangaListFragment(), ActivityResultCallback<Uri> {
viewModel.onMangaRemoved.observe(viewLifecycleOwner, ::onItemRemoved)
}
override fun onRequestMoreItems(offset: Int) {
if (offset == 0) {
viewModel.onRefresh()
}
override fun onRefresh() {
super.onRefresh()
viewModel.onRefresh()
}
override fun onScrolledToEnd() = Unit
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.opt_local, menu)
super.onCreateOptionsMenu(menu, inflater)

View File

@@ -45,11 +45,17 @@ class LocalListViewModel(
}.asLiveData(viewModelScope.coroutineContext + Dispatchers.Default)
init {
loadList()
onRefresh()
}
fun onRefresh() {
loadList()
launchLoadingJob {
withContext(Dispatchers.Default) {
val list = repository.getList(0)
mangaList.value = list
isEmptyState.postValue(list.isEmpty())
}
}
}
fun importFile(uri: Uri) {
@@ -69,7 +75,7 @@ class LocalListViewModel(
}
} ?: throw IOException("Cannot open input stream: $uri")
}
loadList()
onRefresh()
}
}
@@ -88,14 +94,4 @@ class LocalListViewModel(
onMangaRemoved.call(manga)
}
}
private fun loadList() {
launchLoadingJob {
withContext(Dispatchers.Default) {
val list = repository.getList(0)
mangaList.value = list
isEmptyState.postValue(list.isEmpty())
}
}
}
}