Compare commits
1 Commits
feature/IS
...
feature/IS
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c9a07bf9a |
@@ -35,7 +35,6 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
import com.laseroptek.raman.const.LaserParameter
|
import com.laseroptek.raman.const.LaserParameter
|
||||||
import com.laseroptek.raman.const.LASER_STATUS
|
|
||||||
import com.laseroptek.raman.const.LaserStatusType
|
import com.laseroptek.raman.const.LaserStatusType
|
||||||
import com.laseroptek.raman.const.MAX_LASER_COUNT
|
import com.laseroptek.raman.const.MAX_LASER_COUNT
|
||||||
import com.laseroptek.raman.const.PresetButtonType
|
import com.laseroptek.raman.const.PresetButtonType
|
||||||
@@ -93,18 +92,10 @@ fun HomeScreen(
|
|||||||
|
|
||||||
val presetList by mainViewModel.presetList.collectAsState()
|
val presetList by mainViewModel.presetList.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(lampCount, lifeTime.lamp, laserStatus.laserStatus) {
|
LaunchedEffect(Unit) {
|
||||||
Timber.d("LaunchedEffect - HomeScreen")
|
Timber.d("LaunchedEffect - HomeScreen")
|
||||||
focusManager.clearFocus(force = true) // Hide the keyboard
|
focusManager.clearFocus(force = true) // Hide the keyboard
|
||||||
|
|
||||||
// Ensure the system returns to StandBy when lamp thresholds are exceeded
|
|
||||||
val lampLifetimeLimit = lifeTime.lamp
|
|
||||||
val reachedLifetimeLimit = lampLifetimeLimit > 0 && lampCount >= lampLifetimeLimit
|
|
||||||
if (reachedLifetimeLimit && laserStatus.laserStatus != LASER_STATUS.STAND_BY) {
|
|
||||||
Timber.d("HomeScreen load - forcing StandBy state due to lamp count limit")
|
|
||||||
mainViewModel.txLaserStatusEntry(LASER_STATUS.STAND_BY)
|
|
||||||
}
|
|
||||||
|
|
||||||
Timber.d("Attempted to hide keyboard on EngineerScreen launch")
|
Timber.d("Attempted to hide keyboard on EngineerScreen launch")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,18 +482,6 @@ fun HomeScreen(
|
|||||||
return@StandByButton
|
return@StandByButton
|
||||||
}
|
}
|
||||||
|
|
||||||
val lampLifetimeLimit = lifeTime.lamp
|
|
||||||
if (lampLifetimeLimit > 0 && lampCount >= lampLifetimeLimit) {
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
"Lamp lifetime limit reached",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
return@StandByButton
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val hpCount = mainViewModel.getHPCount()
|
val hpCount = mainViewModel.getHPCount()
|
||||||
if (hpCount < 1) {
|
if (hpCount < 1) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
|||||||
@@ -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