From 1009e15aa61f3a717d0fec8a6d7c2d57aacdd4e1 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 8 Dec 2022 22:45:17 -0500 Subject: [PATCH] Reuse basic theme preview annotation --- .../presentation/components/EmptyScreen.kt | 27 +++---------------- .../presentation/manga/MangaSettingsDialog.kt | 11 ++------ .../widget/AppThemePreferenceWidget.kt | 13 ++------- .../more/settings/widget/InfoWidget.kt | 14 ++-------- .../settings/widget/SwitchPreferenceWidget.kt | 8 +++--- .../settings/widget/TextPreferenceWidget.kt | 6 +++-- .../eu/kanade/presentation/util/Preview.kt | 15 +++++++++++ 7 files changed, 32 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/eu/kanade/presentation/util/Preview.kt diff --git a/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt b/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt index 9ef7512ba..44885c1dc 100644 --- a/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt @@ -1,6 +1,5 @@ package eu.kanade.presentation.components -import android.content.res.Configuration.UI_MODE_NIGHT_YES import androidx.annotation.StringRes import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -27,10 +26,10 @@ import androidx.compose.ui.layout.Layout import androidx.compose.ui.layout.layoutId import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.util.fastFirstOrNull import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews import eu.kanade.presentation.util.secondaryItemAlpha import eu.kanade.tachiyomi.R import kotlin.random.Random @@ -146,17 +145,7 @@ private fun ActionButton( } } -@Preview( - name = "Light", - widthDp = 400, - heightDp = 400, -) -@Preview( - name = "Dark", - widthDp = 400, - heightDp = 400, - uiMode = UI_MODE_NIGHT_YES, -) +@ThemePreviews @Composable private fun NoActionPreview() { TachiyomiTheme { @@ -168,17 +157,7 @@ private fun NoActionPreview() { } } -@Preview( - name = "Light", - widthDp = 400, - heightDp = 400, -) -@Preview( - name = "Dark", - widthDp = 400, - heightDp = 400, - uiMode = UI_MODE_NIGHT_YES, -) +@ThemePreviews @Composable private fun WithActionPreview() { TachiyomiTheme { diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaSettingsDialog.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaSettingsDialog.kt index 8a712f22b..7d43549fb 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaSettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaSettingsDialog.kt @@ -1,6 +1,5 @@ package eu.kanade.presentation.manga -import android.content.res.Configuration.UI_MODE_NIGHT_YES import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -47,7 +46,6 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.util.fastForEachIndexed import eu.kanade.domain.manga.model.Manga @@ -59,6 +57,7 @@ import eu.kanade.presentation.components.HorizontalPager import eu.kanade.presentation.components.TabIndicator import eu.kanade.presentation.components.rememberPagerState import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews import eu.kanade.tachiyomi.R import kotlinx.coroutines.launch @@ -472,13 +471,7 @@ private fun DisplayPageItem( private val HorizontalPadding = 24.dp private val VerticalPadding = 8.dp -@Preview( - name = "Light", -) -@Preview( - name = "Dark", - uiMode = UI_MODE_NIGHT_YES, -) +@ThemePreviews @Composable private fun ChapterSettingsDialogPreview() { TachiyomiTheme { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/AppThemePreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/AppThemePreferenceWidget.kt index c6de0330b..3f080dd9e 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/AppThemePreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/AppThemePreferenceWidget.kt @@ -1,6 +1,5 @@ package eu.kanade.presentation.more.settings.widget -import android.content.res.Configuration.UI_MODE_NIGHT_YES import androidx.compose.animation.animateContentSize import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -38,12 +37,12 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import eu.kanade.domain.ui.model.AppTheme import eu.kanade.presentation.components.DIVIDER_ALPHA import eu.kanade.presentation.components.MangaCover import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews import eu.kanade.presentation.util.secondaryItemAlpha import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.DeviceUtil @@ -252,15 +251,7 @@ fun AppThemePreviewItem( } } -@Preview( - name = "light", - showBackground = true, -) -@Preview( - name = "dark", - showBackground = true, - uiMode = UI_MODE_NIGHT_YES, -) +@ThemePreviews @Composable private fun AppThemesListPreview() { var appTheme by remember { mutableStateOf(AppTheme.DEFAULT) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/InfoWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/InfoWidget.kt index 6060902ed..6a4aa74f3 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/InfoWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/InfoWidget.kt @@ -1,6 +1,5 @@ package eu.kanade.presentation.more.settings.widget -import android.content.res.Configuration.UI_MODE_NIGHT_YES import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding @@ -13,9 +12,9 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews import eu.kanade.presentation.util.secondaryItemAlpha import eu.kanade.tachiyomi.R @@ -38,16 +37,7 @@ internal fun InfoWidget(text: String) { } } -@Preview( - name = "Light", - showBackground = true, -) -@Preview( - name = "Dark", - showBackground = true, - uiMode = UI_MODE_NIGHT_YES, - -) +@ThemePreviews @Composable private fun InfoWidgetPreview() { TachiyomiTheme { diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/SwitchPreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/SwitchPreferenceWidget.kt index afbe0f9ff..534a71929 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/SwitchPreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/SwitchPreferenceWidget.kt @@ -4,13 +4,13 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Preview -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Switch import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.tooling.preview.Preview +import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews @Composable fun SwitchPreferenceWidget( @@ -37,10 +37,10 @@ fun SwitchPreferenceWidget( ) } -@Preview +@ThemePreviews @Composable private fun SwitchPreferenceWidgetPreview() { - MaterialTheme { + TachiyomiTheme { Surface { Column { SwitchPreferenceWidget( diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/widget/TextPreferenceWidget.kt b/app/src/main/java/eu/kanade/presentation/more/settings/widget/TextPreferenceWidget.kt index aecf43181..ee27a7b1a 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/widget/TextPreferenceWidget.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/widget/TextPreferenceWidget.kt @@ -13,6 +13,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.tooling.preview.Preview +import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.util.ThemePreviews import eu.kanade.presentation.util.secondaryItemAlpha @Composable @@ -58,10 +60,10 @@ fun TextPreferenceWidget( ) } -@Preview +@ThemePreviews @Composable private fun TextPreferenceWidgetPreview() { - MaterialTheme { + TachiyomiTheme { Surface { Column { TextPreferenceWidget( diff --git a/app/src/main/java/eu/kanade/presentation/util/Preview.kt b/app/src/main/java/eu/kanade/presentation/util/Preview.kt new file mode 100644 index 000000000..35e7314c6 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/util/Preview.kt @@ -0,0 +1,15 @@ +package eu.kanade.presentation.util + +import android.content.res.Configuration +import androidx.compose.ui.tooling.preview.Preview + +@Preview( + name = "Light", + showBackground = true, +) +@Preview( + name = "Dark", + showBackground = true, + uiMode = Configuration.UI_MODE_NIGHT_YES, +) +annotation class ThemePreviews