From 6e6c388505d75e62577cd1d661814e2b7ffc7d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Braun?= Date: Thu, 19 Jan 2023 10:48:43 +0100 Subject: [PATCH 1/2] Create .editorconfig, enable trailing commas Change-Id: Iee83659c4a08ee1260254effac770038e529979f --- .editorconfig | 6 ++++++ gradle/init.gradle.kts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..83be1d5a0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +# https://editorconfig.org/ +# This configuration is used by ktlint when spotless invokes it + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma=true +ij_kotlin_allow_trailing_comma_on_call_site=true diff --git a/gradle/init.gradle.kts b/gradle/init.gradle.kts index bd5658fc0..57f91da08 100644 --- a/gradle/init.gradle.kts +++ b/gradle/init.gradle.kts @@ -14,10 +14,10 @@ * limitations under the License. */ -val ktlintVersion = "0.43.0" +val ktlintVersion = "0.48.1" initscript { - val spotlessVersion = "6.11.0" + val spotlessVersion = "6.13.0" repositories { mavenCentral() From 819dd494ad3d95f9dc742947500ee2f7b461360b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Braun?= Date: Thu, 19 Jan 2023 10:52:53 +0100 Subject: [PATCH 2/2] Run Spotless to add trailing commas (and apply other rule updates) Change-Id: I5f8e49a3ef004c7e9e7dfe4bc55f0a35dc575209 --- .../samples/apps/niacatalog/ui/Catalog.kt | 80 ++++++++-------- .../apps/nowinandroid/ui/NavigationTest.kt | 13 ++- .../apps/nowinandroid/ui/NavigationUiTest.kt | 41 ++++---- .../apps/nowinandroid/ui/NiaAppStateTest.kt | 22 ++--- .../samples/apps/nowinandroid/MainActivity.kt | 4 +- .../nowinandroid/MainActivityViewModel.kt | 6 +- .../apps/nowinandroid/di/JankStatsModule.kt | 2 +- .../nowinandroid/navigation/NiaNavHost.kt | 4 +- .../navigation/TopLevelDestination.kt | 10 +- .../samples/apps/nowinandroid/ui/NiaApp.kt | 54 ++++++----- .../apps/nowinandroid/ui/NiaAppState.kt | 4 +- .../test/uiautomator/UiAutomatorHelpers.kt | 4 +- .../foryou/ScrollForYouFeedBenchmark.kt | 2 +- .../TopicsScreenRecompositionBenchmark.kt | 2 +- .../nowinandroid/startup/StartupBenchmark.kt | 4 +- .../core/network/NiaDispatchers.kt | 2 +- .../nowinandroid/core/result/ResultKtTest.kt | 9 +- .../data/test/AlwaysOnlineNetworkMonitor.kt | 2 +- .../core/data/test/TestDataModule.kt | 10 +- .../nowinandroid/core/data/SyncUtilities.kt | 10 +- .../nowinandroid/core/data/di/DataModule.kt | 8 +- .../core/data/model/NewsResource.kt | 2 +- .../nowinandroid/core/data/model/Topic.kt | 2 +- .../repository/OfflineFirstNewsRepository.kt | 14 +-- .../OfflineFirstTopicsRepository.kt | 6 +- .../OfflineFirstUserDataRepository.kt | 4 +- .../repository/fake/FakeNewsRepository.kt | 8 +- .../repository/fake/FakeTopicsRepository.kt | 8 +- .../repository/fake/FakeUserDataRepository.kt | 2 +- .../util/ConnectivityManagerNetworkMonitor.kt | 8 +- .../core/data/model/NetworkEntityKtTest.kt | 2 +- .../OfflineFirstNewsRepositoryTest.kt | 32 +++---- .../OfflineFirstTopicsRepositoryTest.kt | 22 ++--- .../OfflineFirstUserDataRepositoryTest.kt | 42 ++++----- .../core/data/repository/TestSynchronizer.kt | 4 +- .../data/testdoubles/TestNewsResourceDao.kt | 12 +-- .../testdoubles/TestNiaNetworkDataSource.kt | 12 +-- .../core/data/testdoubles/TestTopicDao.kt | 4 +- .../model/PopulatedNewsResourceKtTest.kt | 10 +- .../util/NewsResourceTypeConverterTest.kt | 20 ++-- .../core/database/dao/NewsResourceDaoTest.kt | 32 +++---- .../core/database/DatabaseMigrations.kt | 16 ++-- .../core/database/DatabaseModule.kt | 2 +- .../nowinandroid/core/database/NiaDatabase.kt | 2 +- .../core/database/dao/NewsResourceDao.kt | 8 +- .../core/database/dao/TopicDao.kt | 6 +- .../core/database/model/NewsResourceEntity.kt | 4 +- .../model/NewsResourceTopicCrossRef.kt | 4 +- .../database/model/PopulatedNewsResource.kt | 6 +- .../datastore/test/TestDataStoreModule.kt | 8 +- .../core/datastore/IntToStringIdsMigration.kt | 4 +- .../core/datastore/ListToMapMigration.kt | 6 +- .../datastore/NiaPreferencesDataSource.kt | 19 ++-- .../core/datastore/di/DataStoreModule.kt | 6 +- .../datastore/IntToStringIdsMigrationTest.kt | 12 +-- .../core/datastore/ListToMapMigrationTest.kt | 16 ++-- .../datastore/NiaPreferencesDataSourceTest.kt | 8 +- .../UserPreferencesSerializerTest.kt | 8 +- .../core/designsystem/ThemeTest.kt | 26 ++--- .../core/designsystem/component/Background.kt | 10 +- .../core/designsystem/component/Button.kt | 47 +++++----- .../core/designsystem/component/Chip.kt | 20 ++-- .../designsystem/component/DropdownMenu.kt | 30 +++--- .../component/DynamicAsyncImage.kt | 4 +- .../core/designsystem/component/IconButton.kt | 8 +- .../designsystem/component/LoadingWheel.kt | 18 ++-- .../core/designsystem/component/Navigation.kt | 22 +++-- .../core/designsystem/component/Tabs.kt | 12 +-- .../core/designsystem/component/Tag.kt | 14 +-- .../core/designsystem/component/TopAppBar.kt | 12 +-- .../core/designsystem/component/ViewToggle.kt | 16 ++-- .../core/designsystem/theme/Background.kt | 2 +- .../core/designsystem/theme/Gradient.kt | 2 +- .../core/designsystem/theme/Theme.kt | 18 ++-- .../core/designsystem/theme/Type.kt | 32 +++---- .../core/domain/GetFollowableTopicsUseCase.kt | 8 +- .../domain/GetUserNewsResourcesUseCase.kt | 8 +- .../core/domain/model/FollowableTopic.kt | 10 +- .../core/domain/model/UserNewsResource.kt | 18 ++-- .../domain/GetFollowableTopicsUseCaseTest.kt | 12 +-- .../domain/GetUserNewsResourcesUseCaseTest.kt | 16 ++-- .../core/domain/UserNewsResourceTest.kt | 14 ++- .../core/model/data/NewsResource.kt | 14 +-- .../core/model/data/NewsResourceType.kt | 22 ++--- .../nowinandroid/core/model/data/Topic.kt | 6 +- .../nowinandroid/core/model/data/UserData.kt | 2 +- .../core/network/di/NetworkModule.kt | 2 +- .../network/fake/FakeNiaNetworkDataSource.kt | 4 +- .../network/model/util/InstantSerializer.kt | 2 +- .../model/util/NewsResourceTypeSerializer.kt | 2 +- .../network/retrofit/RetrofitNiaNetwork.kt | 14 +-- .../fake/FakeNiaNetworkDataSourceTest.kt | 12 +-- .../util/NewsResourceTypeSerializerTest.kt | 22 ++--- .../core/testing/di/TestDispatcherModule.kt | 2 +- .../repository/TestUserDataRepository.kt | 16 +++- .../core/ui/NewsResourceCardTest.kt | 8 +- .../core/ui/JankStatsExtensions.kt | 4 +- .../apps/nowinandroid/core/ui/NewsFeed.kt | 14 +-- .../nowinandroid/core/ui/NewsResourceCard.kt | 50 +++++----- .../core/ui/NewsResourceCardList.kt | 2 +- .../core/ui/TimeZoneBroadcastReceiver.kt | 2 +- .../feature/bookmarks/BookmarksScreenTest.kt | 40 ++++---- .../feature/bookmarks/BookmarksScreen.kt | 22 ++--- .../feature/bookmarks/BookmarksViewModel.kt | 6 +- .../bookmarks/BookmarksViewModelTest.kt | 8 +- .../feature/foryou/ForYouScreenTest.kt | 48 +++++----- .../feature/foryou/ForYouScreen.kt | 77 +++++++-------- .../feature/foryou/ForYouViewModel.kt | 14 +-- .../feature/foryou/OnboardingUiState.kt | 2 +- .../feature/foryou/ForYouViewModelTest.kt | 94 +++++++++---------- .../interests/InterestsScreenTest.kt | 12 +-- .../feature/interests/InterestsItem.kt | 32 +++---- .../feature/interests/InterestsScreen.kt | 8 +- .../feature/interests/InterestsViewModel.kt | 8 +- .../feature/interests/TabContent.kt | 6 +- .../navigation/InterestsNavigation.kt | 4 +- .../interests/InterestsViewModelTest.kt | 34 +++---- .../feature/settings/SettingsDialogTest.kt | 27 +++--- .../feature/settings/SettingsDialog.kt | 59 ++++++------ .../feature/settings/SettingsViewModel.kt | 10 +- .../feature/settings/SettingsViewModelTest.kt | 9 +- .../feature/topic/TopicScreenTest.kt | 26 ++--- .../nowinandroid/feature/topic/TopicScreen.kt | 33 ++++--- .../feature/topic/TopicViewModel.kt | 22 ++--- .../topic/navigation/TopicNavigation.kt | 6 +- .../feature/topic/TopicViewModelTest.kt | 34 +++---- .../lint/designsystem/DesignSystemDetector.kt | 18 ++-- .../designsystem/DesignSystemIssueRegistry.kt | 2 +- .../test/NeverSyncingSyncStatusMonitor.kt | 2 +- .../core/sync/test/TestSyncModule.kt | 4 +- .../sync/workers/SyncWorkerTest.kt | 2 +- .../apps/nowinandroid/sync/di/SyncModule.kt | 2 +- .../sync/initializers/SyncInitializer.kt | 2 +- .../sync/initializers/SyncWorkHelpers.kt | 8 +- .../status/WorkManagerSyncStatusMonitor.kt | 6 +- .../nowinandroid/sync/workers/SyncWorker.kt | 9 +- 136 files changed, 980 insertions(+), 969 deletions(-) diff --git a/app-nia-catalog/src/main/java/com/google/samples/apps/niacatalog/ui/Catalog.kt b/app-nia-catalog/src/main/java/com/google/samples/apps/niacatalog/ui/Catalog.kt index 965d03c47..52e1c7485 100644 --- a/app-nia-catalog/src/main/java/com/google/samples/apps/niacatalog/ui/Catalog.kt +++ b/app-nia-catalog/src/main/java/com/google/samples/apps/niacatalog/ui/Catalog.kt @@ -66,7 +66,7 @@ fun NiaCatalog() { LazyColumn( modifier = Modifier.fillMaxSize(), contentPadding = contentPadding, - verticalArrangement = Arrangement.spacedBy(16.dp) + verticalArrangement = Arrangement.spacedBy(16.dp), ) { item { Text( @@ -93,19 +93,19 @@ fun NiaCatalog() { FlowRow(mainAxisSpacing = 16.dp) { NiaButton( onClick = {}, - enabled = false + enabled = false, ) { Text(text = "Disabled") } NiaOutlinedButton( onClick = {}, - enabled = false + enabled = false, ) { Text(text = "Disabled") } NiaTextButton( onClick = {}, - enabled = false + enabled = false, ) { Text(text = "Disabled") } @@ -119,21 +119,21 @@ fun NiaCatalog() { text = { Text(text = "Enabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) NiaOutlinedButton( onClick = {}, text = { Text(text = "Enabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) NiaTextButton( onClick = {}, text = { Text(text = "Enabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) } } @@ -146,7 +146,7 @@ fun NiaCatalog() { text = { Text(text = "Disabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) NiaOutlinedButton( onClick = {}, @@ -154,7 +154,7 @@ fun NiaCatalog() { text = { Text(text = "Disabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) NiaTextButton( onClick = {}, @@ -162,7 +162,7 @@ fun NiaCatalog() { text = { Text(text = "Disabled") }, leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) - } + }, ) } } @@ -173,14 +173,14 @@ fun NiaCatalog() { text = { Text("Enabled") }, items = listOf("Item 1", "Item 2", "Item 3"), onItemClick = {}, - itemText = { item -> Text(item) } + itemText = { item -> Text(item) }, ) NiaDropdownMenuButton( text = { Text("Disabled") }, items = listOf("Item 1", "Item 2", "Item 3"), onItemClick = {}, itemText = { item -> Text(item) }, - enabled = false + enabled = false, ) } } @@ -191,25 +191,25 @@ fun NiaCatalog() { NiaFilterChip( selected = firstChecked, onSelectedChange = { checked -> firstChecked = checked }, - label = { Text(text = "Enabled") } + label = { Text(text = "Enabled") }, ) var secondChecked by remember { mutableStateOf(true) } NiaFilterChip( selected = secondChecked, onSelectedChange = { checked -> secondChecked = checked }, - label = { Text(text = "Enabled") } + label = { Text(text = "Enabled") }, ) NiaFilterChip( selected = false, onSelectedChange = {}, enabled = false, - label = { Text(text = "Disabled") } + label = { Text(text = "Disabled") }, ) NiaFilterChip( selected = true, onSelectedChange = {}, enabled = false, - label = { Text(text = "Disabled") } + label = { Text(text = "Disabled") }, ) } } @@ -223,15 +223,15 @@ fun NiaCatalog() { icon = { Icon( painter = painterResource(id = NiaIcons.BookmarkBorder), - contentDescription = null + contentDescription = null, ) }, checkedIcon = { Icon( painter = painterResource(id = NiaIcons.Bookmark), - contentDescription = null + contentDescription = null, ) - } + }, ) var secondChecked by remember { mutableStateOf(true) } NiaIconToggleButton( @@ -240,15 +240,15 @@ fun NiaCatalog() { icon = { Icon( painter = painterResource(id = NiaIcons.BookmarkBorder), - contentDescription = null + contentDescription = null, ) }, checkedIcon = { Icon( painter = painterResource(id = NiaIcons.Bookmark), - contentDescription = null + contentDescription = null, ) - } + }, ) NiaIconToggleButton( checked = false, @@ -256,16 +256,16 @@ fun NiaCatalog() { icon = { Icon( painter = painterResource(id = NiaIcons.BookmarkBorder), - contentDescription = null + contentDescription = null, ) }, checkedIcon = { Icon( painter = painterResource(id = NiaIcons.Bookmark), - contentDescription = null + contentDescription = null, ) }, - enabled = false + enabled = false, ) NiaIconToggleButton( checked = true, @@ -273,16 +273,16 @@ fun NiaCatalog() { icon = { Icon( painter = painterResource(id = NiaIcons.BookmarkBorder), - contentDescription = null + contentDescription = null, ) }, checkedIcon = { Icon( painter = painterResource(id = NiaIcons.Bookmark), - contentDescription = null + contentDescription = null, ) }, - enabled = false + enabled = false, ) } } @@ -294,21 +294,21 @@ fun NiaCatalog() { expanded = firstExpanded, onExpandedChange = { expanded -> firstExpanded = expanded }, compactText = { Text(text = "Compact view") }, - expandedText = { Text(text = "Expanded view") } + expandedText = { Text(text = "Expanded view") }, ) var secondExpanded by remember { mutableStateOf(true) } NiaViewToggleButton( expanded = secondExpanded, onExpandedChange = { expanded -> secondExpanded = expanded }, compactText = { Text(text = "Compact view") }, - expandedText = { Text(text = "Expanded view") } + expandedText = { Text(text = "Expanded view") }, ) NiaViewToggleButton( expanded = false, onExpandedChange = {}, compactText = { Text(text = "Disabled") }, expandedText = { Text(text = "Disabled") }, - enabled = false + enabled = false, ) } } @@ -330,7 +330,7 @@ fun NiaCatalog() { text = { Text(text = "Topic 1".uppercase()) }, followText = { Text(text = "Follow") }, unFollowText = { Text(text = "Unfollow") }, - browseText = { Text(text = "Browse topic") } + browseText = { Text(text = "Browse topic") }, ) var secondFollowed by remember { mutableStateOf(true) } NiaTopicTag( @@ -345,7 +345,7 @@ fun NiaCatalog() { text = { Text(text = "Topic 2".uppercase()) }, followText = { Text(text = "Follow") }, unFollowText = { Text(text = "Unfollow") }, - browseText = { Text(text = "Browse topic") } + browseText = { Text(text = "Browse topic") }, ) NiaTopicTag( expanded = false, @@ -355,7 +355,7 @@ fun NiaCatalog() { onUnfollowClick = {}, onBrowseClick = {}, text = { Text(text = "Disabled".uppercase()) }, - enabled = false + enabled = false, ) } } @@ -368,7 +368,7 @@ fun NiaCatalog() { NiaTab( selected = selectedTabIndex == index, onClick = { selectedTabIndex = index }, - text = { Text(text = title) } + text = { Text(text = title) }, ) } } @@ -380,12 +380,12 @@ fun NiaCatalog() { val icons = listOf( NiaIcons.UpcomingBorder, NiaIcons.MenuBookBorder, - NiaIcons.BookmarksBorder + NiaIcons.BookmarksBorder, ) val selectedIcons = listOf( NiaIcons.Upcoming, NiaIcons.MenuBook, - NiaIcons.Bookmarks + NiaIcons.Bookmarks, ) val tagIcon = NiaIcons.Tag NiaNavigationBar { @@ -397,7 +397,7 @@ fun NiaCatalog() { } else { Icon( painter = painterResource(id = icons[index]), - contentDescription = item + contentDescription = item, ) } }, @@ -407,13 +407,13 @@ fun NiaCatalog() { } else { Icon( painter = painterResource(id = selectedIcons[index]), - contentDescription = item + contentDescription = item, ) } }, label = { Text(item) }, selected = selectedItem == index, - onClick = { selectedItem = index } + onClick = { selectedItem = index }, ) } } diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt index 8474c3546..17dd28ac7 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt @@ -29,10 +29,6 @@ import androidx.test.espresso.Espresso import androidx.test.espresso.NoActivityResumedException import com.google.samples.apps.nowinandroid.MainActivity import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR -import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR -import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR -import com.google.samples.apps.nowinandroid.feature.settings.R as SettingsR import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest @@ -40,6 +36,10 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import com.google.samples.apps.nowinandroid.feature.bookmarks.R as BookmarksR +import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR +import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR +import com.google.samples.apps.nowinandroid.feature.settings.R as SettingsR /** * Tests all the navigation flows that are handled by the navigation library. @@ -57,7 +57,8 @@ class NavigationTest { * Create a temporary folder used to create a Data Store file. This guarantees that * the file is removed in between each test, preventing a crash. */ - @BindValue @get:Rule(order = 1) + @BindValue + @get:Rule(order = 1) val tmpFolder: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build() /** @@ -165,7 +166,6 @@ class NavigationTest { @Test fun topLevelDestinations_showTopBarWithTitle() { composeTestRule.apply { - // Verify that the top bar contains the app name on the first screen. onNodeWithText(appName).assertExists() @@ -207,7 +207,6 @@ class NavigationTest { @Test fun whenSettingsDialogDismissed_previousScreenIsDisplayed() { composeTestRule.apply { - // Navigate to the saved screen, open the settings dialog, then close it. onNodeWithText(saved).performClick() onNodeWithContentDescription(settings).performClick() diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationUiTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationUiTest.kt index 67dd5b61c..ca20d4332 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationUiTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationUiTest.kt @@ -30,11 +30,11 @@ import com.google.samples.apps.nowinandroid.uitesthiltmanifest.HiltComponentActi import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest -import javax.inject.Inject import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import javax.inject.Inject /** * Tests that the navigation UI is rendered correctly on different screen sizes. @@ -53,7 +53,8 @@ class NavigationUiTest { * Create a temporary folder used to create a Data Store file. This guarantees that * the file is removed in between each test, preventing a crash. */ - @BindValue @get:Rule(order = 1) + @BindValue + @get:Rule(order = 1) val tmpFolder: TemporaryFolder = TemporaryFolder.builder().assureDeletion().build() /** @@ -77,9 +78,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -96,9 +97,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -115,9 +116,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -134,9 +135,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -153,9 +154,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -172,9 +173,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -191,9 +192,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -210,9 +211,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } @@ -229,9 +230,9 @@ class NavigationUiTest { BoxWithConstraints { NiaApp( windowSizeClass = WindowSizeClass.calculateFromSize( - DpSize(maxWidth, maxHeight) + DpSize(maxWidth, maxHeight), ), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } } diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt index 8e0d65636..64896a544 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt @@ -31,15 +31,15 @@ import androidx.navigation.compose.composable import androidx.navigation.createGraph import androidx.navigation.testing.TestNavHostController import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue /** * Tests [NiaAppState]. @@ -70,7 +70,7 @@ class NiaAppStateTest { windowSizeClass = getCompactWindowClass(), navController = navController, networkMonitor = networkMonitor, - coroutineScope = backgroundScope + coroutineScope = backgroundScope, ) } @@ -91,7 +91,7 @@ class NiaAppStateTest { composeTestRule.setContent { state = rememberNiaAppState( windowSizeClass = getCompactWindowClass(), - networkMonitor = networkMonitor + networkMonitor = networkMonitor, ) } @@ -108,7 +108,7 @@ class NiaAppStateTest { windowSizeClass = getCompactWindowClass(), navController = NavHostController(LocalContext.current), networkMonitor = networkMonitor, - coroutineScope = backgroundScope + coroutineScope = backgroundScope, ) } @@ -123,7 +123,7 @@ class NiaAppStateTest { windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(800.dp, 800.dp)), navController = NavHostController(LocalContext.current), networkMonitor = networkMonitor, - coroutineScope = backgroundScope + coroutineScope = backgroundScope, ) } @@ -133,13 +133,12 @@ class NiaAppStateTest { @Test fun niaAppState_showNavRail_large() = runTest { - composeTestRule.setContent { state = NiaAppState( windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)), navController = NavHostController(LocalContext.current), networkMonitor = networkMonitor, - coroutineScope = backgroundScope + coroutineScope = backgroundScope, ) } @@ -149,13 +148,12 @@ class NiaAppStateTest { @Test fun stateIsOfflineWhenNetworkMonitorIsOffline() = runTest(UnconfinedTestDispatcher()) { - composeTestRule.setContent { state = NiaAppState( windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)), navController = NavHostController(LocalContext.current), networkMonitor = networkMonitor, - coroutineScope = backgroundScope + coroutineScope = backgroundScope, ) } @@ -163,7 +161,7 @@ class NiaAppStateTest { networkMonitor.setConnected(false) assertEquals( true, - state.isOffline.value + state.isOffline.value, ) } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt index 06cbf9c84..e46d2156a 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivity.kt @@ -43,10 +43,10 @@ import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.ui.NiaApp import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import javax.inject.Inject @OptIn(ExperimentalMaterial3WindowSizeClassApi::class) @AndroidEntryPoint @@ -107,7 +107,7 @@ class MainActivity : ComponentActivity() { NiaTheme( darkTheme = darkTheme, androidTheme = shouldUseAndroidTheme(uiState), - disableDynamicTheming = shouldDisableDynamicTheming(uiState) + disableDynamicTheming = shouldDisableDynamicTheming(uiState), ) { NiaApp( networkMonitor = networkMonitor, diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt index 0a182cbd7..ebea4b965 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt @@ -23,22 +23,22 @@ import com.google.samples.apps.nowinandroid.MainActivityUiState.Success import com.google.samples.apps.nowinandroid.core.data.repository.UserDataRepository import com.google.samples.apps.nowinandroid.core.model.data.UserData import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn +import javax.inject.Inject @HiltViewModel class MainActivityViewModel @Inject constructor( - userDataRepository: UserDataRepository + userDataRepository: UserDataRepository, ) : ViewModel() { val uiState: StateFlow = userDataRepository.userData.map { Success(it) }.stateIn( scope = viewModelScope, initialValue = Loading, - started = SharingStarted.WhileSubscribed(5_000) + started = SharingStarted.WhileSubscribed(5_000), ) } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/di/JankStatsModule.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/di/JankStatsModule.kt index 90f844c1b..be64d057f 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/di/JankStatsModule.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/di/JankStatsModule.kt @@ -47,7 +47,7 @@ object JankStatsModule { @Provides fun providesJankStats( window: Window, - frameListener: JankStats.OnFrameListener + frameListener: JankStats.OnFrameListener, ): JankStats { return JankStats.createAndTrack(window, frameListener) } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt index 6146a5527..d6e30a10e 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt @@ -39,7 +39,7 @@ fun NiaNavHost( navController: NavHostController, onBackClick: () -> Unit, modifier: Modifier = Modifier, - startDestination: String = forYouNavigationRoute + startDestination: String = forYouNavigationRoute, ) { NavHost( navController = navController, @@ -54,7 +54,7 @@ fun NiaNavHost( }, nestedGraphs = { topicScreen(onBackClick) - } + }, ) } } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt index 956037f29..396ab8b7b 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt @@ -34,24 +34,24 @@ enum class TopLevelDestination( val selectedIcon: Icon, val unselectedIcon: Icon, val iconTextId: Int, - val titleTextId: Int + val titleTextId: Int, ) { FOR_YOU( selectedIcon = DrawableResourceIcon(NiaIcons.Upcoming), unselectedIcon = DrawableResourceIcon(NiaIcons.UpcomingBorder), iconTextId = forYouR.string.for_you, - titleTextId = R.string.app_name + titleTextId = R.string.app_name, ), BOOKMARKS( selectedIcon = DrawableResourceIcon(NiaIcons.Bookmarks), unselectedIcon = DrawableResourceIcon(NiaIcons.BookmarksBorder), iconTextId = bookmarksR.string.saved, - titleTextId = bookmarksR.string.saved + titleTextId = bookmarksR.string.saved, ), INTERESTS( selectedIcon = ImageVectorIcon(NiaIcons.Grid3x3), unselectedIcon = ImageVectorIcon(NiaIcons.Grid3x3), iconTextId = interestsR.string.interests, - titleTextId = interestsR.string.interests - ) + titleTextId = interestsR.string.interests, + ), } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt index a3f570ad5..14bc11992 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt @@ -68,16 +68,16 @@ import com.google.samples.apps.nowinandroid.core.designsystem.icon.Icon.ImageVec import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.GradientColors import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalGradientColors -import com.google.samples.apps.nowinandroid.feature.settings.R as settingsR import com.google.samples.apps.nowinandroid.feature.settings.SettingsDialog import com.google.samples.apps.nowinandroid.navigation.NiaNavHost import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination +import com.google.samples.apps.nowinandroid.feature.settings.R as settingsR @OptIn( ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class, ExperimentalComposeUiApi::class, - ExperimentalLifecycleComposeApi::class + ExperimentalLifecycleComposeApi::class, ) @Composable fun NiaApp( @@ -85,7 +85,7 @@ fun NiaApp( networkMonitor: NetworkMonitor, appState: NiaAppState = rememberNiaAppState( networkMonitor = networkMonitor, - windowSizeClass = windowSizeClass + windowSizeClass = windowSizeClass, ), ) { val shouldShowGradientBackground = @@ -106,15 +106,17 @@ fun NiaApp( // If user is not connected to the internet show a snack bar to inform them. val notConnectedMessage = stringResource(R.string.not_connected) LaunchedEffect(isOffline) { - if (isOffline) snackbarHostState.showSnackbar( - message = notConnectedMessage, - duration = Indefinite - ) + if (isOffline) { + snackbarHostState.showSnackbar( + message = notConnectedMessage, + duration = Indefinite, + ) + } } if (appState.shouldShowSettingsDialog) { SettingsDialog( - onDismiss = { appState.setShowSettingsDialog(false) } + onDismiss = { appState.setShowSettingsDialog(false) }, ) } @@ -132,10 +134,10 @@ fun NiaApp( destinations = appState.topLevelDestinations, onNavigateToDestination = appState::navigateToTopLevelDestination, currentDestination = appState.currentDestination, - modifier = Modifier.testTag("NiaBottomBar") + modifier = Modifier.testTag("NiaBottomBar"), ) } - } + }, ) { padding -> Row( Modifier @@ -144,9 +146,9 @@ fun NiaApp( .consumedWindowInsets(padding) .windowInsetsPadding( WindowInsets.safeDrawing.only( - WindowInsetsSides.Horizontal - ) - ) + WindowInsetsSides.Horizontal, + ), + ), ) { if (appState.shouldShowNavRail) { NiaNavRail( @@ -155,7 +157,7 @@ fun NiaApp( currentDestination = appState.currentDestination, modifier = Modifier .testTag("NiaNavRail") - .safeDrawingPadding() + .safeDrawingPadding(), ) } @@ -167,18 +169,18 @@ fun NiaApp( titleRes = destination.titleTextId, actionIcon = NiaIcons.Settings, actionIconContentDescription = stringResource( - id = settingsR.string.top_app_bar_action_icon_description + id = settingsR.string.top_app_bar_action_icon_description, ), colors = TopAppBarDefaults.centerAlignedTopAppBarColors( - containerColor = Color.Transparent + containerColor = Color.Transparent, ), - onActionClick = { appState.setShowSettingsDialog(true) } + onActionClick = { appState.setShowSettingsDialog(true) }, ) } NiaNavHost( navController = appState.navController, - onBackClick = appState::onBackClick + onBackClick = appState::onBackClick, ) } @@ -212,15 +214,15 @@ private fun NiaNavRail( when (icon) { is ImageVectorIcon -> Icon( imageVector = icon.imageVector, - contentDescription = null + contentDescription = null, ) is DrawableResourceIcon -> Icon( painter = painterResource(id = icon.id), - contentDescription = null + contentDescription = null, ) } }, - label = { Text(stringResource(destination.iconTextId)) } + label = { Text(stringResource(destination.iconTextId)) }, ) } } @@ -231,10 +233,10 @@ private fun NiaBottomBar( destinations: List, onNavigateToDestination: (TopLevelDestination) -> Unit, currentDestination: NavDestination?, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { NiaNavigationBar( - modifier = modifier + modifier = modifier, ) { destinations.forEach { destination -> val selected = currentDestination.isTopLevelDestinationInHierarchy(destination) @@ -250,16 +252,16 @@ private fun NiaBottomBar( when (icon) { is ImageVectorIcon -> Icon( imageVector = icon.imageVector, - contentDescription = null + contentDescription = null, ) is DrawableResourceIcon -> Icon( painter = painterResource(id = icon.id), - contentDescription = null + contentDescription = null, ) } }, - label = { Text(stringResource(destination.iconTextId)) } + label = { Text(stringResource(destination.iconTextId)) }, ) } } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt index bc5724c02..51df525a0 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt @@ -56,7 +56,7 @@ fun rememberNiaAppState( windowSizeClass: WindowSizeClass, networkMonitor: NetworkMonitor, coroutineScope: CoroutineScope = rememberCoroutineScope(), - navController: NavHostController = rememberNavController() + navController: NavHostController = rememberNavController(), ): NiaAppState { NavigationTrackingSideEffect(navController) return remember(navController, coroutineScope, windowSizeClass, networkMonitor) { @@ -98,7 +98,7 @@ class NiaAppState( .stateIn( scope = coroutineScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = false + initialValue = false, ) /** diff --git a/benchmarks/src/main/java/androidx/test/uiautomator/UiAutomatorHelpers.kt b/benchmarks/src/main/java/androidx/test/uiautomator/UiAutomatorHelpers.kt index 3e5191d34..85867b982 100644 --- a/benchmarks/src/main/java/androidx/test/uiautomator/UiAutomatorHelpers.kt +++ b/benchmarks/src/main/java/androidx/test/uiautomator/UiAutomatorHelpers.kt @@ -28,7 +28,7 @@ import androidx.test.uiautomator.HasChildrenOp.EXACTLY */ fun untilHasChildren( childCount: Int = 1, - op: HasChildrenOp = AT_LEAST + op: HasChildrenOp = AT_LEAST, ): UiObject2Condition { return object : UiObject2Condition() { override fun apply(element: UiObject2): Boolean { @@ -44,5 +44,5 @@ fun untilHasChildren( enum class HasChildrenOp { AT_LEAST, EXACTLY, - AT_MOST + AT_MOST, } diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ScrollForYouFeedBenchmark.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ScrollForYouFeedBenchmark.kt index b4e8352dc..f8945a31c 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ScrollForYouFeedBenchmark.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ScrollForYouFeedBenchmark.kt @@ -47,7 +47,7 @@ class ScrollForYouFeedBenchmark { // Start the app pressHome() startActivityAndWait() - } + }, ) { forYouWaitForContent() forYouSelectTopics() diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt index 69f02d235..24bd233ea 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt @@ -51,7 +51,7 @@ class TopicsScreenRecompositionBenchmark { // Navigate to interests screen device.findObject(By.text("Interests")).click() device.waitForIdle() - } + }, ) { interestsWaitForTopics() repeat(3) { diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt index 5d83d89b2..8e396eda3 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt @@ -66,7 +66,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { @Test fun startupBaselineProfileDisabled() = startup( - CompilationMode.Partial(baselineProfileMode = Disable, warmupIterations = 1) + CompilationMode.Partial(baselineProfileMode = Disable, warmupIterations = 1), ) @Test @@ -83,7 +83,7 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { startupMode = startupMode, setupBlock = { pressHome() - } + }, ) { startActivityAndWait() // Waits until the content is ready to capture Time To Full Display diff --git a/core/common/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt b/core/common/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt index 5895568a7..277b68717 100644 --- a/core/common/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt +++ b/core/common/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt @@ -24,5 +24,5 @@ import kotlin.annotation.AnnotationRetention.RUNTIME annotation class Dispatcher(val niaDispatcher: NiaDispatchers) enum class NiaDispatchers { - IO + IO, } diff --git a/core/common/src/test/java/com/google/samples/apps/nowinandroid/core/result/ResultKtTest.kt b/core/common/src/test/java/com/google/samples/apps/nowinandroid/core/result/ResultKtTest.kt index 90852c7c5..4f1229e9d 100644 --- a/core/common/src/test/java/com/google/samples/apps/nowinandroid/core/result/ResultKtTest.kt +++ b/core/common/src/test/java/com/google/samples/apps/nowinandroid/core/result/ResultKtTest.kt @@ -17,10 +17,10 @@ package com.google.samples.apps.nowinandroid.core.result import app.cash.turbine.test -import kotlin.test.assertEquals import kotlinx.coroutines.flow.flow import kotlinx.coroutines.test.runTest import org.junit.Test +import kotlin.test.assertEquals class ResultKtTest { @@ -38,11 +38,12 @@ class ResultKtTest { when (val errorResult = awaitItem()) { is Result.Error -> assertEquals( "Test Done", - errorResult.exception?.message + errorResult.exception?.message, ) Result.Loading, - is Result.Success -> throw IllegalStateException( - "The flow should have emitted an Error Result" + is Result.Success, + -> throw IllegalStateException( + "The flow should have emitted an Error Result", ) } diff --git a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt index 91e47b688..c00c99ded 100644 --- a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt +++ b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/AlwaysOnlineNetworkMonitor.kt @@ -17,9 +17,9 @@ package com.google.samples.apps.nowinandroid.core.data.test import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf +import javax.inject.Inject class AlwaysOnlineNetworkMonitor @Inject constructor() : NetworkMonitor { override val isOnline: Flow = flowOf(true) diff --git a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt index ca20edc44..f4fc9c7b0 100644 --- a/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt +++ b/core/data-test/src/main/java/com/google/samples/apps/nowinandroid/core/data/test/TestDataModule.kt @@ -32,26 +32,26 @@ import dagger.hilt.testing.TestInstallIn @Module @TestInstallIn( components = [SingletonComponent::class], - replaces = [DataModule::class] + replaces = [DataModule::class], ) interface TestDataModule { @Binds fun bindsTopicRepository( - fakeTopicsRepository: FakeTopicsRepository + fakeTopicsRepository: FakeTopicsRepository, ): TopicsRepository @Binds fun bindsNewsResourceRepository( - fakeNewsRepository: FakeNewsRepository + fakeNewsRepository: FakeNewsRepository, ): NewsRepository @Binds fun bindsUserDataRepository( - userDataRepository: FakeUserDataRepository + userDataRepository: FakeUserDataRepository, ): UserDataRepository @Binds fun bindsNetworkMonitor( - networkMonitor: AlwaysOnlineNetworkMonitor + networkMonitor: AlwaysOnlineNetworkMonitor, ): NetworkMonitor } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt index 0f2a592de..5d069dbaf 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/SyncUtilities.kt @@ -19,9 +19,9 @@ package com.google.samples.apps.nowinandroid.core.data import android.util.Log import com.google.samples.apps.nowinandroid.core.datastore.ChangeListVersions import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList -import kotlin.coroutines.cancellation.CancellationException import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import kotlin.coroutines.cancellation.CancellationException /** * Interface marker for a class that manages synchronization between local data and a remote @@ -62,7 +62,7 @@ private suspend fun suspendRunCatching(block: suspend () -> T): Result = Log.i( "suspendRunCatching", "Failed to evaluate a suspendRunCatchingBlock. Returning failure Result", - exception + exception, ) Result.failure(exception) } @@ -116,10 +116,10 @@ fun combine( flow4: Flow, flow5: Flow, flow6: Flow, - transform: suspend (T1, T2, T3, T4, T5, T6) -> R + transform: suspend (T1, T2, T3, T4, T5, T6) -> R, ): Flow = combine( combine(flow, flow2, flow3, ::Triple), - combine(flow4, flow5, flow6, ::Triple) + combine(flow4, flow5, flow6, ::Triple), ) { t1, t2 -> transform( t1.first, @@ -127,6 +127,6 @@ fun combine( t1.third, t2.first, t2.second, - t2.third + t2.third, ) } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt index c58552416..b4dda701e 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/di/DataModule.kt @@ -35,21 +35,21 @@ interface DataModule { @Binds fun bindsTopicRepository( - topicsRepository: OfflineFirstTopicsRepository + topicsRepository: OfflineFirstTopicsRepository, ): TopicsRepository @Binds fun bindsNewsResourceRepository( - newsRepository: OfflineFirstNewsRepository + newsRepository: OfflineFirstNewsRepository, ): NewsRepository @Binds fun bindsUserDataRepository( - userDataRepository: OfflineFirstUserDataRepository + userDataRepository: OfflineFirstUserDataRepository, ): UserDataRepository @Binds fun bindsNetworkMonitor( - networkMonitor: ConnectivityManagerNetworkMonitor + networkMonitor: ConnectivityManagerNetworkMonitor, ): NetworkMonitor } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/NewsResource.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/NewsResource.kt index ecb2d7a4e..c3ad91dfe 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/NewsResource.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/NewsResource.kt @@ -62,6 +62,6 @@ fun NetworkNewsResource.topicCrossReferences(): List topics.map { topicId -> NewsResourceTopicCrossRef( newsResourceId = id, - topicId = topicId + topicId = topicId, ) } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/Topic.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/Topic.kt index b9acb90a0..188b1e06d 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/Topic.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/model/Topic.kt @@ -25,5 +25,5 @@ fun NetworkTopic.asEntity() = TopicEntity( shortDescription = shortDescription, longDescription = longDescription, url = url, - imageUrl = imageUrl + imageUrl = imageUrl, ) diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt index bd434a7dc..9e041b956 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepository.kt @@ -30,9 +30,9 @@ import com.google.samples.apps.nowinandroid.core.datastore.ChangeListVersions import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map +import javax.inject.Inject /** * Disk storage backed implementation of the [NewsRepository]. @@ -49,9 +49,9 @@ class OfflineFirstNewsRepository @Inject constructor( .map { it.map(PopulatedNewsResource::asExternalModel) } override fun getNewsResources( - filterTopicIds: Set + filterTopicIds: Set, ): Flow> = newsResourceDao.getNewsResources( - filterTopicIds = filterTopicIds + filterTopicIds = filterTopicIds, ) .map { it.map(PopulatedNewsResource::asExternalModel) } @@ -74,18 +74,18 @@ class OfflineFirstNewsRepository @Inject constructor( topicEntities = networkNewsResources .map(NetworkNewsResource::topicEntityShells) .flatten() - .distinctBy(TopicEntity::id) + .distinctBy(TopicEntity::id), ) newsResourceDao.upsertNewsResources( newsResourceEntities = networkNewsResources - .map(NetworkNewsResource::asEntity) + .map(NetworkNewsResource::asEntity), ) newsResourceDao.insertOrIgnoreTopicCrossRefEntities( newsResourceTopicCrossReferences = networkNewsResources .map(NetworkNewsResource::topicCrossReferences) .distinct() - .flatten() + .flatten(), ) - } + }, ) } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt index c3d2cb72e..13dd19e49 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepository.kt @@ -26,9 +26,9 @@ import com.google.samples.apps.nowinandroid.core.datastore.ChangeListVersions import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map +import javax.inject.Inject /** * Disk storage backed implementation of the [TopicsRepository]. @@ -59,8 +59,8 @@ class OfflineFirstTopicsRepository @Inject constructor( modelUpdater = { changedIds -> val networkTopics = network.getTopics(ids = changedIds) topicDao.upsertTopics( - entities = networkTopics.map(NetworkTopic::asEntity) + entities = networkTopics.map(NetworkTopic::asEntity), ) - } + }, ) } diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepository.kt index 954779a3f..200ca4a3d 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepository.kt @@ -20,11 +20,11 @@ import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSou import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData -import javax.inject.Inject import kotlinx.coroutines.flow.Flow +import javax.inject.Inject class OfflineFirstUserDataRepository @Inject constructor( - private val niaPreferencesDataSource: NiaPreferencesDataSource + private val niaPreferencesDataSource: NiaPreferencesDataSource, ) : UserDataRepository { override val userData: Flow = diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt index f74a94a43..d6a712538 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeNewsRepository.kt @@ -26,11 +26,11 @@ import com.google.samples.apps.nowinandroid.core.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource -import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn +import javax.inject.Inject /** * Fake implementation of the [NewsRepository] that retrieves the news resources from a JSON String. @@ -40,7 +40,7 @@ import kotlinx.coroutines.flow.flowOn */ class FakeNewsRepository @Inject constructor( @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource + private val datasource: FakeNiaNetworkDataSource, ) : NewsRepository { override fun getNewsResources(): Flow> = @@ -48,7 +48,7 @@ class FakeNewsRepository @Inject constructor( emit( datasource.getNewsResources() .map(NetworkNewsResource::asEntity) - .map(NewsResourceEntity::asExternalModel) + .map(NewsResourceEntity::asExternalModel), ) }.flowOn(ioDispatcher) @@ -61,7 +61,7 @@ class FakeNewsRepository @Inject constructor( .getNewsResources() .filter { it.topics.intersect(filterTopicIds).isNotEmpty() } .map(NetworkNewsResource::asEntity) - .map(NewsResourceEntity::asExternalModel) + .map(NewsResourceEntity::asExternalModel), ) }.flowOn(ioDispatcher) diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt index 60d876b75..1ab9c9353 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeTopicsRepository.kt @@ -22,12 +22,12 @@ import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.network.Dispatcher import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.IO import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiaNetworkDataSource -import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import javax.inject.Inject /** * Fake implementation of the [TopicsRepository] that retrieves the topics from a JSON String, and @@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.map */ class FakeTopicsRepository @Inject constructor( @Dispatcher(IO) private val ioDispatcher: CoroutineDispatcher, - private val datasource: FakeNiaNetworkDataSource + private val datasource: FakeNiaNetworkDataSource, ) : TopicsRepository { override fun getTopics(): Flow> = flow { emit( @@ -49,9 +49,9 @@ class FakeTopicsRepository @Inject constructor( shortDescription = it.shortDescription, longDescription = it.longDescription, url = it.url, - imageUrl = it.imageUrl + imageUrl = it.imageUrl, ) - } + }, ) }.flowOn(ioDispatcher) diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt index d7920cabc..af206e5c7 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/repository/fake/FakeUserDataRepository.kt @@ -21,8 +21,8 @@ import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSou import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData -import javax.inject.Inject import kotlinx.coroutines.flow.Flow +import javax.inject.Inject /** * Fake implementation of the [UserDataRepository] that returns hardcoded user data. diff --git a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/util/ConnectivityManagerNetworkMonitor.kt b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/util/ConnectivityManagerNetworkMonitor.kt index 0f86f5384..982f47c6e 100644 --- a/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/util/ConnectivityManagerNetworkMonitor.kt +++ b/core/data/src/main/java/com/google/samples/apps/nowinandroid/core/data/util/ConnectivityManagerNetworkMonitor.kt @@ -26,14 +26,14 @@ import android.os.Build.VERSION import android.os.Build.VERSION_CODES import androidx.core.content.getSystemService import dagger.hilt.android.qualifiers.ApplicationContext -import javax.inject.Inject import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate +import javax.inject.Inject class ConnectivityManagerNetworkMonitor @Inject constructor( - @ApplicationContext private val context: Context + @ApplicationContext private val context: Context, ) : NetworkMonitor { override val isOnline: Flow = callbackFlow { val connectivityManager = context.getSystemService() @@ -54,7 +54,7 @@ class ConnectivityManagerNetworkMonitor @Inject constructor( override fun onCapabilitiesChanged( network: Network, - networkCapabilities: NetworkCapabilities + networkCapabilities: NetworkCapabilities, ) { channel.trySend(connectivityManager.isCurrentlyConnected()) } @@ -64,7 +64,7 @@ class ConnectivityManagerNetworkMonitor @Inject constructor( Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(), - callback + callback, ) channel.trySend(connectivityManager.isCurrentlyConnected()) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt index ed0c78c8e..dbbb3a94e 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt @@ -20,9 +20,9 @@ import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Art import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResourceExpanded import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic -import kotlin.test.assertEquals import kotlinx.datetime.Instant import org.junit.Test +import kotlin.test.assertEquals class NetworkEntityKtTest { diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt index cc32bf9bb..74848d655 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstNewsRepositoryTest.kt @@ -35,13 +35,13 @@ import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferen import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource -import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import kotlin.test.assertEquals class OfflineFirstNewsRepositoryTest { @@ -65,8 +65,8 @@ class OfflineFirstNewsRepositoryTest { network = TestNiaNetworkDataSource() synchronizer = TestSynchronizer( NiaPreferencesDataSource( - tmpFolder.testUserPreferencesDataStore() - ) + tmpFolder.testUserPreferencesDataStore(), + ), ) subject = OfflineFirstNewsRepository( @@ -84,7 +84,7 @@ class OfflineFirstNewsRepositoryTest { .first() .map(PopulatedNewsResource::asExternalModel), subject.getNewsResources() - .first() + .first(), ) } @@ -100,7 +100,7 @@ class OfflineFirstNewsRepositoryTest { subject.getNewsResources( filterTopicIds = filteredInterestsIds, ) - .first() + .first(), ) assertEquals( @@ -108,7 +108,7 @@ class OfflineFirstNewsRepositoryTest { subject.getNewsResources( filterTopicIds = nonPresentInterestsIds, ) - .first() + .first(), ) } @@ -127,13 +127,13 @@ class OfflineFirstNewsRepositoryTest { assertEquals( newsResourcesFromNetwork.map(NewsResource::id), - newsResourcesFromDb.map(NewsResource::id) + newsResourcesFromDb.map(NewsResource::id), ) // After sync version should be updated assertEquals( network.latestChangeListVersion(CollectionType.NewsResources), - synchronizer.getChangeListVersions().newsResourceVersion + synchronizer.getChangeListVersions().newsResourceVersion, ) } @@ -155,7 +155,7 @@ class OfflineFirstNewsRepositoryTest { network.editCollection( collectionType = CollectionType.NewsResources, id = it, - isDelete = true + isDelete = true, ) } @@ -168,13 +168,13 @@ class OfflineFirstNewsRepositoryTest { // Assert that items marked deleted on the network have been deleted locally assertEquals( newsResourcesFromNetwork.map(NewsResource::id) - deletedItems, - newsResourcesFromDb.map(NewsResource::id) + newsResourcesFromDb.map(NewsResource::id), ) // After sync version should be updated assertEquals( network.latestChangeListVersion(CollectionType.NewsResources), - synchronizer.getChangeListVersions().newsResourceVersion + synchronizer.getChangeListVersions().newsResourceVersion, ) } @@ -190,7 +190,7 @@ class OfflineFirstNewsRepositoryTest { val changeList = network.changeListsAfter( CollectionType.NewsResources, - version = 7 + version = 7, ) val changeListIds = changeList .map(NetworkChangeList::id) @@ -207,13 +207,13 @@ class OfflineFirstNewsRepositoryTest { assertEquals( newsResourcesFromNetwork.map(NewsResource::id), - newsResourcesFromDb.map(NewsResource::id) + newsResourcesFromDb.map(NewsResource::id), ) // After sync version should be updated assertEquals( changeList.last().changeListVersion, - synchronizer.getChangeListVersions().newsResourceVersion + synchronizer.getChangeListVersions().newsResourceVersion, ) } @@ -228,7 +228,7 @@ class OfflineFirstNewsRepositoryTest { .flatten() .distinctBy(TopicEntity::id), topicDao.getTopicEntities() - .first() + .first(), ) } @@ -242,7 +242,7 @@ class OfflineFirstNewsRepositoryTest { .map(NetworkNewsResource::topicCrossReferences) .distinct() .flatten(), - newsResourceDao.topicCrossReferences + newsResourceDao.topicCrossReferences, ) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt index 5c3f8dfc0..ca9941b8a 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstTopicsRepositoryTest.kt @@ -28,13 +28,13 @@ import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSou import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferencesDataStore import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic -import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import kotlin.test.assertEquals class OfflineFirstTopicsRepositoryTest { @@ -56,13 +56,13 @@ class OfflineFirstTopicsRepositoryTest { topicDao = TestTopicDao() network = TestNiaNetworkDataSource() niaPreferences = NiaPreferencesDataSource( - tmpFolder.testUserPreferencesDataStore() + tmpFolder.testUserPreferencesDataStore(), ) synchronizer = TestSynchronizer(niaPreferences) subject = OfflineFirstTopicsRepository( topicDao = topicDao, - network = network + network = network, ) } @@ -74,7 +74,7 @@ class OfflineFirstTopicsRepositoryTest { .first() .map(TopicEntity::asExternalModel), subject.getTopics() - .first() + .first(), ) } @@ -91,13 +91,13 @@ class OfflineFirstTopicsRepositoryTest { assertEquals( networkTopics.map(TopicEntity::id), - dbTopics.map(TopicEntity::id) + dbTopics.map(TopicEntity::id), ) // After sync version should be updated assertEquals( network.latestChangeListVersion(CollectionType.Topics), - synchronizer.getChangeListVersions().topicVersion + synchronizer.getChangeListVersions().topicVersion, ) } @@ -121,13 +121,13 @@ class OfflineFirstTopicsRepositoryTest { assertEquals( networkTopics.map(TopicEntity::id), - dbTopics.map(TopicEntity::id) + dbTopics.map(TopicEntity::id), ) // After sync version should be updated assertEquals( network.latestChangeListVersion(CollectionType.Topics), - synchronizer.getChangeListVersions().topicVersion + synchronizer.getChangeListVersions().topicVersion, ) } @@ -149,7 +149,7 @@ class OfflineFirstTopicsRepositoryTest { network.editCollection( collectionType = CollectionType.Topics, id = it, - isDelete = true + isDelete = true, ) } @@ -162,13 +162,13 @@ class OfflineFirstTopicsRepositoryTest { // Assert that items marked deleted on the network have been deleted locally assertEquals( networkTopics.map(Topic::id) - deletedItems, - dbTopics.map(Topic::id) + dbTopics.map(Topic::id), ) // After sync version should be updated assertEquals( network.latestChangeListVersion(CollectionType.Topics), - synchronizer.getChangeListVersions().topicVersion + synchronizer.getChangeListVersions().topicVersion, ) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepositoryTest.kt index 926052ea8..055d8e074 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/OfflineFirstUserDataRepositoryTest.kt @@ -21,9 +21,6 @@ import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferen import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import kotlinx.coroutines.test.runTest @@ -31,6 +28,9 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue class OfflineFirstUserDataRepositoryTest { private lateinit var subject: OfflineFirstUserDataRepository @@ -43,11 +43,11 @@ class OfflineFirstUserDataRepositoryTest { @Before fun setup() { niaPreferencesDataSource = NiaPreferencesDataSource( - tmpFolder.testUserPreferencesDataStore() + tmpFolder.testUserPreferencesDataStore(), ) subject = OfflineFirstUserDataRepository( - niaPreferencesDataSource = niaPreferencesDataSource + niaPreferencesDataSource = niaPreferencesDataSource, ) } @@ -61,9 +61,9 @@ class OfflineFirstUserDataRepositoryTest { themeBrand = ThemeBrand.DEFAULT, darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM, useDynamicColor = false, - shouldHideOnboarding = false + shouldHideOnboarding = false, ), - subject.userData.first() + subject.userData.first(), ) } @@ -76,7 +76,7 @@ class OfflineFirstUserDataRepositoryTest { setOf("0"), subject.userData .map { it.followedTopics } - .first() + .first(), ) subject.toggleFollowedTopicId(followedTopicId = "1", followed = true) @@ -85,7 +85,7 @@ class OfflineFirstUserDataRepositoryTest { setOf("0", "1"), subject.userData .map { it.followedTopics } - .first() + .first(), ) assertEquals( @@ -94,7 +94,7 @@ class OfflineFirstUserDataRepositoryTest { .first(), subject.userData .map { it.followedTopics } - .first() + .first(), ) } @@ -107,7 +107,7 @@ class OfflineFirstUserDataRepositoryTest { setOf("1", "2"), subject.userData .map { it.followedTopics } - .first() + .first(), ) assertEquals( @@ -116,7 +116,7 @@ class OfflineFirstUserDataRepositoryTest { .first(), subject.userData .map { it.followedTopics } - .first() + .first(), ) } @@ -129,7 +129,7 @@ class OfflineFirstUserDataRepositoryTest { setOf("0"), subject.userData .map { it.bookmarkedNewsResources } - .first() + .first(), ) subject.updateNewsResourceBookmark(newsResourceId = "1", bookmarked = true) @@ -138,7 +138,7 @@ class OfflineFirstUserDataRepositoryTest { setOf("0", "1"), subject.userData .map { it.bookmarkedNewsResources } - .first() + .first(), ) assertEquals( @@ -147,7 +147,7 @@ class OfflineFirstUserDataRepositoryTest { .first(), subject.userData .map { it.bookmarkedNewsResources } - .first() + .first(), ) } @@ -160,14 +160,14 @@ class OfflineFirstUserDataRepositoryTest { ThemeBrand.ANDROID, subject.userData .map { it.themeBrand } - .first() + .first(), ) assertEquals( ThemeBrand.ANDROID, niaPreferencesDataSource .userData .map { it.themeBrand } - .first() + .first(), ) } @@ -180,14 +180,14 @@ class OfflineFirstUserDataRepositoryTest { true, subject.userData .map { it.useDynamicColor } - .first() + .first(), ) assertEquals( true, niaPreferencesDataSource .userData .map { it.useDynamicColor } - .first() + .first(), ) } @@ -200,14 +200,14 @@ class OfflineFirstUserDataRepositoryTest { DarkThemeConfig.DARK, subject.userData .map { it.darkThemeConfig } - .first() + .first(), ) assertEquals( DarkThemeConfig.DARK, niaPreferencesDataSource .userData .map { it.darkThemeConfig } - .first() + .first(), ) } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/TestSynchronizer.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/TestSynchronizer.kt index e50a3776b..270dd010e 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/TestSynchronizer.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/repository/TestSynchronizer.kt @@ -24,12 +24,12 @@ import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSou * Test synchronizer that delegates to [NiaPreferencesDataSource] */ class TestSynchronizer( - private val niaPreferences: NiaPreferencesDataSource + private val niaPreferences: NiaPreferencesDataSource, ) : Synchronizer { override suspend fun getChangeListVersions(): ChangeListVersions = niaPreferences.getChangeListVersions() override suspend fun updateChangeListVersions( - update: ChangeListVersions.() -> ChangeListVersions + update: ChangeListVersions.() -> ChangeListVersions, ) = niaPreferences.updateChangeListVersion(update) } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt index 6441cf6ed..f63014075 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt @@ -46,8 +46,8 @@ class TestNewsResourceDao : NewsResourceDao { headerImageUrl = "headerImageUrl", type = Video, publishDate = Instant.fromEpochMilliseconds(1), - ) - ) + ), + ), ) internal var topicCrossReferences: List = listOf() @@ -58,7 +58,7 @@ class TestNewsResourceDao : NewsResourceDao { } override fun getNewsResources( - filterTopicIds: Set + filterTopicIds: Set, ): Flow> = getNewsResources() .map { resources -> @@ -68,7 +68,7 @@ class TestNewsResourceDao : NewsResourceDao { } override suspend fun insertOrIgnoreNewsResources( - entities: List + entities: List, ): List { entitiesStateFlow.value = entities // Assume no conflicts on insert @@ -84,7 +84,7 @@ class TestNewsResourceDao : NewsResourceDao { } override suspend fun insertOrIgnoreTopicCrossRefEntities( - newsResourceTopicCrossReferences: List + newsResourceTopicCrossReferences: List, ) { topicCrossReferences = newsResourceTopicCrossReferences } @@ -107,6 +107,6 @@ private fun NewsResourceEntity.asPopulatedNewsResource() = PopulatedNewsResource longDescription = "long description", url = "URL", imageUrl = "image URL", - ) + ), ), ) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt index abbf39f50..8e248a3aa 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNiaNetworkDataSource.kt @@ -27,7 +27,7 @@ import kotlinx.serialization.json.Json enum class CollectionType { Topics, - NewsResources + NewsResources, } /** @@ -37,7 +37,7 @@ class TestNiaNetworkDataSource : NiaNetworkDataSource { private val source = FakeNiaNetworkDataSource( UnconfinedTestDispatcher(), - Json { ignoreUnknownKeys = true } + Json { ignoreUnknownKeys = true }, ) private val allTopics = runBlocking { source.getTopics() } @@ -54,13 +54,13 @@ class TestNiaNetworkDataSource : NiaNetworkDataSource { override suspend fun getTopics(ids: List?): List = allTopics.matchIds( ids = ids, - idGetter = NetworkTopic::id + idGetter = NetworkTopic::id, ) override suspend fun getNewsResources(ids: List?): List = allNewsResources.matchIds( ids = ids, - idGetter = NetworkNewsResource::id + idGetter = NetworkNewsResource::id, ) override suspend fun getTopicChangeList(after: Int?): List = @@ -102,7 +102,7 @@ fun List.after(version: Int?): List = */ private fun List.matchIds( ids: List?, - idGetter: (T) -> String + idGetter: (T) -> String, ) = when (ids) { null -> this else -> ids.toSet().let { idSet -> this.filter { idSet.contains(idGetter(it)) } } @@ -113,7 +113,7 @@ private fun List.matchIds( * [after] simulates which models have changed by excluding items before it */ private fun List.mapToChangeList( - idGetter: (T) -> String + idGetter: (T) -> String, ) = mapIndexed { index, item -> NetworkChangeList( id = idGetter(item), diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt index d842f1501..8ac0dc0b8 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt @@ -37,8 +37,8 @@ class TestTopicDao : TopicDao { longDescription = "long description", url = "URL", imageUrl = "image URL", - ) - ) + ), + ), ) override fun getTopicEntity(topicId: String): Flow { diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt index fa500decb..83158f6cd 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt @@ -19,9 +19,9 @@ package com.google.samples.apps.nowinandroid.core.database.model import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic -import kotlin.test.assertEquals import kotlinx.datetime.Instant import org.junit.Test +import kotlin.test.assertEquals class PopulatedNewsResourceKtTest { @Test @@ -44,7 +44,7 @@ class PopulatedNewsResourceKtTest { longDescription = "long description", url = "URL", imageUrl = "image URL", - ) + ), ), ) val newsResource = populatedNewsResource.asExternalModel() @@ -66,10 +66,10 @@ class PopulatedNewsResourceKtTest { longDescription = "long description", url = "URL", imageUrl = "image URL", - ) - ) + ), + ), ), - newsResource + newsResource, ) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt index 37a25dc7e..77a09819b 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt @@ -17,8 +17,8 @@ package com.google.samples.apps.nowinandroid.core.database.util import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import kotlin.test.assertEquals import org.junit.Test +import kotlin.test.assertEquals class NewsResourceTypeConverterTest { @@ -26,7 +26,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_video() { assertEquals( NewsResourceType.Video, - NewsResourceTypeConverter().stringToNewsResourceType("Video 📺") + NewsResourceTypeConverter().stringToNewsResourceType("Video 📺"), ) } @@ -34,7 +34,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_article() { assertEquals( NewsResourceType.Article, - NewsResourceTypeConverter().stringToNewsResourceType("Article 📚") + NewsResourceTypeConverter().stringToNewsResourceType("Article 📚"), ) } @@ -42,7 +42,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_api_change() { assertEquals( NewsResourceType.APIChange, - NewsResourceTypeConverter().stringToNewsResourceType("API change") + NewsResourceTypeConverter().stringToNewsResourceType("API change"), ) } @@ -50,7 +50,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_codelab() { assertEquals( NewsResourceType.Codelab, - NewsResourceTypeConverter().stringToNewsResourceType("Codelab") + NewsResourceTypeConverter().stringToNewsResourceType("Codelab"), ) } @@ -58,7 +58,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_podcast() { assertEquals( NewsResourceType.Podcast, - NewsResourceTypeConverter().stringToNewsResourceType("Podcast 🎙") + NewsResourceTypeConverter().stringToNewsResourceType("Podcast 🎙"), ) } @@ -66,7 +66,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_docs() { assertEquals( NewsResourceType.Docs, - NewsResourceTypeConverter().stringToNewsResourceType("Docs 📑") + NewsResourceTypeConverter().stringToNewsResourceType("Docs 📑"), ) } @@ -74,7 +74,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_event() { assertEquals( NewsResourceType.Event, - NewsResourceTypeConverter().stringToNewsResourceType("Event 📆") + NewsResourceTypeConverter().stringToNewsResourceType("Event 📆"), ) } @@ -82,7 +82,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_dac() { assertEquals( NewsResourceType.DAC, - NewsResourceTypeConverter().stringToNewsResourceType("DAC") + NewsResourceTypeConverter().stringToNewsResourceType("DAC"), ) } @@ -90,7 +90,7 @@ class NewsResourceTypeConverterTest { fun test_room_news_resource_type_converter_for_umm() { assertEquals( NewsResourceType.Unknown, - NewsResourceTypeConverter().stringToNewsResourceType("umm") + NewsResourceTypeConverter().stringToNewsResourceType("umm"), ) } } diff --git a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt index 5dd1cf624..c1c1b39ba 100644 --- a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt +++ b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt @@ -25,12 +25,12 @@ import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopi import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant import org.junit.Before import org.junit.Test +import kotlin.test.assertEquals class NewsResourceDaoTest { @@ -43,7 +43,7 @@ class NewsResourceDaoTest { val context = ApplicationProvider.getApplicationContext() db = Room.inMemoryDatabaseBuilder( context, - NiaDatabase::class.java + NiaDatabase::class.java, ).build() newsResourceDao = db.newsResourceDao() topicDao = db.topicDao() @@ -70,7 +70,7 @@ class NewsResourceDaoTest { ), ) newsResourceDao.upsertNewsResources( - newsResourceEntities + newsResourceEntities, ) val savedNewsResourceEntities = newsResourceDao.getNewsResources() @@ -80,7 +80,7 @@ class NewsResourceDaoTest { listOf(3L, 2L, 1L, 0L), savedNewsResourceEntities.map { it.asExternalModel().publishDate.toEpochMilliseconds() - } + }, ) } @@ -89,11 +89,11 @@ class NewsResourceDaoTest { val topicEntities = listOf( testTopicEntity( id = "1", - name = "1" + name = "1", ), testTopicEntity( id = "2", - name = "2" + name = "2", ), ) val newsResourceEntities = listOf( @@ -117,18 +117,18 @@ class NewsResourceDaoTest { val newsResourceTopicCrossRefEntities = topicEntities.mapIndexed { index, topicEntity -> NewsResourceTopicCrossRef( newsResourceId = index.toString(), - topicId = topicEntity.id + topicId = topicEntity.id, ) } topicDao.insertOrIgnoreTopics( - topicEntities = topicEntities + topicEntities = topicEntities, ) newsResourceDao.upsertNewsResources( - newsResourceEntities + newsResourceEntities, ) newsResourceDao.insertOrIgnoreTopicCrossRefEntities( - newsResourceTopicCrossRefEntities + newsResourceTopicCrossRefEntities, ) val filteredNewsResources = newsResourceDao.getNewsResources( @@ -139,7 +139,7 @@ class NewsResourceDaoTest { assertEquals( listOf("1", "0"), - filteredNewsResources.map { it.entity.id } + filteredNewsResources.map { it.entity.id }, ) } @@ -169,7 +169,7 @@ class NewsResourceDaoTest { val (toDelete, toKeep) = newsResourceEntities.partition { it.id.toInt() % 2 == 0 } newsResourceDao.deleteNewsResources( - toDelete.map(NewsResourceEntity::id) + toDelete.map(NewsResourceEntity::id), ) assertEquals( @@ -177,26 +177,26 @@ class NewsResourceDaoTest { .toSet(), newsResourceDao.getNewsResources().first() .map { it.entity.id } - .toSet() + .toSet(), ) } } private fun testTopicEntity( id: String = "0", - name: String + name: String, ) = TopicEntity( id = id, name = name, shortDescription = "", longDescription = "", url = "", - imageUrl = "" + imageUrl = "", ) private fun testNewsResource( id: String = "0", - millisSinceEpoch: Long = 0 + millisSinceEpoch: Long = 0, ) = NewsResourceEntity( id = id, title = "", diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseMigrations.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseMigrations.kt index 8d7430fa0..09e0849fe 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseMigrations.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseMigrations.kt @@ -33,31 +33,31 @@ object DatabaseMigrations { @RenameColumn( tableName = "topics", fromColumnName = "description", - toColumnName = "shortDescription" + toColumnName = "shortDescription", ) class Schema2to3 : AutoMigrationSpec @DeleteColumn( tableName = "news_resources", - columnName = "episode_id" + columnName = "episode_id", ) @DeleteTable.Entries( DeleteTable( - tableName = "episodes_authors" + tableName = "episodes_authors", ), DeleteTable( - tableName = "episodes" - ) + tableName = "episodes", + ), ) class Schema10to11 : AutoMigrationSpec @DeleteTable.Entries( DeleteTable( - tableName = "news_resources_authors" + tableName = "news_resources_authors", ), DeleteTable( - tableName = "authors" - ) + tableName = "authors", + ), ) class Schema11to12 : AutoMigrationSpec } diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt index 7d4dd67c8..7d89cd1ac 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt @@ -35,6 +35,6 @@ object DatabaseModule { ): NiaDatabase = Room.databaseBuilder( context, NiaDatabase::class.java, - "nia-database" + "nia-database", ).build() } diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt index 33a186275..83bd46967 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt @@ -46,7 +46,7 @@ import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeC AutoMigration(from = 8, to = 9), AutoMigration(from = 9, to = 10), AutoMigration(from = 10, to = 11, spec = DatabaseMigrations.Schema10to11::class), - AutoMigration(from = 11, to = 12, spec = DatabaseMigrations.Schema11to12::class) + AutoMigration(from = 11, to = 12, spec = DatabaseMigrations.Schema11to12::class), ], exportSchema = true, ) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt index 8f02bb4a8..af0a59bce 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt @@ -39,7 +39,7 @@ interface NewsResourceDao { value = """ SELECT * FROM news_resources ORDER BY publish_date DESC - """ + """, ) fun getNewsResources(): Flow> @@ -53,7 +53,7 @@ interface NewsResourceDao { WHERE topic_id IN (:filterTopicIds) ) ORDER BY publish_date DESC - """ + """, ) fun getNewsResources( filterTopicIds: Set = emptySet(), @@ -79,7 +79,7 @@ interface NewsResourceDao { @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertOrIgnoreTopicCrossRefEntities( - newsResourceTopicCrossReferences: List + newsResourceTopicCrossReferences: List, ) /** @@ -89,7 +89,7 @@ interface NewsResourceDao { value = """ DELETE FROM news_resources WHERE id in (:ids) - """ + """, ) suspend fun deleteNewsResources(ids: List) } diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt index 9d9cde602..37724af69 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt @@ -34,7 +34,7 @@ interface TopicDao { value = """ SELECT * FROM topics WHERE id = :topicId - """ + """, ) fun getTopicEntity(topicId: String): Flow @@ -45,7 +45,7 @@ interface TopicDao { value = """ SELECT * FROM topics WHERE id IN (:ids) - """ + """, ) fun getTopicEntities(ids: Set): Flow> @@ -74,7 +74,7 @@ interface TopicDao { value = """ DELETE FROM topics WHERE id in (:ids) - """ + """, ) suspend fun deleteTopics(ids: List) } diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt index 38cd3c473..a571d8f94 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt @@ -27,7 +27,7 @@ import kotlinx.datetime.Instant * Defines an NiA news resource. */ @Entity( - tableName = "news_resources" + tableName = "news_resources", ) data class NewsResourceEntity( @PrimaryKey @@ -50,5 +50,5 @@ fun NewsResourceEntity.asExternalModel() = NewsResource( headerImageUrl = headerImageUrl, publishDate = publishDate, type = type, - topics = listOf() + topics = listOf(), ) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceTopicCrossRef.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceTopicCrossRef.kt index dac2b5f0b..59bf1458f 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceTopicCrossRef.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceTopicCrossRef.kt @@ -32,13 +32,13 @@ import androidx.room.Index entity = NewsResourceEntity::class, parentColumns = ["id"], childColumns = ["news_resource_id"], - onDelete = ForeignKey.CASCADE + onDelete = ForeignKey.CASCADE, ), ForeignKey( entity = TopicEntity::class, parentColumns = ["id"], childColumns = ["topic_id"], - onDelete = ForeignKey.CASCADE + onDelete = ForeignKey.CASCADE, ), ], indices = [ diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResource.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResource.kt index 6e18cc873..ec8acfb3f 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResource.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResource.kt @@ -34,9 +34,9 @@ data class PopulatedNewsResource( value = NewsResourceTopicCrossRef::class, parentColumn = "news_resource_id", entityColumn = "topic_id", - ) + ), ) - val topics: List + val topics: List, ) fun PopulatedNewsResource.asExternalModel() = NewsResource( @@ -47,5 +47,5 @@ fun PopulatedNewsResource.asExternalModel() = NewsResource( headerImageUrl = entity.headerImageUrl, publishDate = entity.publishDate, type = entity.type, - topics = topics.map(TopicEntity::asExternalModel) + topics = topics.map(TopicEntity::asExternalModel), ) diff --git a/core/datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt b/core/datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt index 62b3abc34..b29728cf1 100644 --- a/core/datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt +++ b/core/datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt @@ -25,13 +25,13 @@ import dagger.Module import dagger.Provides import dagger.hilt.components.SingletonComponent import dagger.hilt.testing.TestInstallIn -import javax.inject.Singleton import org.junit.rules.TemporaryFolder +import javax.inject.Singleton @Module @TestInstallIn( components = [SingletonComponent::class], - replaces = [DataStoreModule::class] + replaces = [DataStoreModule::class], ) object TestDataStoreModule { @@ -39,13 +39,13 @@ object TestDataStoreModule { @Singleton fun providesUserPreferencesDataStore( userPreferencesSerializer: UserPreferencesSerializer, - tmpFolder: TemporaryFolder + tmpFolder: TemporaryFolder, ): DataStore = tmpFolder.testUserPreferencesDataStore(userPreferencesSerializer) } fun TemporaryFolder.testUserPreferencesDataStore( - userPreferencesSerializer: UserPreferencesSerializer = UserPreferencesSerializer() + userPreferencesSerializer: UserPreferencesSerializer = UserPreferencesSerializer(), ) = DataStoreFactory.create( serializer = userPreferencesSerializer, ) { diff --git a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigration.kt b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigration.kt index cd27bb015..98632c652 100644 --- a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigration.kt +++ b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigration.kt @@ -30,14 +30,14 @@ object IntToStringIdsMigration : DataMigration { // Migrate topic ids deprecatedFollowedTopicIds.clear() deprecatedFollowedTopicIds.addAll( - currentData.deprecatedIntFollowedTopicIdsList.map(Int::toString) + currentData.deprecatedIntFollowedTopicIdsList.map(Int::toString), ) deprecatedIntFollowedTopicIds.clear() // Migrate author ids deprecatedFollowedAuthorIds.clear() deprecatedFollowedAuthorIds.addAll( - currentData.deprecatedIntFollowedAuthorIdsList.map(Int::toString) + currentData.deprecatedIntFollowedAuthorIdsList.map(Int::toString), ) deprecatedIntFollowedAuthorIds.clear() diff --git a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigration.kt b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigration.kt index b88b27f74..5bff23340 100644 --- a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigration.kt +++ b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigration.kt @@ -30,21 +30,21 @@ object ListToMapMigration : DataMigration { // Migrate topic id lists followedTopicIds.clear() followedTopicIds.putAll( - currentData.deprecatedFollowedTopicIdsList.associateWith { true } + currentData.deprecatedFollowedTopicIdsList.associateWith { true }, ) deprecatedFollowedTopicIds.clear() // Migrate author ids followedAuthorIds.clear() followedAuthorIds.putAll( - currentData.deprecatedFollowedAuthorIdsList.associateWith { true } + currentData.deprecatedFollowedAuthorIdsList.associateWith { true }, ) deprecatedFollowedAuthorIds.clear() // Migrate bookmarks bookmarkedNewsResourceIds.clear() bookmarkedNewsResourceIds.putAll( - currentData.deprecatedBookmarkedNewsResourceIdsList.associateWith { true } + currentData.deprecatedBookmarkedNewsResourceIdsList.associateWith { true }, ) deprecatedBookmarkedNewsResourceIds.clear() diff --git a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSource.kt b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSource.kt index e82b13950..f5751193a 100644 --- a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSource.kt +++ b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSource.kt @@ -21,13 +21,13 @@ import androidx.datastore.core.DataStore import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData -import java.io.IOException -import javax.inject.Inject import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map +import java.io.IOException +import javax.inject.Inject class NiaPreferencesDataSource @Inject constructor( - private val userPreferences: DataStore + private val userPreferences: DataStore, ) { val userData = userPreferences.data .map { @@ -38,21 +38,23 @@ class NiaPreferencesDataSource @Inject constructor( null, ThemeBrandProto.THEME_BRAND_UNSPECIFIED, ThemeBrandProto.UNRECOGNIZED, - ThemeBrandProto.THEME_BRAND_DEFAULT -> ThemeBrand.DEFAULT + ThemeBrandProto.THEME_BRAND_DEFAULT, + -> ThemeBrand.DEFAULT ThemeBrandProto.THEME_BRAND_ANDROID -> ThemeBrand.ANDROID }, darkThemeConfig = when (it.darkThemeConfig) { null, DarkThemeConfigProto.DARK_THEME_CONFIG_UNSPECIFIED, DarkThemeConfigProto.UNRECOGNIZED, - DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM -> + DarkThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM, + -> DarkThemeConfig.FOLLOW_SYSTEM DarkThemeConfigProto.DARK_THEME_CONFIG_LIGHT -> DarkThemeConfig.LIGHT DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK }, useDynamicColor = it.useDynamicColor, - shouldHideOnboarding = it.shouldHideOnboarding + shouldHideOnboarding = it.shouldHideOnboarding, ) } @@ -153,8 +155,8 @@ class NiaPreferencesDataSource @Inject constructor( val updatedChangeListVersions = update( ChangeListVersions( topicVersion = currentPreferences.topicChangeListVersion, - newsResourceVersion = currentPreferences.newsResourceChangeListVersion - ) + newsResourceVersion = currentPreferences.newsResourceChangeListVersion, + ), ) currentPreferences.copy { @@ -177,7 +179,6 @@ class NiaPreferencesDataSource @Inject constructor( } private fun UserPreferencesKt.Dsl.updateShouldHideOnboardingIfNecessary() { - if (followedTopicIds.isEmpty() && followedAuthorIds.isEmpty()) { shouldHideOnboarding = false } diff --git a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt index f4eb8f848..895e22307 100644 --- a/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt +++ b/core/datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt @@ -30,10 +30,10 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -44,14 +44,14 @@ object DataStoreModule { fun providesUserPreferencesDataStore( @ApplicationContext context: Context, @Dispatcher(IO) ioDispatcher: CoroutineDispatcher, - userPreferencesSerializer: UserPreferencesSerializer + userPreferencesSerializer: UserPreferencesSerializer, ): DataStore = DataStoreFactory.create( serializer = userPreferencesSerializer, scope = CoroutineScope(ioDispatcher + SupervisorJob()), migrations = listOf( IntToStringIdsMigration, - ) + ), ) { context.dataStoreFile("user_preferences.pb") } diff --git a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigrationTest.kt b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigrationTest.kt index e82f74b52..8b97cff34 100644 --- a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigrationTest.kt +++ b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/IntToStringIdsMigrationTest.kt @@ -16,10 +16,10 @@ package com.google.samples.apps.nowinandroid.core.datastore -import kotlin.test.assertEquals -import kotlin.test.assertTrue import kotlinx.coroutines.test.runTest import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue /** * Unit test for [IntToStringIdsMigration] @@ -35,7 +35,7 @@ class IntToStringIdsMigrationTest { // Assert that there are no string topic ids yet assertEquals( emptyList(), - preMigrationUserPreferences.deprecatedFollowedTopicIdsList + preMigrationUserPreferences.deprecatedFollowedTopicIdsList, ) // Run the migration @@ -48,7 +48,7 @@ class IntToStringIdsMigrationTest { deprecatedFollowedTopicIds.addAll(listOf("1", "2", "3")) hasDoneIntToStringIdMigration = true }, - postMigrationUserPreferences + postMigrationUserPreferences, ) // Assert that the migration has been marked complete @@ -64,7 +64,7 @@ class IntToStringIdsMigrationTest { // Assert that there are no string author ids yet assertEquals( emptyList(), - preMigrationUserPreferences.deprecatedFollowedAuthorIdsList + preMigrationUserPreferences.deprecatedFollowedAuthorIdsList, ) // Run the migration @@ -77,7 +77,7 @@ class IntToStringIdsMigrationTest { deprecatedFollowedAuthorIds.addAll(listOf("4", "5", "6")) hasDoneIntToStringIdMigration = true }, - postMigrationUserPreferences + postMigrationUserPreferences, ) // Assert that the migration has been marked complete diff --git a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigrationTest.kt b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigrationTest.kt index c2fdf4f55..f7e083b45 100644 --- a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigrationTest.kt +++ b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/ListToMapMigrationTest.kt @@ -16,10 +16,10 @@ package com.google.samples.apps.nowinandroid.core.datastore -import kotlin.test.assertEquals -import kotlin.test.assertTrue import kotlinx.coroutines.test.runTest import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue class ListToMapMigrationTest { @@ -32,7 +32,7 @@ class ListToMapMigrationTest { // Assert that there are no topic ids in the map yet assertEquals( emptyMap(), - preMigrationUserPreferences.followedTopicIdsMap + preMigrationUserPreferences.followedTopicIdsMap, ) // Run the migration @@ -42,7 +42,7 @@ class ListToMapMigrationTest { // Assert the deprecated topic ids have been migrated to the topic ids map assertEquals( mapOf("1" to true, "2" to true, "3" to true), - postMigrationUserPreferences.followedTopicIdsMap + postMigrationUserPreferences.followedTopicIdsMap, ) // Assert that the migration has been marked complete @@ -58,7 +58,7 @@ class ListToMapMigrationTest { // Assert that there are no author ids in the map yet assertEquals( emptyMap(), - preMigrationUserPreferences.followedAuthorIdsMap + preMigrationUserPreferences.followedAuthorIdsMap, ) // Run the migration @@ -68,7 +68,7 @@ class ListToMapMigrationTest { // Assert the deprecated author ids have been migrated to the author ids map assertEquals( mapOf("4" to true, "5" to true, "6" to true), - postMigrationUserPreferences.followedAuthorIdsMap + postMigrationUserPreferences.followedAuthorIdsMap, ) // Assert that the migration has been marked complete @@ -84,7 +84,7 @@ class ListToMapMigrationTest { // Assert that there are no bookmarks in the map yet assertEquals( emptyMap(), - preMigrationUserPreferences.bookmarkedNewsResourceIdsMap + preMigrationUserPreferences.bookmarkedNewsResourceIdsMap, ) // Run the migration @@ -94,7 +94,7 @@ class ListToMapMigrationTest { // Assert the deprecated bookmarks have been migrated to the bookmarks map assertEquals( mapOf("7" to true, "8" to true, "9" to true), - postMigrationUserPreferences.bookmarkedNewsResourceIdsMap + postMigrationUserPreferences.bookmarkedNewsResourceIdsMap, ) // Assert that the migration has been marked complete diff --git a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSourceTest.kt b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSourceTest.kt index 62a70de11..0d047d310 100644 --- a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSourceTest.kt +++ b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferencesDataSourceTest.kt @@ -17,14 +17,14 @@ package com.google.samples.apps.nowinandroid.core.datastore import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferencesDataStore -import kotlin.test.assertFalse -import kotlin.test.assertTrue import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import kotlin.test.assertFalse +import kotlin.test.assertTrue class NiaPreferencesDataSourceTest { private lateinit var subject: NiaPreferencesDataSource @@ -35,7 +35,7 @@ class NiaPreferencesDataSourceTest { @Before fun setup() { subject = NiaPreferencesDataSource( - tmpFolder.testUserPreferencesDataStore() + tmpFolder.testUserPreferencesDataStore(), ) } @@ -52,7 +52,6 @@ class NiaPreferencesDataSourceTest { @Test fun userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse() = runTest { - // Given: user completes onboarding by selecting a single topic. subject.toggleFollowedTopicId("1", true) subject.setShouldHideOnboarding(true) @@ -66,7 +65,6 @@ class NiaPreferencesDataSourceTest { @Test fun userShouldHideOnboarding_unfollowsAllTopics_shouldHideOnboardingIsFalse() = runTest { - // Given: user completes onboarding by selecting several topics. subject.setFollowedTopicIds(setOf("1", "2")) subject.setShouldHideOnboarding(true) diff --git a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt index 1b10c5672..ad7664fe5 100644 --- a/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt +++ b/core/datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt @@ -17,11 +17,11 @@ package com.google.samples.apps.nowinandroid.core.datastore import androidx.datastore.core.CorruptionException +import kotlinx.coroutines.test.runTest +import org.junit.Test import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import kotlin.test.assertEquals -import kotlinx.coroutines.test.runTest -import org.junit.Test class UserPreferencesSerializerTest { private val userPreferencesSerializer = UserPreferencesSerializer() @@ -32,7 +32,7 @@ class UserPreferencesSerializerTest { userPreferences { // Default value }, - userPreferencesSerializer.defaultValue + userPreferencesSerializer.defaultValue, ) } @@ -53,7 +53,7 @@ class UserPreferencesSerializerTest { assertEquals( expectedUserPreferences, - actualUserPreferences + actualUserPreferences, ) } diff --git a/core/designsystem/src/androidTest/java/com/google/samples/apps/nowinandroid/core/designsystem/ThemeTest.kt b/core/designsystem/src/androidTest/java/com/google/samples/apps/nowinandroid/core/designsystem/ThemeTest.kt index a047d838b..b10df053c 100644 --- a/core/designsystem/src/androidTest/java/com/google/samples/apps/nowinandroid/core/designsystem/ThemeTest.kt +++ b/core/designsystem/src/androidTest/java/com/google/samples/apps/nowinandroid/core/designsystem/ThemeTest.kt @@ -41,9 +41,9 @@ import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalGradien import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalTintTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.TintTheme -import kotlin.test.assertEquals import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals /** * Tests [NiaTheme] using different combinations of the theme mode parameters: @@ -64,7 +64,7 @@ class ThemeTest { NiaTheme( darkTheme = false, disableDynamicTheming = true, - androidTheme = false + androidTheme = false, ) { val colorScheme = LightDefaultColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -84,7 +84,7 @@ class ThemeTest { NiaTheme( darkTheme = true, disableDynamicTheming = true, - androidTheme = false + androidTheme = false, ) { val colorScheme = DarkDefaultColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -104,7 +104,7 @@ class ThemeTest { NiaTheme( darkTheme = false, disableDynamicTheming = false, - androidTheme = false + androidTheme = false, ) { val colorScheme = dynamicLightColorSchemeWithFallback() assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -124,7 +124,7 @@ class ThemeTest { NiaTheme( darkTheme = true, disableDynamicTheming = false, - androidTheme = false + androidTheme = false, ) { val colorScheme = dynamicDarkColorSchemeWithFallback() assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -144,7 +144,7 @@ class ThemeTest { NiaTheme( darkTheme = false, disableDynamicTheming = true, - androidTheme = true + androidTheme = true, ) { val colorScheme = LightAndroidColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -164,7 +164,7 @@ class ThemeTest { NiaTheme( darkTheme = true, disableDynamicTheming = true, - androidTheme = true + androidTheme = true, ) { val colorScheme = DarkAndroidColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -184,7 +184,7 @@ class ThemeTest { NiaTheme( darkTheme = false, disableDynamicTheming = false, - androidTheme = true + androidTheme = true, ) { val colorScheme = LightAndroidColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -204,7 +204,7 @@ class ThemeTest { NiaTheme( darkTheme = true, disableDynamicTheming = false, - androidTheme = true + androidTheme = true, ) { val colorScheme = DarkAndroidColorScheme assertColorSchemesEqual(colorScheme, MaterialTheme.colorScheme) @@ -244,7 +244,7 @@ class ThemeTest { return GradientColors( top = colorScheme.inverseOnSurface, bottom = colorScheme.primaryContainer, - container = colorScheme.surface + container = colorScheme.surface, ) } @@ -259,7 +259,7 @@ class ThemeTest { private fun defaultBackgroundTheme(colorScheme: ColorScheme): BackgroundTheme { return BackgroundTheme( color = colorScheme.surface, - tonalElevation = 2.dp + tonalElevation = 2.dp, ) } @@ -280,7 +280,7 @@ class ThemeTest { */ private fun assertColorSchemesEqual( expectedColorScheme: ColorScheme, - actualColorScheme: ColorScheme + actualColorScheme: ColorScheme, ) { assertEquals(expectedColorScheme.primary, actualColorScheme.primary) assertEquals(expectedColorScheme.onPrimary, actualColorScheme.onPrimary) @@ -291,7 +291,7 @@ class ThemeTest { assertEquals(expectedColorScheme.secondaryContainer, actualColorScheme.secondaryContainer) assertEquals( expectedColorScheme.onSecondaryContainer, - actualColorScheme.onSecondaryContainer + actualColorScheme.onSecondaryContainer, ) assertEquals(expectedColorScheme.tertiary, actualColorScheme.tertiary) assertEquals(expectedColorScheme.onTertiary, actualColorScheme.onTertiary) diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Background.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Background.kt index f81d2e36d..9ef52dd76 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Background.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Background.kt @@ -50,7 +50,7 @@ import kotlin.math.tan @Composable fun NiaBackground( modifier: Modifier = Modifier, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { val color = LocalBackgroundTheme.current.color val tonalElevation = LocalBackgroundTheme.current.tonalElevation @@ -77,7 +77,7 @@ fun NiaBackground( fun NiaGradientBackground( modifier: Modifier = Modifier, gradientColors: GradientColors = LocalGradientColors.current, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { val currentTopColor by rememberUpdatedState(gradientColors.top) val currentBottomColor by rememberUpdatedState(gradientColors.bottom) @@ -87,7 +87,7 @@ fun NiaGradientBackground( } else { gradientColors.container }, - modifier = modifier.fillMaxSize() + modifier = modifier.fillMaxSize(), ) { Box( Modifier @@ -98,7 +98,7 @@ fun NiaGradientBackground( val offset = size.height * tan( Math .toRadians(11.06) - .toFloat() + .toFloat(), ) val start = Offset(size.width / 2 + offset / 2, 0f) @@ -132,7 +132,7 @@ fun NiaGradientBackground( drawRect(topGradient) drawRect(bottomGradient) } - } + }, ) { content() } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Button.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Button.kt index cab6fcd2f..e4b437dfe 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Button.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Button.kt @@ -48,17 +48,17 @@ fun NiaButton( modifier: Modifier = Modifier, enabled: Boolean = true, contentPadding: PaddingValues = ButtonDefaults.ContentPadding, - content: @Composable RowScope.() -> Unit + content: @Composable RowScope.() -> Unit, ) { Button( onClick = onClick, modifier = modifier, enabled = enabled, colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.onBackground + containerColor = MaterialTheme.colorScheme.onBackground, ), contentPadding = contentPadding, - content = content + content = content, ) } @@ -78,7 +78,7 @@ fun NiaButton( modifier: Modifier = Modifier, enabled: Boolean = true, text: @Composable () -> Unit, - leadingIcon: @Composable (() -> Unit)? = null + leadingIcon: @Composable (() -> Unit)? = null, ) { NiaButton( onClick = onClick, @@ -88,11 +88,11 @@ fun NiaButton( ButtonDefaults.ButtonWithIconContentPadding } else { ButtonDefaults.ContentPadding - } + }, ) { NiaButtonContent( text = text, - leadingIcon = leadingIcon + leadingIcon = leadingIcon, ) } } @@ -114,14 +114,14 @@ fun NiaOutlinedButton( modifier: Modifier = Modifier, enabled: Boolean = true, contentPadding: PaddingValues = ButtonDefaults.ContentPadding, - content: @Composable RowScope.() -> Unit + content: @Composable RowScope.() -> Unit, ) { OutlinedButton( onClick = onClick, modifier = modifier, enabled = enabled, colors = ButtonDefaults.outlinedButtonColors( - contentColor = MaterialTheme.colorScheme.onBackground + contentColor = MaterialTheme.colorScheme.onBackground, ), border = BorderStroke( width = NiaButtonDefaults.OutlinedButtonBorderWidth, @@ -129,12 +129,12 @@ fun NiaOutlinedButton( MaterialTheme.colorScheme.outline } else { MaterialTheme.colorScheme.onSurface.copy( - alpha = NiaButtonDefaults.DisabledOutlinedButtonBorderAlpha + alpha = NiaButtonDefaults.DisabledOutlinedButtonBorderAlpha, ) - } + }, ), contentPadding = contentPadding, - content = content + content = content, ) } @@ -154,7 +154,7 @@ fun NiaOutlinedButton( modifier: Modifier = Modifier, enabled: Boolean = true, text: @Composable () -> Unit, - leadingIcon: @Composable (() -> Unit)? = null + leadingIcon: @Composable (() -> Unit)? = null, ) { NiaOutlinedButton( onClick = onClick, @@ -164,11 +164,11 @@ fun NiaOutlinedButton( ButtonDefaults.ButtonWithIconContentPadding } else { ButtonDefaults.ContentPadding - } + }, ) { NiaButtonContent( text = text, - leadingIcon = leadingIcon + leadingIcon = leadingIcon, ) } } @@ -187,16 +187,16 @@ fun NiaTextButton( onClick: () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, - content: @Composable RowScope.() -> Unit + content: @Composable RowScope.() -> Unit, ) { TextButton( onClick = onClick, modifier = modifier, enabled = enabled, colors = ButtonDefaults.textButtonColors( - contentColor = MaterialTheme.colorScheme.onBackground + contentColor = MaterialTheme.colorScheme.onBackground, ), - content = content + content = content, ) } @@ -216,16 +216,16 @@ fun NiaTextButton( modifier: Modifier = Modifier, enabled: Boolean = true, text: @Composable () -> Unit, - leadingIcon: @Composable (() -> Unit)? = null + leadingIcon: @Composable (() -> Unit)? = null, ) { NiaTextButton( onClick = onClick, modifier = modifier, - enabled = enabled + enabled = enabled, ) { NiaButtonContent( text = text, - leadingIcon = leadingIcon + leadingIcon = leadingIcon, ) } } @@ -239,7 +239,7 @@ fun NiaTextButton( @Composable private fun NiaButtonContent( text: @Composable () -> Unit, - leadingIcon: @Composable (() -> Unit)? = null + leadingIcon: @Composable (() -> Unit)? = null, ) { if (leadingIcon != null) { Box(Modifier.sizeIn(maxHeight = ButtonDefaults.IconSize)) { @@ -253,8 +253,8 @@ private fun NiaButtonContent( ButtonDefaults.IconSpacing } else { 0.dp - } - ) + }, + ), ) { text() } @@ -267,6 +267,7 @@ 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 diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt index 663667861..b291b3fa1 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt @@ -46,7 +46,7 @@ fun NiaFilterChip( onSelectedChange: (Boolean) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, - label: @Composable () -> Unit + label: @Composable () -> Unit, ) { FilterChip( selected = selected, @@ -62,7 +62,7 @@ fun NiaFilterChip( { Icon( imageVector = NiaIcons.Check, - contentDescription = null + contentDescription = null, ) } } else { @@ -73,33 +73,33 @@ fun NiaFilterChip( borderColor = MaterialTheme.colorScheme.onBackground, selectedBorderColor = MaterialTheme.colorScheme.onBackground, disabledBorderColor = MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaChipDefaults.DisabledChipContentAlpha + alpha = NiaChipDefaults.DisabledChipContentAlpha, ), disabledSelectedBorderColor = MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaChipDefaults.DisabledChipContentAlpha + alpha = NiaChipDefaults.DisabledChipContentAlpha, ), - selectedBorderWidth = NiaChipDefaults.ChipBorderWidth + selectedBorderWidth = NiaChipDefaults.ChipBorderWidth, ), colors = FilterChipDefaults.filterChipColors( labelColor = MaterialTheme.colorScheme.onBackground, iconColor = MaterialTheme.colorScheme.onBackground, disabledContainerColor = if (selected) { MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaChipDefaults.DisabledChipContainerAlpha + alpha = NiaChipDefaults.DisabledChipContainerAlpha, ) } else { Color.Transparent }, disabledLabelColor = MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaChipDefaults.DisabledChipContentAlpha + alpha = NiaChipDefaults.DisabledChipContentAlpha, ), disabledLeadingIconColor = MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaChipDefaults.DisabledChipContentAlpha + alpha = NiaChipDefaults.DisabledChipContentAlpha, ), selectedContainerColor = MaterialTheme.colorScheme.primaryContainer, selectedLabelColor = MaterialTheme.colorScheme.onBackground, - selectedLeadingIconColor = MaterialTheme.colorScheme.onBackground - ) + selectedLeadingIconColor = MaterialTheme.colorScheme.onBackground, + ), ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DropdownMenu.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DropdownMenu.kt index b8d3fa837..b624ebcb6 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DropdownMenu.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DropdownMenu.kt @@ -61,7 +61,7 @@ fun NiaDropdownMenuButton( text: @Composable () -> Unit, itemText: @Composable (item: T) -> Unit, itemLeadingIcon: @Composable ((item: T) -> Unit)? = null, - itemTrailingIcon: @Composable ((item: T) -> Unit)? = null + itemTrailingIcon: @Composable ((item: T) -> Unit)? = null, ) { var expanded by remember { mutableStateOf(false) } Box(modifier = modifier) { @@ -69,7 +69,7 @@ fun NiaDropdownMenuButton( onClick = { expanded = true }, enabled = enabled, colors = ButtonDefaults.outlinedButtonColors( - contentColor = MaterialTheme.colorScheme.onBackground + contentColor = MaterialTheme.colorScheme.onBackground, ), border = BorderStroke( width = NiaDropdownMenuDefaults.DropdownMenuButtonBorderWidth, @@ -77,11 +77,11 @@ fun NiaDropdownMenuButton( MaterialTheme.colorScheme.outline } else { MaterialTheme.colorScheme.onSurface.copy( - alpha = NiaDropdownMenuDefaults.DisabledDropdownMenuButtonBorderAlpha + alpha = NiaDropdownMenuDefaults.DisabledDropdownMenuButtonBorderAlpha, ) - } + }, ), - contentPadding = NiaDropdownMenuDefaults.DropdownMenuButtonContentPadding + contentPadding = NiaDropdownMenuDefaults.DropdownMenuButtonContentPadding, ) { NiaDropdownMenuButtonContent( text = text, @@ -92,9 +92,9 @@ fun NiaDropdownMenuButton( } else { NiaIcons.ArrowDropDown }, - contentDescription = null + contentDescription = null, ) - } + }, ) } NiaDropdownMenu( @@ -105,7 +105,7 @@ fun NiaDropdownMenuButton( dismissOnItemClick = dismissOnItemClick, itemText = itemText, itemLeadingIcon = itemLeadingIcon, - itemTrailingIcon = itemTrailingIcon + itemTrailingIcon = itemTrailingIcon, ) } } @@ -129,8 +129,8 @@ private fun NiaDropdownMenuButtonContent( ButtonDefaults.IconSpacing } else { 0.dp - } - ) + }, + ), ) { ProvideTextStyle(value = MaterialTheme.typography.labelSmall) { text() @@ -166,11 +166,11 @@ fun NiaDropdownMenu( dismissOnItemClick: Boolean = true, itemText: @Composable (item: T) -> Unit, itemLeadingIcon: @Composable ((item: T) -> Unit)? = null, - itemTrailingIcon: @Composable ((item: T) -> Unit)? = null + itemTrailingIcon: @Composable ((item: T) -> Unit)? = null, ) { DropdownMenu( expanded = expanded, - onDismissRequest = onDismissRequest + onDismissRequest = onDismissRequest, ) { items.forEach { item -> DropdownMenuItem( @@ -188,7 +188,7 @@ fun NiaDropdownMenu( { itemTrailingIcon(item) } } else { null - } + }, ) } } @@ -201,9 +201,11 @@ object NiaDropdownMenuDefaults { // TODO: File bug // OutlinedButton border color doesn't respect disabled state by default const val DisabledDropdownMenuButtonBorderAlpha = 0.12f + // TODO: File bug // OutlinedButton default border width isn't exposed via ButtonDefaults val DropdownMenuButtonBorderWidth = 1.dp + // TODO: File bug // Various default button padding values aren't exposed via ButtonDefaults val DropdownMenuButtonContentPadding = @@ -211,6 +213,6 @@ object NiaDropdownMenuDefaults { start = 24.dp, top = 8.dp, end = 16.dp, - bottom = 8.dp + bottom = 8.dp, ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DynamicAsyncImage.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DynamicAsyncImage.kt index 26f80989f..e26a824af 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DynamicAsyncImage.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/DynamicAsyncImage.kt @@ -31,7 +31,7 @@ fun DynamicAsyncImage( imageUrl: String, contentDescription: String?, modifier: Modifier = Modifier, - placeholder: Painter? = null + placeholder: Painter? = null, ) { val iconTint = LocalTintTheme.current.iconTint AsyncImage( @@ -39,6 +39,6 @@ fun DynamicAsyncImage( model = imageUrl, contentDescription = contentDescription, colorFilter = if (iconTint != null) ColorFilter.tint(iconTint) else null, - modifier = modifier + modifier = modifier, ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/IconButton.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/IconButton.kt index 0eedf23f7..b0dda0af1 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/IconButton.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/IconButton.kt @@ -43,7 +43,7 @@ fun NiaIconToggleButton( modifier: Modifier = Modifier, enabled: Boolean = true, icon: @Composable () -> Unit, - checkedIcon: @Composable () -> Unit = icon + checkedIcon: @Composable () -> Unit = icon, ) { // TODO: File bug // Can't use regular IconToggleButton as it doesn't include a shape (appears square) @@ -57,12 +57,12 @@ fun NiaIconToggleButton( checkedContentColor = MaterialTheme.colorScheme.onPrimaryContainer, disabledContainerColor = if (checked) { MaterialTheme.colorScheme.onBackground.copy( - alpha = NiaIconButtonDefaults.DisabledIconButtonContainerAlpha + alpha = NiaIconButtonDefaults.DisabledIconButtonContainerAlpha, ) } else { Color.Transparent - } - ) + }, + ), ) { if (checked) checkedIcon() else icon() } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/LoadingWheel.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/LoadingWheel.kt index 836558021..55ff143a6 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/LoadingWheel.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/LoadingWheel.kt @@ -53,7 +53,7 @@ import kotlinx.coroutines.launch @Composable fun NiaLoadingWheel( contentDesc: String, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { val infiniteTransition = rememberInfiniteTransition() @@ -68,8 +68,8 @@ fun NiaLoadingWheel( animationSpec = tween( durationMillis = 100, easing = FastOutSlowInEasing, - delayMillis = 40 * index - ) + delayMillis = 40 * index, + ), ) } } @@ -80,8 +80,8 @@ fun NiaLoadingWheel( initialValue = 0F, targetValue = 360F, animationSpec = infiniteRepeatable( - animation = tween(durationMillis = ROTATION_TIME, easing = LinearEasing) - ) + animation = tween(durationMillis = ROTATION_TIME, easing = LinearEasing), + ), ) // Specifies the color animation for the base-to-progress line color change @@ -98,8 +98,8 @@ fun NiaLoadingWheel( baseLineColor at ROTATION_TIME / NUM_OF_LINES with LinearEasing }, repeatMode = RepeatMode.Restart, - initialStartOffset = StartOffset(ROTATION_TIME / NUM_OF_LINES / 2 * index) - ) + initialStartOffset = StartOffset(ROTATION_TIME / NUM_OF_LINES / 2 * index), + ), ) } @@ -121,7 +121,7 @@ fun NiaLoadingWheel( strokeWidth = 4F, cap = StrokeCap.Round, start = Offset(size.width / 2, size.height / 4), - end = Offset(size.width / 2, floatAnimValues[index].value * size.height / 4) + end = Offset(size.width / 2, floatAnimValues[index].value * size.height / 4), ) } } @@ -131,7 +131,7 @@ fun NiaLoadingWheel( @Composable fun NiaOverlayLoadingWheel( contentDesc: String, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { Surface( shape = RoundedCornerShape(60.dp), diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Navigation.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Navigation.kt index 57d70642c..624cf25ac 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Navigation.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Navigation.kt @@ -54,7 +54,7 @@ fun RowScope.NiaNavigationBarItem( selectedIcon: @Composable () -> Unit = icon, enabled: Boolean = true, label: @Composable (() -> Unit)? = null, - alwaysShowLabel: Boolean = true + alwaysShowLabel: Boolean = true, ) { NavigationBarItem( selected = selected, @@ -69,8 +69,8 @@ fun RowScope.NiaNavigationBarItem( unselectedIconColor = NiaNavigationDefaults.navigationContentColor(), selectedTextColor = NiaNavigationDefaults.navigationSelectedItemColor(), unselectedTextColor = NiaNavigationDefaults.navigationContentColor(), - indicatorColor = NiaNavigationDefaults.navigationIndicatorColor() - ) + indicatorColor = NiaNavigationDefaults.navigationIndicatorColor(), + ), ) } @@ -84,13 +84,13 @@ fun RowScope.NiaNavigationBarItem( @Composable fun NiaNavigationBar( modifier: Modifier = Modifier, - content: @Composable RowScope.() -> Unit + content: @Composable RowScope.() -> Unit, ) { NavigationBar( modifier = modifier, contentColor = NiaNavigationDefaults.navigationContentColor(), tonalElevation = 0.dp, - content = content + content = content, ) } @@ -118,7 +118,7 @@ fun NiaNavigationRailItem( selectedIcon: @Composable () -> Unit = icon, enabled: Boolean = true, label: @Composable (() -> Unit)? = null, - alwaysShowLabel: Boolean = true + alwaysShowLabel: Boolean = true, ) { NavigationRailItem( selected = selected, @@ -133,8 +133,8 @@ fun NiaNavigationRailItem( unselectedIconColor = NiaNavigationDefaults.navigationContentColor(), selectedTextColor = NiaNavigationDefaults.navigationSelectedItemColor(), unselectedTextColor = NiaNavigationDefaults.navigationContentColor(), - indicatorColor = NiaNavigationDefaults.navigationIndicatorColor() - ) + indicatorColor = NiaNavigationDefaults.navigationIndicatorColor(), + ), ) } @@ -150,14 +150,14 @@ fun NiaNavigationRailItem( fun NiaNavigationRail( modifier: Modifier = Modifier, header: @Composable (ColumnScope.() -> Unit)? = null, - content: @Composable ColumnScope.() -> Unit + content: @Composable ColumnScope.() -> Unit, ) { NavigationRail( modifier = modifier, containerColor = Color.Transparent, contentColor = NiaNavigationDefaults.navigationContentColor(), header = header, - content = content + content = content, ) } @@ -167,8 +167,10 @@ fun NiaNavigationRail( object NiaNavigationDefaults { @Composable fun navigationContentColor() = MaterialTheme.colorScheme.onSurfaceVariant + @Composable fun navigationSelectedItemColor() = MaterialTheme.colorScheme.onPrimaryContainer + @Composable fun navigationIndicatorColor() = MaterialTheme.colorScheme.primaryContainer } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tabs.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tabs.kt index 76a0a3248..ad2f3799c 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tabs.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tabs.kt @@ -46,7 +46,7 @@ fun NiaTab( onClick: () -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, - text: @Composable () -> Unit + text: @Composable () -> Unit, ) { Tab( selected = selected, @@ -61,9 +61,9 @@ fun NiaTab( Box(modifier = Modifier.padding(top = NiaTabDefaults.TabTopPadding)) { text() } - } + }, ) - } + }, ) } @@ -79,7 +79,7 @@ fun NiaTab( fun NiaTabRow( selectedTabIndex: Int, modifier: Modifier = Modifier, - tabs: @Composable () -> Unit + tabs: @Composable () -> Unit, ) { TabRow( selectedTabIndex = selectedTabIndex, @@ -90,10 +90,10 @@ fun NiaTabRow( TabRowDefaults.Indicator( modifier = Modifier.tabIndicatorOffset(tabPositions[selectedTabIndex]), height = 2.dp, - color = MaterialTheme.colorScheme.onSurface + color = MaterialTheme.colorScheme.onSurface, ) }, - tabs = tabs + tabs = tabs, ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tag.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tag.kt index dae42421c..cf8b246bb 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tag.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Tag.kt @@ -41,15 +41,14 @@ fun NiaTopicTag( text: @Composable () -> Unit, followText: @Composable () -> Unit = { Text(stringResource(R.string.follow)) }, unFollowText: @Composable () -> Unit = { Text(stringResource(R.string.unfollow)) }, - browseText: @Composable () -> Unit = { Text(stringResource(R.string.browse_topic)) } + browseText: @Composable () -> Unit = { Text(stringResource(R.string.browse_topic)) }, ) { - Box(modifier = modifier) { val containerColor = if (followed) { MaterialTheme.colorScheme.primaryContainer } else { MaterialTheme.colorScheme.surfaceVariant.copy( - alpha = NiaTagDefaults.UnfollowedTopicTagContainerAlpha + alpha = NiaTagDefaults.UnfollowedTopicTagContainerAlpha, ) } TextButton( @@ -59,9 +58,9 @@ fun NiaTopicTag( containerColor = containerColor, contentColor = contentColorFor(backgroundColor = containerColor), disabledContainerColor = MaterialTheme.colorScheme.onSurface.copy( - alpha = NiaTagDefaults.DisabledTopicTagContainerAlpha - ) - ) + alpha = NiaTagDefaults.DisabledTopicTagContainerAlpha, + ), + ), ) { ProvideTextStyle(value = MaterialTheme.typography.labelSmall) { text() @@ -84,7 +83,7 @@ fun NiaTopicTag( UNFOLLOW -> unFollowText() BROWSE -> browseText() } - } + }, ) } } @@ -94,6 +93,7 @@ fun NiaTopicTag( */ object NiaTagDefaults { const val UnfollowedTopicTagContainerAlpha = 0.5f + // TODO: File bug // Button disabled container alpha value not exposed by ButtonDefaults const val DisabledTopicTagContainerAlpha = 0.12f diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt index fb4cc0ff0..28007a3b1 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt @@ -46,7 +46,7 @@ fun NiaTopAppBar( modifier: Modifier = Modifier, colors: TopAppBarColors = TopAppBarDefaults.centerAlignedTopAppBarColors(), onNavigationClick: () -> Unit = {}, - onActionClick: () -> Unit = {} + onActionClick: () -> Unit = {}, ) { CenterAlignedTopAppBar( title = { Text(text = stringResource(id = titleRes)) }, @@ -55,7 +55,7 @@ fun NiaTopAppBar( Icon( imageVector = navigationIcon, contentDescription = navigationIconContentDescription, - tint = MaterialTheme.colorScheme.onSurface + tint = MaterialTheme.colorScheme.onSurface, ) } }, @@ -64,7 +64,7 @@ fun NiaTopAppBar( Icon( imageVector = actionIcon, contentDescription = actionIconContentDescription, - tint = MaterialTheme.colorScheme.onSurface + tint = MaterialTheme.colorScheme.onSurface, ) } }, @@ -84,7 +84,7 @@ fun NiaTopAppBar( actionIconContentDescription: String?, modifier: Modifier = Modifier, colors: TopAppBarColors = TopAppBarDefaults.centerAlignedTopAppBarColors(), - onActionClick: () -> Unit = {} + onActionClick: () -> Unit = {}, ) { CenterAlignedTopAppBar( title = { Text(text = stringResource(id = titleRes)) }, @@ -93,7 +93,7 @@ fun NiaTopAppBar( Icon( imageVector = actionIcon, contentDescription = actionIconContentDescription, - tint = MaterialTheme.colorScheme.onSurface + tint = MaterialTheme.colorScheme.onSurface, ) } }, @@ -111,6 +111,6 @@ private fun NiaTopAppBarPreview() { navigationIcon = NiaIcons.Search, navigationIconContentDescription = "Navigation icon", actionIcon = NiaIcons.MoreVert, - actionIconContentDescription = "Action icon" + actionIconContentDescription = "Action icon", ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/ViewToggle.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/ViewToggle.kt index a6721c78c..c6ec77a92 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/ViewToggle.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/ViewToggle.kt @@ -49,25 +49,25 @@ fun NiaViewToggleButton( modifier: Modifier = Modifier, enabled: Boolean = true, compactText: @Composable () -> Unit, - expandedText: @Composable () -> Unit + expandedText: @Composable () -> Unit, ) { TextButton( onClick = { onExpandedChange(!expanded) }, modifier = modifier, enabled = enabled, colors = ButtonDefaults.textButtonColors( - contentColor = MaterialTheme.colorScheme.onBackground + contentColor = MaterialTheme.colorScheme.onBackground, ), - contentPadding = NiaViewToggleDefaults.ViewToggleButtonContentPadding + contentPadding = NiaViewToggleDefaults.ViewToggleButtonContentPadding, ) { NiaViewToggleButtonContent( text = if (expanded) expandedText else compactText, trailingIcon = { Icon( imageVector = if (expanded) NiaIcons.ViewDay else NiaIcons.ShortText, - contentDescription = null + contentDescription = null, ) - } + }, ) } } @@ -91,8 +91,8 @@ private fun NiaViewToggleButtonContent( ButtonDefaults.IconSpacing } else { 0.dp - } - ) + }, + ), ) { ProvideTextStyle(value = MaterialTheme.typography.labelSmall) { text() @@ -116,6 +116,6 @@ object NiaViewToggleDefaults { start = 16.dp, top = 8.dp, end = 12.dp, - bottom = 8.dp + bottom = 8.dp, ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Background.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Background.kt index f91e5a30d..e75758ea8 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Background.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Background.kt @@ -27,7 +27,7 @@ import androidx.compose.ui.unit.Dp @Immutable data class BackgroundTheme( val color: Color = Color.Unspecified, - val tonalElevation: Dp = Dp.Unspecified + val tonalElevation: Dp = Dp.Unspecified, ) /** diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Gradient.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Gradient.kt index f471af761..bad1c62a1 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Gradient.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Gradient.kt @@ -31,7 +31,7 @@ import androidx.compose.ui.graphics.Color data class GradientColors( val top: Color = Color.Unspecified, val bottom: Color = Color.Unspecified, - val container: Color = Color.Unspecified + val container: Color = Color.Unspecified, ) /** diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Theme.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Theme.kt index e7be17c99..582f88473 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Theme.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Theme.kt @@ -61,7 +61,7 @@ val LightDefaultColorScheme = lightColorScheme( onSurfaceVariant = PurpleGray30, inverseSurface = DarkPurpleGray20, inverseOnSurface = DarkPurpleGray95, - outline = PurpleGray50 + outline = PurpleGray50, ) /** @@ -93,7 +93,7 @@ val DarkDefaultColorScheme = darkColorScheme( onSurfaceVariant = PurpleGray80, inverseSurface = DarkPurpleGray90, inverseOnSurface = DarkPurpleGray10, - outline = PurpleGray60 + outline = PurpleGray60, ) /** @@ -125,7 +125,7 @@ val LightAndroidColorScheme = lightColorScheme( onSurfaceVariant = GreenGray30, inverseSurface = DarkGreenGray20, inverseOnSurface = DarkGreenGray95, - outline = GreenGray50 + outline = GreenGray50, ) /** @@ -157,7 +157,7 @@ val DarkAndroidColorScheme = darkColorScheme( onSurfaceVariant = GreenGray80, inverseSurface = DarkGreenGray90, inverseOnSurface = DarkGreenGray10, - outline = GreenGray60 + outline = GreenGray60, ) /** @@ -194,7 +194,7 @@ fun NiaTheme( darkTheme: Boolean = isSystemInDarkTheme(), androidTheme: Boolean = false, disableDynamicTheming: Boolean = true, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { // Color scheme val colorScheme = when { @@ -211,7 +211,7 @@ fun NiaTheme( val defaultGradientColors = GradientColors( top = colorScheme.inverseOnSurface, bottom = colorScheme.primaryContainer, - container = colorScheme.surface + container = colorScheme.surface, ) val gradientColors = when { androidTheme -> if (darkTheme) DarkAndroidGradientColors else LightAndroidGradientColors @@ -221,7 +221,7 @@ fun NiaTheme( // Background theme val defaultBackgroundTheme = BackgroundTheme( color = colorScheme.surface, - tonalElevation = 2.dp + tonalElevation = 2.dp, ) val backgroundTheme = when { androidTheme -> if (darkTheme) DarkAndroidBackgroundTheme else LightAndroidBackgroundTheme @@ -236,12 +236,12 @@ fun NiaTheme( CompositionLocalProvider( LocalGradientColors provides gradientColors, LocalBackgroundTheme provides backgroundTheme, - LocalTintTheme provides tintTheme + LocalTintTheme provides tintTheme, ) { MaterialTheme( colorScheme = colorScheme, typography = NiaTypography, - content = content + content = content, ) } } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Type.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Type.kt index 7c9621caf..0d3b06457 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Type.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/theme/Type.kt @@ -29,90 +29,90 @@ internal val NiaTypography = Typography( fontWeight = FontWeight.Normal, fontSize = 57.sp, lineHeight = 64.sp, - letterSpacing = (-0.25).sp + letterSpacing = (-0.25).sp, ), displayMedium = TextStyle( fontWeight = FontWeight.Normal, fontSize = 45.sp, lineHeight = 52.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), displaySmall = TextStyle( fontWeight = FontWeight.Normal, fontSize = 36.sp, lineHeight = 44.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), headlineLarge = TextStyle( fontWeight = FontWeight.Normal, fontSize = 32.sp, lineHeight = 40.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), headlineMedium = TextStyle( fontWeight = FontWeight.Normal, fontSize = 28.sp, lineHeight = 36.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), headlineSmall = TextStyle( fontWeight = FontWeight.Normal, fontSize = 24.sp, lineHeight = 32.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), titleLarge = TextStyle( fontWeight = FontWeight.Bold, fontSize = 22.sp, lineHeight = 28.sp, - letterSpacing = 0.sp + letterSpacing = 0.sp, ), titleMedium = TextStyle( fontWeight = FontWeight.Bold, fontSize = 18.sp, lineHeight = 24.sp, - letterSpacing = 0.1.sp + letterSpacing = 0.1.sp, ), titleSmall = TextStyle( fontWeight = FontWeight.Medium, fontSize = 14.sp, lineHeight = 20.sp, - letterSpacing = 0.1.sp + letterSpacing = 0.1.sp, ), bodyLarge = TextStyle( fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, - letterSpacing = 0.5.sp + letterSpacing = 0.5.sp, ), bodyMedium = TextStyle( fontWeight = FontWeight.Normal, fontSize = 14.sp, lineHeight = 20.sp, - letterSpacing = 0.25.sp + letterSpacing = 0.25.sp, ), bodySmall = TextStyle( fontWeight = FontWeight.Normal, fontSize = 12.sp, lineHeight = 16.sp, - letterSpacing = 0.4.sp + letterSpacing = 0.4.sp, ), labelLarge = TextStyle( fontWeight = FontWeight.Medium, fontSize = 14.sp, lineHeight = 20.sp, - letterSpacing = 0.1.sp + letterSpacing = 0.1.sp, ), labelMedium = TextStyle( fontWeight = FontWeight.Medium, fontSize = 12.sp, lineHeight = 16.sp, - letterSpacing = 0.5.sp + letterSpacing = 0.5.sp, ), labelSmall = TextStyle( fontWeight = FontWeight.Medium, fontSize = 10.sp, lineHeight = 16.sp, - letterSpacing = 0.sp - ) + letterSpacing = 0.sp, + ), ) diff --git a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCase.kt b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCase.kt index 2fab78d6c..ccc7e4ee1 100644 --- a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCase.kt +++ b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCase.kt @@ -21,16 +21,16 @@ import com.google.samples.apps.nowinandroid.core.data.repository.UserDataReposit import com.google.samples.apps.nowinandroid.core.domain.TopicSortField.NAME import com.google.samples.apps.nowinandroid.core.domain.TopicSortField.NONE import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import javax.inject.Inject /** * A use case which obtains a list of topics with their followed state. */ class GetFollowableTopicsUseCase @Inject constructor( private val topicsRepository: TopicsRepository, - private val userDataRepository: UserDataRepository + private val userDataRepository: UserDataRepository, ) { /** * Returns a list of topics with their associated followed state. @@ -40,13 +40,13 @@ class GetFollowableTopicsUseCase @Inject constructor( operator fun invoke(sortBy: TopicSortField = NONE): Flow> { return combine( userDataRepository.userData, - topicsRepository.getTopics() + topicsRepository.getTopics(), ) { userData, topics -> val followedTopics = topics .map { topic -> FollowableTopic( topic = topic, - isFollowed = topic.id in userData.followedTopics + isFollowed = topic.id in userData.followedTopics, ) } when (sortBy) { diff --git a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCase.kt b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCase.kt index 07cd6d856..db274bbbd 100644 --- a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCase.kt +++ b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCase.kt @@ -22,10 +22,10 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource import com.google.samples.apps.nowinandroid.core.domain.model.mapToUserNewsResources import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.UserData -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNot +import javax.inject.Inject /** * A use case responsible for obtaining news resources with their associated bookmarked (also known @@ -33,7 +33,7 @@ import kotlinx.coroutines.flow.filterNot */ class GetUserNewsResourcesUseCase @Inject constructor( private val newsRepository: NewsRepository, - private val userDataRepository: UserDataRepository + private val userDataRepository: UserDataRepository, ) { /** * Returns a list of UserNewsResources which match the supplied set of topic ids. @@ -42,7 +42,7 @@ class GetUserNewsResourcesUseCase @Inject constructor( * this is empty the list of news resources will not be filtered. */ operator fun invoke( - filterTopicIds: Set = emptySet() + filterTopicIds: Set = emptySet(), ): Flow> = if (filterTopicIds.isEmpty()) { newsRepository.getNewsResources() @@ -52,7 +52,7 @@ class GetUserNewsResourcesUseCase @Inject constructor( } private fun Flow>.mapToUserNewsResources( - userDataStream: Flow + userDataStream: Flow, ): Flow> = filterNot { it.isEmpty() } .combine(userDataStream) { newsResources, userData -> diff --git a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/FollowableTopic.kt b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/FollowableTopic.kt index 4071eb1aa..121f83098 100644 --- a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/FollowableTopic.kt +++ b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/FollowableTopic.kt @@ -24,20 +24,20 @@ import com.google.samples.apps.nowinandroid.core.model.data.previewTopics */ data class FollowableTopic( // TODO consider changing to UserTopic and flattening val topic: Topic, - val isFollowed: Boolean + val isFollowed: Boolean, ) val previewFollowableTopics = listOf( FollowableTopic( previewTopics[0], - isFollowed = false + isFollowed = false, ), FollowableTopic( previewTopics[1], - isFollowed = true + isFollowed = true, ), FollowableTopic( previewTopics[2], - isFollowed = false - ) + isFollowed = false, + ), ) diff --git a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/UserNewsResource.kt b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/UserNewsResource.kt index 872f93f16..7cf511c60 100644 --- a/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/UserNewsResource.kt +++ b/core/domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/model/UserNewsResource.kt @@ -42,7 +42,7 @@ data class UserNewsResource internal constructor( val publishDate: Instant, val type: NewsResourceType, val followableTopics: List, - val isSaved: Boolean + val isSaved: Boolean, ) { constructor(newsResource: NewsResource, userData: UserData) : this( id = newsResource.id, @@ -55,10 +55,10 @@ data class UserNewsResource internal constructor( followableTopics = newsResource.topics.map { topic -> FollowableTopic( topic = topic, - isFollowed = userData.followedTopics.contains(topic.id) + isFollowed = userData.followedTopics.contains(topic.id), ) }, - isSaved = userData.bookmarkedNewsResources.contains(newsResource.id) + isSaved = userData.bookmarkedNewsResources.contains(newsResource.id), ) } @@ -80,11 +80,11 @@ val previewUserNewsResources = listOf( hour = 23, minute = 0, second = 0, - nanosecond = 0 + nanosecond = 0, ).toInstant(TimeZone.UTC), type = Codelab, followableTopics = listOf(previewFollowableTopics[1]), - isSaved = true + isSaved = true, ), UserNewsResource( id = "2", @@ -98,7 +98,7 @@ val previewUserNewsResources = listOf( publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), type = Video, followableTopics = listOf(previewFollowableTopics[0], previewFollowableTopics[1]), - isSaved = false + isSaved = false, ), UserNewsResource( id = "3", @@ -112,7 +112,7 @@ val previewUserNewsResources = listOf( publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), type = Video, followableTopics = listOf(previewFollowableTopics[2]), - isSaved = false + isSaved = false, ), UserNewsResource( id = "4", @@ -124,6 +124,6 @@ val previewUserNewsResources = listOf( publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), type = Unknown, followableTopics = listOf(previewFollowableTopics[2]), - isSaved = true - ) + isSaved = true, + ), ) diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCaseTest.kt index 95ab22b63..8bf63aea4 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetFollowableTopicsUseCaseTest.kt @@ -22,11 +22,11 @@ import com.google.samples.apps.nowinandroid.core.model.data.Topic 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.util.MainDispatcherRule -import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals class GetFollowableTopicsUseCaseTest { @@ -38,12 +38,11 @@ class GetFollowableTopicsUseCaseTest { val useCase = GetFollowableTopicsUseCase( topicsRepository, - userDataRepository + userDataRepository, ) @Test fun whenNoParams_followableTopicsAreReturnedWithNoSorting() = runTest { - // Obtain a stream of followable topics. val followableTopics = useCase() @@ -58,16 +57,15 @@ class GetFollowableTopicsUseCaseTest { FollowableTopic(testTopics[1], false), FollowableTopic(testTopics[2], true), ), - followableTopics.first() + followableTopics.first(), ) } @Test fun whenSortOrderIsByName_topicsSortedByNameAreReturned() = runTest { - // Obtain a stream of followable topics, sorted by name. val followableTopics = useCase( - sortBy = NAME + sortBy = NAME, ) // Send some test topics and their followed state. @@ -81,7 +79,7 @@ class GetFollowableTopicsUseCaseTest { .sortedBy { it.name } .map { FollowableTopic(it, false) - } + }, ) } } diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt index fe50ecf4d..32ee8773c 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/GetUserNewsResourcesUseCaseTest.kt @@ -24,12 +24,12 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepo import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.repository.emptyUserData import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule -import kotlin.test.assertEquals import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals class GetUserNewsResourcesUseCaseTest { @@ -43,7 +43,6 @@ class GetUserNewsResourcesUseCaseTest { @Test fun whenNoFilters_allNewsResourcesAreReturned() = runTest { - // Obtain the user news resources stream. val userNewsResources = useCase() @@ -53,7 +52,7 @@ class GetUserNewsResourcesUseCaseTest { // Construct the test user data with bookmarks and followed topics. val userData = emptyUserData.copy( bookmarkedNewsResources = setOf(sampleNewsResources[0].id, sampleNewsResources[2].id), - followedTopics = setOf(sampleTopic1.id) + followedTopics = setOf(sampleTopic1.id), ) userDataRepository.setUserData(userData) @@ -61,13 +60,12 @@ class GetUserNewsResourcesUseCaseTest { // Check that the correct news resources are returned with their bookmarked state. assertEquals( sampleNewsResources.mapToUserNewsResources(userData), - userNewsResources.first() + userNewsResources.first(), ) } @Test fun whenFilteredByTopicId_matchingNewsResourcesAreReturned() = runTest { - // Obtain a stream of user news resources for the given topic id. val userNewsResources = useCase(filterTopicIds = setOf(sampleTopic1.id)) @@ -80,7 +78,7 @@ class GetUserNewsResourcesUseCaseTest { sampleNewsResources .filter { it.topics.contains(sampleTopic1) } .mapToUserNewsResources(emptyUserData), - userNewsResources.first() + userNewsResources.first(), ) } } @@ -115,7 +113,7 @@ private val sampleNewsResources = listOf( headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), type = Video, - topics = listOf(sampleTopic1) + topics = listOf(sampleTopic1), ), NewsResource( id = "2", @@ -127,7 +125,7 @@ private val sampleNewsResources = listOf( headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), type = Video, - topics = listOf(sampleTopic1, sampleTopic2) + topics = listOf(sampleTopic1, sampleTopic2), ), NewsResource( id = "3", @@ -137,6 +135,6 @@ private val sampleNewsResources = listOf( headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), type = Video, - topics = listOf(sampleTopic2) + topics = listOf(sampleTopic2), ), ) diff --git a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/UserNewsResourceTest.kt b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/UserNewsResourceTest.kt index d06a6d5ac..8350c5178 100644 --- a/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/UserNewsResourceTest.kt +++ b/core/domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/UserNewsResourceTest.kt @@ -38,7 +38,6 @@ class UserNewsResourceTest { */ @Test fun userNewsResourcesAreConstructedFromNewsResourcesAndUserData() { - val newsResource1 = NewsResource( id = "N1", title = "Test news title", @@ -54,7 +53,7 @@ class UserNewsResourceTest { shortDescription = "Topic 1 short description", longDescription = "Topic 1 long description", url = "Topic 1 URL", - imageUrl = "Topic 1 image URL" + imageUrl = "Topic 1 image URL", ), Topic( id = "T2", @@ -62,9 +61,9 @@ class UserNewsResourceTest { shortDescription = "Topic 2 short description", longDescription = "Topic 2 long description", url = "Topic 2 URL", - imageUrl = "Topic 2 image URL" + imageUrl = "Topic 2 image URL", ), - ) + ), ) val userData = UserData( @@ -73,7 +72,7 @@ class UserNewsResourceTest { themeBrand = DEFAULT, darkThemeConfig = FOLLOW_SYSTEM, useDynamicColor = false, - shouldHideOnboarding = true + shouldHideOnboarding = true, ) val userNewsResource = UserNewsResource(newsResource1, userData) @@ -89,11 +88,10 @@ class UserNewsResourceTest { // Check that each Topic has been converted to a FollowedTopic correctly. assertEquals(newsResource1.topics.size, userNewsResource.followableTopics.size) for (topic in newsResource1.topics) { - // Construct the expected FollowableTopic. val followableTopic = FollowableTopic( topic = topic, - isFollowed = userData.followedTopics.contains(topic.id) + isFollowed = userData.followedTopics.contains(topic.id), ) assertTrue(userNewsResource.followableTopics.contains(followableTopic)) } @@ -101,7 +99,7 @@ class UserNewsResourceTest { // Check that the saved flag is set correctly. assertEquals( userData.bookmarkedNewsResources.contains(newsResource1.id), - userNewsResource.isSaved + userNewsResource.isSaved, ) } } diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt index 4f75d27ad..2f60ca43b 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt @@ -37,7 +37,7 @@ data class NewsResource( val headerImageUrl: String?, val publishDate: Instant, val type: NewsResourceType, - val topics: List + val topics: List, ) val previewNewsResources = listOf( @@ -54,10 +54,10 @@ val previewNewsResources = listOf( hour = 23, minute = 0, second = 0, - nanosecond = 0 + nanosecond = 0, ).toInstant(TimeZone.UTC), type = Codelab, - topics = listOf(previewTopics[1]) + topics = listOf(previewTopics[1]), ), NewsResource( id = "2", @@ -70,7 +70,7 @@ val previewNewsResources = listOf( headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), type = Video, - topics = listOf(previewTopics[0], previewTopics[1]) + topics = listOf(previewTopics[0], previewTopics[1]), ), NewsResource( id = "3", @@ -83,7 +83,7 @@ val previewNewsResources = listOf( headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), type = Video, - topics = listOf(previewTopics[2]) + topics = listOf(previewTopics[2]), ), NewsResource( id = "4", @@ -94,6 +94,6 @@ val previewNewsResources = listOf( headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), type = Unknown, - topics = listOf(previewTopics[2]) - ) + topics = listOf(previewTopics[2]), + ), ) diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt index a6a175ff3..bb00f8620 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt @@ -23,53 +23,53 @@ enum class NewsResourceType( val serializedName: String, val displayText: String, // TODO: descriptions should probably be string resources - val description: String + val description: String, ) { Video( serializedName = "Video 📺", displayText = "Video 📺", - description = "A video published on YouTube" + description = "A video published on YouTube", ), APIChange( serializedName = "API change", displayText = "API change", - description = "An addition, deprecation or change to the Android platform APIs." + description = "An addition, deprecation or change to the Android platform APIs.", ), Article( serializedName = "Article 📚", displayText = "Article 📚", - description = "An article, typically on Medium or the official Android blog" + description = "An article, typically on Medium or the official Android blog", ), Codelab( serializedName = "Codelab", displayText = "Codelab", - description = "A new or updated codelab" + description = "A new or updated codelab", ), Podcast( serializedName = "Podcast 🎙", displayText = "Podcast 🎙", - description = "A podcast" + description = "A podcast", ), Docs( serializedName = "Docs 📑", displayText = "Docs 📑", - description = "A new or updated piece of documentation" + description = "A new or updated piece of documentation", ), Event( serializedName = "Event 📆", displayText = "Event 📆", - description = "Information about a developer event e.g. Android Developer Summit" + description = "Information about a developer event e.g. Android Developer Summit", ), DAC( serializedName = "DAC", displayText = "DAC", - description = "Android version features - Information about features in an Android" + description = "Android version features - Information about features in an Android", ), Unknown( serializedName = "Unknown", displayText = "Unknown", - description = "Unknown" - ) + description = "Unknown", + ), } fun String?.asNewsResourceType() = when (this) { diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt index 16dd4e464..03c184e0d 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt @@ -37,7 +37,7 @@ val previewTopics = listOf( shortDescription = "News we want everyone to see", longDescription = "Stay up to date with the latest events and announcements from Android!", imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_Headlines.svg?alt=media&token=506faab0-617a-4668-9e63-4a2fb996603f", - url = "" + url = "", ), Topic( id = "3", @@ -45,7 +45,7 @@ val previewTopics = listOf( shortDescription = "Material Design, Navigation, Text, Paging, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets", longDescription = "Learn how to optimize your app's user interface - everything that users can see and interact with. Stay up to date on tocpis such as Material Design, Navigation, Text, Paging, Compose, Accessibility (a11y), Internationalization (i18n), Localization (l10n), Animations, Large Screens, Widgets, and many more!", imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_UI.svg?alt=media&token=0ee1842b-12e8-435f-87ba-a5bb02c47594", - url = "" + url = "", ), Topic( id = "4", @@ -53,6 +53,6 @@ val previewTopics = listOf( shortDescription = "CI, Espresso, TestLab, etc", longDescription = "Testing is an integral part of the app development process. By running tests against your app consistently, you can verify your app's correctness, functional behavior, and usability before you release it publicly. Stay up to date on the latest tricks in CI, Espresso, and Firebase TestLab.", imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_Testing.svg?alt=media&token=a11533c4-7cc8-4b11-91a3-806158ebf428", - url = "" + url = "", ), ) diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserData.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserData.kt index 56e3fa522..638b90d36 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserData.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserData.kt @@ -25,5 +25,5 @@ data class UserData( val themeBrand: ThemeBrand, val darkThemeConfig: DarkThemeConfig, val useDynamicColor: Boolean, - val shouldHideOnboarding: Boolean + val shouldHideOnboarding: Boolean, ) diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt index d6b6b987d..a272451e5 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -23,8 +23,8 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import kotlinx.serialization.json.Json +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt index 47a8ab4c4..4ffddb20a 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSource.kt @@ -23,12 +23,12 @@ import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic -import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream +import javax.inject.Inject /** * [NiaNetworkDataSource] implementation that provides static news resources to aid development @@ -69,7 +69,7 @@ class FakeNiaNetworkDataSource @Inject constructor( * [NetworkChangeList.id] */ private fun List.mapToChangeList( - idGetter: (T) -> String + idGetter: (T) -> String, ) = mapIndexed { index, item -> NetworkChangeList( id = idGetter(item), diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/InstantSerializer.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/InstantSerializer.kt index f093998cf..dec73dc10 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/InstantSerializer.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/InstantSerializer.kt @@ -31,7 +31,7 @@ object InstantSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( serialName = "Instant", - kind = STRING + kind = STRING, ) override fun serialize(encoder: Encoder, value: Instant) = diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt index 4100a956c..ac40d6182 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt @@ -31,7 +31,7 @@ object NewsResourceTypeSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( serialName = "type", - kind = STRING + kind = STRING, ) override fun serialize(encoder: Encoder, value: NewsResourceType) = diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt index e380c05cc..6b59f16e3 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt @@ -22,8 +22,6 @@ import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import javax.inject.Inject -import javax.inject.Singleton import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json @@ -33,6 +31,8 @@ import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.http.GET import retrofit2.http.Query +import javax.inject.Inject +import javax.inject.Singleton /** * Retrofit API declaration for NIA Network API @@ -66,7 +66,7 @@ private const val NiaBaseUrl = BuildConfig.BACKEND_URL */ @Serializable private data class NetworkResponse( - val data: T + val data: T, ) /** @@ -74,7 +74,7 @@ private data class NetworkResponse( */ @Singleton class RetrofitNiaNetwork @Inject constructor( - networkJson: Json + networkJson: Json, ) : NiaNetworkDataSource { private val networkApi = Retrofit.Builder() @@ -85,13 +85,13 @@ class RetrofitNiaNetwork @Inject constructor( // TODO: Decide logging logic HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) - } + }, ) - .build() + .build(), ) .addConverterFactory( @OptIn(ExperimentalSerializationApi::class) - networkJson.asConverterFactory("application/json".toMediaType()) + networkJson.asConverterFactory("application/json".toMediaType()), ) .build() .create(RetrofitNiaNetworkApi::class.java) diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt index 48eb4746b..f54351750 100644 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt +++ b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt @@ -20,7 +20,6 @@ import JvmUnitTestFakeAssetManager import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic -import kotlin.test.assertEquals import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.runTest import kotlinx.datetime.LocalDateTime @@ -29,6 +28,7 @@ import kotlinx.datetime.toInstant import kotlinx.serialization.json.Json import org.junit.Before import org.junit.Test +import kotlin.test.assertEquals class FakeNiaNetworkDataSourceTest { @@ -41,7 +41,7 @@ class FakeNiaNetworkDataSourceTest { subject = FakeNiaNetworkDataSource( ioDispatcher = testDispatcher, networkJson = Json { ignoreUnknownKeys = true }, - assets = JvmUnitTestFakeAssetManager + assets = JvmUnitTestFakeAssetManager, ) } @@ -55,10 +55,10 @@ class FakeNiaNetworkDataSourceTest { shortDescription = "News you'll definitely be interested in", longDescription = "The latest events and announcements from the world of Android development.", url = "", - imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_Headlines.svg?alt=media&token=506faab0-617a-4668-9e63-4a2fb996603f" + imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_Headlines.svg?alt=media&token=506faab0-617a-4668-9e63-4a2fb996603f", ), /* ktlint-enable max-line-length */ - subject.getTopics().first() + subject.getTopics().first(), ) } @@ -79,13 +79,13 @@ class FakeNiaNetworkDataSourceTest { hour = 23, minute = 0, second = 0, - nanosecond = 0 + nanosecond = 0, ).toInstant(TimeZone.UTC), type = Codelab, topics = listOf("2", "3", "10"), ), /* ktlint-enable max-line-length */ - subject.getNewsResources().find { it.id == "125" } + subject.getNewsResources().find { it.id == "125" }, ) } } diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt index 191501a3d..16ac7df26 100644 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt +++ b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt @@ -17,9 +17,9 @@ package com.google.samples.apps.nowinandroid.core.network.model.util import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import kotlin.test.assertEquals import kotlinx.serialization.json.Json import org.junit.Test +import kotlin.test.assertEquals class NewsResourceTypeSerializerTest { @@ -27,7 +27,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_video() { assertEquals( NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, """"Video 📺"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Video 📺""""), ) } @@ -35,7 +35,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_article() { assertEquals( NewsResourceType.Article, - Json.decodeFromString(NewsResourceTypeSerializer, """"Article 📚"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Article 📚""""), ) } @@ -43,7 +43,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_api_change() { assertEquals( NewsResourceType.APIChange, - Json.decodeFromString(NewsResourceTypeSerializer, """"API change"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"API change""""), ) } @@ -51,7 +51,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_codelab() { assertEquals( NewsResourceType.Codelab, - Json.decodeFromString(NewsResourceTypeSerializer, """"Codelab"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Codelab""""), ) } @@ -59,7 +59,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_podcast() { assertEquals( NewsResourceType.Podcast, - Json.decodeFromString(NewsResourceTypeSerializer, """"Podcast 🎙"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Podcast 🎙""""), ) } @@ -67,7 +67,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_docs() { assertEquals( NewsResourceType.Docs, - Json.decodeFromString(NewsResourceTypeSerializer, """"Docs 📑"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Docs 📑""""), ) } @@ -75,7 +75,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_event() { assertEquals( NewsResourceType.Event, - Json.decodeFromString(NewsResourceTypeSerializer, """"Event 📆"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"Event 📆""""), ) } @@ -83,7 +83,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_dac() { assertEquals( NewsResourceType.DAC, - Json.decodeFromString(NewsResourceTypeSerializer, """"DAC"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"DAC""""), ) } @@ -91,7 +91,7 @@ class NewsResourceTypeSerializerTest { fun test_news_resource_serializer_unknown() { assertEquals( NewsResourceType.Unknown, - Json.decodeFromString(NewsResourceTypeSerializer, """"umm"""") + Json.decodeFromString(NewsResourceTypeSerializer, """"umm""""), ) } @@ -100,7 +100,7 @@ class NewsResourceTypeSerializerTest { val json = Json.encodeToString(NewsResourceTypeSerializer, NewsResourceType.Video) assertEquals( NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, json) + Json.decodeFromString(NewsResourceTypeSerializer, json), ) } } diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/di/TestDispatcherModule.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/di/TestDispatcherModule.kt index d0af32893..66d52dabe 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/di/TestDispatcherModule.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/di/TestDispatcherModule.kt @@ -20,9 +20,9 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import kotlinx.coroutines.test.TestDispatcher import kotlinx.coroutines.test.UnconfinedTestDispatcher +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestUserDataRepository.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestUserDataRepository.kt index c4c6e126f..e1b86cd63 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestUserDataRepository.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestUserDataRepository.kt @@ -31,7 +31,7 @@ val emptyUserData = UserData( themeBrand = ThemeBrand.DEFAULT, darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM, useDynamicColor = false, - shouldHideOnboarding = false + shouldHideOnboarding = false, ) class TestUserDataRepository : UserDataRepository { @@ -50,8 +50,11 @@ class TestUserDataRepository : UserDataRepository { override suspend fun toggleFollowedTopicId(followedTopicId: String, followed: Boolean) { currentUserData.let { current -> - val followedTopics = if (followed) current.followedTopics + followedTopicId - else current.followedTopics - followedTopicId + val followedTopics = if (followed) { + current.followedTopics + followedTopicId + } else { + current.followedTopics - followedTopicId + } _userData.tryEmit(current.copy(followedTopics = followedTopics)) } @@ -59,8 +62,11 @@ class TestUserDataRepository : UserDataRepository { override suspend fun updateNewsResourceBookmark(newsResourceId: String, bookmarked: Boolean) { currentUserData.let { current -> - val bookmarkedNews = if (bookmarked) current.bookmarkedNewsResources + newsResourceId - else current.bookmarkedNewsResources - newsResourceId + val bookmarkedNews = if (bookmarked) { + current.bookmarkedNewsResources + newsResourceId + } else { + current.bookmarkedNewsResources - newsResourceId + } _userData.tryEmit(current.copy(bookmarkedNewsResources = bookmarkedNews)) } diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index 6fbe0b0e4..ddcd2644e 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -40,7 +40,7 @@ class NewsResourceCardTest { userNewsResource = newsWithKnownResourceType, isBookmarked = false, onToggleBookmark = {}, - onClick = {} + onClick = {}, ) dateFormatted = dateFormatted(publishDate = newsWithKnownResourceType.publishDate) @@ -51,8 +51,8 @@ class NewsResourceCardTest { composeTestRule.activity.getString( R.string.card_meta_data_text, dateFormatted, - newsWithKnownResourceType.type.displayText - ) + newsWithKnownResourceType.type.displayText, + ), ) .assertExists() } @@ -67,7 +67,7 @@ class NewsResourceCardTest { userNewsResource = newsWithUnknownResourceType, isBookmarked = false, onToggleBookmark = {}, - onClick = {} + onClick = {}, ) dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate) diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/JankStatsExtensions.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/JankStatsExtensions.kt index d4ca9180d..c9fee1ac8 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/JankStatsExtensions.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/JankStatsExtensions.kt @@ -51,7 +51,7 @@ fun rememberMetricsStateHolder(): Holder { @Composable fun TrackJank( vararg keys: Any?, - reportMetric: suspend CoroutineScope.(state: Holder) -> Unit + reportMetric: suspend CoroutineScope.(state: Holder) -> Unit, ) { val metrics = rememberMetricsStateHolder() LaunchedEffect(metrics, *keys) { @@ -66,7 +66,7 @@ fun TrackJank( @Composable fun TrackDisposableJank( vararg keys: Any?, - reportMetric: DisposableEffectScope.(state: Holder) -> DisposableEffectResult + reportMetric: DisposableEffectScope.(state: Holder) -> DisposableEffectResult, ) { val metrics = rememberMetricsStateHolder() DisposableEffect(metrics, *keys) { diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt index 44c810a36..bbff34e40 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt @@ -46,7 +46,7 @@ import com.google.samples.apps.nowinandroid.core.domain.model.previewUserNewsRes */ fun LazyGridScope.newsFeed( feedState: NewsFeedUiState, - onNewsResourcesCheckedChanged: (String, Boolean) -> Unit + onNewsResourcesCheckedChanged: (String, Boolean) -> Unit, ) { when (feedState) { NewsFeedUiState.Loading -> Unit @@ -65,9 +65,9 @@ fun LazyGridScope.newsFeed( onToggleBookmark = { onNewsResourcesCheckedChanged( userNewsResource.id, - !userNewsResource.isSaved + !userNewsResource.isSaved, ) - } + }, ) } } @@ -100,7 +100,7 @@ sealed interface NewsFeedUiState { /** * The list of news resources contained in this feed. */ - val feed: List + val feed: List, ) : NewsFeedUiState } @@ -111,7 +111,7 @@ private fun NewsFeedLoadingPreview() { LazyVerticalGrid(columns = GridCells.Adaptive(300.dp)) { newsFeed( feedState = NewsFeedUiState.Loading, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -125,9 +125,9 @@ private fun NewsFeedContentPreview() { LazyVerticalGrid(columns = GridCells.Adaptive(300.dp)) { newsFeed( feedState = NewsFeedUiState.Success( - previewUserNewsResources + previewUserNewsResources, ), - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 76657067e..f2ec186e7 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -52,7 +52,6 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.AsyncImage -import com.google.samples.apps.nowinandroid.core.designsystem.R as DesignsystemR import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaIconToggleButton import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopicTag import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons @@ -62,11 +61,12 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource import com.google.samples.apps.nowinandroid.core.domain.model.previewUserNewsResources import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType +import kotlinx.datetime.Instant +import kotlinx.datetime.toJavaInstant import java.time.ZoneId import java.time.format.DateTimeFormatter import java.util.Locale -import kotlinx.datetime.Instant -import kotlinx.datetime.toJavaInstant +import com.google.samples.apps.nowinandroid.core.designsystem.R as DesignsystemR /** * [NewsResource] card used on the following screens: For You, Saved @@ -79,7 +79,7 @@ fun NewsResourceCardExpanded( isBookmarked: Boolean, onToggleBookmark: () -> Unit, onClick: () -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { val clickActionLabel = stringResource(R.string.card_tap_action) Card( @@ -90,7 +90,7 @@ fun NewsResourceCardExpanded( // Pass null for action to only override the label and not the actual action. modifier = modifier.semantics { onClick(label = clickActionLabel, action = null) - } + }, ) { Column { if (!userNewsResource.headerImageUrl.isNullOrEmpty()) { @@ -99,14 +99,14 @@ fun NewsResourceCardExpanded( } } Box( - modifier = Modifier.padding(16.dp) + modifier = Modifier.padding(16.dp), ) { Column { Spacer(modifier = Modifier.height(12.dp)) Row { NewsResourceTitle( userNewsResource.title, - modifier = Modifier.fillMaxWidth((.8f)) + modifier = Modifier.fillMaxWidth((.8f)), ) Spacer(modifier = Modifier.weight(1f)) BookmarkButton(isBookmarked, onToggleBookmark) @@ -125,7 +125,7 @@ fun NewsResourceCardExpanded( @Composable fun NewsResourceHeaderImage( - headerImageUrl: String? + headerImageUrl: String?, ) { AsyncImage( placeholder = if (LocalInspectionMode.current) { @@ -140,14 +140,14 @@ fun NewsResourceHeaderImage( contentScale = ContentScale.Crop, model = headerImageUrl, // TODO b/226661685: Investigate using alt text of image to populate content description - contentDescription = null // decorative image + contentDescription = null, // decorative image ) } @Composable fun NewsResourceTitle( newsResourceTitle: String, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { Text(newsResourceTitle, style = MaterialTheme.typography.headlineSmall, modifier = modifier) } @@ -156,7 +156,7 @@ fun NewsResourceTitle( fun BookmarkButton( isBookmarked: Boolean, onClick: () -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { NiaIconToggleButton( checked = isBookmarked, @@ -165,15 +165,15 @@ fun BookmarkButton( icon = { Icon( painter = painterResource(NiaIcons.BookmarkBorder), - contentDescription = stringResource(R.string.bookmark) + contentDescription = stringResource(R.string.bookmark), ) }, checkedIcon = { Icon( painter = painterResource(NiaIcons.Bookmark), - contentDescription = stringResource(R.string.unbookmark) + contentDescription = stringResource(R.string.unbookmark), ) - } + }, ) } @@ -185,7 +185,7 @@ fun dateFormatted(publishDate: Instant): String { DisposableEffect(context) { val receiver = TimeZoneBroadcastReceiver( - onTimeZoneChanged = { zoneId = ZoneId.systemDefault() } + onTimeZoneChanged = { zoneId = ZoneId.systemDefault() }, ) receiver.register(context) onDispose { @@ -200,7 +200,7 @@ fun dateFormatted(publishDate: Instant): String { @Composable fun NewsResourceMetaData( publishDate: Instant, - resourceType: NewsResourceType + resourceType: NewsResourceType, ) { val formattedDate = dateFormatted(publishDate) Text( @@ -209,21 +209,21 @@ fun NewsResourceMetaData( } else { formattedDate }, - style = MaterialTheme.typography.labelSmall + style = MaterialTheme.typography.labelSmall, ) } @Composable fun NewsResourceLink( @Suppress("UNUSED_PARAMETER") - newsResource: NewsResource + newsResource: NewsResource, ) { TODO() } @Composable fun NewsResourceShortDescription( - newsResourceShortDescription: String + newsResourceShortDescription: String, ) { Text(newsResourceShortDescription, style = MaterialTheme.typography.bodyLarge) } @@ -231,7 +231,7 @@ fun NewsResourceShortDescription( @Composable fun NewsResourceTopics( topics: List, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { // Store the ID of the Topic which has its "following" menu expanded, if any. // To avoid UI confusion, only one topic can have an expanded menu at a time. @@ -255,21 +255,21 @@ fun NewsResourceTopics( val contentDescription = if (followableTopic.isFollowed) { stringResource( R.string.topic_chip_content_description_when_followed, - followableTopic.topic.name + followableTopic.topic.name, ) } else { stringResource( R.string.topic_chip_content_description_when_not_followed, - followableTopic.topic.name + followableTopic.topic.name, ) } Text( text = followableTopic.topic.name.uppercase(Locale.getDefault()), modifier = Modifier.semantics { this.contentDescription = contentDescription - } + }, ) - } + }, ) } } @@ -304,7 +304,7 @@ private fun ExpandedNewsResourcePreview() { userNewsResource = previewUserNewsResources[0], isBookmarked = true, onToggleBookmark = {}, - onClick = {} + onClick = {}, ) } } diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardList.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardList.kt index e0bd22785..a63bae657 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardList.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardList.kt @@ -56,7 +56,7 @@ fun LazyListScope.userNewsResourceCardItems( else -> onItemClick(userNewsResource) } }, - modifier = itemModifier + modifier = itemModifier, ) }, ) diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/TimeZoneBroadcastReceiver.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/TimeZoneBroadcastReceiver.kt index 0e3fc6d1c..f7ae813c4 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/TimeZoneBroadcastReceiver.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/TimeZoneBroadcastReceiver.kt @@ -22,7 +22,7 @@ import android.content.Intent import android.content.IntentFilter class TimeZoneBroadcastReceiver( - val onTimeZoneChanged: () -> Unit + val onTimeZoneChanged: () -> Unit, ) : BroadcastReceiver() { private var registered = false diff --git a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt index 1f51d2bb9..08d4f6c06 100644 --- a/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt +++ b/feature/bookmarks/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreenTest.kt @@ -32,10 +32,10 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollToNode import com.google.samples.apps.nowinandroid.core.domain.model.previewUserNewsResources import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import kotlin.test.assertEquals -import kotlin.test.assertTrue import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue /** * UI tests for [BookmarksScreen] composable. @@ -50,13 +50,13 @@ class BookmarksScreenTest { composeTestRule.setContent { BookmarksScreen( feedState = NewsFeedUiState.Loading, - removeFromBookmarks = { } + removeFromBookmarks = { }, ) } composeTestRule .onNodeWithContentDescription( - composeTestRule.activity.resources.getString(R.string.saved_loading) + composeTestRule.activity.resources.getString(R.string.saved_loading), ) .assertExists() } @@ -66,16 +66,16 @@ class BookmarksScreenTest { composeTestRule.setContent { BookmarksScreen( feedState = NewsFeedUiState.Success( - previewUserNewsResources.take(2) + previewUserNewsResources.take(2), ), - removeFromBookmarks = { } + removeFromBookmarks = { }, ) } composeTestRule .onNodeWithText( previewUserNewsResources[0].title, - substring = true + substring = true, ) .assertExists() .assertHasClickAction() @@ -84,14 +84,14 @@ class BookmarksScreenTest { .performScrollToNode( hasText( previewUserNewsResources[1].title, - substring = true - ) + substring = true, + ), ) composeTestRule .onNodeWithText( previewUserNewsResources[1].title, - substring = true + substring = true, ) .assertExists() .assertHasClickAction() @@ -104,27 +104,27 @@ class BookmarksScreenTest { composeTestRule.setContent { BookmarksScreen( feedState = NewsFeedUiState.Success( - previewUserNewsResources.take(2) + previewUserNewsResources.take(2), ), removeFromBookmarks = { newsResourceId -> assertEquals(previewUserNewsResources[0].id, newsResourceId) removeFromBookmarksCalled = true - } + }, ) } composeTestRule .onAllNodesWithContentDescription( composeTestRule.activity.getString( - com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark - ) + com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark, + ), ).filter( hasAnyAncestor( hasText( previewUserNewsResources[0].title, - substring = true - ) - ) + substring = true, + ), + ), ) .assertCountEquals(1) .onFirst() @@ -138,19 +138,19 @@ class BookmarksScreenTest { composeTestRule.setContent { BookmarksScreen( feedState = NewsFeedUiState.Success(emptyList()), - removeFromBookmarks = { } + removeFromBookmarks = { }, ) } composeTestRule .onNodeWithText( - composeTestRule.activity.getString(R.string.bookmarks_empty_error) + composeTestRule.activity.getString(R.string.bookmarks_empty_error), ) .assertExists() composeTestRule .onNodeWithText( - composeTestRule.activity.getString(R.string.bookmarks_empty_description) + composeTestRule.activity.getString(R.string.bookmarks_empty_description), ) .assertExists() } diff --git a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt index 4531942bb..6b0bca003 100644 --- a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt +++ b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt @@ -65,13 +65,13 @@ import com.google.samples.apps.nowinandroid.core.ui.newsFeed @Composable internal fun BookmarksRoute( modifier: Modifier = Modifier, - viewModel: BookmarksViewModel = hiltViewModel() + viewModel: BookmarksViewModel = hiltViewModel(), ) { val feedState by viewModel.feedUiState.collectAsStateWithLifecycle() BookmarksScreen( feedState = feedState, removeFromBookmarks = viewModel::removeFromSavedResources, - modifier = modifier + modifier = modifier, ) } @@ -83,7 +83,7 @@ internal fun BookmarksRoute( internal fun BookmarksScreen( feedState: NewsFeedUiState, removeFromBookmarks: (String) -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { when (feedState) { Loading -> LoadingState(modifier) @@ -110,7 +110,7 @@ private fun LoadingState(modifier: Modifier = Modifier) { private fun BookmarksGrid( feedState: NewsFeedUiState, removeFromBookmarks: (String) -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { val scrollableState = rememberLazyGridState() TrackScrollJank(scrollableState = scrollableState, stateName = "bookmarks:grid") @@ -122,7 +122,7 @@ private fun BookmarksGrid( state = scrollableState, modifier = modifier .fillMaxSize() - .testTag("bookmarks:feed") + .testTag("bookmarks:feed"), ) { newsFeed( feedState = feedState, @@ -142,14 +142,14 @@ private fun EmptyState(modifier: Modifier = Modifier) { .fillMaxSize() .testTag("bookmarks:empty"), verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally + horizontalAlignment = Alignment.CenterHorizontally, ) { val iconTint = LocalTintTheme.current.iconTint Image( modifier = Modifier.fillMaxWidth(), painter = painterResource(id = R.drawable.img_empty_bookmarks), colorFilter = if (iconTint != null) ColorFilter.tint(iconTint) else null, - contentDescription = null + contentDescription = null, ) Spacer(modifier = Modifier.height(16.dp)) @@ -159,7 +159,7 @@ private fun EmptyState(modifier: Modifier = Modifier) { modifier = Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = MaterialTheme.typography.titleMedium, - fontWeight = FontWeight.Bold + fontWeight = FontWeight.Bold, ) Spacer(modifier = Modifier.height(8.dp)) @@ -168,7 +168,7 @@ private fun EmptyState(modifier: Modifier = Modifier) { text = stringResource(id = R.string.bookmarks_empty_description), modifier = Modifier.fillMaxWidth(), textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyMedium + style = MaterialTheme.typography.bodyMedium, ) } } @@ -187,9 +187,9 @@ private fun BookmarksGridPreview() { NiaTheme { BookmarksGrid( feedState = Success( - previewUserNewsResources + previewUserNewsResources, ), - removeFromBookmarks = {} + removeFromBookmarks = {}, ) } } diff --git a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModel.kt b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModel.kt index db94839be..fe631c287 100644 --- a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModel.kt +++ b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModel.kt @@ -24,7 +24,6 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Loading import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filterNot @@ -32,11 +31,12 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import javax.inject.Inject @HiltViewModel class BookmarksViewModel @Inject constructor( private val userDataRepository: UserDataRepository, - getSaveableNewsResources: GetUserNewsResourcesUseCase + getSaveableNewsResources: GetUserNewsResourcesUseCase, ) : ViewModel() { val feedUiState: StateFlow = getSaveableNewsResources() @@ -47,7 +47,7 @@ class BookmarksViewModel @Inject constructor( .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = Loading + initialValue = Loading, ) fun removeFromSavedResources(newsResourceId: String) { diff --git a/feature/bookmarks/src/test/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt b/feature/bookmarks/src/test/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt index a8da1a4ff..b721218d4 100644 --- a/feature/bookmarks/src/test/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt +++ b/feature/bookmarks/src/test/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt @@ -23,8 +23,6 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserData import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Loading import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success -import kotlin.test.assertEquals -import kotlin.test.assertIs import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -32,6 +30,8 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertIs /** * To learn more about how this test handles Flows created with stateIn, see @@ -45,7 +45,7 @@ class BookmarksViewModelTest { private val newsRepository = TestNewsRepository() private val getUserNewsResourcesUseCase = GetUserNewsResourcesUseCase( newsRepository = newsRepository, - userDataRepository = userDataRepository + userDataRepository = userDataRepository, ) private lateinit var viewModel: BookmarksViewModel @@ -53,7 +53,7 @@ class BookmarksViewModelTest { fun setup() { viewModel = BookmarksViewModel( userDataRepository = userDataRepository, - getSaveableNewsResources = getUserNewsResourcesUseCase + getSaveableNewsResources = getUserNewsResourcesUseCase, ) } diff --git a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt index 70f60811b..9ff4ed8f4 100644 --- a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt +++ b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt @@ -41,7 +41,7 @@ class ForYouScreenTest { private val doneButtonMatcher by lazy { hasText( - composeTestRule.activity.resources.getString(R.string.done) + composeTestRule.activity.resources.getString(R.string.done), ) } @@ -55,14 +55,14 @@ class ForYouScreenTest { feedState = NewsFeedUiState.Loading, onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } composeTestRule .onNodeWithContentDescription( - composeTestRule.activity.resources.getString(R.string.for_you_loading) + composeTestRule.activity.resources.getString(R.string.for_you_loading), ) .assertExists() } @@ -77,14 +77,14 @@ class ForYouScreenTest { feedState = NewsFeedUiState.Success(emptyList()), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } composeTestRule .onNodeWithContentDescription( - composeTestRule.activity.resources.getString(R.string.for_you_loading) + composeTestRule.activity.resources.getString(R.string.for_you_loading), ) .assertExists() } @@ -100,11 +100,11 @@ class ForYouScreenTest { topics = testTopics, ), feedState = NewsFeedUiState.Success( - feed = emptyList() + feed = emptyList(), ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -140,14 +140,14 @@ class ForYouScreenTest { // Follow one topic topics = testTopics.mapIndexed { index, testTopic -> testTopic.copy(isFollowed = index == 1) - } + }, ), feedState = NewsFeedUiState.Success( - feed = emptyList() + feed = emptyList(), ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -183,14 +183,14 @@ class ForYouScreenTest { feedState = NewsFeedUiState.Loading, onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } composeTestRule .onNodeWithContentDescription( - composeTestRule.activity.resources.getString(R.string.for_you_loading) + composeTestRule.activity.resources.getString(R.string.for_you_loading), ) .assertExists() } @@ -205,14 +205,14 @@ class ForYouScreenTest { feedState = NewsFeedUiState.Loading, onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } composeTestRule .onNodeWithContentDescription( - composeTestRule.activity.resources.getString(R.string.for_you_loading) + composeTestRule.activity.resources.getString(R.string.for_you_loading), ) .assertExists() } @@ -224,18 +224,18 @@ class ForYouScreenTest { isSyncing = false, onboardingUiState = OnboardingUiState.NotShown, feedState = NewsFeedUiState.Success( - feed = previewUserNewsResources + feed = previewUserNewsResources, ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } composeTestRule .onNodeWithText( previewUserNewsResources[0].title, - substring = true + substring = true, ) .assertExists() .assertHasClickAction() @@ -244,14 +244,14 @@ class ForYouScreenTest { .performScrollToNode( hasText( previewUserNewsResources[1].title, - substring = true - ) + substring = true, + ), ) composeTestRule .onNodeWithText( previewUserNewsResources[1].title, - substring = true + substring = true, ) .assertExists() .assertHasClickAction() @@ -264,19 +264,19 @@ private val testTopic = Topic( shortDescription = "", longDescription = "", url = "", - imageUrl = "" + imageUrl = "", ) private val testTopics = listOf( FollowableTopic( topic = testTopic.copy(id = "0", name = "Headlines"), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = testTopic.copy(id = "1", name = "UI"), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = testTopic.copy(id = "2", name = "Tools"), - isFollowed = false + isFollowed = false, ), ) diff --git a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index ef714308b..aef60817f 100644 --- a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt +++ b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -93,7 +93,7 @@ import com.google.samples.apps.nowinandroid.core.ui.newsFeed @Composable internal fun ForYouRoute( modifier: Modifier = Modifier, - viewModel: ForYouViewModel = hiltViewModel() + viewModel: ForYouViewModel = hiltViewModel(), ) { val onboardingUiState by viewModel.onboardingUiState.collectAsStateWithLifecycle() val feedState by viewModel.feedState.collectAsStateWithLifecycle() @@ -106,7 +106,7 @@ internal fun ForYouRoute( onTopicCheckedChanged = viewModel::updateTopicSelection, saveFollowedTopics = viewModel::dismissOnboarding, onNewsResourcesCheckedChanged = viewModel::updateNewsResourceSaved, - modifier = modifier + modifier = modifier, ) } @@ -152,7 +152,7 @@ internal fun ForYouScreen( modifier = modifier .fillMaxSize() .testTag("forYou:feed"), - state = state + state = state, ) { onboarding( onboardingUiState = onboardingUiState, @@ -163,13 +163,13 @@ internal fun ForYouScreen( interestsItemModifier = Modifier.layout { measurable, constraints -> val placeable = measurable.measure( constraints.copy( - maxWidth = constraints.maxWidth + 32.dp.roundToPx() - ) + maxWidth = constraints.maxWidth + 32.dp.roundToPx(), + ), ) layout(placeable.width, placeable.height) { placeable.place(0, 0) } - } + }, ) newsFeed( @@ -198,12 +198,12 @@ internal fun ForYouScreen( ) { val loadingContentDescription = stringResource(id = R.string.for_you_loading) Box( - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), ) { NiaOverlayLoadingWheel( modifier = Modifier .align(Alignment.Center), - contentDesc = loadingContentDescription + contentDesc = loadingContentDescription, ) } } @@ -218,12 +218,13 @@ private fun LazyGridScope.onboarding( onboardingUiState: OnboardingUiState, onTopicCheckedChanged: (String, Boolean) -> Unit, saveFollowedTopics: () -> Unit, - interestsItemModifier: Modifier = Modifier + interestsItemModifier: Modifier = Modifier, ) { when (onboardingUiState) { OnboardingUiState.Loading, OnboardingUiState.LoadFailed, - OnboardingUiState.NotShown -> Unit + OnboardingUiState.NotShown, + -> Unit is OnboardingUiState.Shown -> { item(span = { GridItemSpan(maxLineSpan) }) { @@ -234,7 +235,7 @@ private fun LazyGridScope.onboarding( modifier = Modifier .fillMaxWidth() .padding(top = 24.dp), - style = MaterialTheme.typography.titleMedium + style = MaterialTheme.typography.titleMedium, ) Text( text = stringResource(R.string.onboarding_guidance_subtitle), @@ -242,27 +243,27 @@ private fun LazyGridScope.onboarding( .fillMaxWidth() .padding(top = 8.dp, start = 16.dp, end = 16.dp), textAlign = TextAlign.Center, - style = MaterialTheme.typography.bodyMedium + style = MaterialTheme.typography.bodyMedium, ) TopicSelection( onboardingUiState, onTopicCheckedChanged, - Modifier.padding(bottom = 8.dp) + Modifier.padding(bottom = 8.dp), ) // Done button Row( horizontalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), ) { NiaButton( onClick = saveFollowedTopics, enabled = onboardingUiState.isDismissable, modifier = Modifier .padding(horizontal = 40.dp) - .width(364.dp) + .width(364.dp), ) { Text( - text = stringResource(R.string.done) + text = stringResource(R.string.done), ) } } @@ -276,7 +277,7 @@ private fun LazyGridScope.onboarding( private fun TopicSelection( onboardingUiState: OnboardingUiState.Shown, onTopicCheckedChanged: (String, Boolean) -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) = trace("TopicSelection") { val lazyGridState = rememberLazyGridState() val topicSelectionTestTag = "forYou:topicSelection" @@ -301,7 +302,7 @@ private fun TopicSelection( // The maximum of these two bounds is therefore a valid upper bound in all cases. .heightIn(max = max(240.dp, with(LocalDensity.current) { 240.sp.toDp() })) .fillMaxWidth() - .testTag(topicSelectionTestTag) + .testTag(topicSelectionTestTag), ) { items(onboardingUiState.topics) { SingleTopicButton( @@ -309,7 +310,7 @@ private fun TopicSelection( topicId = it.topic.id, imageUrl = it.topic.imageUrl, isSelected = it.isFollowed, - onClick = onTopicCheckedChanged + onClick = onTopicCheckedChanged, ) } } @@ -322,7 +323,7 @@ private fun SingleTopicButton( topicId: String, imageUrl: String, isSelected: Boolean, - onClick: (String, Boolean) -> Unit + onClick: (String, Boolean) -> Unit, ) = trace("SingleTopicButton") { Surface( modifier = Modifier @@ -333,14 +334,14 @@ private fun SingleTopicButton( selected = isSelected, onClick = { onClick(topicId, !isSelected) - } + }, ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(start = 12.dp, end = 8.dp) + modifier = Modifier.padding(start = 12.dp, end = 8.dp), ) { TopicIcon( - imageUrl = imageUrl + imageUrl = imageUrl, ) Text( text = name, @@ -348,7 +349,7 @@ private fun SingleTopicButton( modifier = Modifier .padding(horizontal = 12.dp) .weight(1f), - color = MaterialTheme.colorScheme.onSurface + color = MaterialTheme.colorScheme.onSurface, ) NiaIconToggleButton( checked = isSelected, @@ -356,15 +357,15 @@ private fun SingleTopicButton( icon = { Icon( imageVector = NiaIcons.Add, - contentDescription = name + contentDescription = name, ) }, checkedIcon = { Icon( imageVector = NiaIcons.Check, - contentDescription = name + contentDescription = name, ) - } + }, ) } } @@ -373,7 +374,7 @@ private fun SingleTopicButton( @Composable fun TopicIcon( imageUrl: String, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { DynamicAsyncImage( // TODO b/228077205, show loading image visual instead of static placeholder @@ -382,7 +383,7 @@ fun TopicIcon( contentDescription = null, // decorative modifier = modifier .padding(10.dp) - .size(32.dp) + .size(32.dp), ) } @@ -395,11 +396,11 @@ fun ForYouScreenPopulatedFeed() { isSyncing = false, onboardingUiState = OnboardingUiState.NotShown, feedState = NewsFeedUiState.Success( - feed = previewUserNewsResources + feed = previewUserNewsResources, ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -414,11 +415,11 @@ fun ForYouScreenOfflinePopulatedFeed() { isSyncing = false, onboardingUiState = OnboardingUiState.NotShown, feedState = NewsFeedUiState.Success( - feed = previewUserNewsResources + feed = previewUserNewsResources, ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -435,11 +436,11 @@ fun ForYouScreenTopicSelection() { topics = previewTopics.map { FollowableTopic(it, false) }, ), feedState = NewsFeedUiState.Success( - feed = previewUserNewsResources + feed = previewUserNewsResources, ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -456,7 +457,7 @@ fun ForYouScreenLoading() { feedState = NewsFeedUiState.Loading, onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } @@ -471,11 +472,11 @@ fun ForYouScreenPopulatedAndLoading() { isSyncing = true, onboardingUiState = OnboardingUiState.Loading, feedState = NewsFeedUiState.Success( - feed = previewUserNewsResources + feed = previewUserNewsResources, ), onTopicCheckedChanged = { _, _ -> }, saveFollowedTopics = {}, - onNewsResourcesCheckedChanged = { _, _ -> } + onNewsResourcesCheckedChanged = { _, _ -> }, ) } } diff --git a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt index 6c9218a75..4895f8306 100644 --- a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt +++ b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt @@ -25,7 +25,6 @@ import com.google.samples.apps.nowinandroid.core.domain.GetUserNewsResourcesUseC import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -36,13 +35,14 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import javax.inject.Inject @HiltViewModel class ForYouViewModel @Inject constructor( syncStatusMonitor: SyncStatusMonitor, private val userDataRepository: UserDataRepository, private val getSaveableNewsResources: GetUserNewsResourcesUseCase, - getFollowableTopics: GetFollowableTopicsUseCase + getFollowableTopics: GetFollowableTopicsUseCase, ) : ViewModel() { private val shouldShowOnboarding: Flow = @@ -52,7 +52,7 @@ class ForYouViewModel @Inject constructor( .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = false + initialValue = false, ) val feedState: StateFlow = @@ -67,7 +67,7 @@ class ForYouViewModel @Inject constructor( flowOf(NewsFeedUiState.Success(emptyList())) } else { getSaveableNewsResources( - filterTopicIds = userData.followedTopics + filterTopicIds = userData.followedTopics, ).mapToFeedState() } } @@ -78,13 +78,13 @@ class ForYouViewModel @Inject constructor( .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = NewsFeedUiState.Loading + initialValue = NewsFeedUiState.Loading, ) val onboardingUiState: StateFlow = combine( shouldShowOnboarding, - getFollowableTopics() + getFollowableTopics(), ) { shouldShowOnboarding, topics -> if (shouldShowOnboarding) { OnboardingUiState.Shown(topics = topics) @@ -95,7 +95,7 @@ class ForYouViewModel @Inject constructor( .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = OnboardingUiState.Loading + initialValue = OnboardingUiState.Loading, ) fun updateTopicSelection(topicId: String, isChecked: Boolean) { diff --git a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/OnboardingUiState.kt b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/OnboardingUiState.kt index 73ecfed14..faf368b1e 100644 --- a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/OnboardingUiState.kt +++ b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/OnboardingUiState.kt @@ -41,7 +41,7 @@ sealed interface OnboardingUiState { * There is a onboarding state, with the given lists of topics. */ data class Shown( - val topics: List + val topics: List, ) : OnboardingUiState { /** * True if the onboarding can be dismissed. diff --git a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index 4427b44fe..1f6e010d5 100644 --- a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -32,7 +32,6 @@ import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor import com.google.samples.apps.nowinandroid.core.testing.util.TestSyncStatusMonitor import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState -import kotlin.test.assertEquals import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -42,6 +41,7 @@ import kotlinx.datetime.Instant import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals /** * To learn more about how this test handles Flows created with stateIn, see @@ -58,11 +58,11 @@ class ForYouViewModelTest { private val newsRepository = TestNewsRepository() private val getUserNewsResourcesUseCase = GetUserNewsResourcesUseCase( newsRepository = newsRepository, - userDataRepository = userDataRepository + userDataRepository = userDataRepository, ) private val getFollowableTopicsUseCase = GetFollowableTopicsUseCase( topicsRepository = topicsRepository, - userDataRepository = userDataRepository + userDataRepository = userDataRepository, ) private lateinit var viewModel: ForYouViewModel @@ -72,7 +72,7 @@ class ForYouViewModelTest { syncStatusMonitor = syncStatusMonitor, userDataRepository = userDataRepository, getSaveableNewsResources = getUserNewsResourcesUseCase, - getFollowableTopics = getFollowableTopicsUseCase + getFollowableTopics = getFollowableTopicsUseCase, ) } @@ -80,7 +80,7 @@ class ForYouViewModelTest { fun stateIsInitiallyLoading() = runTest { assertEquals( OnboardingUiState.Loading, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value) } @@ -95,7 +95,7 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Loading, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value) @@ -112,7 +112,7 @@ class ForYouViewModelTest { assertEquals( true, - viewModel.isSyncing.value + viewModel.isSyncing.value, ) collectJob.cancel() @@ -128,7 +128,7 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.Loading, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value) @@ -157,7 +157,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -168,7 +168,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -179,17 +179,17 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), ), ), - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( - feed = emptyList() + feed = emptyList(), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -218,7 +218,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -229,7 +229,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -240,18 +240,18 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), ), ), - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( - feed = emptyList() + feed = emptyList(), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -273,7 +273,7 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.NotShown, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value) @@ -281,13 +281,13 @@ class ForYouViewModelTest { assertEquals( OnboardingUiState.NotShown, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( - feed = sampleNewsResources.mapToUserNewsResources(userData) + feed = sampleNewsResources.mapToUserNewsResources(userData), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -308,15 +308,15 @@ class ForYouViewModelTest { OnboardingUiState.Shown( topics = sampleTopics.map { FollowableTopic(it, false) - } + }, ), - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( feed = emptyList(), ), - viewModel.feedState.value + viewModel.feedState.value, ) val followedTopicId = sampleTopics[1].id @@ -326,9 +326,9 @@ class ForYouViewModelTest { OnboardingUiState.Shown( topics = sampleTopics.map { FollowableTopic(it, it.id == followedTopicId) - } + }, ), - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) val userData = emptyUserData.copy(followedTopics = setOf(followedTopicId)) @@ -338,9 +338,9 @@ class ForYouViewModelTest { feed = listOf( UserNewsResource(sampleNewsResources[1], userData), UserNewsResource(sampleNewsResources[2], userData), - ) + ), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -372,7 +372,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -383,7 +383,7 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( topic = Topic( @@ -394,17 +394,17 @@ class ForYouViewModelTest { url = "URL", imageUrl = "image URL", ), - isFollowed = false - ) + isFollowed = false, + ), ), ), - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( - feed = emptyList() + feed = emptyList(), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -420,7 +420,7 @@ class ForYouViewModelTest { val followedTopicIds = setOf("1") val userData = emptyUserData.copy( followedTopics = followedTopicIds, - shouldHideOnboarding = true + shouldHideOnboarding = true, ) topicsRepository.sendTopics(sampleTopics) @@ -430,25 +430,25 @@ class ForYouViewModelTest { val bookmarkedNewsResourceId = "2" viewModel.updateNewsResourceSaved( newsResourceId = bookmarkedNewsResourceId, - isChecked = true + isChecked = true, ) val userDataExpected = userData.copy( - bookmarkedNewsResources = setOf(bookmarkedNewsResourceId) + bookmarkedNewsResources = setOf(bookmarkedNewsResourceId), ) assertEquals( OnboardingUiState.NotShown, - viewModel.onboardingUiState.value + viewModel.onboardingUiState.value, ) assertEquals( NewsFeedUiState.Success( feed = listOf( UserNewsResource(newsResource = sampleNewsResources[1], userDataExpected), - UserNewsResource(newsResource = sampleNewsResources[2], userDataExpected) - ) + UserNewsResource(newsResource = sampleNewsResources[2], userDataExpected), + ), ), - viewModel.feedState.value + viewModel.feedState.value, ) collectJob1.cancel() @@ -480,7 +480,7 @@ private val sampleTopics = listOf( longDescription = "long description", url = "URL", imageUrl = "image URL", - ) + ), ) private val sampleNewsResources = listOf( @@ -503,7 +503,7 @@ private val sampleNewsResources = listOf( longDescription = "long description", url = "URL", imageUrl = "image URL", - ) + ), ), ), NewsResource( diff --git a/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt b/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt index e44086c4c..2c5ed4844 100644 --- a/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt +++ b/feature/interests/src/androidTest/java/com/google/samples/apps/nowinandroid/interests/InterestsScreenTest.kt @@ -76,7 +76,7 @@ class InterestsScreenTest { fun interestsWithTopics_whenTopicsFollowed_showFollowedAndUnfollowedTopicsWithInfo() { composeTestRule.setContent { InterestsScreen( - uiState = InterestsUiState.Interests(topics = testTopics) + uiState = InterestsUiState.Interests(topics = testTopics), ) } @@ -115,7 +115,7 @@ class InterestsScreenTest { InterestsScreen( uiState = uiState, followTopic = { _, _ -> }, - navigateToTopic = {} + navigateToTopic = {}, ) } } @@ -138,7 +138,7 @@ private val testTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -149,7 +149,7 @@ private val testTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false + isFollowed = false, ), FollowableTopic( Topic( @@ -160,8 +160,8 @@ private val testTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false - ) + isFollowed = false, + ), ) private val numberOfUnfollowedTopics = testTopics.filter { !it.isFollowed }.size diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt index 19ace59f6..f8a7a8d90 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsItem.kt @@ -51,18 +51,18 @@ fun InterestsItem( modifier: Modifier = Modifier, iconModifier: Modifier = Modifier, description: String = "", - itemSeparation: Dp = 16.dp + itemSeparation: Dp = 16.dp, ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = modifier + modifier = modifier, ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .weight(1f) .clickable { onClick() } - .padding(vertical = itemSeparation) + .padding(vertical = itemSeparation), ) { InterestsIcon(topicImageUrl, iconModifier.size(64.dp)) Spacer(modifier = Modifier.width(16.dp)) @@ -75,18 +75,18 @@ fun InterestsItem( Icon( imageVector = NiaIcons.Add, contentDescription = stringResource( - id = string.card_follow_button_content_desc - ) + id = string.card_follow_button_content_desc, + ), ) }, checkedIcon = { Icon( imageVector = NiaIcons.Check, contentDescription = stringResource( - id = string.card_unfollow_button_content_desc - ) + id = string.card_unfollow_button_content_desc, + ), ) - } + }, ) } } @@ -98,13 +98,13 @@ private fun InterestContent(name: String, description: String, modifier: Modifie text = name, style = MaterialTheme.typography.headlineSmall, modifier = Modifier.padding( - vertical = if (description.isEmpty()) 0.dp else 4.dp - ) + vertical = if (description.isEmpty()) 0.dp else 4.dp, + ), ) if (description.isNotEmpty()) { Text( text = description, - style = MaterialTheme.typography.bodyMedium + style = MaterialTheme.typography.bodyMedium, ) } } @@ -124,7 +124,7 @@ private fun InterestsIcon(topicImageUrl: String, modifier: Modifier = Modifier) DynamicAsyncImage( imageUrl = topicImageUrl, contentDescription = null, - modifier = modifier + modifier = modifier, ) } } @@ -140,7 +140,7 @@ private fun InterestsCardPreview() { following = false, topicImageUrl = "", onClick = { }, - onFollowButtonClick = { } + onFollowButtonClick = { }, ) } } @@ -157,7 +157,7 @@ private fun InterestsCardLongNamePreview() { following = true, topicImageUrl = "", onClick = { }, - onFollowButtonClick = { } + onFollowButtonClick = { }, ) } } @@ -175,7 +175,7 @@ private fun InterestsCardLongDescriptionPreview() { following = false, topicImageUrl = "", onClick = { }, - onFollowButtonClick = { } + onFollowButtonClick = { }, ) } } @@ -192,7 +192,7 @@ private fun InterestsCardWithEmptyDescriptionPreview() { following = true, topicImageUrl = "", onClick = { }, - onFollowButtonClick = { } + onFollowButtonClick = { }, ) } } diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt index 8cce790c4..4376d55d6 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt @@ -38,7 +38,7 @@ import com.google.samples.apps.nowinandroid.core.ui.DevicePreviews internal fun InterestsRoute( navigateToTopic: (String) -> Unit, modifier: Modifier = Modifier, - viewModel: InterestsViewModel = hiltViewModel() + viewModel: InterestsViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() @@ -46,7 +46,7 @@ internal fun InterestsRoute( uiState = uiState, followTopic = viewModel::followTopic, navigateToTopic = navigateToTopic, - modifier = modifier + modifier = modifier, ) } @@ -59,7 +59,7 @@ internal fun InterestsScreen( ) { Column( modifier = modifier, - horizontalAlignment = Alignment.CenterHorizontally + horizontalAlignment = Alignment.CenterHorizontally, ) { when (uiState) { InterestsUiState.Loading -> @@ -91,7 +91,7 @@ fun InterestsScreenPopulated() { NiaBackground { InterestsScreen( uiState = InterestsUiState.Interests( - topics = previewTopics.map { FollowableTopic(it, false) } + topics = previewTopics.map { FollowableTopic(it, false) }, ), followTopic = { _, _ -> }, navigateToTopic = {}, diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsViewModel.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsViewModel.kt index 8466a33f0..d6ef94521 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsViewModel.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsViewModel.kt @@ -23,12 +23,12 @@ import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCa import com.google.samples.apps.nowinandroid.core.domain.TopicSortField import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import javax.inject.Inject @HiltViewModel class InterestsViewModel @Inject constructor( @@ -38,11 +38,11 @@ class InterestsViewModel @Inject constructor( val uiState: StateFlow = getFollowableTopics(sortBy = TopicSortField.NAME).map( - InterestsUiState::Interests + InterestsUiState::Interests, ).stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = InterestsUiState.Loading + initialValue = InterestsUiState.Loading, ) fun followTopic(followedTopicId: String, followed: Boolean) { @@ -56,7 +56,7 @@ sealed interface InterestsUiState { object Loading : InterestsUiState data class Interests( - val topics: List + val topics: List, ) : InterestsUiState object Empty : InterestsUiState diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt index 0cff8c82c..dcca35795 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt @@ -34,13 +34,13 @@ fun TopicsTabContent( topics: List, onTopicClick: (String) -> Unit, onFollowButtonClick: (String, Boolean) -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { LazyColumn( modifier = modifier .padding(horizontal = 16.dp) .testTag("interests:topics"), - contentPadding = PaddingValues(top = 8.dp) + contentPadding = PaddingValues(top = 8.dp), ) { topics.forEach { followableTopic -> val topicId = followableTopic.topic.id @@ -51,7 +51,7 @@ fun TopicsTabContent( description = followableTopic.topic.shortDescription, topicImageUrl = followableTopic.topic.imageUrl, onClick = { onTopicClick(topicId) }, - onFollowButtonClick = { onFollowButtonClick(topicId, it) } + onFollowButtonClick = { onFollowButtonClick(topicId, it) }, ) } } diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/navigation/InterestsNavigation.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/navigation/InterestsNavigation.kt index 47facde82..9a5ce7696 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/navigation/InterestsNavigation.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/navigation/InterestsNavigation.kt @@ -32,11 +32,11 @@ fun NavController.navigateToInterestsGraph(navOptions: NavOptions? = null) { fun NavGraphBuilder.interestsGraph( navigateToTopic: (String) -> Unit, - nestedGraphs: NavGraphBuilder.() -> Unit + nestedGraphs: NavGraphBuilder.() -> Unit, ) { navigation( route = interestsGraphRoutePattern, - startDestination = interestsRoute + startDestination = interestsRoute, ) { composable(route = interestsRoute) { InterestsRoute( diff --git a/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt b/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt index c84a8ad45..e47b25021 100644 --- a/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt +++ b/feature/interests/src/test/java/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt @@ -24,7 +24,6 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserData import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.feature.interests.InterestsUiState import com.google.samples.apps.nowinandroid.feature.interests.InterestsViewModel -import kotlin.test.assertEquals import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -32,6 +31,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals /** * To learn more about how this test handles Flows created with stateIn, see @@ -46,7 +46,7 @@ class InterestsViewModelTest { private val topicsRepository = TestTopicsRepository() private val getFollowableTopicsUseCase = GetFollowableTopicsUseCase( topicsRepository = topicsRepository, - userDataRepository = userDataRepository + userDataRepository = userDataRepository, ) private lateinit var viewModel: InterestsViewModel @@ -84,17 +84,17 @@ class InterestsViewModelTest { assertEquals( false, (viewModel.uiState.value as InterestsUiState.Interests) - .topics.first { it.topic.id == toggleTopicId }.isFollowed + .topics.first { it.topic.id == toggleTopicId }.isFollowed, ) viewModel.followTopic( followedTopicId = toggleTopicId, - true + true, ) assertEquals( InterestsUiState.Interests(topics = testOutputTopics), - viewModel.uiState.value + viewModel.uiState.value, ) collectJob.cancel() @@ -108,23 +108,23 @@ class InterestsViewModelTest { topicsRepository.sendTopics(testOutputTopics.map { it.topic }) userDataRepository.setFollowedTopicIds( - setOf(testOutputTopics[0].topic.id, testOutputTopics[1].topic.id) + setOf(testOutputTopics[0].topic.id, testOutputTopics[1].topic.id), ) assertEquals( true, (viewModel.uiState.value as InterestsUiState.Interests) - .topics.first { it.topic.id == toggleTopicId }.isFollowed + .topics.first { it.topic.id == toggleTopicId }.isFollowed, ) viewModel.followTopic( followedTopicId = toggleTopicId, - false + false, ) assertEquals( InterestsUiState.Interests(topics = testInputTopics), - viewModel.uiState.value + viewModel.uiState.value, ) collectJob.cancel() @@ -149,7 +149,7 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -160,7 +160,7 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false + isFollowed = false, ), FollowableTopic( Topic( @@ -171,8 +171,8 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false - ) + isFollowed = false, + ), ) private val testOutputTopics = listOf( @@ -185,7 +185,7 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -196,7 +196,7 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -207,6 +207,6 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false - ) + isFollowed = false, + ), ) diff --git a/feature/settings/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialogTest.kt b/feature/settings/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialogTest.kt index 4643362ff..febc606b0 100644 --- a/feature/settings/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialogTest.kt +++ b/feature/settings/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialogTest.kt @@ -37,14 +37,13 @@ class SettingsDialogTest { @Test fun whenLoading_showsLoadingText() { - composeTestRule.setContent { SettingsDialog( settingsUiState = Loading, onDismiss = {}, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } @@ -61,13 +60,13 @@ class SettingsDialogTest { UserEditableSettings( brand = ANDROID, useDynamicColor = false, - darkThemeConfig = DARK - ) + darkThemeConfig = DARK, + ), ), onDismiss = { }, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } @@ -75,7 +74,7 @@ class SettingsDialogTest { composeTestRule.onNodeWithText(getString(R.string.brand_default)).assertExists() composeTestRule.onNodeWithText(getString(R.string.brand_android)).assertExists() composeTestRule.onNodeWithText( - getString(R.string.dark_mode_config_system_default) + getString(R.string.dark_mode_config_system_default), ).assertExists() composeTestRule.onNodeWithText(getString(R.string.dark_mode_config_light)).assertExists() composeTestRule.onNodeWithText(getString(R.string.dark_mode_config_dark)).assertExists() @@ -94,13 +93,13 @@ class SettingsDialogTest { brand = DEFAULT, darkThemeConfig = DARK, useDynamicColor = false, - ) + ), ), supportDynamicColor = true, onDismiss = {}, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } @@ -121,12 +120,12 @@ class SettingsDialogTest { brand = ANDROID, darkThemeConfig = DARK, useDynamicColor = false, - ) + ), ), onDismiss = {}, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } @@ -145,12 +144,12 @@ class SettingsDialogTest { brand = ANDROID, darkThemeConfig = DARK, useDynamicColor = false, - ) + ), ), onDismiss = {}, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } @@ -169,12 +168,12 @@ class SettingsDialogTest { brand = ANDROID, darkThemeConfig = DARK, useDynamicColor = false, - ) + ), ), onDismiss = {}, onChangeDynamicColorPreference = {}, onChangeThemeBrand = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } diff --git a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt index a824c1db3..bed230d0d 100644 --- a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt +++ b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt @@ -69,7 +69,7 @@ import com.google.samples.apps.nowinandroid.feature.settings.SettingsUiState.Suc @Composable fun SettingsDialog( onDismiss: () -> Unit, - viewModel: SettingsViewModel = hiltViewModel() + viewModel: SettingsViewModel = hiltViewModel(), ) { val settingsUiState by viewModel.settingsUiState.collectAsStateWithLifecycle() SettingsDialog( @@ -89,7 +89,7 @@ fun SettingsDialog( onDismiss: () -> Unit, onChangeThemeBrand: (themeBrand: ThemeBrand) -> Unit, onChangeDynamicColorPreference: (useDynamicColor: Boolean) -> Unit, - onChangeDarkThemeConfig: (darkThemeConfig: DarkThemeConfig) -> Unit + onChangeDarkThemeConfig: (darkThemeConfig: DarkThemeConfig) -> Unit, ) { val configuration = LocalConfiguration.current @@ -107,7 +107,7 @@ fun SettingsDialog( title = { Text( text = stringResource(string.settings_title), - style = MaterialTheme.typography.titleLarge + style = MaterialTheme.typography.titleLarge, ) }, text = { @@ -117,7 +117,7 @@ fun SettingsDialog( Loading -> { Text( text = stringResource(string.loading), - modifier = Modifier.padding(vertical = 16.dp) + modifier = Modifier.padding(vertical = 16.dp), ) } @@ -127,7 +127,7 @@ fun SettingsDialog( supportDynamicColor = supportDynamicColor, onChangeThemeBrand = onChangeThemeBrand, onChangeDynamicColorPreference = onChangeDynamicColorPreference, - onChangeDarkThemeConfig = onChangeDarkThemeConfig + onChangeDarkThemeConfig = onChangeDarkThemeConfig, ) } } @@ -142,9 +142,9 @@ fun SettingsDialog( color = MaterialTheme.colorScheme.primary, modifier = Modifier .padding(horizontal = 8.dp) - .clickable { onDismiss() } + .clickable { onDismiss() }, ) - } + }, ) } @@ -154,19 +154,19 @@ private fun SettingsPanel( supportDynamicColor: Boolean, onChangeThemeBrand: (themeBrand: ThemeBrand) -> Unit, onChangeDynamicColorPreference: (useDynamicColor: Boolean) -> Unit, - onChangeDarkThemeConfig: (darkThemeConfig: DarkThemeConfig) -> Unit + onChangeDarkThemeConfig: (darkThemeConfig: DarkThemeConfig) -> Unit, ) { SettingsDialogSectionTitle(text = stringResource(string.theme)) Column(Modifier.selectableGroup()) { SettingsDialogThemeChooserRow( text = stringResource(string.brand_default), selected = settings.brand == DEFAULT, - onClick = { onChangeThemeBrand(DEFAULT) } + onClick = { onChangeThemeBrand(DEFAULT) }, ) SettingsDialogThemeChooserRow( text = stringResource(string.brand_android), selected = settings.brand == ANDROID, - onClick = { onChangeThemeBrand(ANDROID) } + onClick = { onChangeThemeBrand(ANDROID) }, ) } if (settings.brand == DEFAULT && supportDynamicColor) { @@ -175,12 +175,12 @@ private fun SettingsPanel( SettingsDialogThemeChooserRow( text = stringResource(string.dynamic_color_yes), selected = settings.useDynamicColor, - onClick = { onChangeDynamicColorPreference(true) } + onClick = { onChangeDynamicColorPreference(true) }, ) SettingsDialogThemeChooserRow( text = stringResource(string.dynamic_color_no), selected = !settings.useDynamicColor, - onClick = { onChangeDynamicColorPreference(false) } + onClick = { onChangeDynamicColorPreference(false) }, ) } } @@ -189,17 +189,17 @@ private fun SettingsPanel( SettingsDialogThemeChooserRow( text = stringResource(string.dark_mode_config_system_default), selected = settings.darkThemeConfig == FOLLOW_SYSTEM, - onClick = { onChangeDarkThemeConfig(FOLLOW_SYSTEM) } + onClick = { onChangeDarkThemeConfig(FOLLOW_SYSTEM) }, ) SettingsDialogThemeChooserRow( text = stringResource(string.dark_mode_config_light), selected = settings.darkThemeConfig == LIGHT, - onClick = { onChangeDarkThemeConfig(LIGHT) } + onClick = { onChangeDarkThemeConfig(LIGHT) }, ) SettingsDialogThemeChooserRow( text = stringResource(string.dark_mode_config_dark), selected = settings.darkThemeConfig == DARK, - onClick = { onChangeDarkThemeConfig(DARK) } + onClick = { onChangeDarkThemeConfig(DARK) }, ) } } @@ -209,7 +209,7 @@ private fun SettingsDialogSectionTitle(text: String) { Text( text = text, style = MaterialTheme.typography.titleMedium, - modifier = Modifier.padding(top = 16.dp, bottom = 8.dp) + modifier = Modifier.padding(top = 16.dp, bottom = 8.dp), ) } @@ -217,7 +217,7 @@ private fun SettingsDialogSectionTitle(text: String) { fun SettingsDialogThemeChooserRow( text: String, selected: Boolean, - onClick: () -> Unit + onClick: () -> Unit, ) { Row( Modifier @@ -228,11 +228,11 @@ fun SettingsDialogThemeChooserRow( onClick = onClick, ) .padding(8.dp), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { RadioButton( selected = selected, - onClick = null + onClick = null, ) Spacer(Modifier.width(8.dp)) Text(text) @@ -242,7 +242,7 @@ fun SettingsDialogThemeChooserRow( @Composable private fun LinksPanel() { Row( - modifier = Modifier.padding(top = 16.dp) + modifier = Modifier.padding(top = 16.dp), ) { Column( Modifier.fillMaxWidth(), @@ -251,24 +251,24 @@ private fun LinksPanel() { Row { TextLink( text = stringResource(string.privacy_policy), - url = PRIVACY_POLICY_URL + url = PRIVACY_POLICY_URL, ) Spacer(Modifier.width(16.dp)) TextLink( text = stringResource(string.licenses), - url = LICENSES_URL + url = LICENSES_URL, ) } Spacer(Modifier.height(16.dp)) Row { TextLink( text = stringResource(string.brand_guidelines), - url = BRAND_GUIDELINES_URL + url = BRAND_GUIDELINES_URL, ) Spacer(Modifier.width(16.dp)) TextLink( text = stringResource(string.feedback), - url = FEEDBACK_URL + url = FEEDBACK_URL, ) } } @@ -277,7 +277,6 @@ private fun LinksPanel() { @Composable private fun TextLink(text: String, url: String) { - val launchResourceIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) val context = LocalContext.current @@ -288,7 +287,7 @@ private fun TextLink(text: String, url: String) { modifier = Modifier .clickable { ContextCompat.startActivity(context, launchResourceIntent, null) - } + }, ) } @@ -302,12 +301,12 @@ private fun PreviewSettingsDialog() { UserEditableSettings( brand = DEFAULT, darkThemeConfig = FOLLOW_SYSTEM, - useDynamicColor = false - ) + useDynamicColor = false, + ), ), onChangeThemeBrand = {}, onChangeDynamicColorPreference = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } } @@ -321,7 +320,7 @@ private fun PreviewSettingsDialogLoading() { settingsUiState = Loading, onChangeThemeBrand = {}, onChangeDynamicColorPreference = {}, - onChangeDarkThemeConfig = {} + onChangeDarkThemeConfig = {}, ) } } diff --git a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModel.kt b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModel.kt index c1eac1eee..33bf58a2c 100644 --- a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModel.kt +++ b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModel.kt @@ -24,12 +24,12 @@ import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.feature.settings.SettingsUiState.Loading import com.google.samples.apps.nowinandroid.feature.settings.SettingsUiState.Success import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import javax.inject.Inject @HiltViewModel class SettingsViewModel @Inject constructor( @@ -42,8 +42,8 @@ class SettingsViewModel @Inject constructor( settings = UserEditableSettings( brand = userData.themeBrand, useDynamicColor = userData.useDynamicColor, - darkThemeConfig = userData.darkThemeConfig - ) + darkThemeConfig = userData.darkThemeConfig, + ), ) } .stateIn( @@ -55,7 +55,7 @@ class SettingsViewModel @Inject constructor( // scrollable column. // TODO: Change to SharingStarted.WhileSubscribed(5_000) when b/221643630 is fixed started = SharingStarted.Eagerly, - initialValue = Loading + initialValue = Loading, ) fun updateThemeBrand(themeBrand: ThemeBrand) { @@ -83,7 +83,7 @@ class SettingsViewModel @Inject constructor( data class UserEditableSettings( val brand: ThemeBrand, val useDynamicColor: Boolean, - val darkThemeConfig: DarkThemeConfig + val darkThemeConfig: DarkThemeConfig, ) sealed interface SettingsUiState { diff --git a/feature/settings/src/test/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt b/feature/settings/src/test/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt index 0377490b3..9062abee6 100644 --- a/feature/settings/src/test/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt +++ b/feature/settings/src/test/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt @@ -22,7 +22,6 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserData import com.google.samples.apps.nowinandroid.core.testing.util.MainDispatcherRule import com.google.samples.apps.nowinandroid.feature.settings.SettingsUiState.Loading import com.google.samples.apps.nowinandroid.feature.settings.SettingsUiState.Success -import kotlin.test.assertEquals import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -30,6 +29,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals class SettingsViewModelTest { @@ -52,7 +52,6 @@ class SettingsViewModelTest { @Test fun stateIsSuccessAfterUserDataLoaded() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.settingsUiState.collect() } @@ -64,10 +63,10 @@ class SettingsViewModelTest { UserEditableSettings( brand = ANDROID, darkThemeConfig = DARK, - useDynamicColor = false - ) + useDynamicColor = false, + ), ), - viewModel.settingsUiState.value + viewModel.settingsUiState.value, ) collectJob.cancel() diff --git a/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt b/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt index df9e83315..9f984c4a3 100644 --- a/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt +++ b/feature/topic/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreenTest.kt @@ -120,7 +120,7 @@ class TopicScreenTest { TopicScreen( topicUiState = TopicUiState.Success(testTopic), newsUiState = NewsUiState.Success( - sampleUserNewsResources + sampleUserNewsResources, ), onBackClick = { }, onFollowClick = { }, @@ -149,9 +149,9 @@ private val testTopics = listOf( shortDescription = "", longDescription = TOPIC_DESC, url = "", - imageUrl = "" + imageUrl = "", ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -160,9 +160,9 @@ private val testTopics = listOf( shortDescription = "", longDescription = TOPIC_DESC, url = "", - imageUrl = "" + imageUrl = "", ), - isFollowed = false + isFollowed = false, ), FollowableTopic( Topic( @@ -171,10 +171,10 @@ private val testTopics = listOf( shortDescription = "", longDescription = TOPIC_DESC, url = "", - imageUrl = "" + imageUrl = "", ), - isFollowed = false - ) + isFollowed = false, + ), ) private val sampleUserNewsResources = listOf( @@ -198,10 +198,10 @@ private val sampleUserNewsResources = listOf( shortDescription = "", longDescription = TOPIC_DESC, url = "", - imageUrl = "" - ) - ) + imageUrl = "", + ), + ), ), - userData = emptyUserData.copy(bookmarkedNewsResources = setOf("1")) - ) + userData = emptyUserData.copy(bookmarkedNewsResources = setOf("1")), + ), ) diff --git a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt index 2200fc035..b4d31084b 100644 --- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt +++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt @@ -95,7 +95,7 @@ internal fun TopicScreen( LazyColumn( state = state, modifier = modifier, - horizontalAlignment = Alignment.CenterHorizontally + horizontalAlignment = Alignment.CenterHorizontally, ) { item { Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing)) @@ -122,7 +122,7 @@ internal fun TopicScreen( description = topicUiState.followableTopic.topic.longDescription, news = newsUiState, imageUrl = topicUiState.followableTopic.topic.imageUrl, - onBookmarkChanged = onBookmarkChanged + onBookmarkChanged = onBookmarkChanged, ) } } @@ -137,7 +137,7 @@ private fun LazyListScope.TopicBody( description: String, news: NewsUiState, imageUrl: String, - onBookmarkChanged: (String, Boolean) -> Unit + onBookmarkChanged: (String, Boolean) -> Unit, ) { // TODO: Show icon if available item { @@ -150,7 +150,7 @@ private fun LazyListScope.TopicBody( @Composable private fun TopicHeader(name: String, description: String, imageUrl: String) { Column( - modifier = Modifier.padding(horizontal = 24.dp) + modifier = Modifier.padding(horizontal = 24.dp), ) { DynamicAsyncImage( imageUrl = imageUrl, @@ -158,14 +158,14 @@ private fun TopicHeader(name: String, description: String, imageUrl: String) { modifier = Modifier .align(Alignment.CenterHorizontally) .size(216.dp) - .padding(bottom = 12.dp) + .padding(bottom = 12.dp), ) Text(name, style = MaterialTheme.typography.displayMedium) if (description.isNotEmpty()) { Text( description, modifier = Modifier.padding(top = 24.dp), - style = MaterialTheme.typography.bodyLarge + style = MaterialTheme.typography.bodyLarge, ) } } @@ -174,14 +174,14 @@ private fun TopicHeader(name: String, description: String, imageUrl: String) { // TODO: Could/should this be replaced with [LazyGridScope.newsFeed]? private fun LazyListScope.userNewsResourceCards( news: NewsUiState, - onBookmarkChanged: (String, Boolean) -> Unit + onBookmarkChanged: (String, Boolean) -> Unit, ) { when (news) { is NewsUiState.Success -> { userNewsResourceCardItems( items = news.news, onToggleBookmark = { onBookmarkChanged(it.id, !it.isSaved) }, - itemModifier = Modifier.padding(24.dp) + itemModifier = Modifier.padding(24.dp), ) } @@ -201,8 +201,11 @@ private fun TopicBodyPreview() { NiaTheme { LazyColumn { TopicBody( - "Jetpack Compose", "Lorem ipsum maximum", - NewsUiState.Success(emptyList()), "", { _, _ -> } + "Jetpack Compose", + "Lorem ipsum maximum", + NewsUiState.Success(emptyList()), + "", + { _, _ -> }, ) } } @@ -220,21 +223,21 @@ private fun TopicToolbar( verticalAlignment = Alignment.CenterVertically, modifier = modifier .fillMaxWidth() - .padding(bottom = 32.dp) + .padding(bottom = 32.dp), ) { IconButton(onClick = { onBackClick() }) { Icon( imageVector = NiaIcons.ArrowBack, contentDescription = stringResource( - id = com.google.samples.apps.nowinandroid.core.ui.R.string.back - ) + id = com.google.samples.apps.nowinandroid.core.ui.R.string.back, + ), ) } val selected = uiState.isFollowed NiaFilterChip( selected = selected, onSelectedChange = onFollowClick, - modifier = Modifier.padding(end = 24.dp) + modifier = Modifier.padding(end = 24.dp), ) { if (selected) { Text("FOLLOWING") @@ -253,7 +256,7 @@ fun TopicScreenPopulated() { TopicScreen( topicUiState = TopicUiState.Success(FollowableTopic(previewTopics[0], false)), newsUiState = NewsUiState.Success( - previewUserNewsResources + previewUserNewsResources, ), onBackClick = {}, onFollowClick = {}, diff --git a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt index 260cecbd1..c0c6bbafd 100644 --- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt +++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModel.kt @@ -30,7 +30,6 @@ import com.google.samples.apps.nowinandroid.core.result.Result import com.google.samples.apps.nowinandroid.core.result.asResult import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicArgs import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -38,6 +37,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +import javax.inject.Inject @HiltViewModel class TopicViewModel @Inject constructor( @@ -45,7 +45,7 @@ class TopicViewModel @Inject constructor( stringDecoder: StringDecoder, private val userDataRepository: UserDataRepository, topicsRepository: TopicsRepository, - getSaveableNewsResources: GetUserNewsResourcesUseCase + getSaveableNewsResources: GetUserNewsResourcesUseCase, ) : ViewModel() { private val topicArgs: TopicArgs = TopicArgs(savedStateHandle, stringDecoder) @@ -53,23 +53,23 @@ class TopicViewModel @Inject constructor( val topicUiState: StateFlow = topicUiState( topicId = topicArgs.topicId, userDataRepository = userDataRepository, - topicsRepository = topicsRepository + topicsRepository = topicsRepository, ) .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = TopicUiState.Loading + initialValue = TopicUiState.Loading, ) val newUiState: StateFlow = newsUiState( topicId = topicArgs.topicId, userDataRepository = userDataRepository, - getSaveableNewsResources = getSaveableNewsResources + getSaveableNewsResources = getSaveableNewsResources, ) .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = NewsUiState.Loading + initialValue = NewsUiState.Loading, ) fun followTopicToggle(followed: Boolean) { @@ -97,13 +97,13 @@ private fun topicUiState( // Observe topic information val topicStream: Flow = topicsRepository.getTopic( - id = topicId + id = topicId, ) return combine( followedTopicIds, topicStream, - ::Pair + ::Pair, ) .asResult() .map { followedTopicToTopicResult -> @@ -114,8 +114,8 @@ private fun topicUiState( TopicUiState.Success( followableTopic = FollowableTopic( topic = topic, - isFollowed = followed - ) + isFollowed = followed, + ), ) } is Result.Loading -> { @@ -145,7 +145,7 @@ private fun newsUiState( return combine( newsStream, bookmark, - ::Pair + ::Pair, ) .asResult() .map { newsToBookmarksResult -> diff --git a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt index 808143275..1cc43bbd1 100644 --- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt +++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt @@ -41,13 +41,13 @@ fun NavController.navigateToTopic(topicId: String) { } fun NavGraphBuilder.topicScreen( - onBackClick: () -> Unit + onBackClick: () -> Unit, ) { composable( route = "topic_route/{$topicIdArg}", arguments = listOf( - navArgument(topicIdArg) { type = NavType.StringType } - ) + navArgument(topicIdArg) { type = NavType.StringType }, + ), ) { TopicRoute(onBackClick = onBackClick) } diff --git a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index 6c61e59d5..a8f1b0a88 100644 --- a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -28,8 +28,6 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRe 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.feature.topic.navigation.topicIdArg -import kotlin.test.assertEquals -import kotlin.test.assertIs import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first @@ -40,6 +38,8 @@ import kotlinx.datetime.Instant import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertIs /** * To learn more about how this test handles Flows created with stateIn, see @@ -55,7 +55,7 @@ class TopicViewModelTest { private val newsRepository = TestNewsRepository() private val getUserNewsResourcesUseCase = GetUserNewsResourcesUseCase( newsRepository = newsRepository, - userDataRepository = userDataRepository + userDataRepository = userDataRepository, ) private lateinit var viewModel: TopicViewModel @@ -66,7 +66,7 @@ class TopicViewModelTest { stringDecoder = FakeStringDecoder(), userDataRepository = userDataRepository, topicsRepository = topicsRepository, - getSaveableNewsResources = getUserNewsResourcesUseCase + getSaveableNewsResources = getUserNewsResourcesUseCase, ) } @@ -80,7 +80,7 @@ class TopicViewModelTest { assertIs(item) val topicFromRepository = topicsRepository.getTopic( - testInputTopics[0].topic.id + testInputTopics[0].topic.id, ).first() assertEquals(topicFromRepository, item.followableTopic.topic) @@ -131,7 +131,7 @@ class TopicViewModelTest { combine( viewModel.topicUiState, viewModel.newUiState, - ::Pair + ::Pair, ).collect() } topicsRepository.sendTopics(testInputTopics.map { it.topic }) @@ -158,7 +158,7 @@ class TopicViewModelTest { assertEquals( TopicUiState.Success(followableTopic = testOutputTopics[0]), - viewModel.topicUiState.value + viewModel.topicUiState.value, ) collectJob.cancel() @@ -183,7 +183,7 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -194,7 +194,7 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false + isFollowed = false, ), FollowableTopic( Topic( @@ -205,8 +205,8 @@ private val testInputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false - ) + isFollowed = false, + ), ) private val testOutputTopics = listOf( @@ -219,7 +219,7 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -230,7 +230,7 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = true + isFollowed = true, ), FollowableTopic( Topic( @@ -241,8 +241,8 @@ private val testOutputTopics = listOf( url = TOPIC_URL, imageUrl = TOPIC_IMAGE_URL, ), - isFollowed = false - ) + isFollowed = false, + ), ) private val sampleNewsResources = listOf( @@ -265,7 +265,7 @@ private val sampleNewsResources = listOf( longDescription = "long description", url = "URL", imageUrl = "image URL", - ) + ), ), - ) + ), ) diff --git a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt index 047b5d7ab..39aa07160 100644 --- a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt +++ b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemDetector.kt @@ -38,7 +38,7 @@ class DesignSystemDetector : Detector(), Detector.UastScanner { override fun getApplicableUastTypes(): List> { return listOf( UCallExpression::class.java, - UQualifiedReferenceExpression::class.java + UQualifiedReferenceExpression::class.java, ) } @@ -71,8 +71,8 @@ class DesignSystemDetector : Detector(), Detector.UastScanner { severity = Severity.ERROR, implementation = Implementation( DesignSystemDetector::class.java, - Scope.JAVA_FILE_SCOPE - ) + Scope.JAVA_FILE_SCOPE, + ), ) // Unfortunately :lint is a Java module and thus can't depend on the :core-designsystem @@ -99,21 +99,23 @@ class DesignSystemDetector : Detector(), Detector.UastScanner { "CenterAlignedTopAppBar" to "NiaTopAppBar", "SmallTopAppBar" to "NiaTopAppBar", "MediumTopAppBar" to "NiaTopAppBar", - "LargeTopAppBar" to "NiaTopAppBar" + "LargeTopAppBar" to "NiaTopAppBar", ) val RECEIVER_NAMES = mapOf( - "Icons" to "NiaIcons" + "Icons" to "NiaIcons", ) fun reportIssue( context: JavaContext, node: UElement, name: String, - preferredName: String + preferredName: String, ) { context.report( - ISSUE, node, context.getLocation(node), - "Using $name instead of $preferredName" + ISSUE, + node, + context.getLocation(node), + "Using $name instead of $preferredName", ) } } diff --git a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemIssueRegistry.kt b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemIssueRegistry.kt index 152c07c28..d951151bb 100644 --- a/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemIssueRegistry.kt +++ b/lint/src/main/java/com/google/samples/apps/nowinandroid/lint/designsystem/DesignSystemIssueRegistry.kt @@ -35,6 +35,6 @@ class DesignSystemIssueRegistry : IssueRegistry() { override val vendor: Vendor = Vendor( vendorName = "Now in Android", feedbackUrl = "https://github.com/android/nowinandroid/issues", - contact = "https://github.com/android/nowinandroid" + contact = "https://github.com/android/nowinandroid", ) } diff --git a/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/NeverSyncingSyncStatusMonitor.kt b/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/NeverSyncingSyncStatusMonitor.kt index 0c0069f7d..647dd864e 100644 --- a/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/NeverSyncingSyncStatusMonitor.kt +++ b/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/NeverSyncingSyncStatusMonitor.kt @@ -17,9 +17,9 @@ package com.google.samples.apps.nowinandroid.core.sync.test import com.google.samples.apps.nowinandroid.core.data.util.SyncStatusMonitor -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf +import javax.inject.Inject class NeverSyncingSyncStatusMonitor @Inject constructor() : SyncStatusMonitor { override val isSyncing: Flow = flowOf(false) diff --git a/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/TestSyncModule.kt b/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/TestSyncModule.kt index bc0876a7c..323704b5a 100644 --- a/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/TestSyncModule.kt +++ b/sync/sync-test/src/main/java/com/google/samples/apps/nowinandroid/core/sync/test/TestSyncModule.kt @@ -26,11 +26,11 @@ import dagger.hilt.testing.TestInstallIn @Module @TestInstallIn( components = [SingletonComponent::class], - replaces = [SyncModule::class] + replaces = [SyncModule::class], ) interface TestSyncModule { @Binds fun bindsSyncStatusMonitor( - syncStatusMonitor: NeverSyncingSyncStatusMonitor + syncStatusMonitor: NeverSyncingSyncStatusMonitor, ): SyncStatusMonitor } diff --git a/sync/work/src/androidTest/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorkerTest.kt b/sync/work/src/androidTest/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorkerTest.kt index 4bcc19be8..9c9d13510 100644 --- a/sync/work/src/androidTest/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorkerTest.kt +++ b/sync/work/src/androidTest/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorkerTest.kt @@ -25,10 +25,10 @@ import androidx.work.testing.SynchronousExecutor import androidx.work.testing.WorkManagerTestInitHelper import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest -import kotlin.test.assertEquals import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.test.assertEquals @HiltAndroidTest class SyncWorkerTest { diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/di/SyncModule.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/di/SyncModule.kt index 88e7df4de..68f9eee93 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/di/SyncModule.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/di/SyncModule.kt @@ -28,6 +28,6 @@ import dagger.hilt.components.SingletonComponent interface SyncModule { @Binds fun bindsSyncStatusMonitor( - syncStatusMonitor: WorkManagerSyncStatusMonitor + syncStatusMonitor: WorkManagerSyncStatusMonitor, ): SyncStatusMonitor } diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncInitializer.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncInitializer.kt index 21f98138b..837eb9a20 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncInitializer.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncInitializer.kt @@ -47,7 +47,7 @@ class SyncInitializer : Initializer { enqueueUniqueWork( SyncWorkName, ExistingWorkPolicy.KEEP, - SyncWorker.startUpSyncWork() + SyncWorker.startUpSyncWork(), ) } diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt index bfaef1808..334b3f0c7 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncWorkHelpers.kt @@ -42,7 +42,7 @@ val SyncConstraints */ fun Context.syncForegroundInfo() = ForegroundInfo( SyncNotificationId, - syncWorkNotification() + syncWorkNotification(), ) /** @@ -54,7 +54,7 @@ private fun Context.syncWorkNotification(): Notification { val channel = NotificationChannel( SyncNotificationChannelID, getString(R.string.sync_notification_channel_name), - NotificationManager.IMPORTANCE_DEFAULT + NotificationManager.IMPORTANCE_DEFAULT, ).apply { description = getString(R.string.sync_notification_channel_description) } @@ -67,10 +67,10 @@ private fun Context.syncWorkNotification(): Notification { return NotificationCompat.Builder( this, - SyncNotificationChannelID + SyncNotificationChannelID, ) .setSmallIcon( - com.google.samples.apps.nowinandroid.core.common.R.drawable.ic_nia_notification + com.google.samples.apps.nowinandroid.core.common.R.drawable.ic_nia_notification, ) .setContentTitle(getString(R.string.sync_notification_title)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/status/WorkManagerSyncStatusMonitor.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/status/WorkManagerSyncStatusMonitor.kt index fe9c429e0..9edb630eb 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/status/WorkManagerSyncStatusMonitor.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/status/WorkManagerSyncStatusMonitor.kt @@ -25,20 +25,20 @@ import androidx.work.WorkManager import com.google.samples.apps.nowinandroid.core.data.util.SyncStatusMonitor import com.google.samples.apps.nowinandroid.sync.initializers.SyncWorkName import dagger.hilt.android.qualifiers.ApplicationContext -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.conflate +import javax.inject.Inject /** * [SyncStatusMonitor] backed by [WorkInfo] from [WorkManager] */ class WorkManagerSyncStatusMonitor @Inject constructor( - @ApplicationContext context: Context + @ApplicationContext context: Context, ) : SyncStatusMonitor { override val isSyncing: Flow = Transformations.map( WorkManager.getInstance(context).getWorkInfosForUniqueWorkLiveData(SyncWorkName), - MutableList::anyRunning + MutableList::anyRunning, ) .asFlow() .conflate() diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorker.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorker.kt index 1a7dfb1be..c6ac6fb65 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorker.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/workers/SyncWorker.kt @@ -65,8 +65,11 @@ class SyncWorker @AssistedInject constructor( async { newsRepository.sync() }, ).all { it } - if (syncedSuccessfully) Result.success() - else Result.retry() + if (syncedSuccessfully) { + Result.success() + } else { + Result.retry() + } } } @@ -74,7 +77,7 @@ class SyncWorker @AssistedInject constructor( niaPreferences.getChangeListVersions() override suspend fun updateChangeListVersions( - update: ChangeListVersions.() -> ChangeListVersions + update: ChangeListVersions.() -> ChangeListVersions, ) = niaPreferences.updateChangeListVersion(update) companion object {