Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,67 @@ fun WatchPref<*>.section(): Section = when (this) {

private fun numberPref(item: WatchPreference<Long>, libPebble: LibPebble): SettingsItem {
val pref = item.pref as NumberWatchPref
return basicSettingsNumberItem(
id = pref.id,
title = pref.displayName,
description = pref.description,
topLevelType = TopLevelType.Watch,
section = pref.section(),
value = item.valueOrDefault(),
min = pref.min,
max = pref.max,
onValueChange = {
libPebble.setWatchPref(item.copy(value = it))
},
isDebugSetting = pref.isDebugSetting,
defaultValue = pref.defaultValue,
unit = pref.unit,
)
return when (pref) {
NumberWatchPref.BacklightTimeoutMs -> {
val secValue = item.valueOrDefault() / 1000
basicSettingsNumberItem(
id = pref.id,
title = pref.displayName,
description = pref.description,
topLevelType = TopLevelType.Watch,
section = pref.section(),
value = secValue,
min = 1,
max = 10,
onValueChange = {
libPebble.setWatchPref(item.copy(value = it * 1000))
},
isDebugSetting = pref.isDebugSetting,
defaultValue = pref.defaultValue / 1000,
unit = "seconds",
valueFormatter = { "$it seconds" },
)
}
NumberWatchPref.NotificationTimeoutMs -> {
val secValue = item.valueOrDefault() / 1000
basicSettingsNumberItem(
id = pref.id,
title = pref.displayName,
description = pref.description,
topLevelType = TopLevelType.Watch,
section = pref.section(),
value = secValue,
min = 0,
max = 600,
onValueChange = {
libPebble.setWatchPref(item.copy(value = it * 1000))
},
isDebugSetting = pref.isDebugSetting,
defaultValue = pref.defaultValue / 1000,
unit = "",
valueFormatter = { v ->
"${v / 60}:${(v % 60).toString().padStart(2, '0')}"
},
stepsOverride = 19,
)
}
else -> basicSettingsNumberItem(
id = pref.id,
title = pref.displayName,
description = pref.description,
topLevelType = TopLevelType.Watch,
section = pref.section(),
value = item.valueOrDefault(),
min = pref.min,
max = pref.max,
onValueChange = {
libPebble.setWatchPref(item.copy(value = it))
},
isDebugSetting = pref.isDebugSetting,
defaultValue = pref.defaultValue,
unit = pref.unit,
)
}
}

private fun colorPref(item: WatchPreference<TimelineColor>, libPebble: LibPebble): SettingsItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,7 @@ fun basicSettingsNumberItem(
isDebugSetting: Boolean = false,
defaultValue: Long? = null,
valueFormatter: ((Long) -> String)? = null,
stepsOverride: Int? = null,
) = SettingsItem(
id = id,
title = title,
Expand All @@ -2142,9 +2143,8 @@ fun basicSettingsNumberItem(
}
val minF = remember(min) { min.toFloat() }
val maxF = remember(max) { max.toFloat() }
val steps = remember(max, min) {
val steps = stepsOverride ?: remember(max, min) {
val range = max - min
// Too many steps ANRs the app
if (range in 1..100) range - 1 else 0
}
Slider(
Expand All @@ -2171,7 +2171,7 @@ fun basicSettingsNumberItem(
enabled = value != defaultValue,
) {
Text(
text = "Default: $defaultValue",
text = "Default: ${valueFormatter?.invoke(defaultValue) ?: "$defaultValue $unit"}",
modifier = Modifier.widthIn(max = 150.dp),
maxLines = 1,
lineHeight = 12.sp,
Expand Down