From 64f35744c41f06d37f10684218973ba073a41cce Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 9 Feb 2020 17:03:05 -0800 Subject: [PATCH] Reorganize home screen layout --- .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 59 +++--- .../main/res/layout/include_home_magisk.xml | 188 ++++-------------- .../main/res/layout/include_home_manager.xml | 131 ++---------- app/src/main/res/values/strings.xml | 4 +- 4 files changed, 83 insertions(+), 299 deletions(-) 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 0883a1c03..fd1176813 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 @@ -40,19 +40,23 @@ class HomeViewModel( val stateMagisk = KObservableField(MagiskState.LOADING) val stateManager = KObservableField(MagiskState.LOADING) - val stateVersionMagisk = KObservableField("") - val stateCodeMagisk = KObservableField(0) - val stateVersionManager = KObservableField("") - val stateCodeManager = KObservableField(0) - val stateCodeStub = KObservableField(0) - val statePackageManager = packageName - val statePackageOriginal = statePackageManager == BuildConfig.APPLICATION_ID + val stateMagiskRemoteVersion = KObservableField(R.string.home_loading.res()) + val stateMagiskInstalledVersion get() = + "${Info.env.magiskVersionString} (${Info.env.magiskVersionCode})" + val stateMagiskMode get() = (if (Config.coreOnly) + R.string.home_extra_mode_safe else R.string.home_extra_mode_normal).res() val stateMagiskProgress = KObservableField(0) + + val stateManagerRemoteVersion = KObservableField(R.string.home_loading.res()) + val stateManagerInstalledVersion = Info.stub?.let { + "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}) (${it.version})" + } ?: "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" + val statePackageName = packageName val stateManagerProgress = KObservableField(0) val stateHideManagerName = R.string.manager.res().let { - if (!statePackageOriginal) { + if (packageName != BuildConfig.APPLICATION_ID) { it.replaceRandomWithSpecial(3) } else { it @@ -80,28 +84,24 @@ class HomeViewModel( } override fun refresh() = repoMagisk.fetchUpdate() - .onErrorReturn { Info.remote } - .subscribeK { updateBy(it) } + .onErrorReturn { null } + .subscribeK { it?.updateUI() } - private fun updateBy(info: UpdateInfo) { + private fun UpdateInfo.updateUI() { stateMagisk.value = when { - !info.magisk.isInstalled -> MagiskState.NOT_INSTALLED - info.magisk.isObsolete -> MagiskState.OBSOLETE + !Info.env.isActive -> MagiskState.NOT_INSTALLED + magisk.isObsolete -> MagiskState.OBSOLETE else -> MagiskState.UP_TO_DATE } stateManager.value = when { - !info.app.isUpdateChannelCorrect && isConnected.value -> MagiskState.NOT_INSTALLED - info.app.isObsolete -> MagiskState.OBSOLETE + !app.isUpdateChannelCorrect && isConnected.value -> MagiskState.NOT_INSTALLED + app.isObsolete -> MagiskState.OBSOLETE else -> MagiskState.UP_TO_DATE } - stateVersionMagisk.value = info.magisk.version - stateVersionManager.value = info.app.version - - stateCodeMagisk.value = info.magisk.versionCode - stateCodeManager.value = info.app.versionCode - stateCodeStub.value = info.stub.versionCode + stateMagiskRemoteVersion.value = "${magisk.version} (${magisk.versionCode})" + stateManagerRemoteVersion.value = "${app.version} (${app.versionCode}) (${stub.versionCode})" ensureEnv() } @@ -153,14 +153,11 @@ class HomeViewModel( } } -} + private val MagiskJson.isObsolete + get() = Info.env.isActive && Info.env.magiskVersionCode < versionCode + val ManagerJson.isUpdateChannelCorrect + get() = versionCode > 0 + val ManagerJson.isObsolete + get() = BuildConfig.VERSION_CODE < versionCode -@Suppress("unused") -val MagiskJson.isInstalled - get() = Info.env.magiskVersionCode > 0 -val MagiskJson.isObsolete - get() = Info.env.magiskVersionCode < versionCode && isInstalled -val ManagerJson.isUpdateChannelCorrect - get() = versionCode > 0 -val ManagerJson.isObsolete - get() = BuildConfig.VERSION_CODE < versionCode +} diff --git a/app/src/main/res/layout/include_home_magisk.xml b/app/src/main/res/layout/include_home_magisk.xml index b99a000c6..074610dc3 100644 --- a/app/src/main/res/layout/include_home_magisk.xml +++ b/app/src/main/res/layout/include_home_magisk.xml @@ -9,8 +9,6 @@ - - + android:layout_width="wrap_content" > @@ -127,41 +124,56 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/home_magisk_remote_title" /> + app:layout_constraintTop_toBottomOf="@id/home_magisk_info_title" /> + app:layout_constraintTop_toBottomOf="@id/home_magisk_info_title" > + android:text="@string/module_section_remote" /> + android:text="@{viewModel.isConnected ? viewModel.stateMagiskRemoteVersion : @string/home_extra_stub_na}" + tools:text="20.1 (12345)" /> + app:layout_constraintTop_toBottomOf="@+id/home_magisk_latest_version"> + android:text="@string/installed" /> + android:text="@{Info.env.isActive ? viewModel.stateMagiskInstalledVersion : @string/home_extra_stub_na}" + tools:text="20.1 (12345)" /> + + + + + + + + @@ -181,144 +193,18 @@ style="@style/W.Home.Card" gone="@{Info.env.magiskVersionCode < 0}" android:layout_width="wrap_content" - android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/app/src/main/res/layout/include_home_manager.xml b/app/src/main/res/layout/include_home_manager.xml index bac7eb66d..87fb6bfc4 100644 --- a/app/src/main/res/layout/include_home_manager.xml +++ b/app/src/main/res/layout/include_home_manager.xml @@ -7,8 +7,6 @@ - - @@ -106,7 +104,6 @@ @@ -125,59 +122,39 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/home_manager_remote_title" /> + app:layout_constraintTop_toBottomOf="@+id/home_manager_info_title" /> + app:layout_constraintTop_toBottomOf="@+id/home_manager_info_title"> + android:text="@string/module_section_remote" /> + android:text="@{viewModel.isConnected ? viewModel.stateManagerRemoteVersion : @string/home_extra_stub_na}" + tools:text="8.0.0 (123) (10)" /> - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/home_manager_latest_version"> + android:text="@string/installed" /> + android:text="@{viewModel.stateManagerInstalledVersion}" + tools:text="8.0.0 (123) (10)" /> @@ -198,84 +175,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -324,7 +223,7 @@ @@ -339,4 +238,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c00bbcb01..6c2e63690 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,7 +28,9 @@ Source Magisk is, and always will be, free and open-source. You can however show us that you care by sending a small donation. - Your device + Loading… + + Device Info Manufacturer Model