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.

feat: Start activities on the phone via the wear app!!

Finally, a full cycle, MVP of the wear app!

This commit adds the ability to start activities
on the phone from the wear app. Choose an
activity and the associated tag, and the phone app
will update accordingly.

Of course, the app still has plenty of bugs and
rough edges, but this is a huge milestone!

closes thehale/SimpleTimeTracker-WearOS#5
closes thehale/SimpleTimeTracker-WearOS#8

Joseph Hale (Feb 26, 2024, 10:27 PM -0700) 47556d7c ebbb5c07

+30 -16
+14 -14
app/src/main/java/com/example/util/simpletimetracker/wear/DomainAPI.kt
··· 10 10 import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor 11 11 import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor 12 12 import com.example.util.simpletimetracker.domain.mapper.AppColorMapper 13 + import com.example.util.simpletimetracker.domain.model.RunningRecord 13 14 import com.example.util.simpletimetracker.wearrpc.Activity 14 15 import com.example.util.simpletimetracker.wearrpc.CurrentActivity 15 16 import com.example.util.simpletimetracker.wearrpc.Settings ··· 47 48 } 48 49 49 50 override suspend fun setCurrentActivities(activities: Array<CurrentActivity>) { 50 - TODO("Not yet implemented") 51 - // This is a little tricky... The given `activities` should be considered a declarative 52 - // statement of the activities expected to be running upon successful completion of this 53 - // method. 54 - 55 - // Currently running activities not in the given Array should be stopped 56 - 57 - // Activities in the given Array that are not running should be started 58 - 59 - // For activities in the given Array which are running... 60 - // If the start dates + tags are unchanged, then leave the activity running. 61 - // If the start dates and/or tags are different, stop the current running activity 62 - // instance and restart it as of the requested start date. 63 - 51 + 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 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 + ) } 64 64 } 65 65 66 66 override suspend fun queryTagsForActivity(activityId: Long): Array<Tag> {
+16 -2
wear/src/main/java/com/example/util/simpletimetracker/presentation/screens/TagsScreen.kt
··· 8 8 import androidx.compose.runtime.Composable 9 9 import androidx.compose.ui.platform.LocalContext 10 10 import com.example.util.simpletimetracker.presentation.components.TagList 11 + import com.example.util.simpletimetracker.presentation.remember.rememberCurrentActivities 11 12 import com.example.util.simpletimetracker.presentation.remember.rememberTags 12 13 import com.example.util.simpletimetracker.wearrpc.ContextMessenger 14 + import com.example.util.simpletimetracker.wearrpc.CurrentActivity 13 15 import com.example.util.simpletimetracker.wearrpc.WearRPCClient 16 + import java.time.Instant 14 17 15 18 @Composable 16 19 fun TagsScreen(activityId: Long, onSelectTag: () -> Unit) { 17 20 val rpc = WearRPCClient(ContextMessenger(LocalContext.current)) 18 21 val (tags) = rememberTags(rpc, activityId) 22 + val (_, setCurrents) = rememberCurrentActivities(rpc) 19 23 20 - TagList(tags, onSelectTag = { onSelectTag() } ) 21 - } 24 + TagList( 25 + tags, 26 + onSelectTag = { 27 + setCurrents( 28 + arrayOf( 29 + CurrentActivity(activityId, Instant.now().toEpochMilli(), arrayOf(it)), 30 + ), 31 + ) 32 + onSelectTag() 33 + }, 34 + ) 35 + }