Change theme to use custom colors instead of the material ones to allow usage without material dependency

This commit is contained in:
Wolf Montwé 2023-03-23 13:14:08 +01:00
parent 276f8ead83
commit 744d4bc0ee
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
6 changed files with 107 additions and 8 deletions

View file

@ -167,6 +167,8 @@
<ID>LongMethod:SrvServiceDiscoveryTest.kt$SrvServiceDiscoveryTest$@Test fun discover_withRequiredServices_shouldCorrectlyPrioritize()</ID>
<ID>LongMethod:TextBodyBuilderTest.kt$TextBodyBuilderTest.Companion$@JvmStatic @Parameterized.Parameters(name = "{index}: {0}") fun data(): Collection&lt;TestData&gt;</ID>
<ID>LongMethod:ThreadMessageOperationsTest.kt$ThreadMessageOperationsTest$@Test fun `merge two existing threads`()</ID>
<ID>LongParameterList:Colors.kt$( primary: Color = MaterialColor.deep_purple_200, primaryVariant: Color = MaterialColor.deep_purple_50, secondary: Color = MaterialColor.cyan_300, secondaryVariant: Color = MaterialColor.cyan_100, background: Color = MaterialColor.gray_800, surface: Color = MaterialColor.gray_900, error: Color = MaterialColor.red_300, onPrimary: Color = Color.Black, onSecondary: Color = Color.Black, onBackground: Color = Color.White, onSurface: Color = Color.White, onError: Color = Color.Black, )</ID>
<ID>LongParameterList:Colors.kt$( primary: Color = MaterialColor.deep_purple_600, primaryVariant: Color = MaterialColor.deep_purple_900, secondary: Color = MaterialColor.cyan_600, secondaryVariant: Color = MaterialColor.cyan_800, background: Color = MaterialColor.gray_200, surface: Color = Color.White, error: Color = MaterialColor.red_600, onPrimary: Color = Color.White, onSecondary: Color = Color.Black, onBackground: Color = Color.Black, onSurface: Color = Color.Black, onError: Color = Color.White, )</ID>
<ID>LongParameterList:CopyMessageOperations.kt$DatabaseMessagePart$( val id: Long, val type: Int, val root: Long, val parent: Long, val seq: Int, val mimeType: String?, val decodedBodySize: Long?, val displayName: String?, val header: ByteArray?, val encoding: String?, val charset: String?, val dataLocation: Int, val data: ByteArray?, val preamble: ByteArray?, val epilogue: ByteArray?, val boundary: String?, val contentId: String?, val serverExtra: String?, )</ID>
<ID>LongParameterList:FolderHelpers.kt$( name: String = "irrelevant", type: String = "regular", serverId: String? = null, isLocalOnly: Boolean = true, integrate: Boolean = false, inTopGroup: Boolean = false, displayClass: String = "NO_CLASS", syncClass: String? = "INHERITED", notifyClass: String? = "INHERITED", pushClass: String? = "SECOND_CLASS", lastUpdated: Long = 0L, unreadCount: Int = 0, visibleLimit: Int = 25, status: String? = null, flaggedCount: Int = 0, moreMessages: String = "unknown", )</ID>
<ID>LongParameterList:ImapSync.kt$ImapSync$( remoteFolder: ImapFolder, backendFolder: BackendFolder, largeMessages: List&lt;ImapMessage&gt;, progress: AtomicInteger, downloadedMessageCount: AtomicInteger, todo: Int, highestKnownUid: Long?, listener: SyncListener, maxDownloadSize: Int, )</ID>

View file

@ -729,7 +729,7 @@ style:
Compose:
CompositionLocalAllowlist:
active: true
allowedCompositionLocals: [LocalElevations, LocalImages, LocalSizes, LocalSpacings]
allowedCompositionLocals: [LocalColors, LocalElevations, LocalImages, LocalSizes, LocalSpacings]
ContentEmitterReturningValues:
active: true
# You can optionally add your own composables here

View file

@ -0,0 +1,101 @@
package app.k9mail.core.ui.compose.theme
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.material.Colors as MaterialColors
@Immutable
data class Colors(
val primary: Color,
val primaryVariant: Color,
val secondary: Color,
val secondaryVariant: Color,
val background: Color,
val surface: Color,
val error: Color,
val onPrimary: Color,
val onSecondary: Color,
val onBackground: Color,
val onSurface: Color,
val onError: Color,
val isLight: Boolean,
)
fun lightColors(
primary: Color = Color(0xFF6200EE),
primaryVariant: Color = Color(0xFF3700B3),
secondary: Color = Color(0xFF03DAC6),
secondaryVariant: Color = Color(0xFF018786),
background: Color = Color.White,
surface: Color = Color.White,
error: Color = Color(0xFFB00020),
onPrimary: Color = Color.White,
onSecondary: Color = Color.Black,
onBackground: Color = Color.Black,
onSurface: Color = Color.Black,
onError: Color = Color.White,
) = Colors(
primary = primary,
primaryVariant = primaryVariant,
secondary = secondary,
secondaryVariant = secondaryVariant,
background = background,
surface = surface,
error = error,
onPrimary = onPrimary,
onSecondary = onSecondary,
onBackground = onBackground,
onSurface = onSurface,
onError = onError,
isLight = true,
)
fun darkColors(
primary: Color = Color(0xFFBB86FC),
primaryVariant: Color = Color(0xFF3700B3),
secondary: Color = Color(0xFF03DAC6),
secondaryVariant: Color = secondary,
background: Color = Color(0xFF121212),
surface: Color = Color(0xFF121212),
error: Color = Color(0xFFCF6679),
onPrimary: Color = Color.Black,
onSecondary: Color = Color.Black,
onBackground: Color = Color.White,
onSurface: Color = Color.White,
onError: Color = Color.Black,
) = Colors(
primary = primary,
primaryVariant = primaryVariant,
secondary = secondary,
secondaryVariant = secondaryVariant,
background = background,
surface = surface,
error = error,
onPrimary = onPrimary,
onSecondary = onSecondary,
onBackground = onBackground,
onSurface = onSurface,
onError = onError,
isLight = false,
)
internal fun Colors.toMaterialColors(): MaterialColors {
return MaterialColors(
primary = primary,
primaryVariant = primaryVariant,
secondary = secondary,
secondaryVariant = secondaryVariant,
background = background,
surface = surface,
error = error,
onPrimary = onPrimary,
onSecondary = onSecondary,
onBackground = onBackground,
onSurface = onSurface,
onError = onError,
isLight = isLight,
)
}
internal val LocalColors = staticCompositionLocalOf { lightColors() }

View file

@ -1,8 +1,6 @@
package app.k9mail.core.ui.compose.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
private val k9LightColorPalette = lightColors(

View file

@ -1,7 +1,6 @@
package app.k9mail.core.ui.compose.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Colors
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Shapes
import androidx.compose.material.Typography
@ -30,13 +29,14 @@ fun MainTheme(
}
CompositionLocalProvider(
LocalColors provides colors,
LocalElevations provides Elevations(),
LocalImages provides images,
LocalSizes provides Sizes(),
LocalSpacings provides Spacings(),
) {
MaterialTheme(
colors = colors,
colors = colors.toMaterialColors(),
typography = typography,
shapes = shapes,
content = content,
@ -48,7 +48,7 @@ object MainTheme {
val colors: Colors
@Composable
@ReadOnlyComposable
get() = MaterialTheme.colors
get() = LocalColors.current
val typography: Typography
@Composable

View file

@ -1,8 +1,6 @@
package app.k9mail.core.ui.compose.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
private val thunderbirdLightColorPalette = lightColors(