You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Refactor class names
This commit is contained in:
@@ -3,8 +3,8 @@ package com.topjohnwu.magisk.ui.module
|
||||
import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.model.module.Module
|
||||
import com.topjohnwu.magisk.core.model.module.Repo
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
@@ -39,7 +39,7 @@ class SectionTitle(
|
||||
override fun contentSameAs(other: SectionTitle): Boolean = this === other
|
||||
}
|
||||
|
||||
sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() {
|
||||
sealed class RepoItem(val item: OnlineModule) : ObservableItem<RepoItem>() {
|
||||
override val layoutRes: Int = R.layout.item_repo_md2
|
||||
|
||||
@get:Bindable
|
||||
@@ -51,21 +51,21 @@ sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() {
|
||||
override fun contentSameAs(other: RepoItem): Boolean = item == other.item
|
||||
override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id
|
||||
|
||||
class Update(item: Repo) : RepoItem(item) {
|
||||
class Update(item: OnlineModule) : RepoItem(item) {
|
||||
override val isUpdate get() = true
|
||||
}
|
||||
|
||||
class Remote(item: Repo) : RepoItem(item) {
|
||||
class Remote(item: OnlineModule) : RepoItem(item) {
|
||||
override val isUpdate get() = false
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleItem(val item: Module) : ObservableItem<ModuleItem>() {
|
||||
class ModuleItem(val item: LocalModule) : ObservableItem<ModuleItem>() {
|
||||
|
||||
override val layoutRes = R.layout.item_module_md2
|
||||
|
||||
@get:Bindable
|
||||
var repo: Repo? = null
|
||||
var repo: OnlineModule? = null
|
||||
set(value) = set(value, field, { field = it }, BR.repo)
|
||||
|
||||
@get:Bindable
|
||||
|
||||
@@ -9,10 +9,9 @@ import com.topjohnwu.magisk.arch.*
|
||||
import com.topjohnwu.magisk.core.Config
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.download.Subject
|
||||
import com.topjohnwu.magisk.core.model.module.Module
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.core.tasks.RepoUpdater
|
||||
import com.topjohnwu.magisk.data.database.RepoByNameDao
|
||||
import com.topjohnwu.magisk.data.database.RepoByUpdatedDao
|
||||
import com.topjohnwu.magisk.data.database.RepoDao
|
||||
import com.topjohnwu.magisk.databinding.RvItem
|
||||
import com.topjohnwu.magisk.events.OpenReadmeEvent
|
||||
import com.topjohnwu.magisk.events.SelectModuleEvent
|
||||
@@ -44,8 +43,7 @@ import kotlin.math.roundToInt
|
||||
* */
|
||||
|
||||
class ModuleViewModel(
|
||||
private val repoName: RepoByNameDao,
|
||||
private val repoUpdated: RepoByUpdatedDao,
|
||||
private val repoDB: RepoDao,
|
||||
private val repoUpdater: RepoUpdater
|
||||
) : BaseViewModel(), Queryable {
|
||||
|
||||
@@ -117,12 +115,6 @@ class ModuleViewModel(
|
||||
// ---
|
||||
|
||||
private var refetch = false
|
||||
private val dao
|
||||
get() = when (Config.repoOrder) {
|
||||
Config.Value.ORDER_DATE -> repoUpdated
|
||||
Config.Value.ORDER_NAME -> repoName
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
@@ -186,7 +178,7 @@ class ModuleViewModel(
|
||||
}
|
||||
|
||||
private suspend fun loadInstalled() {
|
||||
val installed = Module.installed().map { ModuleItem(it) }
|
||||
val installed = LocalModule.installed().map { ModuleItem(it) }
|
||||
val diff = withContext(Dispatchers.Default) {
|
||||
itemsInstalled.calculateDiff(installed)
|
||||
}
|
||||
@@ -197,11 +189,11 @@ class ModuleViewModel(
|
||||
val (updates, diff) = withContext(Dispatchers.IO) {
|
||||
itemsInstalled.forEach {
|
||||
launch {
|
||||
it.repo = dao.getRepoById(it.item.id)
|
||||
it.repo = repoDB.getModule(it.item.id)
|
||||
}
|
||||
}
|
||||
val updates = itemsInstalled
|
||||
.mapNotNull { dao.getUpdatableRepoById(it.item.id, it.item.versionCode) }
|
||||
.mapNotNull { repoDB.getUpdatableModule(it.item.id, it.item.versionCode) }
|
||||
.map { RepoItem.Update(it) }
|
||||
val diff = itemsUpdatable.calculateDiff(updates)
|
||||
return@withContext updates to diff
|
||||
@@ -219,7 +211,7 @@ class ModuleViewModel(
|
||||
|
||||
remoteJob = viewModelScope.launch {
|
||||
suspend fun loadRemoteDB(offset: Int) = withContext(Dispatchers.IO) {
|
||||
dao.getRepos(offset).map { RepoItem.Remote(it) }
|
||||
repoDB.getModules(offset).map { RepoItem.Remote(it) }
|
||||
}
|
||||
|
||||
isRemoteLoading = true
|
||||
@@ -253,7 +245,7 @@ class ModuleViewModel(
|
||||
listOf()
|
||||
} else {
|
||||
withContext(Dispatchers.IO) {
|
||||
dao.searchRepos(query, offset).map { RepoItem.Remote(it) }
|
||||
repoDB.searchModules(query, offset).map { RepoItem.Remote(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user