Remove strip in settings item

This commit is contained in:
topjohnwu 2020-08-11 00:54:19 -07:00
parent 9df6b0618a
commit 87b6bf2c26
11 changed files with 46 additions and 101 deletions

View File

@ -82,7 +82,7 @@ dependencies {
implementation(project(":app:signing")) implementation(project(":app:signing"))
implementation("com.github.topjohnwu:jtar:1.0.0") implementation("com.github.topjohnwu:jtar:1.0.0")
implementation("com.github.topjohnwu:indeterminate-checkbox:1.0.6") implementation("com.github.topjohnwu:indeterminate-checkbox:1.0.7")
implementation("com.jakewharton.timber:timber:4.7.1") implementation("com.jakewharton.timber:timber:4.7.1")
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))

View File

@ -10,6 +10,7 @@ import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.databinding.ObservableItem
import com.topjohnwu.magisk.utils.TransitiveText import com.topjohnwu.magisk.utils.TransitiveText
import com.topjohnwu.magisk.utils.asTransitive
import com.topjohnwu.magisk.utils.set import com.topjohnwu.magisk.utils.set
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
@ -94,22 +95,20 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
} }
} }
abstract class Input : Value<String>(), KoinComponent { abstract class Input : Value<String>() {
override val layoutRes = R.layout.item_settings_input override val layoutRes = R.layout.item_settings_input
open val showStrip = true
protected val resources get() = get<Resources>() protected abstract val inputResult: String?
protected abstract val intermediate: String?
override fun onPressed(view: View) { override fun onPressed(view: View) {
MagiskDialog(view.context) MagiskDialog(view.context)
.applyTitle(title.getText(resources)) .applyTitle(title.getText(view.resources))
.applyView(getView(view.context)) .applyView(getView(view.context))
.applyButton(MagiskDialog.ButtonType.POSITIVE) { .applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = android.R.string.ok titleRes = android.R.string.ok
onClick { onClick {
intermediate?.let { result -> inputResult?.let { result ->
preventDismiss = false preventDismiss = false
value = result value = result
it.dismiss() it.dismiss()
@ -125,7 +124,6 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
} }
abstract fun getView(context: Context): View abstract fun getView(context: Context): View
} }
abstract class Selector : Value<Int>(), KoinComponent { abstract class Selector : Value<Int>(), KoinComponent {
@ -141,12 +139,12 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
open val entryValues get() = resources.getArrayOrEmpty(entryValRes) open val entryValues get() = resources.getArrayOrEmpty(entryValRes)
@get:Bindable @get:Bindable
val selectedEntry override val description: TransitiveText
get() = entries.getOrNull(value) get() = entries.getOrNull(value)?.asTransitive() ?: TransitiveText.EMPTY
protected inline fun <reified T> setS( protected inline fun <reified T> setS(
new: T, old: T, setter: (T) -> Unit, afterChanged: (T) -> Unit = {}) { new: T, old: T, setter: (T) -> Unit, afterChanged: (T) -> Unit = {}) {
setV(new, old, setter, BR.selectedEntry, BR.description, afterChanged = afterChanged) setV(new, old, setter, BR.description, afterChanged = afterChanged)
} }
private fun Resources.getArrayOrEmpty(id: Int): Array<String> = private fun Resources.getArrayOrEmpty(id: Int): Array<String> =

View File

@ -79,15 +79,15 @@ object ClearRepoCache : SettingsItem.Blank() {
object Hide : SettingsItem.Input() { object Hide : SettingsItem.Input() {
override val title = R.string.settings_hide_manager_title.asTransitive() override val title = R.string.settings_hide_manager_title.asTransitive()
override val description = R.string.settings_hide_manager_summary.asTransitive() override val description = R.string.settings_hide_manager_summary.asTransitive()
override val showStrip = false
override var value = resources.getString(R.string.re_app_name) @get:Bindable
override var value = "Manager"
set(value) = setV(value, field, { field = it }, BR.error) set(value) = setV(value, field, { field = it }, BR.error)
@get:Bindable @get:Bindable
val isError get() = value.length > 14 || value.isBlank() val isError get() = value.length > 14 || value.isBlank()
override val intermediate: String? override val inputResult get() = if (isError) null else value
get() = if (isError) null else value
override fun getView(context: Context) = DialogSettingsAppNameBinding override fun getView(context: Context) = DialogSettingsAppNameBinding
.inflate(LayoutInflater.from(context)).also { it.data = this }.root .inflate(LayoutInflater.from(context)).also { it.data = this }.root
@ -105,8 +105,11 @@ fun HideOrRestore() =
object DownloadPath : SettingsItem.Input() { object DownloadPath : SettingsItem.Input() {
override var value = Config.downloadPath override var value = Config.downloadPath
set(value) = setV(value, field, { field = it }) { Config.downloadPath = it } set(value) = setV(value, field, { field = it }) { Config.downloadPath = it }
override val title = R.string.settings_download_path_title.asTransitive() override val title = R.string.settings_download_path_title.asTransitive()
override val intermediate: String? override val description get() = path.asTransitive()
override val inputResult: String?
get() = if (Utils.ensureDownloadPath(result) != null) result else null get() = if (Utils.ensureDownloadPath(result) != null) result else null
@get:Bindable @get:Bindable
@ -135,7 +138,8 @@ object UpdateChannelUrl : SettingsItem.Input() {
override val title = R.string.settings_update_custom.asTransitive() override val title = R.string.settings_update_custom.asTransitive()
override var value = Config.customChannelUrl override var value = Config.customChannelUrl
set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it } set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it }
override val intermediate: String? get() = result
override val inputResult get() = result
@get:Bindable @get:Bindable
var result = value var result = value

View File

@ -259,7 +259,6 @@ fun setState(view: IndeterminateCheckBox, state: Boolean?) {
@InverseBindingAdapter(attribute = "state") @InverseBindingAdapter(attribute = "state")
fun getState(view: IndeterminateCheckBox) = view.state fun getState(view: IndeterminateCheckBox) = view.state
@BindingAdapter("stateAttrChanged") @BindingAdapter("stateAttrChanged")
fun setListeners( fun setListeners(
view: IndeterminateCheckBox, view: IndeterminateCheckBox,

View File

@ -17,7 +17,7 @@
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/margin_generic"> android:padding="@dimen/margin_generic">
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/dialog_custom_download_title" android:id="@+id/dialog_custom_download_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -30,7 +30,6 @@
android:paddingEnd="@dimen/l_50" android:paddingEnd="@dimen/l_50"
android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l1}" android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:spanCount="1"
tools:layout_marginTop="24dp" tools:layout_marginTop="24dp"
tools:listitem="@layout/item_settings_toggle" tools:listitem="@layout/item_settings_toggle"
tools:paddingTop="@dimen/l1" /> tools:paddingTop="@dimen/l1" />

View File

@ -29,7 +29,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/blank_icon" android:id="@+id/blank_icon"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}" gone="@{item.icon == 0}"
@ -41,7 +41,7 @@
app:srcCompat="@{item.icon}" app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" /> tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/blank_indicator" android:id="@+id/blank_indicator"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
android:background="@null" android:background="@null"
@ -65,7 +65,7 @@
app:layout_constraintStart_toEndOf="@+id/blank_icon" app:layout_constraintStart_toEndOf="@+id/blank_icon"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/blank_title" android:id="@+id/blank_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -77,7 +77,7 @@
tools:lines="2" tools:lines="2"
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/blank_description" android:id="@+id/blank_description"
gone="@{item.description.empty}" gone="@{item.description.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -29,25 +29,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/input_icon" android:id="@+id/input_icon"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}" gone="@{item.icon == 0}"
android:background="@null" android:background="@null"
android:rotation="180" android:rotation="180"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/input_divider"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@{item.icon}" app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" /> tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/input_indicator" android:id="@+id/input_indicator"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
android:background="@null" android:background="@null"
android:rotation="180" android:rotation="180"
app:layout_constraintBottom_toTopOf="@+id/input_divider" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back_md2" /> app:srcCompat="@drawable/ic_back_md2" />
@ -61,12 +60,12 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="@dimen/l1" android:paddingTop="@dimen/l1"
android:paddingBottom="@dimen/l1" android:paddingBottom="@dimen/l1"
app:layout_constraintBottom_toTopOf="@+id/input_divider" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/input_indicator" app:layout_constraintEnd_toStartOf="@+id/input_indicator"
app:layout_constraintStart_toEndOf="@+id/input_icon" app:layout_constraintStart_toEndOf="@+id/input_icon"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/input_title" android:id="@+id/input_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -78,7 +77,7 @@
tools:lines="1" tools:lines="1"
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/input_description" android:id="@+id/input_description"
gone="@{item.description.empty}" gone="@{item.description.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -90,34 +89,8 @@
</LinearLayout> </LinearLayout>
<View
android:id="@+id/input_divider"
gone="@{item.value.empty || !item.showStrip}"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha=".5"
android:background="?colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/input_text" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/input_selection"
gone="@{item.value.empty || !item.showStrip}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/l1"
android:paddingTop="@dimen/l_75"
android:paddingEnd="@dimen/l1"
android:paddingBottom="@dimen/l_75"
android:text="@{item.value}"
android:textAppearance="@style/AppearanceFoundation.Tiny.Variant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/input_text"
app:layout_constraintTop_toTopOf="@+id/input_divider"
tools:text="@tools:sample/lorem" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout> </layout>

View File

@ -17,7 +17,7 @@
android:paddingTop="@dimen/l1" android:paddingTop="@dimen/l1"
android:paddingBottom="@dimen/l_50"> android:paddingBottom="@dimen/l_50">
<androidx.appcompat.widget.AppCompatTextView <TextView
gone="@{item.title.empty}" gone="@{item.title.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -26,7 +26,7 @@
android:textStyle="bold" android:textStyle="bold"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<androidx.appcompat.widget.AppCompatTextView <TextView
gone="@{item.description.empty}" gone="@{item.description.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -29,25 +29,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/selector_icon" android:id="@+id/selector_icon"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}" gone="@{item.icon == 0}"
android:background="@null" android:background="@null"
android:rotation="180" android:rotation="180"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/selector_divider"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@{item.icon}" app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" /> tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/selector_indicator" android:id="@+id/selector_indicator"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
android:background="@null" android:background="@null"
android:rotation="180" android:rotation="180"
app:layout_constraintBottom_toTopOf="@+id/selector_divider" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back_md2" /> app:srcCompat="@drawable/ic_back_md2" />
@ -61,12 +60,12 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="@dimen/l1" android:paddingTop="@dimen/l1"
android:paddingBottom="@dimen/l1" android:paddingBottom="@dimen/l1"
app:layout_constraintBottom_toTopOf="@+id/selector_divider" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/selector_indicator" app:layout_constraintEnd_toStartOf="@+id/selector_indicator"
app:layout_constraintStart_toEndOf="@+id/selector_icon" app:layout_constraintStart_toEndOf="@+id/selector_icon"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/selector_title" android:id="@+id/selector_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -78,7 +77,7 @@
tools:lines="1" tools:lines="1"
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/selector_description" android:id="@+id/selector_description"
gone="@{item.description.empty}" gone="@{item.description.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -90,34 +89,8 @@
</LinearLayout> </LinearLayout>
<View
android:id="@+id/selector_divider"
gone="@{item.selectedEntry == null}"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha=".5"
android:background="?colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/selector_text" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/selector_selection"
gone="@{item.selectedEntry == null}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/l1"
android:paddingTop="@dimen/l_75"
android:paddingEnd="@dimen/l1"
android:paddingBottom="@dimen/l_75"
android:text="@{item.selectedEntry}"
android:textAppearance="@style/AppearanceFoundation.Tiny.Variant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/selector_text"
app:layout_constraintTop_toTopOf="@+id/selector_divider"
tools:text="@tools:sample/lorem" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout> </layout>

View File

@ -31,7 +31,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView <ImageView
android:id="@+id/toggle_icon" android:id="@+id/toggle_icon"
style="@style/WidgetFoundation.Icon" style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}" gone="@{item.icon == 0}"
@ -42,11 +42,10 @@
app:srcCompat="@{item.icon}" app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" /> tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/toggle_indicator" android:id="@+id/toggle_indicator"
style="@style/WidgetFoundation.Switch" android:checked="@={item.value}"
isEnabled="@{item.enabled}" isEnabled="@{item.enabled}"
isSelected="@{item.value}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/l_25" android:layout_marginEnd="@dimen/l_25"
@ -68,7 +67,7 @@
app:layout_constraintStart_toEndOf="@+id/toggle_icon" app:layout_constraintStart_toEndOf="@+id/toggle_icon"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/toggle_title" android:id="@+id/toggle_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -80,7 +79,7 @@
tools:lines="1" tools:lines="1"
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView <TextView
android:id="@+id/toggle_description" android:id="@+id/toggle_description"
gone="@{item.description.empty}" gone="@{item.description.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -96,4 +95,4 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout> </layout>