Added simple ui blocks for whenever connection drops out
This commit is contained in:
parent
4ef19d17da
commit
085ede6d93
@ -4,6 +4,7 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||
import com.topjohnwu.magisk.ClassMap
|
||||
import com.topjohnwu.magisk.Config
|
||||
import com.topjohnwu.magisk.Const.Key.OPEN_SECTION
|
||||
@ -20,7 +21,6 @@ import com.topjohnwu.magisk.ui.module.ReposFragment
|
||||
import com.topjohnwu.magisk.ui.settings.SettingsFragment
|
||||
import com.topjohnwu.magisk.ui.superuser.SuperuserFragment
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.net.Networking
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import kotlin.reflect.KClass
|
||||
@ -57,6 +57,10 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
||||
checkHideSection()
|
||||
setSupportActionBar(binding.mainInclude.mainToolbar)
|
||||
|
||||
viewModel.isConnected.addOnPropertyChangedCallback {
|
||||
checkHideSection()
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
intent.getStringExtra(OPEN_SECTION)?.let {
|
||||
onEventDispatched(Navigation.fromSection(it))
|
||||
@ -110,7 +114,7 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
||||
menu.findItem(R.id.modulesFragment).isVisible =
|
||||
Shell.rootAccess() && Info.magiskVersionCode >= 0
|
||||
menu.findItem(R.id.reposFragment).isVisible =
|
||||
(Networking.checkNetworkStatus(this) && Shell.rootAccess() && Info.magiskVersionCode >= 0)
|
||||
(viewModel.isConnected.value && Shell.rootAccess() && Info.magiskVersionCode >= 0)
|
||||
menu.findItem(R.id.logFragment).isVisible =
|
||||
Shell.rootAccess()
|
||||
menu.findItem(R.id.superuserFragment).isVisible =
|
||||
|
@ -25,7 +25,10 @@ class HomeViewModel(
|
||||
val isForceEncryption = KObservableField(Info.keepEnc)
|
||||
val isKeepVerity = KObservableField(Info.keepVerity)
|
||||
|
||||
val magiskState = KObservableField(MagiskState.LOADING)
|
||||
private val _magiskState = KObservableField(MagiskState.LOADING)
|
||||
val magiskState = Observer(_magiskState, isConnected) {
|
||||
if (isConnected.value) _magiskState.value else MagiskState.UP_TO_DATE
|
||||
}
|
||||
val magiskStateText = Observer(magiskState) {
|
||||
when (magiskState.value) {
|
||||
MagiskState.NO_ROOT -> TODO()
|
||||
@ -44,7 +47,10 @@ class HomeViewModel(
|
||||
""
|
||||
}
|
||||
|
||||
val managerState = KObservableField(MagiskState.LOADING)
|
||||
private val _managerState = KObservableField(MagiskState.LOADING)
|
||||
val managerState = Observer(_managerState, isConnected) {
|
||||
if (isConnected.value) _managerState.value else MagiskState.UP_TO_DATE
|
||||
}
|
||||
val managerStateText = Observer(managerState) {
|
||||
when (managerState.value) {
|
||||
MagiskState.NO_ROOT -> "wtf"
|
||||
@ -89,6 +95,9 @@ class HomeViewModel(
|
||||
isKeepVerity.addOnPropertyChangedCallback {
|
||||
Info.keepVerity = it ?: return@addOnPropertyChangedCallback
|
||||
}
|
||||
isConnected.addOnPropertyChangedCallback {
|
||||
if (it == true) refresh()
|
||||
}
|
||||
|
||||
refresh()
|
||||
}
|
||||
@ -154,8 +163,8 @@ class HomeViewModel(
|
||||
magiskRepo.fetchUpdate()
|
||||
.applyViewModel(this)
|
||||
.doOnSubscribeUi {
|
||||
magiskState.value = MagiskState.LOADING
|
||||
managerState.value = MagiskState.LOADING
|
||||
_magiskState.value = MagiskState.LOADING
|
||||
_managerState.value = MagiskState.LOADING
|
||||
ctsState.value = SafetyNetState.IDLE
|
||||
basicIntegrityState.value = SafetyNetState.IDLE
|
||||
safetyNetTitle.value = R.string.safetyNet_check_text
|
||||
@ -170,7 +179,7 @@ class HomeViewModel(
|
||||
|
||||
private fun updateSelf() {
|
||||
state = State.LOADED
|
||||
magiskState.value = when (Info.magiskVersionCode) {
|
||||
_magiskState.value = when (Info.magiskVersionCode) {
|
||||
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED
|
||||
!in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
|
||||
else -> MagiskState.UP_TO_DATE
|
||||
@ -185,7 +194,7 @@ class HomeViewModel(
|
||||
magiskLatestVersion.value = version
|
||||
.format(Info.remote.magisk.version, Info.remote.magisk.versionCode)
|
||||
|
||||
managerState.value = when (Info.remote.app.versionCode) {
|
||||
_managerState.value = when (Info.remote.app.versionCode) {
|
||||
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
|
||||
|
@ -215,4 +215,9 @@ fun setScrollListener(view: RecyclerView, listener: InverseBindingListener) {
|
||||
@InverseBindingAdapter(attribute = "scrollPosition", event = "recyclerScrollEvent")
|
||||
fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayoutManager)
|
||||
?.findLastCompletelyVisibleItemPosition()
|
||||
?: -1
|
||||
?: -1
|
||||
|
||||
@BindingAdapter("isEnabled")
|
||||
fun setEnabled(view: View, isEnabled: Boolean) {
|
||||
view.isEnabled = isEnabled
|
||||
}
|
@ -66,8 +66,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@ -194,7 +194,7 @@
|
||||
android:layout_margin="@dimen/margin_generic" />
|
||||
|
||||
<LinearLayout
|
||||
gone="@{!viewModel.hasRoot}"
|
||||
gone="@{!viewModel.hasRoot || !viewModel.isConnected}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
@ -202,8 +202,8 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/margin_generic_half"
|
||||
android:paddingTop="@dimen/margin_generic_half">
|
||||
android:paddingTop="@dimen/margin_generic_half"
|
||||
android:paddingBottom="@dimen/margin_generic_half">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sn_logo"
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
<import type="com.topjohnwu.magisk.ui.home.MagiskState" />
|
||||
|
||||
<import type="com.topjohnwu.magisk.ui.home.MagiskItem" />
|
||||
|
||||
<import type="com.topjohnwu.magisk.R" />
|
||||
|
||||
<variable
|
||||
@ -49,7 +51,7 @@
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/install"
|
||||
style="@style/Widget.Button.Text"
|
||||
gone="@{state == MagiskState.LOADING}"
|
||||
gone="@{state == MagiskState.LOADING || !viewModel.isConnected}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
@ -118,7 +120,7 @@
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/latest_version"
|
||||
gone="@{currentVersion == latestVersion}"
|
||||
gone="@{currentVersion == latestVersion || !viewModel.isConnected}"
|
||||
android:layout_width="0dp"
|
||||
style="@style/Widget.Text.Caption.Inactive"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -106,6 +106,8 @@
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/download"
|
||||
style="@style/Widget.Icon"
|
||||
isEnabled="@{viewModel.isConnected}"
|
||||
android:alpha="@{viewModel.isConnected ? 1f : .2f}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
|
Loading…
Reference in New Issue
Block a user