1 Commits

Author SHA1 Message Date
areumwoo
3c9a07bf9a feat: 우선순위 중복 시 기존 항목을 NONE으로 초기화하도록 수정 2026-03-02 13:08:44 +09:00
3 changed files with 30 additions and 28 deletions

View File

@@ -334,7 +334,7 @@ fun DcdSettingPopup(
modifier = Modifier modifier = Modifier
.fillMaxHeight() .fillMaxHeight()
.size(40.px.dp, 210.px.dp), .size(40.px.dp, 210.px.dp),
chargeRate = gasChargeRate chargeRate = gasChargeRate.toInt()
) )
// Icon // Icon

View File

@@ -28,26 +28,14 @@ import com.laseroptek.raman.ui.screens.main.MainViewModel
import com.laseroptek.raman.utils.DefaultDispatcherProvider import com.laseroptek.raman.utils.DefaultDispatcherProvider
import com.laseroptek.raman.utils.ext.px import com.laseroptek.raman.utils.ext.px
import timber.log.Timber import timber.log.Timber
import kotlin.math.abs
import kotlin.math.ceil
@Composable @Composable
fun GradientSlider( fun GradientSlider(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
chargeRate: Float = 0f, chargeRate: Int = 0, // Value from (0 .. 100)
) { ) {
val normalizedRate = chargeRate.coerceIn(0f, 100f) val chargeIndex = ((chargeRate.coerceIn(0, 100) + 4) / 5).toInt() // 0..19
val bucket = normalizedRate / 5f
val remainder = normalizedRate % 5f
val isExactMultiple = abs(remainder) < 0.0001f
val chargeIndex = when {
normalizedRate == 0f -> -1
isExactMultiple -> (bucket - 1f).toInt().coerceAtLeast(-1)
else -> (ceil(bucket.toDouble()).toInt() - 1)
}.coerceIn(-1, 19)
Timber.d("chargeRate: $chargeRate, chargeIndex: $chargeIndex") Timber.d("chargeRate: $chargeRate, chargeIndex: $chargeIndex")
Box( Box(
@@ -115,6 +103,6 @@ fun GradientSliderPreview(
//mainViewModel = mainViewModel //mainViewModel = mainViewModel
modifier = Modifier modifier = Modifier
.size(40.px.dp, 210.px.dp), .size(40.px.dp, 210.px.dp),
chargeRate = 20f chargeRate = 20
) )
} }

View File

@@ -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.")