diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt index 747481a33..c1906cbd9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -14,7 +14,9 @@ import io.reactivex.Observable import io.reactivex.subjects.PublishSubject -abstract class MagiskViewModel : LoadingViewModel() { +abstract class MagiskViewModel( + initialState: State = State.LOADING +) : LoadingViewModel(initialState) { val isConnected = KObservableField(true) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 3775f8b7f..d14dc9d8e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -31,7 +31,7 @@ enum class MagiskItem { class HomeViewModel( private val magiskRepo: MagiskRepository -) : MagiskViewModel() { +) : MagiskViewModel(State.LOADED) { val hasGMS = runCatching { get().getPackageInfo("com.google.android.gms", 0); true @@ -177,14 +177,7 @@ class HomeViewModel( } fun refresh() { - magiskCurrentVersion.value = if (magiskState.value != MagiskState.NOT_INSTALLED) { - version.format(Info.magiskVersionString, Info.magiskVersionCode) - } else { - "" - } - - managerCurrentVersion.value = version - .format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) + refreshVersions() magiskRepo.fetchUpdate() .applyViewModel(this) @@ -198,13 +191,24 @@ class HomeViewModel( .subscribeK { updateSelf() ensureEnv() + refreshVersions() } hasRoot.value = Shell.rootAccess() } + private fun refreshVersions() { + magiskCurrentVersion.value = if (magiskState.value != MagiskState.NOT_INSTALLED) { + version.format(Info.magiskVersionString, Info.magiskVersionCode) + } else { + "" + } + + managerCurrentVersion.value = version + .format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) + } + private fun updateSelf() { - state = State.LOADED _magiskState.value = when (Info.magiskVersionCode) { in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED !in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE