Skip to content

Commit

Permalink
fix zero untracked time after repeat record
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 9, 2024
1 parent fd5295e commit 24e55e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ class RecordActionRepeatMediator @Inject constructor(
comment: String,
tagIds: List<Long>,
) {
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,
)
}
}

0 comments on commit 24e55e5

Please sign in to comment.