From cf6f7c521cde88f20c1eef3a6a63a2b73601523f Mon Sep 17 00:00:00 2001 From: Caleb Morris Date: Thu, 11 Jan 2024 16:22:21 -0700 Subject: [PATCH] Fixed dev UI preview (#10385) The TachiyomiTheme introduced a dependency-injection construct that didn't exist at the time of rendering previews, so I've changed the preview function to use a preview version of the theme that uses declarative configuration over dependency injection --- .../presentation/components/EmptyScreen.kt | 6 ++-- .../kanade/presentation/crash/CrashScreen.kt | 4 +-- .../presentation/history/HistoryScreen.kt | 4 +-- .../history/components/HistoryDialogs.kt | 4 +-- .../history/components/HistoryItem.kt | 4 +-- .../library/components/LibraryBadges.kt | 4 +-- .../components/MissingChapterCountListItem.kt | 4 +-- .../presentation/more/NewUpdateScreen.kt | 4 +-- .../more/onboarding/GuidesStep.kt | 4 +-- .../widget/AppThemePreferenceWidget.kt | 7 +++- .../more/settings/widget/InfoWidget.kt | 4 +-- .../settings/widget/SwitchPreferenceWidget.kt | 4 +-- .../settings/widget/TextPreferenceWidget.kt | 4 +-- .../presentation/reader/ChapterTransition.kt | 12 +++---- .../reader/OrientationSelectDialog.kt | 4 +-- .../presentation/reader/PageIndicatorText.kt | 4 +-- .../reader/ReadingModeSelectDialog.kt | 4 +-- .../reader/components/ModeSelectionDialog.kt | 4 +-- .../presentation/theme/TachiyomiTheme.kt | 32 +++++++++++++++---- .../presentation/track/TrackInfoDialogHome.kt | 4 +-- .../track/TrackInfoDialogSelector.kt | 4 +-- .../presentation/track/TrackerSearch.kt | 4 +-- .../track/components/TrackLogoIcon.kt | 4 +-- 23 files changed, 79 insertions(+), 54 deletions(-) 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 ddcf22cb4..5355318a9 100644 --- a/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/components/EmptyScreen.kt @@ -6,7 +6,7 @@ import androidx.compose.material.icons.outlined.Refresh import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import kotlinx.collections.immutable.persistentListOf import tachiyomi.i18n.MR import tachiyomi.presentation.core.screens.EmptyScreen @@ -15,7 +15,7 @@ import tachiyomi.presentation.core.screens.EmptyScreenAction @PreviewLightDark @Composable private fun NoActionPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { EmptyScreen( stringRes = MR.strings.empty_screen, @@ -27,7 +27,7 @@ private fun NoActionPreview() { @PreviewLightDark @Composable private fun WithActionPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { EmptyScreen( stringRes = MR.strings.empty_screen, diff --git a/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt b/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt index 5504f13cc..fd8b27030 100644 --- a/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt @@ -14,7 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.util.CrashLogUtil import kotlinx.coroutines.launch import tachiyomi.i18n.MR @@ -63,7 +63,7 @@ fun CrashScreen( @PreviewLightDark @Composable private fun CrashScreenPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { CrashScreen(exception = RuntimeException("Dummy")) {} } } diff --git a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt index a4c47af5e..ec25769dc 100644 --- a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt @@ -17,7 +17,7 @@ import eu.kanade.presentation.components.AppBarTitle import eu.kanade.presentation.components.SearchToolbar import eu.kanade.presentation.components.relativeDateText import eu.kanade.presentation.history.components.HistoryItem -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.ui.history.HistoryScreenModel import kotlinx.collections.immutable.persistentListOf import tachiyomi.domain.history.model.HistoryWithRelations @@ -143,7 +143,7 @@ internal fun HistoryScreenPreviews( @PreviewParameter(HistoryScreenModelStateProvider::class) historyState: HistoryScreenModel.State, ) { - TachiyomiTheme { + TachiyomiPreviewTheme { HistoryScreen( state = historyState, snackbarHostState = SnackbarHostState(), diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt index 9aaaa6bdd..1d242cdea 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt @@ -12,7 +12,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.LabeledCheckbox import tachiyomi.presentation.core.components.material.padding @@ -91,7 +91,7 @@ fun HistoryDeleteAllDialog( @PreviewLightDark @Composable private fun HistoryDeleteDialogPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { HistoryDeleteDialog( onDismissRequest = {}, onDelete = {}, diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt index 846903b1b..4298ba43c 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt @@ -23,7 +23,7 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import eu.kanade.presentation.manga.components.MangaCover -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.presentation.util.formatChapterNumber import eu.kanade.tachiyomi.util.lang.toTimestampString import tachiyomi.domain.history.model.HistoryWithRelations @@ -98,7 +98,7 @@ private fun HistoryItemPreviews( @PreviewParameter(HistoryWithRelationsProvider::class) historyWithRelations: HistoryWithRelations, ) { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { HistoryItem( history = historyWithRelations, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt index 608edb8f4..5d0222cf4 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt @@ -6,7 +6,7 @@ import androidx.compose.material.icons.outlined.Folder import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.presentation.core.components.Badge @Composable @@ -50,7 +50,7 @@ internal fun LanguageBadge( @PreviewLightDark @Composable private fun BadgePreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Column { DownloadsBadge(count = 10) UnreadBadge(count = 10) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MissingChapterCountListItem.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MissingChapterCountListItem.kt index e40f1bd69..baca38c34 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MissingChapterCountListItem.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MissingChapterCountListItem.kt @@ -11,7 +11,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.pluralStringResource @@ -44,7 +44,7 @@ fun MissingChapterCountListItem( @PreviewLightDark @Composable private fun Preview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { MissingChapterCountListItem(count = 42) } diff --git a/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt b/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt index 96fd421dd..3d561b0c3 100644 --- a/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/NewUpdateScreen.kt @@ -19,7 +19,7 @@ import com.halilibo.richtext.markdown.Markdown import com.halilibo.richtext.ui.RichTextStyle import com.halilibo.richtext.ui.material3.RichText import com.halilibo.richtext.ui.string.RichTextStringStyle -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource @@ -69,7 +69,7 @@ fun NewUpdateScreen( @PreviewLightDark @Composable private fun NewUpdateScreenPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { NewUpdateScreen( versionName = "v0.99.9", changelogInfo = """ diff --git a/app/src/main/java/eu/kanade/presentation/more/onboarding/GuidesStep.kt b/app/src/main/java/eu/kanade/presentation/more/onboarding/GuidesStep.kt index ca4485966..5a095b0ef 100644 --- a/app/src/main/java/eu/kanade/presentation/more/onboarding/GuidesStep.kt +++ b/app/src/main/java/eu/kanade/presentation/more/onboarding/GuidesStep.kt @@ -13,7 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource @@ -61,7 +61,7 @@ const val GETTING_STARTED_URL = "https://tachiyomi.org/docs/guides/getting-start @PreviewLightDark @Composable private fun GuidesStepPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { GuidesStep( onRestoreBackup = {}, ).Content() 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 2be6e03a4..b9dbbbfb8 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 @@ -42,15 +42,19 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp import androidx.core.app.ActivityCompat +import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.AppTheme import eu.kanade.presentation.manga.components.MangaCover import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable +import tachiyomi.core.preference.InMemoryPreferenceStore import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.util.secondaryItemAlpha +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.fullType @Composable internal fun AppThemePreferenceWidget( @@ -258,7 +262,8 @@ fun AppThemePreviewItem( @Composable private fun AppThemesListPreview() { var appTheme by remember { mutableStateOf(AppTheme.DEFAULT) } - TachiyomiTheme { + Injekt.addSingleton(fullType(), UiPreferences(InMemoryPreferenceStore())) + TachiyomiTheme(appTheme = appTheme) { Surface { AppThemesList( currentTheme = appTheme, 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 5d9d8db85..46fee1e1c 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 @@ -12,7 +12,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource @@ -43,7 +43,7 @@ internal fun InfoWidget(text: String) { @PreviewLightDark @Composable private fun InfoWidgetPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { InfoWidget(text = stringResource(MR.strings.download_ahead_info)) } 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 bc026d3ba..41690242d 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 @@ -10,7 +10,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme @Composable fun SwitchPreferenceWidget( @@ -40,7 +40,7 @@ fun SwitchPreferenceWidget( @PreviewLightDark @Composable private fun SwitchPreferenceWidgetPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { 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 05bd7f85d..f3423d8e4 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,7 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.tooling.preview.PreviewLightDark -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.presentation.core.util.secondaryItemAlpha @Composable @@ -62,7 +62,7 @@ fun TextPreferenceWidget( @PreviewLightDark @Composable private fun TextPreferenceWidgetPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { Column { TextPreferenceWidget( diff --git a/app/src/main/java/eu/kanade/presentation/reader/ChapterTransition.kt b/app/src/main/java/eu/kanade/presentation/reader/ChapterTransition.kt index d464382c3..5fb749828 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ChapterTransition.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ChapterTransition.kt @@ -33,7 +33,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter @@ -306,7 +306,7 @@ private val FakeChapterLongTitle = previewChapter( @PreviewLightDark @Composable private fun TransitionTextPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface(modifier = Modifier.padding(48.dp)) { ChapterTransition( transition = ChapterTransition.Next(ReaderChapter(FakeChapter), ReaderChapter(FakeChapter)), @@ -320,7 +320,7 @@ private fun TransitionTextPreview() { @PreviewLightDark @Composable private fun TransitionTextLongTitlePreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface(modifier = Modifier.padding(48.dp)) { ChapterTransition( transition = ChapterTransition.Next(ReaderChapter(FakeChapterLongTitle), ReaderChapter(FakeChapter)), @@ -334,7 +334,7 @@ private fun TransitionTextLongTitlePreview() { @PreviewLightDark @Composable private fun TransitionTextWithGapPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface(modifier = Modifier.padding(48.dp)) { ChapterTransition( transition = ChapterTransition.Next(ReaderChapter(FakeChapter), ReaderChapter(FakeGapChapter)), @@ -348,7 +348,7 @@ private fun TransitionTextWithGapPreview() { @PreviewLightDark @Composable private fun TransitionTextNoNextPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface(modifier = Modifier.padding(48.dp)) { ChapterTransition( transition = ChapterTransition.Next(ReaderChapter(FakeChapter), null), @@ -362,7 +362,7 @@ private fun TransitionTextNoNextPreview() { @PreviewLightDark @Composable private fun TransitionTextNoPreviousPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface(modifier = Modifier.padding(48.dp)) { ChapterTransition( transition = ChapterTransition.Prev(ReaderChapter(FakeChapter), null), diff --git a/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt index 22a02444c..5943dd65a 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/OrientationSelectDialog.kt @@ -16,7 +16,7 @@ import dev.icerock.moko.resources.StringResource import eu.kanade.domain.manga.model.readerOrientation import eu.kanade.presentation.components.AdaptiveSheet import eu.kanade.presentation.reader.components.ModeSelectionDialog -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import tachiyomi.i18n.MR @@ -81,7 +81,7 @@ private fun DialogContent( @PreviewLightDark @Composable private fun DialogContentPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { Column { DialogContent( diff --git a/app/src/main/java/eu/kanade/presentation/reader/PageIndicatorText.kt b/app/src/main/java/eu/kanade/presentation/reader/PageIndicatorText.kt index ab2b05095..3dd057a56 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/PageIndicatorText.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/PageIndicatorText.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.sp -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme @Composable fun PageIndicatorText( @@ -51,7 +51,7 @@ fun PageIndicatorText( @PreviewLightDark @Composable private fun PageIndicatorTextPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { PageIndicatorText(currentPage = 10, totalPages = 69) } diff --git a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt index 25c0893c6..20e219c7e 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ReadingModeSelectDialog.kt @@ -18,7 +18,7 @@ import dev.icerock.moko.resources.StringResource import eu.kanade.domain.manga.model.readingMode import eu.kanade.presentation.components.AdaptiveSheet import eu.kanade.presentation.reader.components.ModeSelectionDialog -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode import tachiyomi.i18n.MR @@ -79,7 +79,7 @@ private fun DialogContent( @PreviewLightDark @Composable private fun DialogContentPreview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { Column { DialogContent( diff --git a/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt index 683534e9a..c6286bf22 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/components/ModeSelectionDialog.kt @@ -19,7 +19,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.SettingsItemsPaddings import tachiyomi.presentation.core.components.material.padding @@ -70,7 +70,7 @@ fun ModeSelectionDialog( @PreviewLightDark @Composable private fun Preview() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { Column { ModeSelectionDialog( diff --git a/app/src/main/java/eu/kanade/presentation/theme/TachiyomiTheme.kt b/app/src/main/java/eu/kanade/presentation/theme/TachiyomiTheme.kt index fd650f53c..4dd9a9754 100644 --- a/app/src/main/java/eu/kanade/presentation/theme/TachiyomiTheme.kt +++ b/app/src/main/java/eu/kanade/presentation/theme/TachiyomiTheme.kt @@ -28,9 +28,30 @@ fun TachiyomiTheme( appTheme: AppTheme? = null, amoled: Boolean? = null, content: @Composable () -> Unit, +) { + val uiPreferences = Injekt.get() + BaseTachiyomiTheme( + appTheme = appTheme ?: uiPreferences.appTheme().get(), + isAmoled = amoled ?: uiPreferences.themeDarkAmoled().get(), + content = content, + ) +} + +@Composable +fun TachiyomiPreviewTheme( + appTheme: AppTheme = AppTheme.DEFAULT, + isAmoled: Boolean = false, + content: @Composable () -> Unit, +) = BaseTachiyomiTheme(appTheme, isAmoled, content) + +@Composable +private fun BaseTachiyomiTheme( + appTheme: AppTheme, + isAmoled: Boolean, + content: @Composable () -> Unit, ) { MaterialTheme( - colorScheme = getThemeColorScheme(appTheme, amoled), + colorScheme = getThemeColorScheme(appTheme, isAmoled), content = content, ) } @@ -38,11 +59,10 @@ fun TachiyomiTheme( @Composable @ReadOnlyComposable private fun getThemeColorScheme( - appTheme: AppTheme?, - amoled: Boolean?, + appTheme: AppTheme, + isAmoled: Boolean, ): ColorScheme { - val uiPreferences = Injekt.get() - val colorScheme = when (appTheme ?: uiPreferences.appTheme().get()) { + val colorScheme = when (appTheme) { AppTheme.DEFAULT -> TachiyomiColorScheme AppTheme.MONET -> MonetColorScheme(LocalContext.current) AppTheme.GREEN_APPLE -> GreenAppleColorScheme @@ -59,6 +79,6 @@ private fun getThemeColorScheme( } return colorScheme.getColorScheme( isSystemInDarkTheme(), - amoled ?: uiPreferences.themeDarkAmoled().get(), + isAmoled, ) } diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt index 0aec41dce..2dd518f3a 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt @@ -48,7 +48,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import dev.icerock.moko.resources.StringResource import eu.kanade.presentation.components.DropdownMenu -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.presentation.track.components.TrackLogoIcon import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.ui.manga.track.TrackItem @@ -323,7 +323,7 @@ private fun TrackInfoDialogHomePreviews( @PreviewParameter(TrackInfoDialogHomePreviewProvider::class) content: @Composable () -> Unit, ) { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { content() } diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt index 3531df865..a2c8cc918 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt @@ -32,7 +32,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp import dev.icerock.moko.resources.StringResource -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentMapOf import kotlinx.collections.immutable.toImmutableList @@ -229,7 +229,7 @@ private fun BaseSelector( @PreviewLightDark @Composable private fun TrackStatusSelectorPreviews() { - TachiyomiTheme { + TachiyomiPreviewTheme { Surface { TrackStatusSelector( selection = 1, diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt b/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt index 08738c2ee..1a2ef7800 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackerSearch.kt @@ -68,7 +68,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.manga.components.MangaCover -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.util.system.openInBrowser import tachiyomi.i18n.MR @@ -380,5 +380,5 @@ private fun TrackerSearchPreviews( @PreviewParameter(TrackerSearchPreviewProvider::class) content: @Composable () -> Unit, ) { - TachiyomiTheme { content() } + TachiyomiPreviewTheme { content() } } diff --git a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt index 835cce95c..4dd03ecc7 100644 --- a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt +++ b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt @@ -14,7 +14,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp -import eu.kanade.presentation.theme.TachiyomiTheme +import eu.kanade.presentation.theme.TachiyomiPreviewTheme import eu.kanade.tachiyomi.data.track.Tracker import tachiyomi.presentation.core.util.clickableNoIndication @@ -49,7 +49,7 @@ private fun TrackLogoIconPreviews( @PreviewParameter(TrackLogoIconPreviewProvider::class) tracker: Tracker, ) { - TachiyomiTheme { + TachiyomiPreviewTheme { TrackLogoIcon( tracker = tracker, onClick = null,