diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRunningRecordMediator.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRunningRecordMediator.kt index 24ccd1433..54284e479 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRunningRecordMediator.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/AddRunningRecordMediator.kt @@ -59,11 +59,16 @@ class AddRunningRecordMediator @Inject constructor( typeId: Long, tagIds: List, 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() @@ -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, @@ -279,7 +288,7 @@ class AddRunningRecordMediator @Inject constructor( private suspend fun processMultitasking( typeId: Long, isMultitaskingAllowedByRules: ResultContainer, - timeEnded: Long, + splitTime: Long, ) { val isMultitaskingAllowedByDefault = prefsInteractor.getAllowMultitasking() val isMultitaskingAllowed = isMultitaskingAllowedByRules.getValueOrNull() @@ -294,7 +303,7 @@ class AddRunningRecordMediator @Inject constructor( removeRunningRecordMediator.removeWithRecordAdd( runningRecord = it, updateWidgets = false, - timeEnded = timeEnded, + timeEnded = splitTime, ) } } @@ -323,4 +332,10 @@ class AddRunningRecordMediator @Inject constructor( val tagIds: List, val updateNotificationSwitch: Boolean, ) + + sealed interface StartTime { + data class Current(val currentTimeStampMs: Long) : StartTime + data class Timestamp(val timestampMs: Long) : StartTime + object TakeCurrent : StartTime + } } \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionContinueMediator.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionContinueMediator.kt index 721c34174..c6b5a9ea0 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionContinueMediator.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionContinueMediator.kt @@ -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, ) } diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionRepeatMediator.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionRepeatMediator.kt index 8ec80ff24..afa456d45 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionRepeatMediator.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordActionRepeatMediator.kt @@ -28,7 +28,7 @@ class RecordActionRepeatMediator @Inject constructor( typeId = typeId, comment = comment, tagIds = tagIds, - timeStarted = currentTime, + timeStarted = AddRunningRecordMediator.StartTime.Current(currentTime), ) } } \ No newline at end of file