diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
index f2e28cb55..daaef422f 100644
--- a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
@@ -30,5 +30,5 @@ val viewModelModules = module {
// redesign
viewModel { RedesignViewModel() }
- viewModel { RedesignHomeViewModel() }
+ viewModel { RedesignHomeViewModel(get()) }
}
diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt
index c17c5be56..621158a16 100644
--- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt
@@ -1,13 +1,69 @@
package com.topjohnwu.magisk.redesign.home
+import com.skoumal.teanity.extensions.subscribeK
import com.skoumal.teanity.util.KObservableField
+import com.topjohnwu.magisk.BuildConfig
+import com.topjohnwu.magisk.Info
+import com.topjohnwu.magisk.R
+import com.topjohnwu.magisk.data.repository.MagiskRepository
+import com.topjohnwu.magisk.extensions.res
+import com.topjohnwu.magisk.model.entity.MagiskJson
+import com.topjohnwu.magisk.model.entity.ManagerJson
+import com.topjohnwu.magisk.model.entity.UpdateInfo
+import com.topjohnwu.magisk.model.observer.Observer
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
+import com.topjohnwu.magisk.ui.home.MagiskState
-class HomeViewModel : CompatViewModel() {
+class HomeViewModel(
+ private val repoMagisk: MagiskRepository
+) : CompatViewModel() {
- val stateTextMagisk = KObservableField("is up to date")
- val stateTextManager = KObservableField("is up to date")
+ val stateMagisk = KObservableField(MagiskState.LOADING)
+ val stateManager = KObservableField(MagiskState.LOADING)
+ val stateTextMagisk = Observer(stateMagisk) {
+ when (stateMagisk.value) {
+ MagiskState.NOT_INSTALLED -> R.string.magisk_version_error.res()
+ MagiskState.UP_TO_DATE -> R.string.magisk_up_to_date.res()
+ MagiskState.LOADING -> R.string.checking_for_updates.res()
+ MagiskState.OBSOLETE -> R.string.magisk_update_title.res()
+ }
+ }
+ val stateTextManager = Observer(stateManager) {
+ when (stateManager.value) {
+ MagiskState.NOT_INSTALLED -> R.string.invalid_update_channel.res()
+ MagiskState.UP_TO_DATE -> R.string.manager_up_to_date.res()
+ MagiskState.LOADING -> R.string.checking_for_updates.res()
+ MagiskState.OBSOLETE -> R.string.manager_update_title.res()
+ }
+ }
+
+ override fun refresh() = repoMagisk.fetchUpdate()
+ .subscribeK { updateBy(it) }
+
+ private fun updateBy(info: UpdateInfo) {
+ stateMagisk.value = when {
+ !info.magisk.isInstalled -> MagiskState.NOT_INSTALLED
+ info.magisk.isObsolete -> MagiskState.OBSOLETE
+ else -> MagiskState.UP_TO_DATE
+ }
+
+ stateManager.value = when {
+ !info.app.isUpdateChannelCorrect -> MagiskState.NOT_INSTALLED
+ info.app.isObsolete -> MagiskState.OBSOLETE
+ else -> MagiskState.UP_TO_DATE
+ }
+ }
fun onDeletePressed() {}
-}
\ No newline at end of file
+}
+
+@Suppress("unused")
+val MagiskJson.isInstalled
+ get() = Info.magiskVersionCode > 0
+val MagiskJson.isObsolete
+ get() = Info.magiskVersionCode < versionCode
+val ManagerJson.isUpdateChannelCorrect
+ get() = versionCode > 0
+val ManagerJson.isObsolete
+ get() = BuildConfig.VERSION_CODE < versionCode
\ No newline at end of file
diff --git a/app/src/main/res/color/color_primary_delete_transient.xml b/app/src/main/res/color/color_primary_delete_transient.xml
index 7be83a094..b0bcb827a 100644
--- a/app/src/main/res/color/color_primary_delete_transient.xml
+++ b/app/src/main/res/color/color_primary_delete_transient.xml
@@ -1,5 +1,6 @@
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml
index 9e88a8f09..ec056d4b6 100644
--- a/app/src/main/res/layout/fragment_home_md2.xml
+++ b/app/src/main/res/layout/fragment_home_md2.xml
@@ -5,6 +5,8 @@
+
+
@@ -32,6 +34,7 @@
android:id="@+id/home_magisk_wrapper"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
app:layout_constraintEnd_toStartOf="@+id/home_manager_wrapper"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -39,6 +42,7 @@