mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Slightly change update UI logic
This commit is contained in:
parent
a73acfb9c2
commit
761a8dde65
@ -14,15 +14,18 @@ import java.util.*
|
|||||||
data class LocalModule(
|
data class LocalModule(
|
||||||
private val path: String,
|
private val path: String,
|
||||||
) : Module() {
|
) : Module() {
|
||||||
|
private val svc get() = ServiceLocator.networkService
|
||||||
|
|
||||||
override var id: String = ""
|
override var id: String = ""
|
||||||
override var name: String = ""
|
override var name: String = ""
|
||||||
override var version: String = ""
|
override var version: String = ""
|
||||||
override var versionCode: Int = -1
|
override var versionCode: Int = -1
|
||||||
var author: String = ""
|
var author: String = ""
|
||||||
var description: String = ""
|
var description: String = ""
|
||||||
var updateJson: String = ""
|
|
||||||
var updateInfo: OnlineModule? = null
|
var updateInfo: OnlineModule? = null
|
||||||
|
var outdated = false
|
||||||
|
|
||||||
|
private var updateUrl: String = ""
|
||||||
private val removeFile = SuFile(path, "remove")
|
private val removeFile = SuFile(path, "remove")
|
||||||
private val disableFile = SuFile(path, "disable")
|
private val disableFile = SuFile(path, "disable")
|
||||||
private val updateFile = SuFile(path, "update")
|
private val updateFile = SuFile(path, "update")
|
||||||
@ -93,7 +96,7 @@ data class LocalModule(
|
|||||||
"versionCode" -> versionCode = value.toInt()
|
"versionCode" -> versionCode = value.toInt()
|
||||||
"author" -> author = value
|
"author" -> author = value
|
||||||
"description" -> description = value
|
"description" -> description = value
|
||||||
"updateJson" -> updateJson = value
|
"updateJson" -> updateUrl = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,20 +116,21 @@ data class LocalModule(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun load():Boolean {
|
suspend fun fetch(): Boolean {
|
||||||
if (updateJson.isEmpty()) return false
|
if (updateUrl.isEmpty())
|
||||||
|
return false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val json = ServiceLocator.networkService.fetchModuleJson(updateJson)
|
val json = svc.fetchModuleJson(updateUrl)
|
||||||
if (json.versionCode > versionCode) {
|
|
||||||
updateInfo = OnlineModule(this, json)
|
updateInfo = OnlineModule(this, json)
|
||||||
|
outdated = json.versionCode > versionCode
|
||||||
return true
|
return true
|
||||||
}
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
} catch (e: JsonDataException) {
|
} catch (e: JsonDataException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +54,18 @@ class LocalModuleRvItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@get:Bindable
|
@get:Bindable
|
||||||
var updateReady: Boolean
|
val showUpdate get() = item.updateInfo != null
|
||||||
get() = item.updateInfo != null && !isRemoved && isEnabled
|
|
||||||
set(_) = notifyPropertyChanged(BR.updateReady)
|
@get:Bindable
|
||||||
|
val updateReady get() = item.outdated && !isRemoved && isEnabled
|
||||||
|
|
||||||
val isUpdated = item.updated
|
val isUpdated = item.updated
|
||||||
|
|
||||||
|
fun fetchedUpdateInfo() {
|
||||||
|
notifyPropertyChanged(BR.showUpdate)
|
||||||
|
notifyPropertyChanged(BR.updateReady)
|
||||||
|
}
|
||||||
|
|
||||||
fun delete() {
|
fun delete() {
|
||||||
isRemoved = !isRemoved
|
isRemoved = !isRemoved
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,8 @@ class ModuleViewModel : BaseViewModel() {
|
|||||||
private suspend fun loadUpdateInfo() {
|
private suspend fun loadUpdateInfo() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
itemsInstalled.forEach {
|
itemsInstalled.forEach {
|
||||||
it.updateReady = it.item.load()
|
if (it.item.fetch())
|
||||||
|
it.fetchedUpdateInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@
|
|||||||
<Button
|
<Button
|
||||||
android:id="@+id/module_update"
|
android:id="@+id/module_update"
|
||||||
style="@style/WidgetFoundation.Button.Text"
|
style="@style/WidgetFoundation.Button.Text"
|
||||||
gone="@{item.item.updateJson.length == 0}"
|
goneUnless="@{item.showUpdate}"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
|
Loading…
Reference in New Issue
Block a user