Compare commits
1 Commits
feature/IS
...
feature/IS
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c9a07bf9a |
@@ -31,7 +31,7 @@ fun HourItemView(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
hour: Int = 0,
|
hour: Int = 0,
|
||||||
onClick: () -> Unit = {},
|
onClick: () -> Unit = {},
|
||||||
title: String = ""
|
title:String = ""
|
||||||
) {
|
) {
|
||||||
Row(modifier = modifier,
|
Row(modifier = modifier,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -129,4 +129,4 @@ fun PreviewHourItemView() {
|
|||||||
title = "Hour Item View"
|
title = "Hour Item View"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ fun LifeTimeView(
|
|||||||
|
|
||||||
// Temp 0..7
|
// Temp 0..7
|
||||||
for (i in 0..lifeTimeTypes.size -1) {
|
for (i in 0..lifeTimeTypes.size -1) {
|
||||||
val value = when (i) {
|
val hour = when (i) {
|
||||||
0 -> lifeTime.lamp
|
0 -> lifeTime.lamp
|
||||||
1 -> lifeTime.hp5x5
|
1 -> lifeTime.hp5x5
|
||||||
2 -> lifeTime.hp7x7
|
2 -> lifeTime.hp7x7
|
||||||
@@ -70,35 +70,22 @@ fun LifeTimeView(
|
|||||||
7 -> lifeTime.water
|
7 -> lifeTime.water
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
val modifier = Modifier
|
HourItemView(
|
||||||
.fillMaxSize()
|
modifier = Modifier
|
||||||
.weight(1f)
|
.fillMaxSize()
|
||||||
.padding(
|
.weight(1f)
|
||||||
start = 20.px.dp,
|
.padding(
|
||||||
end = 20.px.dp,
|
start = 20.px.dp,
|
||||||
//bottom = 10.px.dp
|
end = 20.px.dp,
|
||||||
)
|
//bottom = 10.px.dp
|
||||||
val title = lifeTimeTypes[i]
|
),
|
||||||
val onItemClick = {
|
title = lifeTimeTypes[i],
|
||||||
Timber.d("onClick > Temp $i ($title)")
|
hour = hour,
|
||||||
onClick.invoke(i)
|
onClick = {
|
||||||
}
|
Timber.d("onClick > Temp $i (${lifeTimeTypes[i]})")
|
||||||
|
onClick.invoke(i)
|
||||||
if (i <= 4) {
|
}
|
||||||
CountItemView(
|
)
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
count = value,
|
|
||||||
onClick = onItemClick
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
HourItemView(
|
|
||||||
modifier = modifier,
|
|
||||||
title = title,
|
|
||||||
hour = value,
|
|
||||||
onClick = onItemClick
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < lifeTimeTypes.size -1) {
|
if (i < lifeTimeTypes.size -1) {
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
@@ -121,4 +108,4 @@ fun LifeTimeView(
|
|||||||
@Composable
|
@Composable
|
||||||
fun PreviewLifeTimeView() {
|
fun PreviewLifeTimeView() {
|
||||||
LifeTimeView()
|
LifeTimeView()
|
||||||
}
|
}
|
||||||
@@ -646,7 +646,7 @@ fun PresetLoadPopup(
|
|||||||
Timber.d("onClick - Confirm Save")
|
Timber.d("onClick - Confirm Save")
|
||||||
|
|
||||||
// Check empty names and conflict priority exist in the preset viewmodel's presetList
|
// Check empty names and conflict priority exist in the preset viewmodel's presetList
|
||||||
val listToValidate = presetViewModel.presetList.value
|
var listToValidate = presetViewModel.presetList.value
|
||||||
|
|
||||||
// Check for any presets with an empty name
|
// Check for any presets with an empty name
|
||||||
val hasEmptyName =
|
val hasEmptyName =
|
||||||
@@ -678,18 +678,32 @@ fun PresetLoadPopup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for duplicate priorities (ignoring priority 0)
|
// Check for duplicate priorities (ignoring priority 0)
|
||||||
val priorityConflicts = listToValidate
|
val duplicatePriorityGroups = listToValidate
|
||||||
.filter { it.priority > 0 } // Only consider prioritized items
|
.filter { it.priority > 0 }
|
||||||
.groupBy { it.priority } // Group them by priority
|
.groupBy { it.priority }
|
||||||
.any { it.value.size > 1 } // Check if any group is larger than 1
|
.filter { it.value.size > 1 }
|
||||||
|
|
||||||
if (priorityConflicts) {
|
if (duplicatePriorityGroups.isNotEmpty()) {
|
||||||
Toast.makeText(
|
val resolvedList = listToValidate.map { it.copy() }.toMutableList()
|
||||||
context,
|
val selectedPreset = resolvedList.getOrNull(selectedPresetIndex)
|
||||||
"There are duplicate priorities. Please ensure each priority is unique.",
|
|
||||||
Toast.LENGTH_LONG
|
duplicatePriorityGroups.forEach { (priorityValue, presets) ->
|
||||||
).show()
|
val keeperId = presets
|
||||||
return@noRippleClickable // Stop the process
|
.firstOrNull { preset ->
|
||||||
|
selectedPreset != null && preset.id == selectedPreset.id
|
||||||
|
}
|
||||||
|
?.id
|
||||||
|
?: presets.first().id
|
||||||
|
|
||||||
|
resolvedList.forEachIndexed { index, preset ->
|
||||||
|
if (preset.priority == priorityValue && preset.id != keeperId) {
|
||||||
|
resolvedList[index] = preset.copy(priority = 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
presetViewModel.setPresetList(resolvedList)
|
||||||
|
listToValidate = resolvedList
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.d("Validation successful. Saving list to MainViewModel.")
|
Timber.d("Validation successful. Saving list to MainViewModel.")
|
||||||
|
|||||||
Reference in New Issue
Block a user