1 Commits

Author SHA1 Message Date
areumwoo
1fc9640e38 Gradient 슬라이더 계산 로직 수정 2026-03-02 16:27:04 +09:00
3 changed files with 28 additions and 30 deletions

View File

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

View File

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

View File

@@ -646,7 +646,7 @@ fun PresetLoadPopup(
Timber.d("onClick - Confirm Save")
// Check empty names and conflict priority exist in the preset viewmodel's presetList
var listToValidate = presetViewModel.presetList.value
val listToValidate = presetViewModel.presetList.value
// Check for any presets with an empty name
val hasEmptyName =
@@ -678,32 +678,18 @@ fun PresetLoadPopup(
}
// Check for duplicate priorities (ignoring priority 0)
val duplicatePriorityGroups = listToValidate
.filter { it.priority > 0 }
.groupBy { it.priority }
.filter { it.value.size > 1 }
val priorityConflicts = listToValidate
.filter { it.priority > 0 } // Only consider prioritized items
.groupBy { it.priority } // Group them by priority
.any { it.value.size > 1 } // Check if any group is larger than 1
if (duplicatePriorityGroups.isNotEmpty()) {
val resolvedList = listToValidate.map { it.copy() }.toMutableList()
val selectedPreset = resolvedList.getOrNull(selectedPresetIndex)
duplicatePriorityGroups.forEach { (priorityValue, presets) ->
val keeperId = presets
.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
if (priorityConflicts) {
Toast.makeText(
context,
"There are duplicate priorities. Please ensure each priority is unique.",
Toast.LENGTH_LONG
).show()
return@noRippleClickable // Stop the process
}
Timber.d("Validation successful. Saving list to MainViewModel.")