Skip to content

Commit

Permalink
fix continue while timer running creating negative records
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 9, 2024
1 parent 100ebf8 commit e4e36ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ class AddRunningRecordMediator @Inject constructor(
typeId: Long,
tagIds: List<Long>,
comment: String,
timeStarted: Long? = null,
timeStarted: StartTime = StartTime.TakeCurrent,
updateNotificationSwitch: Boolean = true,
checkDefaultDuration: Boolean = true,
) {
val actualTimeStarted = timeStarted ?: System.currentTimeMillis()
val currentTime = System.currentTimeMillis()
val actualTimeStarted = when (timeStarted) {
is StartTime.Current -> timeStarted.currentTimeStampMs
is StartTime.TakeCurrent -> currentTime
is StartTime.Timestamp -> timeStarted.timestampMs
}
val retroactiveTrackingMode = prefsInteractor.getRetroactiveTrackingMode()
val prevRecord = if (retroactiveTrackingMode) {
recordInteractor.getPrev(actualTimeStarted).firstOrNull()
Expand All @@ -87,7 +92,11 @@ class AddRunningRecordMediator @Inject constructor(
processMultitasking(
typeId = typeId,
isMultitaskingAllowedByRules = rulesResult.isMultitaskingAllowed,
timeEnded = actualTimeStarted,
splitTime = when (timeStarted) {
is StartTime.Current -> timeStarted.currentTimeStampMs
is StartTime.TakeCurrent -> currentTime
is StartTime.Timestamp -> currentTime
},
)
val actualTags = getAllTags(
typeId = typeId,
Expand Down Expand Up @@ -279,7 +288,7 @@ class AddRunningRecordMediator @Inject constructor(
private suspend fun processMultitasking(
typeId: Long,
isMultitaskingAllowedByRules: ResultContainer<Boolean>,
timeEnded: Long,
splitTime: Long,
) {
val isMultitaskingAllowedByDefault = prefsInteractor.getAllowMultitasking()
val isMultitaskingAllowed = isMultitaskingAllowedByRules.getValueOrNull()
Expand All @@ -294,7 +303,7 @@ class AddRunningRecordMediator @Inject constructor(
removeRunningRecordMediator.removeWithRecordAdd(
runningRecord = it,
updateWidgets = false,
timeEnded = timeEnded,
timeEnded = splitTime,
)
}
}
Expand Down Expand Up @@ -323,4 +332,10 @@ class AddRunningRecordMediator @Inject constructor(
val tagIds: List<Long>,
val updateNotificationSwitch: Boolean,
)

sealed interface StartTime {
data class Current(val currentTimeStampMs: Long) : StartTime
data class Timestamp(val timestampMs: Long) : StartTime
object TakeCurrent : StartTime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class RecordActionContinueMediator @Inject constructor(
// Add new running record.
addRunningRecordMediator.startTimer(
typeId = typeId,
timeStarted = timeStarted,
comment = comment,
tagIds = tagIds,
timeStarted = AddRunningRecordMediator.StartTime.Timestamp(timeStarted),
checkDefaultDuration = false,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RecordActionRepeatMediator @Inject constructor(
typeId = typeId,
comment = comment,
tagIds = tagIds,
timeStarted = currentTime,
timeStarted = AddRunningRecordMediator.StartTime.Current(currentTime),
)
}
}

0 comments on commit e4e36ef

Please sign in to comment.