Reorganize home screen layout

This commit is contained in:
topjohnwu 2020-02-09 17:03:05 -08:00
parent b512528148
commit 64f35744c4
4 changed files with 83 additions and 299 deletions

View File

@ -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
}

View File

@ -9,8 +9,6 @@
<import type="com.topjohnwu.magisk.core.InfoKt" />
<import type="com.topjohnwu.magisk.core.Config" />
<import type="com.topjohnwu.magisk.ui.home.MagiskState" />
<variable
@ -108,17 +106,16 @@
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card.First"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:alpha="@{viewModel.stateCodeMagisk &lt; 0 ? .5f : 1f}">
android:layout_width="wrap_content" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_magisk_remote_title"
android:id="@+id/home_magisk_info_title"
style="@style/W.Home.Title"
android:text="@string/module_section_remote"
android:text="@string/home_device_info_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -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" />
<LinearLayout
android:id="@+id/home_magisk_remote_version"
android:id="@+id/home_magisk_latest_version"
style="@style/W.Home.Item.Top"
invisible="@{viewModel.stateCodeMagisk &lt; 0}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_remote_title">
app:layout_constraintTop_toBottomOf="@id/home_magisk_info_title" >
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_version" />
android:text="@string/module_section_remote" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{viewModel.stateVersionMagisk}"
tools:text="20.1" />
android:text="@{viewModel.isConnected ? viewModel.stateMagiskRemoteVersion : @string/home_extra_stub_na}"
tools:text="20.1 (12345)" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_magisk_remote_version_code"
style="@style/W.Home.Item.Bottom"
invisible="@{viewModel.stateCodeMagisk &lt; 0}"
android:id="@+id/home_magisk_installed_version"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_remote_version">
app:layout_constraintTop_toBottomOf="@+id/home_magisk_latest_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_code" />
android:text="@string/installed" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Integer.toString(viewModel.stateCodeMagisk)}"
tools:text="12345" />
android:text="@{Info.env.isActive ? viewModel.stateMagiskInstalledVersion : @string/home_extra_stub_na}"
tools:text="20.1 (12345)" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_magisk_mode"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_installed_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_mode" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.env.isActive ? viewModel.stateMagiskMode : @string/home_extra_stub_na}"
tools:text="Normal" />
</LinearLayout>
@ -181,144 +193,18 @@
style="@style/W.Home.Card"
gone="@{Info.env.magiskVersionCode &lt; 0}"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_magisk_internal_title"
style="@style/W.Home.Title"
android:text="@string/installed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_internal_title" />
<LinearLayout
android:id="@+id/home_magisk_internal_version"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_internal_title">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_version" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.env.magiskVersionString}"
tools:text="20.1" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_magisk_internal_version_code"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_internal_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_code" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Integer.toString(Info.env.magiskVersionCode)}"
tools:text="12345" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card"
gone="@{Info.env.magiskVersionCode &lt; 0}"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_magisk_details_title"
style="@style/W.Home.Title"
android:text="@string/home_details_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_details_title" />
<LinearLayout
android:id="@+id/home_magisk_internal_mode"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_details_title">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_mode" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Config.coreOnly ? @string/home_extra_mode_safe : @string/home_extra_mode_normal}"
tools:text="Normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_magisk_internal_connection"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_internal_mode">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_connection" />
<!--todo(topjohnwu) fix connection type-->
<!--don't forget to bind verbose values to proper resources-->
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_magisk_extra_connection_value"
style="@style/W.Home.ItemContent.Right"
tools:text="Normal" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card"
gone="@{Info.env.magiskVersionCode &lt; 0}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:onClick="@{() -> viewModel.onDeletePressed()}">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<View
android:id="@+id/view"
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -340,8 +226,8 @@
<androidx.appcompat.widget.AppCompatImageView
style="@style/WidgetFoundation.Icon.Error"
android:layout_marginTop="@dimen/l_50"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_delete"
@ -357,4 +243,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
</layout>

View File

@ -7,8 +7,6 @@
<import type="com.topjohnwu.magisk.core.Info" />
<import type="com.topjohnwu.magisk.BuildConfig" />
<import type="com.topjohnwu.magisk.core.InfoKt" />
<import type="com.topjohnwu.magisk.ui.home.MagiskState" />
@ -106,7 +104,6 @@
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card.First"
android:layout_width="wrap_content"
android:alpha="@{viewModel.stateCodeManager &lt; 0 ? .5f : 1f}"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
@ -114,9 +111,9 @@
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_manager_remote_title"
android:id="@+id/home_manager_info_title"
style="@style/W.Home.Title"
android:text="@string/module_section_remote"
android:text="@string/home_device_info_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -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" />
<LinearLayout
android:id="@+id/home_manager_remote_version"
android:id="@+id/home_manager_latest_version"
style="@style/W.Home.Item.Top"
invisible="@{viewModel.stateCodeManager &lt; 0}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_remote_title">
app:layout_constraintTop_toBottomOf="@+id/home_manager_info_title">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_version" />
android:text="@string/module_section_remote" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{viewModel.stateVersionManager}"
tools:text="20.1" />
android:text="@{viewModel.isConnected ? viewModel.stateManagerRemoteVersion : @string/home_extra_stub_na}"
tools:text="8.0.0 (123) (10)" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_manager_remote_version_code"
style="@style/W.Home.Item"
invisible="@{viewModel.stateCodeManager &lt; 0}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_remote_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_code" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Integer.toString(viewModel.stateCodeManager)}"
tools:text="12345" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_manager_remote_stub_version_code"
android:id="@+id/home_manager_installed_version"
style="@style/W.Home.Item.Bottom"
invisible="@{viewModel.stateCodeManager &lt; 0}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_remote_version_code">
app:layout_constraintTop_toBottomOf="@+id/home_manager_latest_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_stub" />
android:text="@string/installed" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Integer.toString(viewModel.stateCodeStub)}"
tools:text="5" />
android:text="@{viewModel.stateManagerInstalledVersion}"
tools:text="8.0.0 (123) (10)" />
</LinearLayout>
@ -198,84 +175,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_manager_internal_title"
style="@style/W.Home.Title"
android:text="@string/installed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
style="@style/W.Home.Section"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_internal_title" />
<LinearLayout
android:id="@+id/home_manager_internal_version"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_internal_title">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_version" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{BuildConfig.VERSION_NAME}"
tools:text="20.1" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_manager_internal_version_code"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_internal_version">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_code" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Integer.toString(BuildConfig.VERSION_CODE)}"
tools:text="12345" />
</LinearLayout>
<LinearLayout
android:id="@+id/home_manager_internal_stub_version_code"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_internal_version_code">
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent"
android:text="@string/home_extra_stub" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/W.Home.ItemContent.Right"
android:text="@{Info.stub != null ? Integer.toString(Info.stub.version) : @string/home_extra_stub_na}"
tools:text="5" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="@style/W.Home.Card"
gone="@{Info.env.magiskVersionCode &lt; 0}"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
@ -324,7 +223,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_manager_extra_connection_value"
style="@style/W.Home.ItemContent.Right"
android:text="@{viewModel.statePackageManager}"
android:text="@{viewModel.statePackageName}"
tools:text="com.topjohnwu.magisk" />
</LinearLayout>
@ -339,4 +238,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
</layout>

View File

@ -28,7 +28,9 @@
<string name="home_item_source">Source</string>
<string name="home_support_content">Magisk is, and always will be, free and open-source. You can however show us that you care by sending a small donation.</string>
<string name="home_device_title">Your device</string>
<string name="home_loading">Loading…</string>
<string name="home_device_title">Device</string>
<string name="home_device_info_title">Info</string>
<string name="home_device_extra_manufacturer">Manufacturer</string>
<string name="home_device_extra_model">Model</string>