diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index c829a01fe..86d13c915 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -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() { 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() { 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 = 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 1f75c1bc3..671956c90 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 @@ -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 diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index b9338b3f0..ad61131f8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -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 \ No newline at end of file + ?: -1 + +@BindingAdapter("isEnabled") +fun setEnabled(view: View, isEnabled: Boolean) { + view.isEnabled = isEnabled +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_magisk.xml b/app/src/main/res/layout/fragment_magisk.xml index 8491913cc..ff32122a5 100644 --- a/app/src/main/res/layout/fragment_magisk.xml +++ b/app/src/main/res/layout/fragment_magisk.xml @@ -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" /> @@ -202,8 +202,8 @@ + android:paddingTop="@dimen/margin_generic_half" + android:paddingBottom="@dimen/margin_generic_half"> + +