From dc61dfbde6d092e09a643f24190f7b766f063c3d Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 25 Jan 2021 04:13:08 -0800 Subject: [PATCH] Cache update check results --- app/src/main/java/com/topjohnwu/magisk/core/Info.kt | 9 ++++++++- .../topjohnwu/magisk/data/repository/NetworkService.kt | 1 - .../java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt | 2 +- .../com/topjohnwu/magisk/ui/settings/SettingsItems.kt | 10 ++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index 787c5e909..298927274 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -4,6 +4,7 @@ import androidx.databinding.ObservableBoolean import com.topjohnwu.magisk.DynAPK import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.core.utils.net.NetworkObserver +import com.topjohnwu.magisk.data.repository.NetworkService import com.topjohnwu.magisk.ktx.get import com.topjohnwu.magisk.ktx.getProperty import com.topjohnwu.superuser.Shell @@ -18,7 +19,13 @@ object Info { var stub: DynAPK.Data? = null - var remote = UpdateInfo() + val EMPTY_REMOTE = UpdateInfo() + var remote = EMPTY_REMOTE + suspend fun getRemote(svc: NetworkService): UpdateInfo? { + return if (remote === EMPTY_REMOTE) { + svc.fetchUpdate()?.apply { remote = this } + } else remote + } // Device state @JvmStatic val env by lazy { loadState() } diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt index ab95f4775..ef2435671 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt @@ -36,7 +36,6 @@ class NetworkService( Config.updateChannel = BETA_CHANNEL info = fetchBetaUpdate() } - Info.remote = info info } 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 585158d30..030718ce9 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 @@ -76,7 +76,7 @@ class HomeViewModel( override fun refresh() = viewModelScope.launch { state = State.LOADING notifyPropertyChanged(BR.showSafetyNet) - svc.fetchUpdate()?.apply { + Info.getRemote(svc)?.apply { state = State.LOADED stateManager = when { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt index 8ea449d28..d2124c3b3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt @@ -141,7 +141,10 @@ object DownloadPath : BaseSettingsItem.Input() { object UpdateChannel : BaseSettingsItem.Selector() { override var value = Config.updateChannel - set(value) = setV(value, field, { field = it }) { Config.updateChannel = it } + set(value) = setV(value, field, { field = it }) { + Config.updateChannel = it + Info.remote = Info.EMPTY_REMOTE + } override val title = R.string.settings_update_channel_title.asTransitive() override val entries: Array = resources.getStringArray(R.array.update_channel).let { @@ -155,7 +158,10 @@ object UpdateChannel : BaseSettingsItem.Selector() { object UpdateChannelUrl : BaseSettingsItem.Input() { override val title = R.string.settings_update_custom.asTransitive() override var value = Config.customChannelUrl - set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it } + set(value) = setV(value, field, { field = it }) { + Config.customChannelUrl = it + Info.remote = Info.EMPTY_REMOTE + } override val description get() = value.asTransitive() override val inputResult get() = result