Added simple ui blocks for whenever connection drops out

This commit is contained in:
Viktor De Pasquale 2019-08-06 16:14:58 +02:00 committed by John Wu
parent 4ef19d17da
commit 085ede6d93
6 changed files with 37 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const.Key.OPEN_SECTION 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.settings.SettingsFragment
import com.topjohnwu.magisk.ui.superuser.SuperuserFragment import com.topjohnwu.magisk.ui.superuser.SuperuserFragment
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.net.Networking
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.androidx.viewmodel.ext.android.viewModel
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -57,6 +57,10 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
checkHideSection() checkHideSection()
setSupportActionBar(binding.mainInclude.mainToolbar) setSupportActionBar(binding.mainInclude.mainToolbar)
viewModel.isConnected.addOnPropertyChangedCallback {
checkHideSection()
}
if (savedInstanceState == null) { if (savedInstanceState == null) {
intent.getStringExtra(OPEN_SECTION)?.let { intent.getStringExtra(OPEN_SECTION)?.let {
onEventDispatched(Navigation.fromSection(it)) onEventDispatched(Navigation.fromSection(it))
@ -110,7 +114,7 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
menu.findItem(R.id.modulesFragment).isVisible = menu.findItem(R.id.modulesFragment).isVisible =
Shell.rootAccess() && Info.magiskVersionCode >= 0 Shell.rootAccess() && Info.magiskVersionCode >= 0
menu.findItem(R.id.reposFragment).isVisible = 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 = menu.findItem(R.id.logFragment).isVisible =
Shell.rootAccess() Shell.rootAccess()
menu.findItem(R.id.superuserFragment).isVisible = menu.findItem(R.id.superuserFragment).isVisible =

View File

@ -25,7 +25,10 @@ class HomeViewModel(
val isForceEncryption = KObservableField(Info.keepEnc) val isForceEncryption = KObservableField(Info.keepEnc)
val isKeepVerity = KObservableField(Info.keepVerity) 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) { val magiskStateText = Observer(magiskState) {
when (magiskState.value) { when (magiskState.value) {
MagiskState.NO_ROOT -> TODO() 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) { val managerStateText = Observer(managerState) {
when (managerState.value) { when (managerState.value) {
MagiskState.NO_ROOT -> "wtf" MagiskState.NO_ROOT -> "wtf"
@ -89,6 +95,9 @@ class HomeViewModel(
isKeepVerity.addOnPropertyChangedCallback { isKeepVerity.addOnPropertyChangedCallback {
Info.keepVerity = it ?: return@addOnPropertyChangedCallback Info.keepVerity = it ?: return@addOnPropertyChangedCallback
} }
isConnected.addOnPropertyChangedCallback {
if (it == true) refresh()
}
refresh() refresh()
} }
@ -154,8 +163,8 @@ class HomeViewModel(
magiskRepo.fetchUpdate() magiskRepo.fetchUpdate()
.applyViewModel(this) .applyViewModel(this)
.doOnSubscribeUi { .doOnSubscribeUi {
magiskState.value = MagiskState.LOADING _magiskState.value = MagiskState.LOADING
managerState.value = MagiskState.LOADING _managerState.value = MagiskState.LOADING
ctsState.value = SafetyNetState.IDLE ctsState.value = SafetyNetState.IDLE
basicIntegrityState.value = SafetyNetState.IDLE basicIntegrityState.value = SafetyNetState.IDLE
safetyNetTitle.value = R.string.safetyNet_check_text safetyNetTitle.value = R.string.safetyNet_check_text
@ -170,7 +179,7 @@ class HomeViewModel(
private fun updateSelf() { private fun updateSelf() {
state = State.LOADED state = State.LOADED
magiskState.value = when (Info.magiskVersionCode) { _magiskState.value = when (Info.magiskVersionCode) {
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED
!in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE !in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
else -> MagiskState.UP_TO_DATE else -> MagiskState.UP_TO_DATE
@ -185,7 +194,7 @@ class HomeViewModel(
magiskLatestVersion.value = version magiskLatestVersion.value = version
.format(Info.remote.magisk.version, Info.remote.magisk.versionCode) .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 Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED //wrong update channel
in (BuildConfig.VERSION_CODE + 1)..Int.MAX_VALUE -> MagiskState.OBSOLETE in (BuildConfig.VERSION_CODE + 1)..Int.MAX_VALUE -> MagiskState.OBSOLETE
else -> MagiskState.UP_TO_DATE else -> MagiskState.UP_TO_DATE

View File

@ -216,3 +216,8 @@ fun setScrollListener(view: RecyclerView, listener: InverseBindingListener) {
fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayoutManager) fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayoutManager)
?.findLastCompletelyVisibleItemPosition() ?.findLastCompletelyVisibleItemPosition()
?: -1 ?: -1
@BindingAdapter("isEnabled")
fun setEnabled(view: View, isEnabled: Boolean) {
view.isEnabled = isEnabled
}

View File

@ -66,8 +66,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="@string/app_name" android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" android:textAppearance="@style/TextAppearance.AppCompat.Headline"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@ -194,7 +194,7 @@
android:layout_margin="@dimen/margin_generic" /> android:layout_margin="@dimen/margin_generic" />
<LinearLayout <LinearLayout
gone="@{!viewModel.hasRoot}" gone="@{!viewModel.hasRoot || !viewModel.isConnected}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@ -202,8 +202,8 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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 <ImageView
android:id="@+id/sn_logo" android:id="@+id/sn_logo"

View File

@ -7,6 +7,8 @@
<import type="com.topjohnwu.magisk.ui.home.MagiskState" /> <import type="com.topjohnwu.magisk.ui.home.MagiskState" />
<import type="com.topjohnwu.magisk.ui.home.MagiskItem" />
<import type="com.topjohnwu.magisk.R" /> <import type="com.topjohnwu.magisk.R" />
<variable <variable
@ -49,7 +51,7 @@
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/install" android:id="@+id/install"
style="@style/Widget.Button.Text" style="@style/Widget.Button.Text"
gone="@{state == MagiskState.LOADING}" gone="@{state == MagiskState.LOADING || !viewModel.isConnected}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
@ -118,7 +120,7 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/latest_version" android:id="@+id/latest_version"
gone="@{currentVersion == latestVersion}" gone="@{currentVersion == latestVersion || !viewModel.isConnected}"
android:layout_width="0dp" android:layout_width="0dp"
style="@style/Widget.Text.Caption.Inactive" style="@style/Widget.Text.Caption.Inactive"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -106,6 +106,8 @@
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/download" android:id="@+id/download"
style="@style/Widget.Icon" style="@style/Widget.Icon"
isEnabled="@{viewModel.isConnected}"
android:alpha="@{viewModel.isConnected ? 1f : .2f}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"