Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fun Context.loadThemeMode(): CloudStreamThemeMode {
"Black" -> CloudStreamThemeMode.Dark
"Light" -> CloudStreamThemeMode.Light
"Amoled" -> CloudStreamThemeMode.Amoled
"AmoledLight" -> CloudStreamThemeMode.Amoled
"AmoledLight" -> CloudStreamThemeMode.AmoledLight
"Dracula" -> CloudStreamThemeMode.Dracula
"Lavender" -> CloudStreamThemeMode.Lavender
"SilentBlue" -> CloudStreamThemeMode.SilentBlue
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ internal fun amoledScheme() = darkScheme().copy(
surfaceContainer = CloudStreamPalette.AmoledBlack,
)

internal fun amoledLightScheme() = amoledScheme().copy(
surfaceVariant = CloudStreamPalette.AmoledLightBlackBg,
surfaceContainer = CloudStreamPalette.AmoledLightBlackBg,
)

internal fun lightScheme() = CloudStreamColorScheme(
background = CloudStreamPalette.LightBlackBg,
surfaceVariant = CloudStreamPalette.LightPrimaryGrayBg,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.lagradost.cloudstream4.ui.theme

import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import com.lagradost.cloudstream4.generated.resources.Res
import com.lagradost.cloudstream4.generated.resources.productsans_black
import com.lagradost.cloudstream4.generated.resources.productsans_blackitalic
import com.lagradost.cloudstream4.generated.resources.productsans_bold
import com.lagradost.cloudstream4.generated.resources.productsans_bolditalic
import com.lagradost.cloudstream4.generated.resources.productsans_italic
import com.lagradost.cloudstream4.generated.resources.productsans_light
import com.lagradost.cloudstream4.generated.resources.productsans_lightitalic
import com.lagradost.cloudstream4.generated.resources.productsans_medium
import com.lagradost.cloudstream4.generated.resources.productsans_mediumitalic
import com.lagradost.cloudstream4.generated.resources.productsans_regular
import com.lagradost.cloudstream4.generated.resources.productsans_thin
import com.lagradost.cloudstream4.generated.resources.productsans_thinitalic

object CloudStreamDefaultFonts {
val GoogleSans: CloudStreamFontSpec.Bundled = CloudStreamFontSpec.Bundled(
listOf(
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_thin, FontWeight.Thin, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_thinitalic, FontWeight.Thin, FontStyle.Italic),

CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_light, FontWeight.Light, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_lightitalic, FontWeight.Light, FontStyle.Italic),

CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_regular, FontWeight.Normal, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_italic, FontWeight.Normal, FontStyle.Italic),

CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_medium, FontWeight.Medium, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_mediumitalic, FontWeight.Medium, FontStyle.Italic),

CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_bold, FontWeight.Bold, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_bolditalic, FontWeight.Bold, FontStyle.Italic),

CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_black, FontWeight.Black, FontStyle.Normal),
CloudStreamFontSpec.Bundled.Entry(Res.font.productsans_blackitalic, FontWeight.Black, FontStyle.Italic),
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.lagradost.cloudstream4.ui.theme

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import org.jetbrains.compose.resources.Font
import org.jetbrains.compose.resources.FontResource

sealed interface CloudStreamFontSpec {

data object SystemDefault : CloudStreamFontSpec

/** A font bundled via composeResources */
data class Bundled(val entries: List<Entry>) : CloudStreamFontSpec {
data class Entry(
val resource: FontResource,
val weight: FontWeight,
val style: FontStyle,
)
}

/** A user-uploaded font, resolved later from a file path/URI. */
data class Custom(val path: String) : CloudStreamFontSpec
}

// Not yet implemented
/** Platform-specific loading of a user-uploaded font from a file path/URI. */
// expect fun loadCustomFontFamily(path: String): FontFamily?

@Composable
fun CloudStreamFontSpec.resolve(): FontFamily = when (this) {
is CloudStreamFontSpec.SystemDefault -> FontFamily.Default

is CloudStreamFontSpec.Bundled -> {
val fonts = entries.map { entry ->
Font(entry.resource, weight = entry.weight, style = entry.style)
}
remember(fonts) { FontFamily(fonts) }
}

// Not yet implemented
is CloudStreamFontSpec.Custom -> FontFamily.Default /* remember(path) {
loadCustomFontFamily(path) ?: FontFamily.Default
} */
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ internal object CloudStreamPalette {
val AmoledBlack = Color(0xFF000000)
val AmoledNearBlack = Color(0xFF111111)

// AmoledLight
val AmoledLightBlackBg = Color(0xFF121213)

// Light
val LightPrimaryGrayBg = Color(0xFFF1F1F1)
val LightBlackBg = Color(0xFFFFFFFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lagradost.cloudstream4.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
Expand All @@ -10,6 +11,7 @@ import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily

val LocalCloudStreamColors = staticCompositionLocalOf { darkScheme() }

Expand Down Expand Up @@ -46,10 +48,33 @@ private fun CloudStreamColorScheme.toMaterial3ColorScheme() = if (isLight) {
)
}

private fun Typography.withFontFamily(fontFamily: FontFamily): Typography = copy(
displayLarge = displayLarge.copy(fontFamily = fontFamily),
displayMedium = displayMedium.copy(fontFamily = fontFamily),
displaySmall = displaySmall.copy(fontFamily = fontFamily),

headlineLarge = headlineLarge.copy(fontFamily = fontFamily),
headlineMedium = headlineMedium.copy(fontFamily = fontFamily),
headlineSmall = headlineSmall.copy(fontFamily = fontFamily),

titleLarge = titleLarge.copy(fontFamily = fontFamily),
titleMedium = titleMedium.copy(fontFamily = fontFamily),
titleSmall = titleSmall.copy(fontFamily = fontFamily),

bodyLarge = bodyLarge.copy(fontFamily = fontFamily),
bodyMedium = bodyMedium.copy(fontFamily = fontFamily),
bodySmall = bodySmall.copy(fontFamily = fontFamily),

labelLarge = labelLarge.copy(fontFamily = fontFamily),
labelMedium = labelMedium.copy(fontFamily = fontFamily),
labelSmall = labelSmall.copy(fontFamily = fontFamily),
)

@Composable
fun CloudStreamTheme(
mode: CloudStreamThemeMode = CloudStreamThemeMode.FollowSystem,
primaryColor: CloudStreamPrimaryColor = CloudStreamPrimaryColor.NORMAL,
fontSpec: CloudStreamFontSpec = CloudStreamDefaultFonts.GoogleSans,
content: @Composable () -> Unit,
) {
val systemDark = isSystemInDarkTheme()
Expand All @@ -62,6 +87,7 @@ fun CloudStreamTheme(
val base = when (mode) {
CloudStreamThemeMode.Dark -> darkScheme()
CloudStreamThemeMode.Amoled -> amoledScheme()
CloudStreamThemeMode.AmoledLight -> amoledLightScheme()
CloudStreamThemeMode.Light -> lightScheme()
CloudStreamThemeMode.Dracula -> draculaScheme()
CloudStreamThemeMode.Lavender -> lavenderScheme()
Expand All @@ -77,9 +103,16 @@ fun CloudStreamTheme(
}
}

val resolvedFontFamily = fontSpec.resolve()
val baseTypography = MaterialTheme.typography
val typography = remember(baseTypography, resolvedFontFamily) {
baseTypography.withFontFamily(resolvedFontFamily)
}

CompositionLocalProvider(LocalCloudStreamColors provides csColors) {
MaterialTheme(
colorScheme = csColors.toMaterial3ColorScheme(),
typography = typography,
content = content,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.lagradost.cloudstream4.ui.theme
enum class CloudStreamThemeMode {
/** "Black" standard dark, #111111 backgrounds */
Dark,
/** "Amoled" / "AmoledLight" pure black (#000000) */
/** "Amoled" pure black (#000000) */
Amoled,
/** "AmoledLight" pure black (#000000) background, lighter (#121213) surfaces */
AmoledLight,
/** "Light" white/gray backgrounds, dark text */
Light,
/** "Dracula" */
Expand Down