Added logic to redesigned home
(partially)
This commit is contained in:
parent
277d8773f2
commit
6afcc83955
@ -30,5 +30,5 @@ val viewModelModules = module {
|
|||||||
// redesign
|
// redesign
|
||||||
|
|
||||||
viewModel { RedesignViewModel() }
|
viewModel { RedesignViewModel() }
|
||||||
viewModel { RedesignHomeViewModel() }
|
viewModel { RedesignHomeViewModel(get()) }
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,69 @@
|
|||||||
package com.topjohnwu.magisk.redesign.home
|
package com.topjohnwu.magisk.redesign.home
|
||||||
|
|
||||||
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.skoumal.teanity.util.KObservableField
|
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.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 stateMagisk = KObservableField(MagiskState.LOADING)
|
||||||
val stateTextManager = KObservableField("is up to date")
|
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() {}
|
fun onDeletePressed() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:color="?colorError" android:state_selected="true" />
|
<item android:color="?colorError" android:state_selected="true" />
|
||||||
|
<item android:color="?colorDisabled" android:state_enabled="false" />
|
||||||
<item android:color="?colorPrimary" />
|
<item android:color="?colorPrimary" />
|
||||||
</selector>
|
</selector>
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
|
<import type="com.topjohnwu.magisk.ui.home.MagiskState" />
|
||||||
|
|
||||||
<variable
|
<variable
|
||||||
name="viewModel"
|
name="viewModel"
|
||||||
type="com.topjohnwu.magisk.redesign.home.HomeViewModel" />
|
type="com.topjohnwu.magisk.redesign.home.HomeViewModel" />
|
||||||
@ -32,6 +34,7 @@
|
|||||||
android:id="@+id/home_magisk_wrapper"
|
android:id="@+id/home_magisk_wrapper"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/home_manager_wrapper"
|
app:layout_constraintEnd_toStartOf="@+id/home_manager_wrapper"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
@ -39,6 +42,7 @@
|
|||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/home_magisk_icon"
|
android:id="@+id/home_magisk_icon"
|
||||||
style="?styleIconPrimary"
|
style="?styleIconPrimary"
|
||||||
|
isEnabled="@{viewModel.stateMagisk != MagiskState.LOADING}"
|
||||||
onSelectClick="@{() -> viewModel.onDeletePressed()}"
|
onSelectClick="@{() -> viewModel.onDeletePressed()}"
|
||||||
onSelectReset="@{10000L}"
|
onSelectReset="@{10000L}"
|
||||||
android:padding="@dimen/l_25"
|
android:padding="@dimen/l_25"
|
||||||
@ -71,15 +75,18 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/home_magisk_title" />
|
app:layout_constraintTop_toBottomOf="@+id/home_magisk_title" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
gone="@{viewModel.stateMagisk == MagiskState.LOADING}"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/l1"
|
android:layout_marginTop="@dimen/l1"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/home_magisk_status">
|
app:layout_constraintTop_toBottomOf="@+id/home_magisk_status">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
style="?styleButtonDefault"
|
style="?styleButtonDefault"
|
||||||
|
gone="@{viewModel.stateMagisk != MagiskState.OBSOLETE}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/update"
|
android:text="@string/update"
|
||||||
@ -91,6 +98,7 @@
|
|||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
style="?styleButtonText"
|
style="?styleButtonText"
|
||||||
|
gone="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/install"
|
android:text="@string/install"
|
||||||
@ -147,6 +155,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/l1"
|
android:layout_marginTop="@dimen/l1"
|
||||||
|
gone="@{viewModel.stateManager == MagiskState.LOADING}"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/home_manager_status">
|
app:layout_constraintTop_toBottomOf="@+id/home_manager_status">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
@ -154,6 +163,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/update"
|
android:text="@string/update"
|
||||||
|
gone="@{viewModel.stateManager != MagiskState.OBSOLETE}"
|
||||||
app:icon="@drawable/ic_update_md2"
|
app:icon="@drawable/ic_update_md2"
|
||||||
app:iconGravity="textEnd"
|
app:iconGravity="textEnd"
|
||||||
app:iconPadding="@dimen/l_50"
|
app:iconPadding="@dimen/l_50"
|
||||||
@ -164,6 +174,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/install"
|
android:text="@string/install"
|
||||||
|
gone="@{viewModel.stateManager == MagiskState.OBSOLETE}"
|
||||||
app:icon="@drawable/ic_install"
|
app:icon="@drawable/ic_install"
|
||||||
app:iconGravity="textEnd"
|
app:iconGravity="textEnd"
|
||||||
app:iconPadding="@dimen/l_50"
|
app:iconPadding="@dimen/l_50"
|
||||||
|
Loading…
Reference in New Issue
Block a user