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.

refactoring

razeeman (Mar 2, 2024, 9:05 PM +0300) ca5062da e0fece08

+41 -63
-3
app/src/main/res/values/colors.xml
··· 1 - <?xml version="1.0" encoding="utf-8"?> 2 - <resources> 3 - </resources>
+4 -4
wear/src/main/java/com/example/util/simpletimetracker/presentation/MainActivity.kt
··· 9 9 import androidx.activity.ComponentActivity 10 10 import androidx.activity.compose.setContent 11 11 import androidx.compose.runtime.Composable 12 - import com.example.util.simpletimetracker.presentation.navigation.StartActivityNavigator 13 - import com.example.util.simpletimetracker.presentation.theme.SimpleTimeTrackerForWearOSTheme 12 + import com.example.util.simpletimetracker.presentation.navigation.WearNavigator 13 + import com.example.util.simpletimetracker.presentation.theme.WearTheme 14 14 15 15 class MainActivity : ComponentActivity() { 16 16 override fun onCreate(savedInstanceState: Bundle?) { ··· 23 23 24 24 @Composable 25 25 fun WearApp() { 26 - SimpleTimeTrackerForWearOSTheme { 27 - StartActivityNavigator() 26 + WearTheme { 27 + WearNavigator() 28 28 } 29 29 }
+16
wear/src/main/java/com/example/util/simpletimetracker/presentation/navigation/NavigationExtensions.kt
··· 1 + /* 2 + * This Source Code Form is subject to the terms of the Mozilla Public 3 + * License, v. 2.0. If a copy of the MPL was not distributed with this 4 + * file, You can obtain one at https://mozilla.org/MPL/2.0/. 5 + */ 6 + package com.example.util.simpletimetracker.presentation.navigation 7 + 8 + import androidx.navigation.NavHostController 9 + 10 + fun NavHostController.navigateToRoot(route: String) { 11 + // Inspired by: https://stackoverflow.com/a/72856761/14765128 12 + navigate(route) { 13 + popUpTo(graph.startDestinationId) { inclusive = true } 14 + graph.setStartDestination(route) 15 + } 16 + }
+16 -10
wear/src/main/java/com/example/util/simpletimetracker/presentation/navigation/StartActivityNavigator.kt wear/src/main/java/com/example/util/simpletimetracker/presentation/navigation/WearNavigator.kt
··· 20 20 } 21 21 22 22 @Composable 23 - fun StartActivityNavigator() { 23 + fun WearNavigator() { 24 24 val navigation = rememberSwipeDismissableNavController() 25 25 SwipeDismissableNavHost( 26 26 navController = navigation, ··· 29 29 composable(Route.Activities) { 30 30 ActivitiesScreen( 31 31 onRequestTagSelection = { 32 - navigation.navigate(Route.Tags.replace("{id}", it.toString())) 32 + val route = Route.Tags.replace("{id}", it.toString()) 33 + navigation.navigate(route) 34 + }, 35 + onRequestCredits = { 36 + navigation.navigate(Route.Credits) 33 37 }, 34 - onRequestCredits = { navigation.navigate(Route.Credits) }, 35 38 ) 36 39 } 37 40 composable(Route.Tags) { 41 + val activityId = it.arguments 42 + ?.getString("id") 43 + ?.toLong() 44 + ?: return@composable 45 + 38 46 TagsScreen( 39 - activityId = it.arguments?.getString("id")?.toLong()!!, 47 + activityId = activityId, 40 48 onComplete = { 41 - // Inspired by: https://stackoverflow.com/a/72856761/14765128 42 - navigation.navigate(Route.Activities) { 43 - popUpTo(navigation.graph.startDestinationId) { inclusive = true } 44 - navigation.graph.setStartDestination(Route.Activities) 45 - } 49 + navigation.navigateToRoot(Route.Activities) 46 50 }, 47 51 ) 48 52 } 49 - composable(Route.Credits) { CreditsScreen() } 53 + composable(Route.Credits) { 54 + CreditsScreen() 55 + } 50 56 } 51 57 }
+1 -17
wear/src/main/java/com/example/util/simpletimetracker/presentation/theme/Color.kt
··· 5 5 */ 6 6 package com.example.util.simpletimetracker.presentation.theme 7 7 8 - import androidx.compose.ui.graphics.Color 9 8 import androidx.wear.compose.material.Colors 10 9 11 - val Purple200 = Color(0xFFBB86FC) 12 - val Purple700 = Color(0xFF3700B3) 13 - val Teal200 = Color(0xFF03DAC5) 14 - val Red400 = Color(0xFFCF6679) 15 - 16 - internal val wearColorPalette: Colors = 17 - Colors( 18 - primary = Purple200, 19 - primaryVariant = Purple700, 20 - secondary = Teal200, 21 - secondaryVariant = Teal200, 22 - error = Red400, 23 - onPrimary = Color.Black, 24 - onSecondary = Color.Black, 25 - onError = Color.Black, 26 - ) 10 + internal val wearColors: Colors = Colors()
+3 -3
wear/src/main/java/com/example/util/simpletimetracker/presentation/theme/Theme.kt
··· 9 9 import androidx.wear.compose.material.MaterialTheme 10 10 11 11 @Composable 12 - fun SimpleTimeTrackerForWearOSTheme(content: @Composable () -> Unit) { 12 + fun WearTheme(content: @Composable () -> Unit) { 13 13 MaterialTheme( 14 - colors = wearColorPalette, 15 - typography = Typography, 14 + colors = wearColors, 15 + typography = wearTypography, 16 16 // For shapes, we generally recommend using the default Material Wear shapes which are 17 17 // optimized for round and non-round devices. 18 18 content = content,
+1 -26
wear/src/main/java/com/example/util/simpletimetracker/presentation/theme/Type.kt
··· 5 5 */ 6 6 package com.example.util.simpletimetracker.presentation.theme 7 7 8 - import androidx.compose.ui.text.TextStyle 9 - import androidx.compose.ui.text.font.FontFamily 10 - import androidx.compose.ui.text.font.FontWeight 11 - import androidx.compose.ui.unit.sp 12 8 import androidx.wear.compose.material.Typography 13 9 14 - // Set of Material typography styles to start with 15 - val Typography = 16 - Typography( 17 - body1 = 18 - TextStyle( 19 - fontFamily = FontFamily.Default, 20 - fontWeight = FontWeight.Normal, 21 - fontSize = 16.sp, 22 - ), 23 - /* Other default text styles to override 24 - button = TextStyle( 25 - fontFamily = FontFamily.Default, 26 - fontWeight = FontWeight.W500, 27 - fontSize = 14.sp 28 - ), 29 - caption = TextStyle( 30 - fontFamily = FontFamily.Default, 31 - fontWeight = FontWeight.Normal, 32 - fontSize = 12.sp 33 - ) 34 - */ 35 - ) 10 + internal val wearTypography = Typography()