From 70174e093b9ef89690de22e76268288a2f104f91 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Mon, 31 Aug 2020 03:56:36 +0800 Subject: [PATCH] Optimize network status display --- .../topjohnwu/magisk/data/repository/MagiskRepository.kt | 4 ++++ .../java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt | 8 +++++++- .../topjohnwu/magisk/utils/net/LollipopNetworkObserver.kt | 2 +- app/src/main/res/layout/fragment_home_md2.xml | 4 ++-- app/src/main/res/layout/include_home_magisk.xml | 2 +- app/src/main/res/layout/include_home_manager.xml | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt index f33827f95..5a5ae85cd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.data.repository import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.data.network.GithubRawServices +import retrofit2.HttpException import timber.log.Timber import java.io.IOException @@ -28,6 +29,9 @@ class MagiskRepository( } catch (e: IOException) { Timber.e(e) null + } catch (e: HttpException) { + Timber.e(e) + null } } 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 69f853374..6f7b9d149 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 @@ -70,6 +70,9 @@ class HomeViewModel( val showUninstall get() = Info.env.magiskVersionCode > 0 && stateMagisk != MagiskState.LOADING && isConnected.get() + @get:Bindable + val showSafetyNet get() = Info.hasGMS && isConnected.get() + val itemBinding = itemBindingOf { it.bindExtra(BR.viewModel, this) } @@ -77,8 +80,11 @@ class HomeViewModel( private var shownDialog = false override fun refresh() = viewModelScope.launch { + state = State.LOADING notifyPropertyChanged(BR.showUninstall) + notifyPropertyChanged(BR.showSafetyNet) repoMagisk.fetchUpdate()?.apply { + state = State.LOADED stateMagisk = when { !Info.env.isActive -> MagiskState.NOT_INSTALLED magisk.isObsolete -> MagiskState.OBSOLETE @@ -99,7 +105,7 @@ class HomeViewModel( launch { ensureEnv() } - } + } ?: apply { state = State.LOADING_FAILED } } val showTest = false diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/net/LollipopNetworkObserver.kt b/app/src/main/java/com/topjohnwu/magisk/utils/net/LollipopNetworkObserver.kt index 112ded03b..76f922a2a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/net/LollipopNetworkObserver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/net/LollipopNetworkObserver.kt @@ -32,7 +32,7 @@ open class LollipopNetworkObserver( } override fun onLost(network: Network) { - emit(Connectivity.create(manager, network)) + emit(Connectivity()) } } } diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index 98837d6b3..7a14d6d8c 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -108,7 +108,7 @@ + gone="@{!viewModel.showSafetyNet && !viewModel.showUninstall}" />