Optimize network status display

This commit is contained in:
vvb2060
2020-08-31 03:56:36 +08:00
committed by GitHub
parent 0333e82e86
commit 70174e093b
6 changed files with 16 additions and 6 deletions

View File

@@ -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
}
}

View File

@@ -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<IconLink> {
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

View File

@@ -32,7 +32,7 @@ open class LollipopNetworkObserver(
}
override fun onLost(network: Network) {
emit(Connectivity.create(manager, network))
emit(Connectivity())
}
}
}