Optimize network status display
This commit is contained in:
parent
0333e82e86
commit
70174e093b
@ -3,6 +3,7 @@ package com.topjohnwu.magisk.data.repository
|
|||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.data.network.GithubRawServices
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
|
import retrofit2.HttpException
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@ -28,6 +29,9 @@ class MagiskRepository(
|
|||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
null
|
null
|
||||||
|
} catch (e: HttpException) {
|
||||||
|
Timber.e(e)
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,9 @@ class HomeViewModel(
|
|||||||
val showUninstall get() =
|
val showUninstall get() =
|
||||||
Info.env.magiskVersionCode > 0 && stateMagisk != MagiskState.LOADING && isConnected.get()
|
Info.env.magiskVersionCode > 0 && stateMagisk != MagiskState.LOADING && isConnected.get()
|
||||||
|
|
||||||
|
@get:Bindable
|
||||||
|
val showSafetyNet get() = Info.hasGMS && isConnected.get()
|
||||||
|
|
||||||
val itemBinding = itemBindingOf<IconLink> {
|
val itemBinding = itemBindingOf<IconLink> {
|
||||||
it.bindExtra(BR.viewModel, this)
|
it.bindExtra(BR.viewModel, this)
|
||||||
}
|
}
|
||||||
@ -77,8 +80,11 @@ class HomeViewModel(
|
|||||||
private var shownDialog = false
|
private var shownDialog = false
|
||||||
|
|
||||||
override fun refresh() = viewModelScope.launch {
|
override fun refresh() = viewModelScope.launch {
|
||||||
|
state = State.LOADING
|
||||||
notifyPropertyChanged(BR.showUninstall)
|
notifyPropertyChanged(BR.showUninstall)
|
||||||
|
notifyPropertyChanged(BR.showSafetyNet)
|
||||||
repoMagisk.fetchUpdate()?.apply {
|
repoMagisk.fetchUpdate()?.apply {
|
||||||
|
state = State.LOADED
|
||||||
stateMagisk = when {
|
stateMagisk = when {
|
||||||
!Info.env.isActive -> MagiskState.NOT_INSTALLED
|
!Info.env.isActive -> MagiskState.NOT_INSTALLED
|
||||||
magisk.isObsolete -> MagiskState.OBSOLETE
|
magisk.isObsolete -> MagiskState.OBSOLETE
|
||||||
@ -99,7 +105,7 @@ class HomeViewModel(
|
|||||||
launch {
|
launch {
|
||||||
ensureEnv()
|
ensureEnv()
|
||||||
}
|
}
|
||||||
}
|
} ?: apply { state = State.LOADING_FAILED }
|
||||||
}
|
}
|
||||||
|
|
||||||
val showTest = false
|
val showTest = false
|
||||||
|
@ -32,7 +32,7 @@ open class LollipopNetworkObserver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
emit(Connectivity.create(manager, network))
|
emit(Connectivity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@
|
|||||||
<Space
|
<Space
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/l1"
|
android:layout_height="@dimen/l1"
|
||||||
gone="@{!Info.hasGMS && !viewModel.showUninstall}" />
|
gone="@{!viewModel.showSafetyNet && !viewModel.showUninstall}" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
style="@style/WidgetFoundation.Button.Outlined"
|
style="@style/WidgetFoundation.Button.Outlined"
|
||||||
@ -120,7 +120,7 @@
|
|||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:onClick="@{() -> viewModel.onSafetyNetPressed()}"
|
android:onClick="@{() -> viewModel.onSafetyNetPressed()}"
|
||||||
gone="@{!Info.hasGMS}"
|
gone="@{!viewModel.showSafetyNet}"
|
||||||
app:cornerRadius="@dimen/r1"
|
app:cornerRadius="@dimen/r1"
|
||||||
app:icon="@drawable/ic_safetynet_md2" />
|
app:icon="@drawable/ic_safetynet_md2" />
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/W.Home.ItemContent.Right"
|
style="@style/W.Home.ItemContent.Right"
|
||||||
android:text="@{viewModel.isConnected ? viewModel.magiskRemoteVersion : @string/not_available}"
|
android:text="@{viewModel.loadFailed ? @string/not_available : viewModel.magiskRemoteVersion }"
|
||||||
tools:text="20.1 (12345)" />
|
tools:text="20.1 (12345)" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/W.Home.ItemContent.Right"
|
style="@style/W.Home.ItemContent.Right"
|
||||||
android:text="@{viewModel.isConnected ? viewModel.managerRemoteVersion : @string/not_available}"
|
android:text="@{viewModel.loadFailed ? @string/not_available : viewModel.managerRemoteVersion}"
|
||||||
tools:text="8.0.0 (123) (10)" />
|
tools:text="8.0.0 (123) (10)" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user