Improve Cards layout number controls
This commit is contained in:
@@ -2,10 +2,8 @@ package se.ajpanton.notificationsmaster
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.Button
|
||||||
import android.widget.ArrayAdapter
|
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import android.widget.Spinner
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
@@ -50,10 +48,10 @@ class CardsLayoutFragment : Fragment(R.layout.fragment_cards_layout) {
|
|||||||
currentSettings: (VisibilityPolicy) -> CardsGridSettings,
|
currentSettings: (VisibilityPolicy) -> CardsGridSettings,
|
||||||
update: (VisibilityPolicy, CardsGridSettings) -> VisibilityPolicy,
|
update: (VisibilityPolicy, CardsGridSettings) -> VisibilityPolicy,
|
||||||
) {
|
) {
|
||||||
controls.rows.bindNumbers(0..5, initial.maxRows) { value ->
|
controls.rows.bind(0..5, initial.maxRows) { value ->
|
||||||
save(currentSettings, update) { it.copy(maxRows = value) }
|
save(currentSettings, update) { it.copy(maxRows = value) }
|
||||||
}
|
}
|
||||||
controls.icons.bindNumbers(1..15, initial.maxIconsPerRow) { value ->
|
controls.icons.bind(1..15, initial.maxIconsPerRow) { value ->
|
||||||
save(currentSettings, update) { it.copy(maxIconsPerRow = value) }
|
save(currentSettings, update) { it.copy(maxIconsPerRow = value) }
|
||||||
}
|
}
|
||||||
controls.even.isChecked = initial.evenDistribution
|
controls.even.isChecked = initial.evenDistribution
|
||||||
@@ -90,48 +88,57 @@ class CardsLayoutFragment : Fragment(R.layout.fragment_cards_layout) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Spinner.bindNumbers(range: IntRange, selected: Int, changed: (Int) -> Unit) {
|
private fun NumberStepper.bind(range: IntRange, selected: Int, changed: (Int) -> Unit) {
|
||||||
var current = selected
|
var current = selected
|
||||||
adapter = ArrayAdapter(
|
fun show() {
|
||||||
requireContext(),
|
value.text = current.toString()
|
||||||
android.R.layout.simple_spinner_dropdown_item,
|
minus.isEnabled = current > range.first
|
||||||
range.map(Int::toString),
|
plus.isEnabled = current < range.last
|
||||||
)
|
|
||||||
setSelection(selected - range.first, false)
|
|
||||||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
|
||||||
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
|
||||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
|
||||||
val value = range.first + position
|
|
||||||
if (value != current) {
|
|
||||||
current = value
|
|
||||||
changed(value)
|
|
||||||
}
|
}
|
||||||
|
fun step(amount: Int) {
|
||||||
|
val next = (current + amount).coerceIn(range)
|
||||||
|
if (next != current) {
|
||||||
|
current = next
|
||||||
|
show()
|
||||||
|
changed(next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
minus.setOnClickListener { step(-1) }
|
||||||
|
plus.setOnClickListener { step(1) }
|
||||||
|
show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun controls(lockscreen: Boolean): Controls {
|
private fun controls(lockscreen: Boolean): Controls {
|
||||||
val b = binding!!
|
val b = binding!!
|
||||||
return if (lockscreen) b.lockscreenSettings.run {
|
return if (lockscreen) b.lockscreenSettings.run {
|
||||||
Controls(
|
Controls(
|
||||||
lockscreenMaxRows,
|
NumberStepper(lockscreenMaxRowsMinus, lockscreenMaxRows, lockscreenMaxRowsPlus),
|
||||||
lockscreenMaxIcons,
|
NumberStepper(lockscreenMaxIconsMinus, lockscreenMaxIcons, lockscreenMaxIconsPlus),
|
||||||
lockscreenEvenDistribution,
|
lockscreenEvenDistribution,
|
||||||
lockscreenLimitWidth,
|
lockscreenLimitWidth,
|
||||||
lockscreenIconHeight,
|
lockscreenIconHeight,
|
||||||
lockscreenIconHeightValue,
|
lockscreenIconHeightValue,
|
||||||
)
|
)
|
||||||
} else b.aodSettings.run {
|
} else b.aodSettings.run {
|
||||||
Controls(aodMaxRows, aodMaxIcons, aodEvenDistribution, aodLimitWidth, aodIconHeight, aodIconHeightValue)
|
Controls(
|
||||||
|
NumberStepper(aodMaxRowsMinus, aodMaxRows, aodMaxRowsPlus),
|
||||||
|
NumberStepper(aodMaxIconsMinus, aodMaxIcons, aodMaxIconsPlus),
|
||||||
|
aodEvenDistribution,
|
||||||
|
aodLimitWidth,
|
||||||
|
aodIconHeight,
|
||||||
|
aodIconHeightValue,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class Controls(
|
private data class Controls(
|
||||||
val rows: Spinner,
|
val rows: NumberStepper,
|
||||||
val icons: Spinner,
|
val icons: NumberStepper,
|
||||||
val even: SwitchMaterial,
|
val even: SwitchMaterial,
|
||||||
val limit: SwitchMaterial,
|
val limit: SwitchMaterial,
|
||||||
val height: SeekBar,
|
val height: SeekBar,
|
||||||
val heightValue: TextView,
|
val heightValue: TextView,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private data class NumberStepper(val minus: Button, val value: TextView, val plus: Button)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,17 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="Max rows" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="Max rows" />
|
||||||
<Spinner android:id="@+id/aod_max_rows" android:layout_width="wrap_content" android:layout_height="wrap_content" android:popupBackground="@drawable/dropdown_popup_background" />
|
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/aod_max_rows_minus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Decrease max rows" android:text="−" />
|
||||||
|
<TextView android:id="@+id/aod_max_rows" android:layout_width="48dp" android:layout_height="wrap_content" android:gravity="center" android:textAppearance="?attr/textAppearanceBody1" />
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/aod_max_rows_plus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Increase max rows" android:text="+" />
|
||||||
|
</LinearLayout>
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Max icons per row" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Max icons per row" />
|
||||||
<Spinner android:id="@+id/aod_max_icons" android:layout_width="wrap_content" android:layout_height="wrap_content" android:popupBackground="@drawable/dropdown_popup_background" />
|
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/aod_max_icons_minus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Decrease max icons per row" android:text="−" />
|
||||||
|
<TextView android:id="@+id/aod_max_icons" android:layout_width="48dp" android:layout_height="wrap_content" android:gravity="center" android:textAppearance="?attr/textAppearanceBody1" />
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/aod_max_icons_plus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Increase max icons per row" android:text="+" />
|
||||||
|
</LinearLayout>
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/aod_even_distribution" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Even distribution" />
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/aod_even_distribution" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Even distribution" />
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/aod_limit_width" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Limit to screen width" />
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/aod_limit_width" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Limit to screen width" />
|
||||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center_vertical" android:orientation="horizontal">
|
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
|||||||
@@ -5,9 +5,17 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="Max rows" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="Max rows" />
|
||||||
<Spinner android:id="@+id/lockscreen_max_rows" android:layout_width="wrap_content" android:layout_height="wrap_content" android:popupBackground="@drawable/dropdown_popup_background" />
|
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/lockscreen_max_rows_minus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Decrease max rows" android:text="−" />
|
||||||
|
<TextView android:id="@+id/lockscreen_max_rows" android:layout_width="48dp" android:layout_height="wrap_content" android:gravity="center" android:textAppearance="?attr/textAppearanceBody1" />
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/lockscreen_max_rows_plus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Increase max rows" android:text="+" />
|
||||||
|
</LinearLayout>
|
||||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Max icons per row" />
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Max icons per row" />
|
||||||
<Spinner android:id="@+id/lockscreen_max_icons" android:layout_width="wrap_content" android:layout_height="wrap_content" android:popupBackground="@drawable/dropdown_popup_background" />
|
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/lockscreen_max_icons_minus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Decrease max icons per row" android:text="−" />
|
||||||
|
<TextView android:id="@+id/lockscreen_max_icons" android:layout_width="48dp" android:layout_height="wrap_content" android:gravity="center" android:textAppearance="?attr/textAppearanceBody1" />
|
||||||
|
<com.google.android.material.button.MaterialButton android:id="@+id/lockscreen_max_icons_plus" style="?attr/materialButtonOutlinedStyle" android:layout_width="48dp" android:layout_height="wrap_content" android:contentDescription="Increase max icons per row" android:text="+" />
|
||||||
|
</LinearLayout>
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/lockscreen_even_distribution" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Even distribution" />
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/lockscreen_even_distribution" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="Even distribution" />
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/lockscreen_limit_width" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Limit to screen width" />
|
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/lockscreen_limit_width" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Limit to screen width" />
|
||||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center_vertical" android:orientation="horizontal">
|
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:gravity="center_vertical" android:orientation="horizontal">
|
||||||
|
|||||||
Reference in New Issue
Block a user