diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt index 9cedb57a5..44593c779 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt @@ -14,15 +14,18 @@ import java.util.* data class LocalModule( private val path: String, ) : Module() { + private val svc get() = ServiceLocator.networkService + override var id: String = "" override var name: String = "" override var version: String = "" override var versionCode: Int = -1 var author: String = "" var description: String = "" - var updateJson: String = "" var updateInfo: OnlineModule? = null + var outdated = false + private var updateUrl: String = "" private val removeFile = SuFile(path, "remove") private val disableFile = SuFile(path, "disable") private val updateFile = SuFile(path, "update") @@ -93,7 +96,7 @@ data class LocalModule( "versionCode" -> versionCode = value.toInt() "author" -> author = value "description" -> description = value - "updateJson" -> updateJson = value + "updateJson" -> updateUrl = value } } } @@ -113,20 +116,21 @@ data class LocalModule( } } - suspend fun load():Boolean { - if (updateJson.isEmpty()) return false + suspend fun fetch(): Boolean { + if (updateUrl.isEmpty()) + return false try { - val json = ServiceLocator.networkService.fetchModuleJson(updateJson) - if (json.versionCode > versionCode) { - updateInfo = OnlineModule(this, json) - return true - } + val json = svc.fetchModuleJson(updateUrl) + updateInfo = OnlineModule(this, json) + outdated = json.versionCode > versionCode + return true } catch (e: IOException) { Timber.w(e) } catch (e: JsonDataException) { Timber.w(e) } + return false } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt index d7d9e6842..cbbaaabad 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleRvItem.kt @@ -54,12 +54,18 @@ class LocalModuleRvItem( } @get:Bindable - var updateReady: Boolean - get() = item.updateInfo != null && !isRemoved && isEnabled - set(_) = notifyPropertyChanged(BR.updateReady) + val showUpdate get() = item.updateInfo != null + + @get:Bindable + val updateReady get() = item.outdated && !isRemoved && isEnabled val isUpdated = item.updated + fun fetchedUpdateInfo() { + notifyPropertyChanged(BR.showUpdate) + notifyPropertyChanged(BR.updateReady) + } + fun delete() { isRemoved = !isRemoved } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 7296121cb..34f11e694 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -59,7 +59,8 @@ class ModuleViewModel : BaseViewModel() { private suspend fun loadUpdateInfo() { withContext(Dispatchers.IO) { itemsInstalled.forEach { - it.updateReady = it.item.load() + if (it.item.fetch()) + it.fetchedUpdateInfo() } } } diff --git a/app/src/main/res/layout/item_module_md2.xml b/app/src/main/res/layout/item_module_md2.xml index d20b8902e..2989c0ba6 100644 --- a/app/src/main/res/layout/item_module_md2.xml +++ b/app/src/main/res/layout/item_module_md2.xml @@ -130,7 +130,7 @@