Fix adding new days to rule during blocked time area self limit adding

This commit is contained in:
Jonas Lochmann 2023-05-01 02:00:00 +02:00
parent 01d5fce6cd
commit c92b24519d
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -47,7 +47,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import java.io.Serializable import java.io.Serializable
import kotlin.experimental.and import kotlin.experimental.or
object ManageCategoryBlockedTimes { object ManageCategoryBlockedTimes {
private const val LOG_TAG = "ManageBlockedTimes" private const val LOG_TAG = "ManageBlockedTimes"
@ -157,9 +157,12 @@ object ManageCategoryBlockedTimes {
if (existingRuleId == null) rulesToCreate.add(rule.value) if (existingRuleId == null) rulesToCreate.add(rule.value)
else rulesToUpdate.add(rule.value.copy(id = existingRuleId)) else rulesToUpdate.add(rule.value.copy(id = existingRuleId))
} else { } else {
if (!isChild || currentRule.dayMask and rule.value.dayMask == currentRule.dayMask) val targetDayMask =
if (currentRule.dayMask != rule.value.dayMask) rulesToUpdate.add( if (isChild) currentRule.dayMask or rule.value.dayMask
currentRule.copy(dayMask = rule.value.dayMask) else rule.value.dayMask
if (currentRule.dayMask != targetDayMask) rulesToUpdate.add(
currentRule.copy(dayMask = targetDayMask)
) )
} }
} }