Remote -> Online

This commit is contained in:
topjohnwu 2020-08-11 03:36:41 -07:00
parent 537ae1a315
commit 36a70e995f
2 changed files with 17 additions and 16 deletions

View File

@ -83,7 +83,7 @@ class ModuleViewModel(
private val itemsInstalled = diffListOf<ModuleItem>() private val itemsInstalled = diffListOf<ModuleItem>()
private val itemsUpdatable = diffListOf<RepoItem.Update>() private val itemsUpdatable = diffListOf<RepoItem.Update>()
private val itemsRemote = diffListOf<RepoItem.Remote>() private val itemsOnline = diffListOf<RepoItem.Remote>()
private val sectionUpdate = SectionTitle( private val sectionUpdate = SectionTitle(
R.string.module_section_pending, R.string.module_section_pending,
@ -98,8 +98,8 @@ class ModuleViewModel(
R.drawable.ic_restart R.drawable.ic_restart
).also { it.hasButton = false } ).also { it.hasButton = false }
private val sectionRemote = SectionTitle( private val sectionOnline = SectionTitle(
R.string.module_section_remote, R.string.module_section_online,
R.string.sorting_order R.string.sorting_order
).apply { updateOrderIcon() } ).apply { updateOrderIcon() }
@ -110,8 +110,8 @@ class ModuleViewModel(
.insertList(itemsUpdatable) .insertList(itemsUpdatable)
.insertList(installSectionList) .insertList(installSectionList)
.insertList(itemsInstalled) .insertList(itemsInstalled)
.insertItem(sectionRemote) .insertItem(sectionOnline)
.insertList(itemsRemote)!! .insertList(itemsOnline)
val itemBinding = itemBindingOf<RvItem> { val itemBinding = itemBindingOf<RvItem> {
it.bindExtra(BR.viewModel, this) it.bindExtra(BR.viewModel, this)
} }
@ -170,7 +170,7 @@ class ModuleViewModel(
val items = withContext(Dispatchers.Default) { val items = withContext(Dispatchers.Default) {
val predicate = { it: RepoItem -> it.item.id == subject.module.id } val predicate = { it: RepoItem -> it.item.id == subject.module.id }
itemsUpdatable.filter(predicate) + itemsUpdatable.filter(predicate) +
itemsRemote.filter(predicate) + itemsOnline.filter(predicate) +
itemsSearch.filter(predicate) itemsSearch.filter(predicate)
} }
items.forEach { it.progress = progress.times(100).roundToInt() } items.forEach { it.progress = progress.times(100).roundToInt() }
@ -181,7 +181,7 @@ class ModuleViewModel(
return viewModelScope.launch { return viewModelScope.launch {
state = State.LOADING state = State.LOADING
loadInstalled() loadInstalled()
if (itemsRemote.isEmpty()) if (itemsOnline.isEmpty())
loadRemote() loadRemote()
state = State.LOADED state = State.LOADED
} }
@ -225,7 +225,7 @@ class ModuleViewModel(
if (remoteJob?.isActive == true) if (remoteJob?.isActive == true)
return return
if (itemsRemote.isEmpty()) if (itemsOnline.isEmpty())
EndlessRecyclerScrollListener.ResetState().publish() EndlessRecyclerScrollListener.ResetState().publish()
remoteJob = viewModelScope.launch { remoteJob = viewModelScope.launch {
@ -234,21 +234,21 @@ class ModuleViewModel(
} }
isRemoteLoading = true isRemoteLoading = true
val repos = if (itemsRemote.isEmpty()) { val repos = if (itemsOnline.isEmpty()) {
repoUpdater.run(refetch) repoUpdater.run(refetch)
loadUpdatable() loadUpdatable()
loadRemoteDB(0) loadRemoteDB(0)
} else { } else {
loadRemoteDB(itemsRemote.size) loadRemoteDB(itemsOnline.size)
} }
isRemoteLoading = false isRemoteLoading = false
refetch = false refetch = false
queryHandler.post { itemsRemote.addAll(repos) } queryHandler.post { itemsOnline.addAll(repos) }
} }
} }
fun forceRefresh() { fun forceRefresh() {
itemsRemote.clear() itemsOnline.clear()
itemsUpdatable.clear() itemsUpdatable.clear()
itemsSearch.clear() itemsSearch.clear()
refetch = true refetch = true
@ -299,15 +299,15 @@ class ModuleViewModel(
fun sectionPressed(item: SectionTitle) = when (item) { fun sectionPressed(item: SectionTitle) = when (item) {
sectionInstalled -> reboot() // TODO add reboot picker, regular reboot is not always preferred sectionInstalled -> reboot() // TODO add reboot picker, regular reboot is not always preferred
sectionRemote -> { sectionOnline -> {
Config.repoOrder = when (Config.repoOrder) { Config.repoOrder = when (Config.repoOrder) {
Config.Value.ORDER_NAME -> Config.Value.ORDER_DATE Config.Value.ORDER_NAME -> Config.Value.ORDER_DATE
Config.Value.ORDER_DATE -> Config.Value.ORDER_NAME Config.Value.ORDER_DATE -> Config.Value.ORDER_NAME
else -> Config.Value.ORDER_NAME else -> Config.Value.ORDER_NAME
} }
sectionRemote.updateOrderIcon() sectionOnline.updateOrderIcon()
queryHandler.post { queryHandler.post {
itemsRemote.clear() itemsOnline.clear()
loadRemote() loadRemote()
} }
Unit Unit

View File

@ -119,7 +119,7 @@
<string name="hide_filters">Filters</string> <string name="hide_filters">Filters</string>
<string name="hide_search">Search</string> <string name="hide_search">Search</string>
<!--Module Fragment--> <!--Module -->
<string name="no_info_provided">(No info provided)</string> <string name="no_info_provided">(No info provided)</string>
<string name="no_modules_found">No modules found</string> <string name="no_modules_found">No modules found</string>
<string name="reboot_recovery">Reboot to Recovery</string> <string name="reboot_recovery">Reboot to Recovery</string>
@ -137,6 +137,7 @@
<string name="module_update_none">Your modules are up to date!</string> <string name="module_update_none">Your modules are up to date!</string>
<string name="update_available">Update Available</string> <string name="update_available">Update Available</string>
<string name="module_installed">@string/home_installed_version</string> <string name="module_installed">@string/home_installed_version</string>
<string name="module_section_online">Online</string>
<string name="sorting_order">Sorting Order</string> <string name="sorting_order">Sorting Order</string>
<!--Settings --> <!--Settings -->