From 735178c4ff595c8712903e44e660175ab8eb9028 Mon Sep 17 00:00:00 2001 From: Wing <44992537+wingio@users.noreply.github.com> Date: Tue, 17 Sep 2024 01:11:11 -0400 Subject: [PATCH] Refactor custom themed colors No clue what the hell i was smoking when i wrote this --- .../gloom/ui/theme/GloomTheme.android.kt | 23 ++ .../materiiapps/gloom/ui/theme/GloomTheme.kt | 35 --- .../gloom/ui/theme/Themes.android.kt | 36 --- .../gloom/ui/component/TextBanner.kt | 7 +- .../gloom/ui/component/scrollbar/ScrollBar.kt | 3 +- .../explore/component/TrendingRepoItem.kt | 8 +- .../gloom/ui/screen/release/ReleaseScreen.kt | 6 +- .../screen/release/component/ReleaseHeader.kt | 6 +- .../gloom/ui/screen/repo/RepoScreen.kt | 10 +- .../ui/screen/repo/component/IssueItem.kt | 8 +- .../ui/screen/repo/component/IssueOrPRItem.kt | 16 +- .../screen/repo/component/LicenseDetails.kt | 8 +- .../screen/repo/component/PullRequestItem.kt | 10 +- .../ui/screen/repo/component/RepoItem.kt | 4 +- .../settings/component/about/LibraryItem.kt | 6 +- .../gloom/ui/theme/GloomColorScheme.kt | 220 +----------------- .../materiiapps/gloom/ui/theme/GloomTheme.kt | 34 ++- .../com/materiiapps/gloom/ui/theme/Themes.kt | 8 +- .../gloom/ui/widget/reaction/ReactionRow.kt | 6 +- .../gloom/ui/theme/GloomTheme.desktop.kt | 14 ++ .../materiiapps/gloom/ui/theme/GloomTheme.kt | 30 --- 21 files changed, 121 insertions(+), 377 deletions(-) create mode 100644 ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.android.kt delete mode 100644 ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt delete mode 100644 ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.android.kt create mode 100644 ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.desktop.kt delete mode 100644 ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt diff --git a/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.android.kt b/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.android.kt new file mode 100644 index 00000000..016d775f --- /dev/null +++ b/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.android.kt @@ -0,0 +1,23 @@ +package com.materiiapps.gloom.ui.theme + +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext +import com.materiiapps.gloom.util.supportsMonet + +@Composable +actual fun getColorSchemes(darkTheme: Boolean, dynamicColor: Boolean): Pair { + // We don't technically need to check for dynamic theming support + // here because its locked behind a setting that itself is SDK restricted + // but its good to be cautious anyways. + return when { + dynamicColor && darkTheme && supportsMonet -> dynamicDarkColorScheme(LocalContext.current) to darkGloomColorScheme() + dynamicColor && !darkTheme && supportsMonet -> dynamicLightColorScheme(LocalContext.current) to lightGloomColorScheme() + darkTheme -> darkColorScheme() to darkGloomColorScheme() + else -> lightColorScheme() to lightGloomColorScheme() + } +} \ No newline at end of file diff --git a/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt b/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt deleted file mode 100644 index dadc5e85..00000000 --- a/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.materiiapps.gloom.ui.theme - -import android.annotation.SuppressLint -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Shapes -import androidx.compose.material3.Typography -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.platform.LocalContext - -@Composable -@SuppressLint("NewApi") -actual fun GloomTheme( - darkTheme: Boolean, - dynamicColor: Boolean, - content: @Composable () -> Unit -) { - val colors = when { - dynamicColor && darkTheme -> dynamicDarkTheme(LocalContext.current) - dynamicColor && !darkTheme -> dynamicLightTheme(LocalContext.current) - darkTheme -> darkTheme() - else -> lightTheme() - } - - CompositionLocalProvider( - LocalColors provides colors - ) { - MaterialTheme( - colorScheme = colors.toColorScheme(), - typography = Typography(), - shapes = Shapes(), - content = content - ) - } -} \ No newline at end of file diff --git a/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.android.kt b/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.android.kt deleted file mode 100644 index bb302af0..00000000 --- a/ui/src/androidMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.android.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.materiiapps.gloom.ui.theme - -import android.content.Context -import android.os.Build -import androidx.annotation.RequiresApi -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme -import androidx.compose.ui.graphics.Color - -@RequiresApi(Build.VERSION_CODES.S) -fun dynamicDarkTheme(context: Context) = GloomColorScheme( - dynamicDarkColorScheme(context), - statusGreen = DarkGreen, - statusPurple = LightPurple, - statusRed = PinkRed, - statusGrey = Grey, - statusYellow = Yellow, - warning = YellowAlt1, - onWarning = DarkBrown, - warningContainer = DarkBronze, - onWarningContainer = Shandy -) - -@RequiresApi(Build.VERSION_CODES.S) -fun dynamicLightTheme(context: Context) = GloomColorScheme( - dynamicLightColorScheme(context), - statusGreen = LightGreen, - statusPurple = DarkPurple, - statusRed = Red, - statusGrey = LightGrey, - statusYellow = Gold, - warning = BronzeYellow, - onWarning = Color.White, - warningContainer = Shandy, - onWarningContainer = DarkerBrown -) \ No newline at end of file diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/TextBanner.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/TextBanner.kt index bc95a187..f495c6bd 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/TextBanner.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/TextBanner.kt @@ -15,7 +15,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp -import com.materiiapps.gloom.ui.theme.colors /** * A full-width banner that displays text @@ -32,9 +31,9 @@ fun TextBanner( text: @Composable () -> Unit, modifier: Modifier = Modifier, icon: (@Composable () -> Unit)? = null, - backgroundColor: Color = MaterialTheme.colors.secondaryContainer, - contentColor: Color = MaterialTheme.colors.onSecondaryContainer, - outlineColor: Color = MaterialTheme.colors.secondary + backgroundColor: Color = MaterialTheme.colorScheme.secondaryContainer, + contentColor: Color = MaterialTheme.colorScheme.onSecondaryContainer, + outlineColor: Color = MaterialTheme.colorScheme.secondary ) { Row( horizontalArrangement = Arrangement.spacedBy(ButtonDefaults.IconSpacing, Alignment.CenterHorizontally), diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/scrollbar/ScrollBar.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/scrollbar/ScrollBar.kt index 27e94e45..11e63ecf 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/scrollbar/ScrollBar.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/component/scrollbar/ScrollBar.kt @@ -28,7 +28,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import com.materiiapps.gloom.ui.theme.colors import com.materiiapps.gloom.ui.util.toDp import com.materiiapps.gloom.ui.util.toPx import kotlinx.coroutines.delay @@ -40,7 +39,7 @@ fun ScrollBar( orientation: Orientation = Orientation.Vertical, thickness: Dp = 6.dp, safeAreaPadding: Dp = 6.dp, - thumbColor: Color = MaterialTheme.colors.tertiary, + thumbColor: Color = MaterialTheme.colorScheme.tertiary, trackColor: Color = Color.Transparent, idleOpacity: Float = 0.07f, activeOpacity: Float = 0.65f, diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/explore/component/TrendingRepoItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/explore/component/TrendingRepoItem.kt index 6e2c5240..7f673bdb 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/explore/component/TrendingRepoItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/explore/component/TrendingRepoItem.kt @@ -34,7 +34,7 @@ import com.materiiapps.gloom.api.dto.user.User import com.materiiapps.gloom.domain.manager.TrendingPeriodPreference import com.materiiapps.gloom.gql.fragment.TrendingRepository import com.materiiapps.gloom.ui.component.Avatar -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.util.NumberFormatter import com.materiiapps.gloom.ui.util.parsedColor import com.seiko.imageloader.rememberImagePainter @@ -110,8 +110,8 @@ fun TrendingRepoItem( if (shouldStar) onStarClick() else onUnstarClick() }, colors = IconButtonDefaults.filledTonalIconToggleButtonColors( - checkedContentColor = MaterialTheme.colors.statusYellow, - checkedContainerColor = MaterialTheme.colors.statusYellow.copy(alpha = 0.2f) + checkedContentColor = MaterialTheme.gloomColorScheme.statusYellow, + checkedContainerColor = MaterialTheme.gloomColorScheme.statusYellow.copy(alpha = 0.2f) ), enabled = starToggleEnabled ) { @@ -132,7 +132,7 @@ fun TrendingRepoItem( LabeledIcon( icon = Icons.Filled.Star, - iconTint = MaterialTheme.colors.statusYellow, + iconTint = MaterialTheme.gloomColorScheme.statusYellow, label = stringResource( when (trendingPeriod) { TrendingPeriodPreference.MONTHLY -> Res.strings.label_stars_month diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/ReleaseScreen.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/ReleaseScreen.kt index b456131a..a39fc3b5 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/ReleaseScreen.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/ReleaseScreen.kt @@ -1,9 +1,7 @@ package com.materiiapps.gloom.ui.screen.release -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -45,7 +43,7 @@ import com.materiiapps.gloom.domain.manager.ShareManager import com.materiiapps.gloom.gql.fragment.ReleaseDetails import com.materiiapps.gloom.ui.component.BackButton import com.materiiapps.gloom.ui.component.ThinDivider -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.screen.release.viewmodel.ReleaseViewModel import com.materiiapps.gloom.ui.widget.Markdown import com.materiiapps.gloom.ui.widget.alert.LocalAlertController @@ -174,7 +172,7 @@ class ReleaseScreen( Text( text = stringResource(Res.strings.title_contributors), style = MaterialTheme.typography.labelLarge, - color = MaterialTheme.colors.primary, + color = MaterialTheme.colorScheme.primary, modifier = Modifier.padding(horizontal = 16.dp) ) } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/component/ReleaseHeader.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/component/ReleaseHeader.kt index bae739d3..0bc38a6d 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/component/ReleaseHeader.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/release/component/ReleaseHeader.kt @@ -24,7 +24,7 @@ import com.materiiapps.gloom.gql.fragment.ReleaseDetails import com.materiiapps.gloom.ui.component.Avatar import com.materiiapps.gloom.ui.component.Label import com.materiiapps.gloom.ui.screen.repo.RepoScreen -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.util.ifNullOrBlank import dev.icerock.moko.resources.compose.stringResource @@ -80,14 +80,14 @@ fun ReleaseHeader( if (details.isLatest) { Label( text = stringResource(Res.strings.label_latest), - textColor = MaterialTheme.colors.statusGreen + textColor = MaterialTheme.gloomColorScheme.statusGreen ) } if (details.isPrerelease) { Label( text = stringResource(Res.strings.label_prerelease), - textColor = MaterialTheme.colors.statusYellow + textColor = MaterialTheme.gloomColorScheme.statusYellow ) } } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/RepoScreen.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/RepoScreen.kt index a4f7ceb5..6d461d8d 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/RepoScreen.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/RepoScreen.kt @@ -1,7 +1,6 @@ package com.materiiapps.gloom.ui.screen.repo import androidx.compose.animation.animateColorAsState -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.clickable @@ -34,7 +33,6 @@ import androidx.compose.material3.Tab import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior -import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue @@ -62,7 +60,7 @@ import com.materiiapps.gloom.ui.component.BackButton import com.materiiapps.gloom.ui.component.Collapsable import com.materiiapps.gloom.ui.component.TextBanner import com.materiiapps.gloom.ui.screen.profile.ProfileScreen -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.util.navigate import com.materiiapps.gloom.ui.screen.repo.viewmodel.RepoViewModel import dev.icerock.moko.resources.compose.stringResource @@ -136,9 +134,9 @@ class RepoScreen( modifier = Modifier.size(18.dp) ) }, - backgroundColor = MaterialTheme.colors.warningContainer, - contentColor = MaterialTheme.colors.onWarningContainer, - outlineColor = MaterialTheme.colors.warning + backgroundColor = MaterialTheme.gloomColorScheme.warningContainer, + contentColor = MaterialTheme.gloomColorScheme.onWarningContainer, + outlineColor = MaterialTheme.gloomColorScheme.warning ) } } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueItem.kt index 70d9e65b..65e1e606 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueItem.kt @@ -9,7 +9,7 @@ import androidx.compose.runtime.Composable import com.materiiapps.gloom.Res import com.materiiapps.gloom.gql.fragment.IssueOverview import com.materiiapps.gloom.gql.type.IssueStateReason -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import dev.icerock.moko.resources.compose.stringResource @Composable @@ -17,19 +17,19 @@ fun IssueItem(issue: IssueOverview) { val (icon, color, titleCDRes) = when (issue.stateReason) { IssueStateReason.COMPLETED -> Triple( Icons.Outlined.CheckCircle, - MaterialTheme.colors.statusPurple, + MaterialTheme.gloomColorScheme.statusPurple, Res.strings.cd_issue_title_completed ) IssueStateReason.NOT_PLANNED -> Triple( Icons.Outlined.DoNotDisturb, - MaterialTheme.colors.statusGrey, + MaterialTheme.gloomColorScheme.statusGrey, Res.strings.cd_issue_title_not_planned ) else -> Triple( Icons.Outlined.ModeStandby, - MaterialTheme.colors.statusGreen, + MaterialTheme.gloomColorScheme.statusGreen, Res.strings.cd_issue_title_opened ) } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueOrPRItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueOrPRItem.kt index 8c880cf1..26c8673b 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueOrPRItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/IssueOrPRItem.kt @@ -40,7 +40,7 @@ import com.materiiapps.gloom.Res import com.materiiapps.gloom.gql.type.PullRequestReviewDecision import com.materiiapps.gloom.gql.type.StatusState import com.materiiapps.gloom.ui.component.Label -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.util.TimeUtils.getTimeSince import com.materiiapps.gloom.ui.util.parsedColor import com.seiko.imageloader.rememberImagePainter @@ -173,25 +173,25 @@ fun IssueOrPRItem( val (statusIcon, statusColor, statusLabelRes) = when (checksStatus) { StatusState.EXPECTED -> Triple( Icons.Outlined.Circle, - MaterialTheme.colors.surfaceTint, + MaterialTheme.colorScheme.surfaceTint, Res.strings.label_checks ) StatusState.PENDING -> Triple( Icons.Filled.Circle, - MaterialTheme.colors.statusYellow, + MaterialTheme.gloomColorScheme.statusYellow, Res.strings.label_checks ) StatusState.SUCCESS -> Triple( Icons.Filled.CheckCircle, - MaterialTheme.colors.statusGreen, + MaterialTheme.gloomColorScheme.statusGreen, Res.strings.label_checks ) else -> Triple( Icons.Filled.Cancel, - MaterialTheme.colors.error, + MaterialTheme.colorScheme.error, Res.strings.label_checks_failed ) } @@ -208,9 +208,9 @@ fun IssueOrPRItem( if (reviewDecision != null) { val (statusIcon, statusColor) = when (reviewDecision) { - PullRequestReviewDecision.CHANGES_REQUESTED -> Icons.Filled.Cancel to MaterialTheme.colors.error - PullRequestReviewDecision.APPROVED -> Icons.Filled.CheckCircle to MaterialTheme.colors.statusGreen - else -> Icons.Filled.Circle to MaterialTheme.colors.surfaceTint + PullRequestReviewDecision.CHANGES_REQUESTED -> Icons.Filled.Cancel to MaterialTheme.colorScheme.error + PullRequestReviewDecision.APPROVED -> Icons.Filled.CheckCircle to MaterialTheme.gloomColorScheme.statusGreen + else -> Icons.Filled.Circle to MaterialTheme.colorScheme.surfaceTint } Label( diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/LicenseDetails.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/LicenseDetails.kt index 640f53ef..86dea8b4 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/LicenseDetails.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/LicenseDetails.kt @@ -38,7 +38,7 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.materiiapps.gloom.Res import com.materiiapps.gloom.gql.fragment.RepoLicense -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import dev.icerock.moko.resources.compose.stringResource @Composable @@ -80,7 +80,7 @@ fun LicenseDetails( label = stringResource(Res.strings.label_permissions), conditions = license.permissions.mapNotNull { it?.label }, icon = Icons.Outlined.Check, - iconColor = MaterialTheme.colors.statusGreen + iconColor = MaterialTheme.gloomColorScheme.statusGreen ) } @@ -89,7 +89,7 @@ fun LicenseDetails( label = stringResource(Res.strings.label_limitations), conditions = license.limitations.mapNotNull { it?.label }, icon = Icons.Outlined.Close, - iconColor = MaterialTheme.colors.statusRed + iconColor = MaterialTheme.gloomColorScheme.statusRed ) } @@ -98,7 +98,7 @@ fun LicenseDetails( label = stringResource(Res.strings.label_conditions), conditions = license.conditions.mapNotNull { it?.label }, icon = Icons.Outlined.Info, - iconColor = MaterialTheme.colors.secondary + iconColor = MaterialTheme.colorScheme.secondary ) } } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/PullRequestItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/PullRequestItem.kt index 26a9c947..dce87297 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/PullRequestItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/PullRequestItem.kt @@ -11,7 +11,7 @@ import com.materiiapps.gloom.ui.icon.Custom import com.materiiapps.gloom.ui.icon.custom.DraftPullRequest import com.materiiapps.gloom.ui.icon.custom.MergedPullRequest import com.materiiapps.gloom.ui.icon.custom.OpenPullRequest -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import dev.icerock.moko.resources.compose.stringResource @Composable @@ -21,25 +21,25 @@ fun PullRequestItem( val (icon, color, titleCDRes) = when { pullRequest.state == PullRequestState.MERGED -> Triple( Icons.Custom.MergedPullRequest, - MaterialTheme.colors.statusPurple, + MaterialTheme.gloomColorScheme.statusPurple, Res.strings.cd_pr_title_merged ) pullRequest.state == PullRequestState.CLOSED -> Triple( Icons.Custom.ClosedPullRequest, - MaterialTheme.colors.statusRed, + MaterialTheme.gloomColorScheme.statusRed, Res.strings.cd_pr_title_closed ) pullRequest.state == PullRequestState.OPEN && pullRequest.isDraft -> Triple( Icons.Custom.DraftPullRequest, - MaterialTheme.colors.statusGrey, + MaterialTheme.gloomColorScheme.statusGrey, Res.strings.cd_pr_title_draft ) else -> Triple( Icons.Custom.OpenPullRequest, - MaterialTheme.colors.statusGreen, + MaterialTheme.gloomColorScheme.statusGreen, Res.strings.cd_pr_title_opened ) } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/RepoItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/RepoItem.kt index aa3267e5..e5e84a06 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/RepoItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/repo/component/RepoItem.kt @@ -35,7 +35,7 @@ import com.materiiapps.gloom.ui.component.Avatar import com.materiiapps.gloom.ui.icon.Custom import com.materiiapps.gloom.ui.icon.custom.Fork import com.materiiapps.gloom.ui.screen.repo.RepoScreen -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.util.NumberFormatter import com.materiiapps.gloom.ui.util.navigate import com.materiiapps.gloom.ui.util.parsedColor @@ -143,7 +143,7 @@ fun RepoItem( Icons.Outlined.Star, contentDescription = null, modifier = Modifier.size(18.dp), - tint = MaterialTheme.colors.statusYellow + tint = MaterialTheme.gloomColorScheme.statusYellow ) Text(text = NumberFormatter.compact(repo.stars ?: 0)) } diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/settings/component/about/LibraryItem.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/settings/component/about/LibraryItem.kt index 02a7ac49..a3dc1cc2 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/settings/component/about/LibraryItem.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/screen/settings/component/about/LibraryItem.kt @@ -26,7 +26,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.materiiapps.gloom.Res import com.materiiapps.gloom.ui.component.Label -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme import com.materiiapps.gloom.ui.util.contentDescription import com.materiiapps.gloom.util.LocalLinkHandler import com.materiiapps.gloom.util.author @@ -116,13 +116,13 @@ fun LibraryItem( val (label, color, icon) = if (library.openSource) Triple( Res.strings.label_open_source, - MaterialTheme.colors.statusGreen, + MaterialTheme.gloomColorScheme.statusGreen, Icons.Filled.CheckCircle ) else Triple( Res.strings.label_closed_source, - MaterialTheme.colors.statusRed, + MaterialTheme.gloomColorScheme.statusRed, Icons.Filled.Cancel ) diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomColorScheme.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomColorScheme.kt index d72a1a79..ef543e1c 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomColorScheme.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomColorScheme.kt @@ -1,6 +1,5 @@ package com.materiiapps.gloom.ui.theme -import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable @@ -12,46 +11,11 @@ import androidx.compose.runtime.setValue import androidx.compose.runtime.structuralEqualityPolicy import androidx.compose.ui.graphics.Color +/** + * Set of theme-able colors specific to us + */ @Immutable class GloomColorScheme( - primary: Color, - onPrimary: Color, - primaryContainer: Color, - onPrimaryContainer: Color, - inversePrimary: Color, - secondary: Color, - onSecondary: Color, - secondaryContainer: Color, - onSecondaryContainer: Color, - tertiary: Color, - onTertiary: Color, - tertiaryContainer: Color, - onTertiaryContainer: Color, - background: Color, - onBackground: Color, - surface: Color, - onSurface: Color, - surfaceVariant: Color, - onSurfaceVariant: Color, - surfaceTint: Color, - inverseSurface: Color, - inverseOnSurface: Color, - error: Color, - onError: Color, - errorContainer: Color, - onErrorContainer: Color, - outline: Color, - outlineVariant: Color, - scrim: Color, - surfaceBright: Color, - surfaceDim: Color, - surfaceContainer: Color, - surfaceContainerHigh: Color, - surfaceContainerHighest: Color, - surfaceContainerLow: Color, - surfaceContainerLowest: Color, - - //Custom colors statusGreen: Color, statusPurple: Color, statusRed: Color, @@ -63,138 +27,6 @@ class GloomColorScheme( onWarningContainer: Color ) { - constructor( - colorScheme: ColorScheme, - statusGreen: Color, - statusPurple: Color, - statusRed: Color, - statusGrey: Color, - statusYellow: Color, - warning: Color, - onWarning: Color, - warningContainer: Color, - onWarningContainer: Color - ) : this( - colorScheme.primary, - colorScheme.onPrimary, - colorScheme.primaryContainer, - colorScheme.onPrimaryContainer, - colorScheme.inversePrimary, - colorScheme.secondary, - colorScheme.onSecondary, - colorScheme.secondaryContainer, - colorScheme.onSecondaryContainer, - colorScheme.tertiary, - colorScheme.onTertiary, - colorScheme.tertiaryContainer, - colorScheme.onTertiaryContainer, - colorScheme.background, - colorScheme.onBackground, - colorScheme.surface, - colorScheme.onSurface, - colorScheme.surfaceVariant, - colorScheme.onSurfaceVariant, - colorScheme.surfaceTint, - colorScheme.inverseSurface, - colorScheme.inverseOnSurface, - colorScheme.error, - colorScheme.onError, - colorScheme.errorContainer, - colorScheme.onErrorContainer, - colorScheme.outline, - colorScheme.outlineVariant, - colorScheme.scrim, - colorScheme.surfaceBright, - colorScheme.surfaceDim, - colorScheme.surfaceContainer, - colorScheme.surfaceContainerHigh, - colorScheme.surfaceContainerHighest, - colorScheme.surfaceContainerLow, - colorScheme.surfaceContainerLowest, - statusGreen, - statusPurple, - statusRed, - statusGrey, - statusYellow, - warning, - onWarning, - warningContainer, - onWarningContainer - ) - - var primary by mutableStateOf(primary, structuralEqualityPolicy()) - internal set - var onPrimary by mutableStateOf(onPrimary, structuralEqualityPolicy()) - internal set - var primaryContainer by mutableStateOf(primaryContainer, structuralEqualityPolicy()) - internal set - var onPrimaryContainer by mutableStateOf(onPrimaryContainer, structuralEqualityPolicy()) - internal set - var inversePrimary by mutableStateOf(inversePrimary, structuralEqualityPolicy()) - internal set - var secondary by mutableStateOf(secondary, structuralEqualityPolicy()) - internal set - var onSecondary by mutableStateOf(onSecondary, structuralEqualityPolicy()) - internal set - var secondaryContainer by mutableStateOf(secondaryContainer, structuralEqualityPolicy()) - internal set - var onSecondaryContainer by mutableStateOf(onSecondaryContainer, structuralEqualityPolicy()) - internal set - var tertiary by mutableStateOf(tertiary, structuralEqualityPolicy()) - internal set - var onTertiary by mutableStateOf(onTertiary, structuralEqualityPolicy()) - internal set - var tertiaryContainer by mutableStateOf(tertiaryContainer, structuralEqualityPolicy()) - internal set - var onTertiaryContainer by mutableStateOf(onTertiaryContainer, structuralEqualityPolicy()) - internal set - var background by mutableStateOf(background, structuralEqualityPolicy()) - internal set - var onBackground by mutableStateOf(onBackground, structuralEqualityPolicy()) - internal set - var surface by mutableStateOf(surface, structuralEqualityPolicy()) - internal set - var onSurface by mutableStateOf(onSurface, structuralEqualityPolicy()) - internal set - var surfaceVariant by mutableStateOf(surfaceVariant, structuralEqualityPolicy()) - internal set - var onSurfaceVariant by mutableStateOf(onSurfaceVariant, structuralEqualityPolicy()) - internal set - var surfaceTint by mutableStateOf(surfaceTint, structuralEqualityPolicy()) - internal set - var inverseSurface by mutableStateOf(inverseSurface, structuralEqualityPolicy()) - internal set - var inverseOnSurface by mutableStateOf(inverseOnSurface, structuralEqualityPolicy()) - internal set - var error by mutableStateOf(error, structuralEqualityPolicy()) - internal set - var onError by mutableStateOf(onError, structuralEqualityPolicy()) - internal set - var errorContainer by mutableStateOf(errorContainer, structuralEqualityPolicy()) - internal set - var onErrorContainer by mutableStateOf(onErrorContainer, structuralEqualityPolicy()) - internal set - var outline by mutableStateOf(outline, structuralEqualityPolicy()) - internal set - var outlineVariant by mutableStateOf(outlineVariant, structuralEqualityPolicy()) - internal set - var scrim by mutableStateOf(scrim, structuralEqualityPolicy()) - internal set - var surfaceBright by mutableStateOf(surfaceBright, structuralEqualityPolicy()) - internal set - var surfaceDim by mutableStateOf(surfaceDim, structuralEqualityPolicy()) - internal set - var surfaceContainer by mutableStateOf(surfaceContainer, structuralEqualityPolicy()) - internal set - var surfaceContainerHigh by mutableStateOf(surfaceContainerHigh, structuralEqualityPolicy()) - internal set - var surfaceContainerHighest by mutableStateOf(surfaceContainerHighest, structuralEqualityPolicy()) - internal set - var surfaceContainerLow by mutableStateOf(surfaceContainerLow, structuralEqualityPolicy()) - internal set - var surfaceContainerLowest by mutableStateOf(surfaceContainerLowest, structuralEqualityPolicy()) - internal set - var statusGreen by mutableStateOf(statusGreen, structuralEqualityPolicy()) internal set @@ -222,51 +54,11 @@ class GloomColorScheme( var onWarningContainer by mutableStateOf(onWarningContainer, structuralEqualityPolicy()) internal set - fun toColorScheme() = with(this) { - ColorScheme( - primary, - onPrimary, - primaryContainer, - onPrimaryContainer, - inversePrimary, - secondary, - onSecondary, - secondaryContainer, - onSecondaryContainer, - tertiary, - onTertiary, - tertiaryContainer, - onTertiaryContainer, - background, - onBackground, - surface, - onSurface, - surfaceVariant, - onSurfaceVariant, - surfaceTint, - inverseSurface, - inverseOnSurface, - error, - onError, - errorContainer, - onErrorContainer, - outline, - outlineVariant, - scrim, - surfaceBright, - surfaceDim, - surfaceContainer, - surfaceContainerHigh, - surfaceContainerHighest, - surfaceContainerLow, - surfaceContainerLowest - ) - } } -val LocalColors = compositionLocalOf { error("No colors initialized") } +val LocalGloomColorScheme = compositionLocalOf { error("No colors initialized") } -val MaterialTheme.colors: GloomColorScheme +val MaterialTheme.gloomColorScheme: GloomColorScheme @Composable @ReadOnlyComposable - get() = LocalColors.current \ No newline at end of file + get() = LocalGloomColorScheme.current \ No newline at end of file diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt index e87e93ef..9433fb1d 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt @@ -1,11 +1,37 @@ package com.materiiapps.gloom.ui.theme -import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Shapes +import androidx.compose.material3.Typography import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider @Composable -expect fun GloomTheme( - darkTheme: Boolean = isSystemInDarkTheme(), +fun GloomTheme( + darkTheme: Boolean, dynamicColor: Boolean, content: @Composable () -> Unit -) \ No newline at end of file +) { + val (colors, gloomColors) = getColorSchemes(darkTheme, dynamicColor) + + CompositionLocalProvider( + LocalGloomColorScheme provides gloomColors + ) { + MaterialTheme( + colorScheme = colors, + typography = Typography(), + shapes = Shapes(), + content = content + ) + } +} + +/** + * Retrieves the color schemes to be used based on user settings + * + * @param darkTheme Whether or not to use the dark theme variant + * @param dynamicColor (Android 12+ only) Whether or not to use a dynamic color scheme + */ +@Composable +expect fun getColorSchemes(darkTheme: Boolean, dynamicColor: Boolean): Pair \ No newline at end of file diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.kt index 83ee164b..f4c2007d 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/theme/Themes.kt @@ -1,11 +1,8 @@ package com.materiiapps.gloom.ui.theme -import androidx.compose.material3.darkColorScheme -import androidx.compose.material3.lightColorScheme import androidx.compose.ui.graphics.Color -fun darkTheme() = GloomColorScheme( - darkColorScheme(), +fun darkGloomColorScheme() = GloomColorScheme( statusGreen = DarkGreen, statusPurple = LightPurple, statusRed = PinkRed, @@ -17,8 +14,7 @@ fun darkTheme() = GloomColorScheme( onWarningContainer = Shandy ) -fun lightTheme() = GloomColorScheme( - lightColorScheme(), +fun lightGloomColorScheme() = GloomColorScheme( statusGreen = LightGreen, statusPurple = DarkPurple, statusRed = Red, diff --git a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/widget/reaction/ReactionRow.kt b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/widget/reaction/ReactionRow.kt index 3cb7bef8..145f524a 100644 --- a/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/widget/reaction/ReactionRow.kt +++ b/ui/src/commonMain/kotlin/com/materiiapps/gloom/ui/widget/reaction/ReactionRow.kt @@ -31,7 +31,7 @@ import androidx.compose.ui.unit.dp import com.materiiapps.gloom.api.REACTION_EMOJIS import com.materiiapps.gloom.gql.fragment.Reaction import com.materiiapps.gloom.gql.type.ReactionContent -import com.materiiapps.gloom.ui.theme.colors +import com.materiiapps.gloom.ui.theme.gloomColorScheme @Composable fun ReactionRow( @@ -123,9 +123,9 @@ fun ReactionRow( _reactions.forEach { reaction -> val (backgroundColor, textColor) = if (reaction.viewerHasReacted) - MaterialTheme.colors.primaryContainer to MaterialTheme.colors.primary + MaterialTheme.colorScheme.primaryContainer to MaterialTheme.colorScheme.primary else - MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp) to MaterialTheme.colors.onSurface + MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp) to MaterialTheme.colorScheme.onSurface Row( verticalAlignment = Alignment.CenterVertically, diff --git a/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.desktop.kt b/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.desktop.kt new file mode 100644 index 00000000..0ba2d57a --- /dev/null +++ b/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.desktop.kt @@ -0,0 +1,14 @@ +package com.materiiapps.gloom.ui.theme + +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable + +@Composable +actual fun getColorSchemes(darkTheme: Boolean, dynamicColor: Boolean): Pair { + return when { + darkTheme -> darkColorScheme() to darkGloomColorScheme() + else -> lightColorScheme() to lightGloomColorScheme() + } +} \ No newline at end of file diff --git a/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt b/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt deleted file mode 100644 index b687f446..00000000 --- a/ui/src/desktopMain/kotlin/com/materiiapps/gloom/ui/theme/GloomTheme.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.materiiapps.gloom.ui.theme - -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Shapes -import androidx.compose.material3.Typography -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider - -@Composable -actual fun GloomTheme( - darkTheme: Boolean, - dynamicColor: Boolean, - content: @Composable () -> Unit -) { - val colors = when { - darkTheme -> darkTheme() - else -> lightTheme() - } - - CompositionLocalProvider( - LocalColors provides colors - ) { - MaterialTheme( - colorScheme = colors.toColorScheme(), - typography = Typography(), - shapes = Shapes(), - content = content - ) - } -} \ No newline at end of file