A fully functional Android app built entirely with Kotlin and Jetpack Compose
Introduce Multipreview annotation to simplify the preview configurations
Takeshi Hagikura74737cad49dc
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.ktindex a3af38f23..6525acc0a 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@@ -133,8 +133,15 @@ fun NiaGradientBackground(}}+/**+ * Multipreview annotation that represents light and dark themes. Add this annotation to a+ * composable to render the both themes.+ */@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+private annotation class ThemePreviews++@ThemePreviews@Composablefun BackgroundDefault() {NiaTheme {@@ -142,8 +149,7 @@ fun BackgroundDefault() {}}-@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")-@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+@ThemePreviews@Composablefun BackgroundDynamic() {NiaTheme(dynamicColor = true) {@@ -151,8 +157,7 @@ fun BackgroundDynamic() {}}-@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")-@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+@ThemePreviews@Composablefun BackgroundAndroid() {NiaTheme(androidTheme = true) {@@ -160,8 +165,7 @@ fun BackgroundAndroid() {}}-@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")-@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+@ThemePreviews@Composablefun GradientBackgroundDefault() {NiaTheme {@@ -169,8 +173,7 @@ fun GradientBackgroundDefault() {}}-@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")-@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+@ThemePreviews@Composablefun GradientBackgroundDynamic() {NiaTheme(dynamicColor = true) {@@ -178,8 +181,7 @@ fun GradientBackgroundDynamic() {}}-@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")-@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")+@ThemePreviews@Composablefun GradientBackgroundAndroid() {NiaTheme(androidTheme = true) {diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/MultipreviewAnnotations.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/MultipreviewAnnotations.ktnew file mode 100644index 000000000..1daa4a70b--- /dev/null+++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/MultipreviewAnnotations.kt@@ -0,0 +1,29 @@+/*+ * Copyright 2022 The Android Open Source Project+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * https://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package com.google.samples.apps.nowinandroid.core.ui++import androidx.compose.ui.tooling.preview.Preview++/**+ * Multipreview annotation that represents various device sizes. Add this annotation to a composable+ * to render various devices.+ */+@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")+@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")+@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")+@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+annotation class DevicePreviewsdiff --git a/feature/author/src/main/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreen.kt b/feature/author/src/main/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreen.ktindex b1f45c9eb..22e704f3f 100644--- a/feature/author/src/main/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreen.kt+++ b/feature/author/src/main/java/com/google/samples/apps/nowinandroid/feature/author/AuthorScreen.kt@@ -59,6 +59,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthorimport com.google.samples.apps.nowinandroid.core.model.data.SaveableNewsResourceimport com.google.samples.apps.nowinandroid.core.model.data.previewAuthorsimport com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources+import com.google.samples.apps.nowinandroid.core.ui.DevicePreviewsimport com.google.samples.apps.nowinandroid.core.ui.newsResourceCardItems@OptIn(ExperimentalLifecycleComposeApi::class)@@ -227,10 +228,7 @@ private fun AuthorToolbar(}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun AuthorScreenPopulated() {NiaTheme {@@ -253,10 +251,7 @@ fun AuthorScreenPopulated() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun AuthorScreenLoading() {NiaTheme {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.ktindex 27372beb1..014797159 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,6 +93,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.SaveableNewsResourceimport com.google.samples.apps.nowinandroid.core.model.data.previewAuthorsimport com.google.samples.apps.nowinandroid.core.model.data.previewNewsResourcesimport com.google.samples.apps.nowinandroid.core.model.data.previewTopics+import com.google.samples.apps.nowinandroid.core.ui.DevicePreviewsimport com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiStateimport com.google.samples.apps.nowinandroid.core.ui.TrackScrollJankimport com.google.samples.apps.nowinandroid.core.ui.newsFeed@@ -421,10 +422,7 @@ fun TopicIcon()}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun ForYouScreenPopulatedFeed() {BoxWithConstraints {@@ -445,10 +443,7 @@ fun ForYouScreenPopulatedFeed() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun ForYouScreenTopicSelection() {BoxWithConstraints {@@ -472,10 +467,7 @@ fun ForYouScreenTopicSelection() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun ForYouScreenLoading() {BoxWithConstraints {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.ktindex 06d5c8e9f..6b739e2f8 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@@ -44,6 +44,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthorimport com.google.samples.apps.nowinandroid.core.model.data.FollowableTopicimport com.google.samples.apps.nowinandroid.core.model.data.previewAuthorsimport com.google.samples.apps.nowinandroid.core.model.data.previewTopics+import com.google.samples.apps.nowinandroid.core.ui.DevicePreviewsimport com.google.samples.apps.nowinandroid.core.ui.JankMetricDisposableEffect@OptIn(ExperimentalLifecycleComposeApi::class)@@ -174,10 +175,7 @@ private fun InterestsEmptyScreen() {Text(text = stringResource(id = R.string.interests_empty_header))}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun InterestsScreenPopulated() {NiaTheme {@@ -201,10 +199,7 @@ fun InterestsScreenPopulated() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun InterestsScreenLoading() {NiaTheme {@@ -225,10 +220,7 @@ fun InterestsScreenLoading() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun InterestsScreenEmpty() {NiaTheme {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.ktindex 08cd7a8ad..b85fc6817 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@@ -54,6 +54,7 @@ import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaThemeimport com.google.samples.apps.nowinandroid.core.model.data.FollowableTopicimport com.google.samples.apps.nowinandroid.core.model.data.previewNewsResourcesimport com.google.samples.apps.nowinandroid.core.model.data.previewTopics+import com.google.samples.apps.nowinandroid.core.ui.DevicePreviewsimport com.google.samples.apps.nowinandroid.core.ui.newsResourceCardItemsimport com.google.samples.apps.nowinandroid.feature.topic.R.stringimport com.google.samples.apps.nowinandroid.feature.topic.TopicUiState.Loading@@ -228,10 +229,7 @@ private fun TopicToolbar(}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun TopicScreenPopulated() {NiaTheme {@@ -246,10 +244,7 @@ fun TopicScreenPopulated() {}}-@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480")-@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")-@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")-@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")+@DevicePreviews@Composablefun TopicScreenLoading() {NiaTheme {diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 0c09ab117..e61b222fd 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -1,7 +1,7 @@[versions]accompanist = "0.24.8-beta"androidDesugarJdkLibs = "1.1.5"-androidGradlePlugin = "7.2.2"+androidGradlePlugin = "7.3.0"androidxActivity = "1.5.1"androidxAppCompat = "1.5.1"androidxCompose = "1.3.0-beta02"