From 3c9a07bf9a65f50d99a47ffd29add907f924b8fb Mon Sep 17 00:00:00 2001 From: areumwoo Date: Mon, 2 Mar 2026 13:08:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9A=B0=EC=84=A0=EC=88=9C=EC=9C=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=ED=95=AD?= =?UTF-8?q?=EB=AA=A9=EC=9D=84=20NONE=EC=9C=BC=EB=A1=9C=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/screens/home/preset/PresetLoadPopup.kt | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/laseroptek/raman/ui/screens/home/preset/PresetLoadPopup.kt b/app/src/main/java/com/laseroptek/raman/ui/screens/home/preset/PresetLoadPopup.kt index cd617ab..1863790 100644 --- a/app/src/main/java/com/laseroptek/raman/ui/screens/home/preset/PresetLoadPopup.kt +++ b/app/src/main/java/com/laseroptek/raman/ui/screens/home/preset/PresetLoadPopup.kt @@ -646,7 +646,7 @@ fun PresetLoadPopup( Timber.d("onClick - Confirm Save") // 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 val hasEmptyName = @@ -678,18 +678,32 @@ fun PresetLoadPopup( } // Check for duplicate priorities (ignoring priority 0) - 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 + val duplicatePriorityGroups = listToValidate + .filter { it.priority > 0 } + .groupBy { it.priority } + .filter { it.value.size > 1 } - if (priorityConflicts) { - Toast.makeText( - context, - "There are duplicate priorities. Please ensure each priority is unique.", - Toast.LENGTH_LONG - ).show() - return@noRippleClickable // Stop the process + 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 } Timber.d("Validation successful. Saving list to MainViewModel.") -- 2.47.3