A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

fix: Persist completed activity records

The DomainAPI was removing stopped activity records without
saving them to the database.

Now, the DomainAPI persists completed records as expected :D

What's more, it also follows the settings for minimum durations
for activity records.

Joseph Hale (Feb 26, 2024, 10:27 PM -0700) f7bc8f07 047c536f

+20 -11
+15 -11
app/src/main/java/com/example/util/simpletimetracker/wear/DomainAPI.kt
··· 8 8 import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor 9 9 import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor 10 10 import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor 11 + import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator 11 12 import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor 12 13 import com.example.util.simpletimetracker.domain.mapper.AppColorMapper 13 14 import com.example.util.simpletimetracker.domain.model.RunningRecord ··· 22 23 private val recordTypeInteractor: RecordTypeInteractor, 23 24 private val recordTagInteractor: RecordTagInteractor, 24 25 private val runningRecordInteractor: RunningRecordInteractor, 26 + private val removeRunningRecordMediator: RemoveRunningRecordMediator, 25 27 private val appColorMapper: AppColorMapper, 26 28 ) : SimpleTimeTrackerAPI { 27 29 ··· 49 51 50 52 override suspend fun setCurrentActivities(activities: Array<CurrentActivity>) { 51 53 val currents = queryCurrentActivities() 52 - val unchanged = currents.filter { c -> activities.any {a -> a == c} } 53 - val stopped = currents.filter { c -> unchanged.none { u -> u == c} } 54 + val unchanged = currents.filter { c -> activities.any { a -> a == c } } 55 + val stopped = currents.filter { c -> unchanged.none { u -> u == c } } 54 56 val started = activities.filter { a -> currents.none { c -> a == c } } 55 - stopped.forEach { runningRecordInteractor.remove(it.id) } 56 - started.forEach { runningRecordInteractor.add( 57 - RunningRecord( 58 - id = it.id, 59 - timeStarted = it.startedAt, 60 - comment = "", 61 - tagIds = it.tags.map { t -> t.id }, 62 - ) 63 - ) } 57 + stopped.forEach { removeRunningRecordMediator.removeWithRecordAdd(asRunningRecord(it)) } 58 + started.forEach { runningRecordInteractor.add(asRunningRecord(it)) } 59 + } 60 + 61 + private fun asRunningRecord(currentActivity: CurrentActivity): RunningRecord { 62 + return RunningRecord( 63 + id = currentActivity.id, 64 + timeStarted = currentActivity.startedAt, 65 + comment = "", 66 + tagIds = currentActivity.tags.map { t -> t.id }, 67 + ) 64 68 } 65 69 66 70 override suspend fun queryTagsForActivity(activityId: Long): Array<Tag> {
+5
app/src/main/java/com/example/util/simpletimetracker/wear/WearService.kt
··· 8 8 import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor 9 9 import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor 10 10 import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor 11 + import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator 11 12 import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor 12 13 import com.example.util.simpletimetracker.domain.mapper.AppColorMapper 13 14 import com.example.util.simpletimetracker.wearrpc.WearRPCServer ··· 40 41 lateinit var runningRecordInteractor: RunningRecordInteractor 41 42 42 43 @Inject 44 + lateinit var removeRunningRecordMediator: RemoveRunningRecordMediator 45 + 46 + @Inject 43 47 lateinit var appColorMapper: AppColorMapper 44 48 45 49 override fun onRequest(nodeId: String, path: String, request: ByteArray): Task<ByteArray>? { ··· 49 53 recordTypeInteractor, 50 54 recordTagInteractor, 51 55 runningRecordInteractor, 56 + removeRunningRecordMediator, 52 57 appColorMapper, 53 58 ), 54 59 )