mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Improve NumberPicker usage in numerical habits
This commit is contained in:
@@ -33,6 +33,7 @@ import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.InterfaceUtils
|
||||
import java.text.DecimalFormatSymbols
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
@@ -51,7 +52,10 @@ class NumberPickerFactory
|
||||
|
||||
val picker = view.findViewById<NumberPicker>(R.id.picker)
|
||||
val picker2 = view.findViewById<NumberPicker>(R.id.picker2)
|
||||
val tvUnit = view.findViewById<TextView>(R.id.tvUnit)
|
||||
|
||||
view.findViewById<TextView>(R.id.tvUnit).text = unit
|
||||
view.findViewById<TextView>(R.id.tvSeparator).text =
|
||||
DecimalFormatSymbols.getInstance().decimalSeparator.toString()
|
||||
|
||||
val intValue = (value * 100).roundToLong().toInt()
|
||||
|
||||
@@ -61,19 +65,17 @@ class NumberPickerFactory
|
||||
picker.wrapSelectorWheel = false
|
||||
|
||||
picker2.minValue = 0
|
||||
picker2.maxValue = 19
|
||||
picker2.setFormatter { v -> String.format("%02d", 5 * v) }
|
||||
picker2.value = intValue % 100 / 5
|
||||
picker2.maxValue = 99
|
||||
picker2.setFormatter { v -> String.format("%02d", v) }
|
||||
picker2.value = intValue % 100
|
||||
refreshInitialValue(picker2)
|
||||
|
||||
tvUnit.text = unit
|
||||
|
||||
val dialog = AlertDialog.Builder(context)
|
||||
.setView(view)
|
||||
.setTitle(R.string.change_value)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
picker.clearFocus()
|
||||
val v = picker.value + 0.05 * picker2.value
|
||||
val v = picker.value + 0.01 * picker2.value
|
||||
callback.onNumberPicked(v)
|
||||
}
|
||||
.setOnDismissListener {
|
||||
|
||||
@@ -34,14 +34,13 @@
|
||||
android:id="@+id/tvSeparator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="."/>
|
||||
/>
|
||||
|
||||
<NumberPicker
|
||||
android:id="@+id/picker2"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in New Issue
Block a user