From e5959377402bb8f68f38c38f65aa333c0349bfb3 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Mon, 7 Oct 2019 20:09:12 +0200 Subject: [PATCH] Added versions to home screen To overview (when updatable) - It is very hard to spot a difference in versions so versions are now regarded as commit messages (after dash [-]) when applicable - This will result in more clear, understandable text - Bleeding edge (canary) user would see: ffed229 > ffe02ed or 19.4 > ffe02ed as opposed to: 19.4-ffed229 (19404) 19.5-ffe02ed (19501) - Regular beta+ user would see: 19.4 > 19.5 To bottom of the screen - This change is with respect to regular user. They don't care which version they run as long as they know that "up-to-date" is a gold standard - It takes tons of real-estate on the screen which takes away the glance-ability from the overview. --- .../main/java/com/topjohnwu/magisk/Info.kt | 2 + .../magisk/redesign/home/HomeViewModel.kt | 22 ++++++++ app/src/main/res/layout/fragment_home_md2.xml | 55 +++++++++++++++---- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/Info.kt b/app/src/main/java/com/topjohnwu/magisk/Info.kt index f226ae5cf..7ff76faff 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Info.kt @@ -6,8 +6,10 @@ import com.topjohnwu.superuser.ShellUtils object Info { + @JvmStatic var magiskVersionCode = -1 + @JvmStatic var magiskVersionString = "" var remote = UpdateInfo() diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt index 2eb5b60cb..3c61fbf9f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt @@ -44,6 +44,10 @@ class HomeViewModel( MagiskState.OBSOLETE -> R.string.obsolete_md2.res() } } + val stateVersionMagisk = Info.magiskVersionString + val stateVersionManager = BuildConfig.VERSION_NAME + val stateVersionUpdateMagisk = KObservableField("") + val stateVersionUpdateManager = KObservableField("") val stateHideManagerName = R.string.manager.res().let { val result = R.string.manager.res() @@ -80,6 +84,22 @@ class HomeViewModel( info.app.isObsolete -> MagiskState.OBSOLETE else -> MagiskState.UP_TO_DATE } + + stateVersionUpdateMagisk.value = when { + info.magisk.isObsolete -> "%s > %s".format( + Info.magiskVersionString.clipVersion(), + info.magisk.version.clipVersion() + ) + else -> "" + } + + stateVersionUpdateManager.value = when { + info.app.isObsolete -> "%s > %s".format( + BuildConfig.VERSION_NAME.clipVersion(), + info.app.version.clipVersion() + ) + else -> "" + } } fun onDeletePressed() {} @@ -97,6 +117,8 @@ val ManagerJson.isUpdateChannelCorrect val ManagerJson.isObsolete get() = BuildConfig.VERSION_CODE < versionCode +fun String.clipVersion() = substringAfter('-') + inline fun > itemBindingOf( crossinline body: (ItemBinding<*>) -> Unit = {} ) = OnItemBind { itemBinding, _, item -> diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index 136edee2b..df173d3fd 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -5,6 +5,10 @@ + + + + + + + app:layout_constraintTop_toBottomOf="@+id/home_magisk_version"> + + + app:layout_constraintTop_toBottomOf="@+id/home_manager_version"> - - + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/l1"> + + + +