Added back version checking (and version boxes) after transitioning homepage to MVVM
Fixed several errors caused along the way
This commit is contained in:
parent
bd00ae8ede
commit
9bb4dfad13
@ -73,6 +73,9 @@ dependencies {
|
|||||||
implementation("org.koin:koin-android:${koin}")
|
implementation("org.koin:koin-android:${koin}")
|
||||||
implementation("org.koin:koin-androidx-viewmodel:${koin}")
|
implementation("org.koin:koin-androidx-viewmodel:${koin}")
|
||||||
|
|
||||||
|
def timber = "4.7.1"
|
||||||
|
implementation "com.jakewharton.timber:timber:${timber}"
|
||||||
|
|
||||||
implementation("com.github.skoumalcz:teanity:0.3.3") {
|
implementation("com.github.skoumalcz:teanity:0.3.3") {
|
||||||
exclude group: 'androidx.work', module: 'work-runtime-ktx'
|
exclude group: 'androidx.work', module: 'work-runtime-ktx'
|
||||||
exclude group: 'androidx.room', module: 'room-runtime'
|
exclude group: 'androidx.room', module: 'room-runtime'
|
||||||
|
@ -20,6 +20,7 @@ import com.topjohnwu.net.Networking
|
|||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
|
import timber.log.Timber
|
||||||
import java.util.concurrent.ThreadPoolExecutor
|
import java.util.concurrent.ThreadPoolExecutor
|
||||||
|
|
||||||
open class App : Application(), Application.ActivityLifecycleCallbacks {
|
open class App : Application(), Application.ActivityLifecycleCallbacks {
|
||||||
@ -39,6 +40,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
androidContext(this@App)
|
androidContext(this@App)
|
||||||
modules(koinModules)
|
modules(koinModules)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timber.plant(Timber.DebugTree())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context) {
|
override fun attachBaseContext(base: Context) {
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
package com.topjohnwu.magisk.ui.base
|
package com.topjohnwu.magisk.ui.base
|
||||||
|
|
||||||
import com.skoumal.teanity.viewmodel.LoadingViewModel
|
import com.skoumal.teanity.viewmodel.LoadingViewModel
|
||||||
|
import com.topjohnwu.magisk.utils.Event
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
|
||||||
abstract class MagiskViewModel : LoadingViewModel()
|
abstract class MagiskViewModel : LoadingViewModel(), Event.AutoListener {
|
||||||
|
|
||||||
|
init {
|
||||||
|
Event.register(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEvent(event: Int) = Timber.i("Event of $event was not handled")
|
||||||
|
override fun getListeningEvents(): IntArray = intArrayOf()
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -2,14 +2,14 @@ package com.topjohnwu.magisk.ui.home
|
|||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import com.skoumal.teanity.util.KObservableField
|
import com.skoumal.teanity.util.KObservableField
|
||||||
import com.topjohnwu.magisk.App
|
import com.topjohnwu.magisk.*
|
||||||
import com.topjohnwu.magisk.Config
|
|
||||||
import com.topjohnwu.magisk.Const
|
|
||||||
import com.topjohnwu.magisk.R
|
|
||||||
import com.topjohnwu.magisk.model.events.*
|
import com.topjohnwu.magisk.model.events.*
|
||||||
import com.topjohnwu.magisk.model.observer.Observer
|
import com.topjohnwu.magisk.model.observer.Observer
|
||||||
|
import com.topjohnwu.magisk.tasks.CheckUpdates
|
||||||
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||||
|
import com.topjohnwu.magisk.utils.Event
|
||||||
import com.topjohnwu.magisk.utils.toggle
|
import com.topjohnwu.magisk.utils.toggle
|
||||||
|
import com.topjohnwu.net.Networking
|
||||||
|
|
||||||
|
|
||||||
class HomeViewModel(
|
class HomeViewModel(
|
||||||
@ -19,8 +19,8 @@ class HomeViewModel(
|
|||||||
|
|
||||||
val isAdvancedExpanded = KObservableField(false)
|
val isAdvancedExpanded = KObservableField(false)
|
||||||
|
|
||||||
val isForceEncryption = KObservableField(false /*todo*/)
|
val isForceEncryption = KObservableField(Config.keepEnc)
|
||||||
val isKeepVerity = KObservableField(false /*todo*/)
|
val isKeepVerity = KObservableField(Config.keepVerity)
|
||||||
|
|
||||||
private val prefsObserver = Observer(isForceEncryption, isKeepVerity) {
|
private val prefsObserver = Observer(isForceEncryption, isKeepVerity) {
|
||||||
Config.keepEnc = isForceEncryption.value
|
Config.keepEnc = isForceEncryption.value
|
||||||
@ -29,13 +29,12 @@ class HomeViewModel(
|
|||||||
|
|
||||||
val magiskState = KObservableField(MagiskState.LOADING)
|
val magiskState = KObservableField(MagiskState.LOADING)
|
||||||
val magiskStateText = Observer(magiskState) {
|
val magiskStateText = Observer(magiskState) {
|
||||||
@Suppress("WhenWithOnlyElse")
|
|
||||||
when (magiskState.value) {
|
when (magiskState.value) {
|
||||||
MagiskState.NO_ROOT -> TODO()
|
MagiskState.NO_ROOT -> TODO()
|
||||||
MagiskState.NOT_INSTALLED -> TODO()
|
MagiskState.NOT_INSTALLED -> resources.getString(R.string.magisk_version_error)
|
||||||
MagiskState.UP_TO_DATE -> TODO()
|
MagiskState.UP_TO_DATE -> resources.getString(R.string.magisk_up_to_date)
|
||||||
MagiskState.LOADING -> TODO()
|
MagiskState.LOADING -> resources.getString(R.string.checking_for_updates)
|
||||||
MagiskState.OBSOLETE -> TODO()
|
MagiskState.OBSOLETE -> resources.getString(R.string.magisk_update_title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val magiskCurrentVersion = KObservableField("")
|
val magiskCurrentVersion = KObservableField("")
|
||||||
@ -49,13 +48,12 @@ class HomeViewModel(
|
|||||||
|
|
||||||
val managerState = KObservableField(MagiskState.LOADING)
|
val managerState = KObservableField(MagiskState.LOADING)
|
||||||
val managerStateText = Observer(managerState) {
|
val managerStateText = Observer(managerState) {
|
||||||
@Suppress("WhenWithOnlyElse")
|
|
||||||
when (managerState.value) {
|
when (managerState.value) {
|
||||||
MagiskState.NO_ROOT -> TODO()
|
MagiskState.NO_ROOT -> "wtf"
|
||||||
MagiskState.NOT_INSTALLED -> TODO()
|
MagiskState.NOT_INSTALLED -> resources.getString(R.string.invalid_update_channel)
|
||||||
MagiskState.UP_TO_DATE -> TODO()
|
MagiskState.UP_TO_DATE -> resources.getString(R.string.manager_up_to_date)
|
||||||
MagiskState.LOADING -> TODO()
|
MagiskState.LOADING -> resources.getString(R.string.checking_for_updates)
|
||||||
MagiskState.OBSOLETE -> TODO()
|
MagiskState.OBSOLETE -> resources.getString(R.string.manager_update_title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val managerCurrentVersion = KObservableField("")
|
val managerCurrentVersion = KObservableField("")
|
||||||
@ -67,6 +65,16 @@ class HomeViewModel(
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val current = resources.getString(R.string.current_installed)
|
||||||
|
private val latest = resources.getString(R.string.latest_version)
|
||||||
|
|
||||||
|
init {
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEvent(event: Int) = updateSelf()
|
||||||
|
override fun getListeningEvents(): IntArray = intArrayOf(Event.UPDATE_CHECK_DONE)
|
||||||
|
|
||||||
fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish()
|
fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish()
|
||||||
fun patreonPressed() = OpenLinkEvent(Const.Url.PATREON_URL).publish()
|
fun patreonPressed() = OpenLinkEvent(Const.Url.PATREON_URL).publish()
|
||||||
fun twitterPressed() = OpenLinkEvent(Const.Url.TWITTER_URL).publish()
|
fun twitterPressed() = OpenLinkEvent(Const.Url.TWITTER_URL).publish()
|
||||||
@ -74,8 +82,6 @@ class HomeViewModel(
|
|||||||
fun xdaPressed() = OpenLinkEvent(Const.Url.XDA_THREAD).publish()
|
fun xdaPressed() = OpenLinkEvent(Const.Url.XDA_THREAD).publish()
|
||||||
fun uninstallPressed() = UninstallEvent.publish()
|
fun uninstallPressed() = UninstallEvent.publish()
|
||||||
|
|
||||||
fun refresh() {}
|
|
||||||
|
|
||||||
fun advancedPressed() = isAdvancedExpanded.toggle()
|
fun advancedPressed() = isAdvancedExpanded.toggle()
|
||||||
|
|
||||||
fun installPressed(item: MagiskItem) = when (item) {
|
fun installPressed(item: MagiskItem) = when (item) {
|
||||||
@ -88,4 +94,52 @@ class HomeViewModel(
|
|||||||
MagiskItem.MAGISK -> MagiskChangelogEvent.publish()
|
MagiskItem.MAGISK -> MagiskChangelogEvent.publish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun refresh() {
|
||||||
|
state = State.LOADING
|
||||||
|
magiskState.value = MagiskState.LOADING
|
||||||
|
managerState.value = MagiskState.LOADING
|
||||||
|
Event.reset(this)
|
||||||
|
Config.remoteMagiskVersionString = null
|
||||||
|
Config.remoteMagiskVersionCode = -1
|
||||||
|
|
||||||
|
if (Networking.checkNetworkStatus(app)) {
|
||||||
|
CheckUpdates.check()
|
||||||
|
} else {
|
||||||
|
state = State.LOADING_FAILED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSelf() {
|
||||||
|
state = State.LOADED
|
||||||
|
magiskState.value = when (Config.magiskVersionCode) {
|
||||||
|
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED
|
||||||
|
!in Config.remoteMagiskVersionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||||
|
else -> MagiskState.UP_TO_DATE
|
||||||
|
}
|
||||||
|
|
||||||
|
magiskCurrentVersion.value = version
|
||||||
|
.format(Config.magiskVersionString, Config.magiskVersionCode)
|
||||||
|
.let { current.format(it) }
|
||||||
|
magiskLatestVersion.value = version
|
||||||
|
.format(Config.remoteMagiskVersionString, Config.remoteMagiskVersionCode)
|
||||||
|
.let { latest.format(it) }
|
||||||
|
|
||||||
|
managerState.value = when (Config.remoteManagerVersionCode) {
|
||||||
|
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED //wrong update channel
|
||||||
|
in (BuildConfig.VERSION_CODE + 1)..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||||
|
else -> MagiskState.UP_TO_DATE
|
||||||
|
}
|
||||||
|
|
||||||
|
managerCurrentVersion.value = version
|
||||||
|
.format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
|
||||||
|
.let { current.format(it) }
|
||||||
|
managerLatestVersion.value = version
|
||||||
|
.format(Config.remoteManagerVersionString, Config.remoteManagerVersionCode)
|
||||||
|
.let { latest.format(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val version = "%s (%d)"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package com.topjohnwu.magisk.ui.home
|
package com.topjohnwu.magisk.ui.home
|
||||||
|
|
||||||
import com.skoumal.teanity.viewevents.ViewEvent
|
import com.skoumal.teanity.viewevents.ViewEvent
|
||||||
|
import com.topjohnwu.magisk.BuildConfig
|
||||||
import com.topjohnwu.magisk.Config
|
import com.topjohnwu.magisk.Config
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.model.events.MagiskInstallEvent
|
import com.topjohnwu.magisk.model.events.*
|
||||||
import com.topjohnwu.magisk.model.events.ManagerInstallEvent
|
|
||||||
import com.topjohnwu.magisk.model.events.OpenLinkEvent
|
|
||||||
import com.topjohnwu.magisk.model.events.UninstallEvent
|
|
||||||
import com.topjohnwu.magisk.utils.Event
|
import com.topjohnwu.magisk.utils.Event
|
||||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||||
import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog
|
import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog
|
||||||
@ -62,6 +60,7 @@ class MagiskFragment : NewMagiskFragment<HomeViewModel, com.topjohnwu.magisk.dat
|
|||||||
is ManagerInstallEvent -> installManager()
|
is ManagerInstallEvent -> installManager()
|
||||||
is MagiskInstallEvent -> installMagisk()
|
is MagiskInstallEvent -> installMagisk()
|
||||||
is UninstallEvent -> uninstall()
|
is UninstallEvent -> uninstall()
|
||||||
|
is ManagerChangelogEvent -> changelogManager()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.utils
|
package com.topjohnwu.magisk.utils
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.appcompat.widget.AppCompatImageView
|
import androidx.appcompat.widget.AppCompatImageView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
@ -16,3 +17,8 @@ fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener
|
|||||||
fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) {
|
fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) {
|
||||||
view.setImageResource(resId)
|
view.setImageResource(resId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BindingAdapter("app:tint")
|
||||||
|
fun setTint(view: AppCompatImageView, @ColorInt tint: Int) {
|
||||||
|
view.setColorFilter(tint)
|
||||||
|
}
|
||||||
|
@ -79,6 +79,7 @@
|
|||||||
android:layout_height="25dp"
|
android:layout_height="25dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
|
app:tint="@{state == MagiskState.UP_TO_DATE ? @color/colorCorrect : (state == MagiskState.OBSOLETE ? @color/colorUpdate : @color/colorError)}"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/status"
|
app:layout_constraintEnd_toStartOf="@+id/status"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@ -86,7 +87,7 @@
|
|||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progress"
|
android:id="@+id/progress"
|
||||||
gone="state != MagiskState.LOADING"
|
gone="@{state != MagiskState.LOADING}"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/status_icon"
|
app:layout_constraintBottom_toBottomOf="@+id/status_icon"
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
<color name="colorInactive">#66000000</color>
|
<color name="colorInactive">#66000000</color>
|
||||||
|
|
||||||
|
<color name="colorCorrect">@color/green500</color>
|
||||||
|
<color name="colorError">@color/red500</color>
|
||||||
|
<color name="colorUpdate">@color/blue500</color>
|
||||||
<!--new colors ^^-->
|
<!--new colors ^^-->
|
||||||
|
|
||||||
<color name="primary">#009688</color>
|
<color name="primary">#009688</color>
|
||||||
|
Loading…
Reference in New Issue
Block a user