Unify const naming conventions

Change-Id: I481d97778f599ead624164057fbafb36c3ea2c55
refactor/const_naming_convention
Miłosz Moczkowski 2 years ago
parent 2bf3018898
commit 8732f98dd3

@ -20,7 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute import com.google.samples.apps.nowinandroid.feature.foryou.navigation.FOR_YOU_ROUTE
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph
import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen
@ -40,7 +40,7 @@ import com.google.samples.apps.nowinandroid.ui.NiaAppState
fun NiaNavHost( fun NiaNavHost(
appState: NiaAppState, appState: NiaAppState,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
startDestination: String = forYouNavigationRoute, startDestination: String = FOR_YOU_ROUTE,
) { ) {
val navController = appState.navController val navController = appState.navController
NavHost( NavHost(

@ -33,11 +33,11 @@ import androidx.tracing.trace
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository
import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
import com.google.samples.apps.nowinandroid.core.ui.TrackDisposableJank import com.google.samples.apps.nowinandroid.core.ui.TrackDisposableJank
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksRoute import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BOOKMARKS_ROUTE
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.navigateToBookmarks import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.navigateToBookmarks
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute import com.google.samples.apps.nowinandroid.feature.foryou.navigation.FOR_YOU_ROUTE
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.navigateToForYou import com.google.samples.apps.nowinandroid.feature.foryou.navigation.navigateToForYou
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsRoute import com.google.samples.apps.nowinandroid.feature.interests.navigation.INTERESTS_ROUTE
import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterestsGraph import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterestsGraph
import com.google.samples.apps.nowinandroid.feature.search.navigation.navigateToSearch import com.google.samples.apps.nowinandroid.feature.search.navigation.navigateToSearch
import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination
@ -91,9 +91,9 @@ class NiaAppState(
val currentTopLevelDestination: TopLevelDestination? val currentTopLevelDestination: TopLevelDestination?
@Composable get() = when (currentDestination?.route) { @Composable get() = when (currentDestination?.route) {
forYouNavigationRoute -> FOR_YOU FOR_YOU_ROUTE -> FOR_YOU
bookmarksRoute -> BOOKMARKS BOOKMARKS_ROUTE -> BOOKMARKS
interestsRoute -> INTERESTS INTERESTS_ROUTE -> INTERESTS
else -> null else -> null
} }

@ -31,6 +31,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
private const val DISABLED_OUTLINED_BUTTON_BORDER_ALPHA = 0.12f
private val outlinedButtonBorderWidth = 1.dp
/** /**
* Now in Android filled button with generic content slot. Wraps Material 3 [Button]. * Now in Android filled button with generic content slot. Wraps Material 3 [Button].
* *
@ -124,12 +127,12 @@ fun NiaOutlinedButton(
contentColor = MaterialTheme.colorScheme.onBackground, contentColor = MaterialTheme.colorScheme.onBackground,
), ),
border = BorderStroke( border = BorderStroke(
width = NiaButtonDefaults.OutlinedButtonBorderWidth, width = outlinedButtonBorderWidth,
color = if (enabled) { color = if (enabled) {
MaterialTheme.colorScheme.outline MaterialTheme.colorScheme.outline
} else { } else {
MaterialTheme.colorScheme.onSurface.copy( MaterialTheme.colorScheme.onSurface.copy(
alpha = NiaButtonDefaults.DisabledOutlinedButtonBorderAlpha, alpha = DISABLED_OUTLINED_BUTTON_BORDER_ALPHA,
) )
}, },
), ),
@ -259,16 +262,3 @@ private fun NiaButtonContent(
text() text()
} }
} }
/**
* Now in Android button default values.
*/
object NiaButtonDefaults {
// TODO: File bug
// OutlinedButton border color doesn't respect disabled state by default
const val DisabledOutlinedButtonBorderAlpha = 0.12f
// TODO: File bug
// OutlinedButton default border width isn't exposed via ButtonDefaults
val OutlinedButtonBorderWidth = 1.dp
}

@ -29,6 +29,10 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
private const val DISABLED_CHIP_CONTAINER_ALPHA = 0.12f
private const val DISABLED_CHIP_CONTENT_ALPHA = 0.38f
private val chipBorderWidth = 1.dp
/** /**
* Now in Android filter chip with included leading checked icon as well as text content slot. * Now in Android filter chip with included leading checked icon as well as text content slot.
* *
@ -73,28 +77,28 @@ fun NiaFilterChip(
borderColor = MaterialTheme.colorScheme.onBackground, borderColor = MaterialTheme.colorScheme.onBackground,
selectedBorderColor = MaterialTheme.colorScheme.onBackground, selectedBorderColor = MaterialTheme.colorScheme.onBackground,
disabledBorderColor = MaterialTheme.colorScheme.onBackground.copy( disabledBorderColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha, alpha = DISABLED_CHIP_CONTENT_ALPHA,
), ),
disabledSelectedBorderColor = MaterialTheme.colorScheme.onBackground.copy( disabledSelectedBorderColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha, alpha = DISABLED_CHIP_CONTENT_ALPHA,
), ),
selectedBorderWidth = NiaChipDefaults.ChipBorderWidth, selectedBorderWidth = chipBorderWidth,
), ),
colors = FilterChipDefaults.filterChipColors( colors = FilterChipDefaults.filterChipColors(
labelColor = MaterialTheme.colorScheme.onBackground, labelColor = MaterialTheme.colorScheme.onBackground,
iconColor = MaterialTheme.colorScheme.onBackground, iconColor = MaterialTheme.colorScheme.onBackground,
disabledContainerColor = if (selected) { disabledContainerColor = if (selected) {
MaterialTheme.colorScheme.onBackground.copy( MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContainerAlpha, alpha = DISABLED_CHIP_CONTAINER_ALPHA,
) )
} else { } else {
Color.Transparent Color.Transparent
}, },
disabledLabelColor = MaterialTheme.colorScheme.onBackground.copy( disabledLabelColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha, alpha = DISABLED_CHIP_CONTENT_ALPHA,
), ),
disabledLeadingIconColor = MaterialTheme.colorScheme.onBackground.copy( disabledLeadingIconColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha, alpha = DISABLED_CHIP_CONTENT_ALPHA,
), ),
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer, selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onBackground, selectedLabelColor = MaterialTheme.colorScheme.onBackground,
@ -102,14 +106,3 @@ fun NiaFilterChip(
), ),
) )
} }
/**
* Now in Android chip default values.
*/
object NiaChipDefaults {
// TODO: File bug
// FilterChip default values aren't exposed via FilterChipDefaults
const val DisabledChipContainerAlpha = 0.12f
const val DisabledChipContentAlpha = 0.38f
val ChipBorderWidth = 1.dp
}

@ -24,6 +24,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
private const val DISABLED_ICON_BUTTON_CONTAINER_ALPHA = 0.12f
/** /**
* Now in Android toggle button with icon and checked icon content slots. Wraps Material 3 * Now in Android toggle button with icon and checked icon content slots. Wraps Material 3
* [IconButton]. * [IconButton].
@ -57,7 +59,7 @@ fun NiaIconToggleButton(
checkedContentColor = MaterialTheme.colorScheme.onPrimaryContainer, checkedContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
disabledContainerColor = if (checked) { disabledContainerColor = if (checked) {
MaterialTheme.colorScheme.onBackground.copy( MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaIconButtonDefaults.DisabledIconButtonContainerAlpha, alpha = DISABLED_ICON_BUTTON_CONTAINER_ALPHA,
) )
} else { } else {
Color.Transparent Color.Transparent
@ -67,12 +69,3 @@ fun NiaIconToggleButton(
if (checked) checkedIcon() else icon() if (checked) checkedIcon() else icon()
} }
} }
/**
* Now in Android icon button default values.
*/
object NiaIconButtonDefaults {
// TODO: File bug
// IconToggleButton disabled container alpha not exposed by IconButtonDefaults
const val DisabledIconButtonContainerAlpha = 0.12f
}

@ -25,6 +25,9 @@ import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
private const val UNFOLLOWED_TOPIC_TAG_CONTAINER_ALPHA = 0.5f
private const val DISABLED_TOPIC_TAG_CONTAINER_ALPHA = 0.12f
@Composable @Composable
fun NiaTopicTag( fun NiaTopicTag(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@ -38,7 +41,7 @@ fun NiaTopicTag(
MaterialTheme.colorScheme.primaryContainer MaterialTheme.colorScheme.primaryContainer
} else { } else {
MaterialTheme.colorScheme.surfaceVariant.copy( MaterialTheme.colorScheme.surfaceVariant.copy(
alpha = NiaTagDefaults.UnfollowedTopicTagContainerAlpha, alpha = UNFOLLOWED_TOPIC_TAG_CONTAINER_ALPHA,
) )
} }
TextButton( TextButton(
@ -48,7 +51,7 @@ fun NiaTopicTag(
containerColor = containerColor, containerColor = containerColor,
contentColor = contentColorFor(backgroundColor = containerColor), contentColor = contentColorFor(backgroundColor = containerColor),
disabledContainerColor = MaterialTheme.colorScheme.onSurface.copy( disabledContainerColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = NiaTagDefaults.DisabledTopicTagContainerAlpha, alpha = DISABLED_TOPIC_TAG_CONTAINER_ALPHA,
), ),
), ),
) { ) {
@ -58,14 +61,3 @@ fun NiaTopicTag(
} }
} }
} }
/**
* Now in Android tag default values.
*/
object NiaTagDefaults {
const val UnfollowedTopicTagContainerAlpha = 0.5f
// TODO: File bug
// Button disabled container alpha value not exposed by ButtonDefaults
const val DisabledTopicTagContainerAlpha = 0.12f
}

@ -57,10 +57,8 @@ private interface RetrofitNiaNetworkApi {
): List<NetworkChangeList> ): List<NetworkChangeList>
} }
private const val NiaBaseUrl = BuildConfig.BACKEND_URL
/** /**
* Wrapper for data provided from the [NiaBaseUrl] * Wrapper for data provided from the [BuildConfig.BACKEND_URL]
*/ */
@Serializable @Serializable
private data class NetworkResponse<T>( private data class NetworkResponse<T>(
@ -77,7 +75,7 @@ class RetrofitNiaNetwork @Inject constructor(
) : NiaNetworkDataSource { ) : NiaNetworkDataSource {
private val networkApi = Retrofit.Builder() private val networkApi = Retrofit.Builder()
.baseUrl(NiaBaseUrl) .baseUrl(BuildConfig.BACKEND_URL)
.callFactory(okhttpCallFactory) .callFactory(okhttpCallFactory)
.addConverterFactory( .addConverterFactory(
networkJson.asConverterFactory("application/json".toMediaType()), networkJson.asConverterFactory("application/json".toMediaType()),

@ -22,14 +22,14 @@ import androidx.navigation.NavOptions
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import com.google.samples.apps.nowinandroid.feature.bookmarks.BookmarksRoute import com.google.samples.apps.nowinandroid.feature.bookmarks.BookmarksRoute
const val bookmarksRoute = "bookmarks_route" const val BOOKMARKS_ROUTE = "bookmarks_route"
fun NavController.navigateToBookmarks(navOptions: NavOptions? = null) { fun NavController.navigateToBookmarks(navOptions: NavOptions? = null) {
this.navigate(bookmarksRoute, navOptions) this.navigate(BOOKMARKS_ROUTE, navOptions)
} }
fun NavGraphBuilder.bookmarksScreen(onTopicClick: (String) -> Unit) { fun NavGraphBuilder.bookmarksScreen(onTopicClick: (String) -> Unit) {
composable(route = bookmarksRoute) { composable(route = BOOKMARKS_ROUTE) {
BookmarksRoute(onTopicClick) BookmarksRoute(onTopicClick)
} }
} }

@ -26,17 +26,17 @@ import androidx.navigation.navDeepLink
import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute
const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId" const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId"
const val forYouNavigationRoute = "for_you_route/{$LINKED_NEWS_RESOURCE_ID}" const val FOR_YOU_ROUTE = "for_you_route/{$LINKED_NEWS_RESOURCE_ID}"
private const val DEEP_LINK_URI_PATTERN = private const val DEEP_LINK_URI_PATTERN =
"https://www.nowinandroid.apps.samples.google.com/foryou/{$LINKED_NEWS_RESOURCE_ID}" "https://www.nowinandroid.apps.samples.google.com/foryou/{$LINKED_NEWS_RESOURCE_ID}"
fun NavController.navigateToForYou(navOptions: NavOptions? = null) { fun NavController.navigateToForYou(navOptions: NavOptions? = null) {
this.navigate(forYouNavigationRoute, navOptions) this.navigate(FOR_YOU_ROUTE, navOptions)
} }
fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) { fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) {
composable( composable(
route = forYouNavigationRoute, route = FOR_YOU_ROUTE,
deepLinks = listOf( deepLinks = listOf(
navDeepLink { uriPattern = DEEP_LINK_URI_PATTERN }, navDeepLink { uriPattern = DEEP_LINK_URI_PATTERN },
), ),

@ -23,11 +23,11 @@ import androidx.navigation.compose.composable
import androidx.navigation.navigation import androidx.navigation.navigation
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
private const val interestsGraphRoutePattern = "interests_graph" private const val INTERESTS_GRAPH_ROUTE_PATTERN = "interests_graph"
const val interestsRoute = "interests_route" const val INTERESTS_ROUTE = "interests_route"
fun NavController.navigateToInterestsGraph(navOptions: NavOptions? = null) { fun NavController.navigateToInterestsGraph(navOptions: NavOptions? = null) {
this.navigate(interestsGraphRoutePattern, navOptions) this.navigate(INTERESTS_GRAPH_ROUTE_PATTERN, navOptions)
} }
fun NavGraphBuilder.interestsGraph( fun NavGraphBuilder.interestsGraph(
@ -35,10 +35,10 @@ fun NavGraphBuilder.interestsGraph(
nestedGraphs: NavGraphBuilder.() -> Unit, nestedGraphs: NavGraphBuilder.() -> Unit,
) { ) {
navigation( navigation(
route = interestsGraphRoutePattern, route = INTERESTS_GRAPH_ROUTE_PATTERN,
startDestination = interestsRoute, startDestination = INTERESTS_ROUTE,
) { ) {
composable(route = interestsRoute) { composable(route = INTERESTS_ROUTE) {
InterestsRoute(onTopicClick) InterestsRoute(onTopicClick)
} }
nestedGraphs() nestedGraphs()

@ -22,10 +22,10 @@ import androidx.navigation.NavOptions
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import com.google.samples.apps.nowinandroid.feature.search.SearchRoute import com.google.samples.apps.nowinandroid.feature.search.SearchRoute
const val searchRoute = "search_route" const val SEARCH_ROUTE = "search_route"
fun NavController.navigateToSearch(navOptions: NavOptions? = null) { fun NavController.navigateToSearch(navOptions: NavOptions? = null) {
this.navigate(searchRoute, navOptions) this.navigate(SEARCH_ROUTE, navOptions)
} }
fun NavGraphBuilder.searchScreen( fun NavGraphBuilder.searchScreen(
@ -35,7 +35,7 @@ fun NavGraphBuilder.searchScreen(
) { ) {
// TODO: Handle back stack for each top-level destination. At the moment each top-level // TODO: Handle back stack for each top-level destination. At the moment each top-level
// destination may have own search screen's back stack. // destination may have own search screen's back stack.
composable(route = searchRoute) { composable(route = SEARCH_ROUTE) {
SearchRoute( SearchRoute(
onBackClick = onBackClick, onBackClick = onBackClick,
onInterestsClick = onInterestsClick, onInterestsClick = onInterestsClick,

@ -28,11 +28,11 @@ import com.google.samples.apps.nowinandroid.core.decoder.StringDecoder
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
@VisibleForTesting @VisibleForTesting
internal const val topicIdArg = "topicId" internal const val TOPIC_ID_ARG = "topicId"
internal class TopicArgs(val topicId: String) { internal class TopicArgs(val topicId: String) {
constructor(savedStateHandle: SavedStateHandle, stringDecoder: StringDecoder) : constructor(savedStateHandle: SavedStateHandle, stringDecoder: StringDecoder) :
this(stringDecoder.decodeString(checkNotNull(savedStateHandle[topicIdArg]))) this(stringDecoder.decodeString(checkNotNull(savedStateHandle[TOPIC_ID_ARG])))
} }
fun NavController.navigateToTopic(topicId: String) { fun NavController.navigateToTopic(topicId: String) {
@ -47,9 +47,9 @@ fun NavGraphBuilder.topicScreen(
onTopicClick: (String) -> Unit, onTopicClick: (String) -> Unit,
) { ) {
composable( composable(
route = "topic_route/{$topicIdArg}", route = "topic_route/{$TOPIC_ID_ARG}",
arguments = listOf( arguments = listOf(
navArgument(topicIdArg) { type = NavType.StringType }, navArgument(TOPIC_ID_ARG) { type = NavType.StringType },
), ),
) { ) {
TopicRoute(onBackClick = onBackClick, onTopicClick = onTopicClick) TopicRoute(onBackClick = onBackClick, onTopicClick = onTopicClick)

@ -27,7 +27,7 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepo
import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository
import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule
import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicIdArg import com.google.samples.apps.nowinandroid.feature.topic.navigation.TOPIC_ID_ARG
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -62,7 +62,7 @@ class TopicViewModelTest {
@Before @Before
fun setup() { fun setup() {
viewModel = TopicViewModel( viewModel = TopicViewModel(
savedStateHandle = SavedStateHandle(mapOf(topicIdArg to testInputTopics[0].topic.id)), savedStateHandle = SavedStateHandle(mapOf(TOPIC_ID_ARG to testInputTopics[0].topic.id)),
stringDecoder = FakeStringDecoder(), stringDecoder = FakeStringDecoder(),
userDataRepository = userDataRepository, userDataRepository = userDataRepository,
topicsRepository = topicsRepository, topicsRepository = topicsRepository,

@ -28,7 +28,7 @@ object Sync {
WorkManager.getInstance(context).apply { WorkManager.getInstance(context).apply {
// Run sync on app startup and ensure only one sync worker runs at any time // Run sync on app startup and ensure only one sync worker runs at any time
enqueueUniqueWork( enqueueUniqueWork(
SyncWorkName, SYNC_WORK_NAME,
ExistingWorkPolicy.KEEP, ExistingWorkPolicy.KEEP,
SyncWorker.startUpSyncWork(), SyncWorker.startUpSyncWork(),
) )
@ -37,4 +37,4 @@ object Sync {
} }
// This name should not be changed otherwise the app may have concurrent sync requests running // This name should not be changed otherwise the app may have concurrent sync requests running
internal const val SyncWorkName = "SyncWorkName" internal const val SYNC_WORK_NAME = "SyncWorkName"

@ -24,7 +24,7 @@ import androidx.work.WorkInfo
import androidx.work.WorkInfo.State import androidx.work.WorkInfo.State
import androidx.work.WorkManager import androidx.work.WorkManager
import com.google.samples.apps.nowinandroid.core.data.util.SyncManager import com.google.samples.apps.nowinandroid.core.data.util.SyncManager
import com.google.samples.apps.nowinandroid.sync.initializers.SyncWorkName import com.google.samples.apps.nowinandroid.sync.initializers.SYNC_WORK_NAME
import com.google.samples.apps.nowinandroid.sync.workers.SyncWorker import com.google.samples.apps.nowinandroid.sync.workers.SyncWorker
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -38,7 +38,7 @@ class WorkManagerSyncManager @Inject constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
) : SyncManager { ) : SyncManager {
override val isSyncing: Flow<Boolean> = override val isSyncing: Flow<Boolean> =
WorkManager.getInstance(context).getWorkInfosForUniqueWorkLiveData(SyncWorkName) WorkManager.getInstance(context).getWorkInfosForUniqueWorkLiveData(SYNC_WORK_NAME)
.map(MutableList<WorkInfo>::anyRunning) .map(MutableList<WorkInfo>::anyRunning)
.asFlow() .asFlow()
.conflate() .conflate()
@ -47,7 +47,7 @@ class WorkManagerSyncManager @Inject constructor(
val workManager = WorkManager.getInstance(context) val workManager = WorkManager.getInstance(context)
// Run sync on app startup and ensure only one sync worker runs at any time // Run sync on app startup and ensure only one sync worker runs at any time
workManager.enqueueUniqueWork( workManager.enqueueUniqueWork(
SyncWorkName, SYNC_WORK_NAME,
ExistingWorkPolicy.KEEP, ExistingWorkPolicy.KEEP,
SyncWorker.startUpSyncWork(), SyncWorker.startUpSyncWork(),
) )

Loading…
Cancel
Save