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("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(kotlin("stdlib"))

View File

@ -10,6 +10,7 @@ import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ObservableItem
import com.topjohnwu.magisk.utils.TransitiveText
import com.topjohnwu.magisk.utils.asTransitive
import com.topjohnwu.magisk.utils.set
import com.topjohnwu.magisk.view.MagiskDialog
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
open val showStrip = true
protected val resources get() = get<Resources>()
protected abstract val intermediate: String?
protected abstract val inputResult: String?
override fun onPressed(view: View) {
MagiskDialog(view.context)
.applyTitle(title.getText(resources))
.applyTitle(title.getText(view.resources))
.applyView(getView(view.context))
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = android.R.string.ok
onClick {
intermediate?.let { result ->
inputResult?.let { result ->
preventDismiss = false
value = result
it.dismiss()
@ -125,7 +124,6 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
}
abstract fun getView(context: Context): View
}
abstract class Selector : Value<Int>(), KoinComponent {
@ -141,12 +139,12 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
open val entryValues get() = resources.getArrayOrEmpty(entryValRes)
@get:Bindable
val selectedEntry
get() = entries.getOrNull(value)
override val description: TransitiveText
get() = entries.getOrNull(value)?.asTransitive() ?: TransitiveText.EMPTY
protected inline fun <reified T> setS(
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> =

View File

@ -79,15 +79,15 @@ object ClearRepoCache : SettingsItem.Blank() {
object Hide : SettingsItem.Input() {
override val title = R.string.settings_hide_manager_title.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)
@get:Bindable
val isError get() = value.length > 14 || value.isBlank()
override val intermediate: String?
get() = if (isError) null else value
override val inputResult get() = if (isError) null else value
override fun getView(context: Context) = DialogSettingsAppNameBinding
.inflate(LayoutInflater.from(context)).also { it.data = this }.root
@ -105,8 +105,11 @@ fun HideOrRestore() =
object DownloadPath : SettingsItem.Input() {
override var value = Config.downloadPath
set(value) = setV(value, field, { field = it }) { Config.downloadPath = it }
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:Bindable
@ -135,7 +138,8 @@ object UpdateChannelUrl : SettingsItem.Input() {
override val title = R.string.settings_update_custom.asTransitive()
override var value = Config.customChannelUrl
set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it }
override val intermediate: String? get() = result
override val inputResult get() = result
@get:Bindable
var result = value

View File

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

View File

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

View File

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

View File

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

View File

@ -29,25 +29,24 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/input_icon"
style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}"
android:background="@null"
android:rotation="180"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/input_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/input_indicator"
style="@style/WidgetFoundation.Icon"
android:background="@null"
android:rotation="180"
app:layout_constraintBottom_toTopOf="@+id/input_divider"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back_md2" />
@ -61,12 +60,12 @@
android:orientation="vertical"
android:paddingTop="@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_constraintStart_toEndOf="@+id/input_icon"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/input_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -78,7 +77,7 @@
tools:lines="1"
tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/input_description"
gone="@{item.description.empty}"
android:layout_width="match_parent"
@ -90,34 +89,8 @@
</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>
</com.google.android.material.card.MaterialCardView>
</layout>
</layout>

View File

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

View File

@ -29,25 +29,24 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/selector_icon"
style="@style/WidgetFoundation.Icon"
gone="@{item.icon == 0}"
android:background="@null"
android:rotation="180"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/selector_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_fingerprint" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/selector_indicator"
style="@style/WidgetFoundation.Icon"
android:background="@null"
android:rotation="180"
app:layout_constraintBottom_toTopOf="@+id/selector_divider"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_back_md2" />
@ -61,12 +60,12 @@
android:orientation="vertical"
android:paddingTop="@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_constraintStart_toEndOf="@+id/selector_icon"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/selector_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -78,7 +77,7 @@
tools:lines="1"
tools:text="@tools:sample/lorem/random" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/selector_description"
gone="@{item.description.empty}"
android:layout_width="match_parent"
@ -90,34 +89,8 @@
</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>
</com.google.android.material.card.MaterialCardView>
</layout>
</layout>

View File

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