diff --git a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/repo/RunningRecordRepoImpl.kt b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/repo/RunningRecordRepoImpl.kt index 45dddd3f5..d1423a007 100644 --- a/data_local/src/main/java/com/example/util/simpletimetracker/data_local/repo/RunningRecordRepoImpl.kt +++ b/data_local/src/main/java/com/example/util/simpletimetracker/data_local/repo/RunningRecordRepoImpl.kt @@ -6,6 +6,7 @@ import com.example.util.simpletimetracker.data_local.utils.logDataAccess import com.example.util.simpletimetracker.data_local.utils.removeIf import com.example.util.simpletimetracker.data_local.utils.replaceWith import com.example.util.simpletimetracker.data_local.utils.withLockedCache +import com.example.util.simpletimetracker.domain.extension.dropMillis import com.example.util.simpletimetracker.domain.model.RunningRecord import com.example.util.simpletimetracker.domain.repo.RunningRecordRepo import kotlinx.coroutines.sync.Mutex @@ -51,7 +52,11 @@ class RunningRecordRepoImpl @Inject constructor( logMessage = "add", accessSource = { dao.insert(runningRecord.let(mapper::map)) }, afterSourceAccess = { id -> - cache = cache?.replaceWith(runningRecord.copy(id = id)) { it.id == id } + val new = runningRecord.copy( + id = id, + timeStarted = runningRecord.timeStarted.dropMillis(), + ) + cache = cache?.replaceWith(new) { it.id == id } }, ) 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 37aef3e04..8ec80ff24 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 @@ -13,15 +13,22 @@ class RecordActionRepeatMediator @Inject constructor( comment: String, tagIds: List, ) { + val currentTime = System.currentTimeMillis() // Stop same type running record if exist (only one of the same type can run at once). // Widgets will update on adding. - runningRecordInteractor.get(typeId) - ?.let { removeRunningRecordMediator.removeWithRecordAdd(it, updateWidgets = false) } + runningRecordInteractor.get(typeId)?.let { + removeRunningRecordMediator.removeWithRecordAdd( + runningRecord = it, + updateWidgets = false, + timeEnded = currentTime, + ) + } // Add new running record. addRunningRecordMediator.startTimer( typeId = typeId, comment = comment, tagIds = tagIds, + timeStarted = currentTime, ) } } \ No newline at end of file