commit 06d57ab83c217631870d4af12ae6955283ae892e
parent cadcbc958e496e665eef185e936b646a4ec8c118
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sat, 16 Dec 2023 00:26:38 +0100

refactor: move compose view factory to common

Diffstat:
Dapp/src/main/kotlin/me/rhunk/snapenhance/ui/Theme.kt | 163-------------------------------------------------------------------------------
Mapp/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt | 2+-
Dapp/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/ComposeOverlay.kt | 72------------------------------------------------------------------------
Mapp/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/SettingsOverlay.kt | 26+++++++++++---------------
Mapp/src/main/kotlin/me/rhunk/snapenhance/ui/setup/SetupActivity.kt | 2+-
Mcommon/build.gradle.kts | 13+++++++++++++
Acommon/src/main/kotlin/me/rhunk/snapenhance/common/ui/ComposeViewFactory.kt | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/src/main/kotlin/me/rhunk/snapenhance/common/ui/Theme.kt | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/build.gradle.kts | 16++++++++++++++++
9 files changed, 284 insertions(+), 252 deletions(-)

diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/Theme.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/Theme.kt @@ -1,162 +0,0 @@ -package me.rhunk.snapenhance.ui - -import android.os.Build -import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme -import androidx.compose.material3.lightColorScheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalContext - -val md_theme_light_primary = Color(0xFF6750A4) -val md_theme_light_onPrimary = Color(0xFFFFFFFF) -val md_theme_light_primaryContainer = Color(0xFFE9DDFF) -val md_theme_light_onPrimaryContainer = Color(0xFF22005D) -val md_theme_light_secondary = Color(0xFF625B71) -val md_theme_light_onSecondary = Color(0xFFFFFFFF) -val md_theme_light_secondaryContainer = Color(0xFFE8DEF8) -val md_theme_light_onSecondaryContainer = Color(0xFF1E192B) -val md_theme_light_tertiary = Color(0xFF3C5BA9) -val md_theme_light_onTertiary = Color(0xFFFFFFFF) -val md_theme_light_tertiaryContainer = Color(0xFFDBE1FF) -val md_theme_light_onTertiaryContainer = Color(0xFF001849) -val md_theme_light_error = Color(0xFFBA1A1A) -val md_theme_light_errorContainer = Color(0xFFFFDAD6) -val md_theme_light_onError = Color(0xFFFFFFFF) -val md_theme_light_onErrorContainer = Color(0xFF410002) -val md_theme_light_background = Color(0xFFFFFBFF) -val md_theme_light_onBackground = Color(0xFF1C1B1E) -val md_theme_light_surface = Color(0xFFFFFBFF) -val md_theme_light_onSurface = Color(0xFF1C1B1E) -val md_theme_light_surfaceVariant = Color(0xFFE7E0EB) -val md_theme_light_onSurfaceVariant = Color(0xFF49454E) -val md_theme_light_outline = Color(0xFF7A757F) -val md_theme_light_inverseOnSurface = Color(0xFFF4EFF4) -val md_theme_light_inverseSurface = Color(0xFF313033) -val md_theme_light_inversePrimary = Color(0xFFCFBCFF) -val md_theme_light_surfaceTint = Color(0xFF6750A4) -val md_theme_light_outlineVariant = Color(0xFFCAC4CF) -val md_theme_light_scrim = Color(0xFF000000) - -val md_theme_dark_primary = Color(0xFFCFBCFF) -val md_theme_dark_onPrimary = Color(0xFF381E72) -val md_theme_dark_primaryContainer = Color(0xFF4F378A) -val md_theme_dark_onPrimaryContainer = Color(0xFFE9DDFF) -val md_theme_dark_secondary = Color(0xFFCBC2DB) -val md_theme_dark_onSecondary = Color(0xFF332D41) -val md_theme_dark_secondaryContainer = Color(0xFF4A4458) -val md_theme_dark_onSecondaryContainer = Color(0xFFE8DEF8) -val md_theme_dark_tertiary = Color(0xFFB3C5FF) -val md_theme_dark_onTertiary = Color(0xFF002B75) -val md_theme_dark_tertiaryContainer = Color(0xFF21428F) -val md_theme_dark_onTertiaryContainer = Color(0xFFDBE1FF) -val md_theme_dark_error = Color(0xFFFFB4AB) -val md_theme_dark_errorContainer = Color(0xFF93000A) -val md_theme_dark_onError = Color(0xFF690005) -val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) -val md_theme_dark_background = Color(0xFF1C1B1E) -val md_theme_dark_onBackground = Color(0xFFE6E1E6) -val md_theme_dark_surface = Color(0xFF1C1B1E) -val md_theme_dark_onSurface = Color(0xFFE6E1E6) -val md_theme_dark_surfaceVariant = Color(0xFF49454E) -val md_theme_dark_onSurfaceVariant = Color(0xFFCAC4CF) -val md_theme_dark_outline = Color(0xFF948F99) -val md_theme_dark_inverseOnSurface = Color(0xFF1C1B1E) -val md_theme_dark_inverseSurface = Color(0xFFE6E1E6) -val md_theme_dark_inversePrimary = Color(0xFF6750A4) -val md_theme_dark_surfaceTint = Color(0xFFCFBCFF) -val md_theme_dark_outlineVariant = Color(0xFF49454E) -val md_theme_dark_scrim = Color(0xFF000000) - - -val seed = Color(0xFF6750A4) - - -private val LightThemeColors = lightColorScheme( - primary = md_theme_light_primary, - onPrimary = md_theme_light_onPrimary, - primaryContainer = md_theme_light_primaryContainer, - onPrimaryContainer = md_theme_light_onPrimaryContainer, - secondary = md_theme_light_secondary, - onSecondary = md_theme_light_onSecondary, - secondaryContainer = md_theme_light_secondaryContainer, - onSecondaryContainer = md_theme_light_onSecondaryContainer, - tertiary = md_theme_light_tertiary, - onTertiary = md_theme_light_onTertiary, - tertiaryContainer = md_theme_light_tertiaryContainer, - onTertiaryContainer = md_theme_light_onTertiaryContainer, - error = md_theme_light_error, - onError = md_theme_light_onError, - errorContainer = md_theme_light_errorContainer, - onErrorContainer = md_theme_light_onErrorContainer, - background = md_theme_light_background, - onBackground = md_theme_light_onBackground, - surface = md_theme_light_surface, - onSurface = md_theme_light_onSurface, - surfaceVariant = md_theme_light_surfaceVariant, - onSurfaceVariant = md_theme_light_onSurfaceVariant, - outline = md_theme_light_outline, - inverseOnSurface = md_theme_light_inverseOnSurface, - inverseSurface = md_theme_light_inverseSurface, - inversePrimary = md_theme_light_inversePrimary, - surfaceTint = md_theme_light_surfaceTint, - outlineVariant = md_theme_light_outlineVariant, - scrim = md_theme_light_scrim -) - -private val DarkThemeColors = lightColorScheme( - primary = md_theme_dark_primary, - onPrimary = md_theme_dark_onPrimary, - primaryContainer = md_theme_dark_primaryContainer, - onPrimaryContainer = md_theme_dark_onPrimaryContainer, - secondary = md_theme_dark_secondary, - onSecondary = md_theme_dark_onSecondary, - secondaryContainer = md_theme_dark_secondaryContainer, - onSecondaryContainer = md_theme_dark_onSecondaryContainer, - tertiary = md_theme_dark_tertiary, - onTertiary = md_theme_dark_onTertiary, - tertiaryContainer = md_theme_dark_tertiaryContainer, - onTertiaryContainer = md_theme_dark_onTertiaryContainer, - error = md_theme_dark_error, - onError = md_theme_dark_onError, - errorContainer = md_theme_dark_errorContainer, - onErrorContainer = md_theme_dark_onErrorContainer, - background = md_theme_dark_background, - onBackground = md_theme_dark_onBackground, - surface = md_theme_dark_surface, - onSurface = md_theme_dark_onSurface, - surfaceVariant = md_theme_dark_surfaceVariant, - onSurfaceVariant = md_theme_dark_onSurfaceVariant, - outline = md_theme_dark_outline, - inverseOnSurface = md_theme_dark_inverseOnSurface, - inverseSurface = md_theme_dark_inverseSurface, - inversePrimary = md_theme_dark_inversePrimary, - surfaceTint = md_theme_dark_surfaceTint, - outlineVariant = md_theme_dark_outlineVariant, - scrim = md_theme_dark_scrim -) - -@Composable -fun AppMaterialTheme( - isDarkTheme: Boolean = isSystemInDarkTheme(), - content: @Composable () -> Unit -) { - val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - val colorScheme = when { - dynamicColor && isDarkTheme -> { - dynamicDarkColorScheme(LocalContext.current) - } - dynamicColor && !isDarkTheme -> { - dynamicLightColorScheme(LocalContext.current) - } - !isDarkTheme -> LightThemeColors - else -> DarkThemeColors - } - - MaterialTheme( - colorScheme = colorScheme, - content = content - ) -}- \ No newline at end of file diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt @@ -12,7 +12,7 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import me.rhunk.snapenhance.RemoteSideContext import me.rhunk.snapenhance.SharedContextHolder -import me.rhunk.snapenhance.ui.AppMaterialTheme +import me.rhunk.snapenhance.common.ui.AppMaterialTheme class MainActivity : ComponentActivity() { private lateinit var sections: Map<EnumSection, Section> diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/ComposeOverlay.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/ComposeOverlay.kt @@ -1,71 +0,0 @@ -package me.rhunk.snapenhance.ui.overlay - -import android.content.Context -import android.os.Bundle -import androidx.activity.OnBackPressedDispatcher -import androidx.activity.OnBackPressedDispatcherOwner -import androidx.activity.setViewTreeOnBackPressedDispatcherOwner -import androidx.compose.runtime.Recomposer -import androidx.compose.ui.platform.AndroidUiDispatcher -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.compose.ui.platform.compositionContext -import androidx.lifecycle.* -import androidx.savedstate.SavedStateRegistry -import androidx.savedstate.SavedStateRegistryController -import androidx.savedstate.SavedStateRegistryOwner -import androidx.savedstate.setViewTreeSavedStateRegistryOwner -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch - -// https://github.com/tberghuis/FloatingCountdownTimer/blob/master/app/src/main/java/xyz/tberghuis/floatingtimer/service/overlayViewFactory.kt -fun overlayComposeView(service: Context) = ComposeView(service).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - val lifecycleOwner = OverlayLifecycleOwner().apply { - performRestore(null) - handleLifecycleEvent(Lifecycle.Event.ON_CREATE) - } - setViewTreeLifecycleOwner(lifecycleOwner) - setViewTreeSavedStateRegistryOwner(lifecycleOwner) - - val viewModelStore = ViewModelStore() - setViewTreeViewModelStoreOwner(object : ViewModelStoreOwner { - override val viewModelStore: ViewModelStore - get() = viewModelStore - }) - - val backPressedDispatcherOwner = OnBackPressedDispatcher() - setViewTreeOnBackPressedDispatcherOwner(object: OnBackPressedDispatcherOwner { - override val lifecycle: Lifecycle - get() = lifecycleOwner.lifecycle - override val onBackPressedDispatcher: OnBackPressedDispatcher - get() = backPressedDispatcherOwner - }) - - val coroutineContext = AndroidUiDispatcher.CurrentThread - val runRecomposeScope = CoroutineScope(coroutineContext) - val recomposer = Recomposer(coroutineContext) - compositionContext = recomposer - runRecomposeScope.launch { - recomposer.runRecomposeAndApplyChanges() - } -} - -private class OverlayLifecycleOwner : SavedStateRegistryOwner { - private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this) - private var mSavedStateRegistryController: SavedStateRegistryController = - SavedStateRegistryController.create(this) - override val lifecycle: Lifecycle - get() = mLifecycleRegistry - override val savedStateRegistry: SavedStateRegistry - get() = mSavedStateRegistryController.savedStateRegistry - fun handleLifecycleEvent(event: Lifecycle.Event) { - mLifecycleRegistry.handleLifecycleEvent(event) - } - fun performRestore(savedState: Bundle?) { - mSavedStateRegistryController.performRestore(savedState) - } - fun performSave(outBundle: Bundle) { - mSavedStateRegistryController.performSave(outBundle) - } -}- \ No newline at end of file diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/SettingsOverlay.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/overlay/SettingsOverlay.kt @@ -24,7 +24,7 @@ import androidx.navigation.compose.rememberNavController import com.arthenica.ffmpegkit.Packages.getPackageName import me.rhunk.snapenhance.R import me.rhunk.snapenhance.RemoteSideContext -import me.rhunk.snapenhance.ui.AppMaterialTheme +import me.rhunk.snapenhance.common.ui.createComposeView import me.rhunk.snapenhance.ui.manager.EnumSection import me.rhunk.snapenhance.ui.manager.Navigation import me.rhunk.snapenhance.ui.manager.sections.features.FeaturesSection @@ -117,20 +117,16 @@ class SettingsOverlay( } dialog.setContentView( - overlayComposeView(context.androidContext).apply { - setContent { - Column( - modifier = Modifier - .fillMaxSize() - .padding(start = 15.dp, end = 15.dp, top = 25.dp, bottom = 25.dp) - .clip(shape = MaterialTheme.shapes.large), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center - ) { - AppMaterialTheme { - OverlayContent() - } - } + createComposeView(context.androidContext) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(start = 15.dp, end = 15.dp, top = 25.dp, bottom = 25.dp) + .clip(shape = MaterialTheme.shapes.large), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + OverlayContent() } } ) diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/SetupActivity.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/SetupActivity.kt @@ -27,7 +27,7 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import me.rhunk.snapenhance.SharedContextHolder -import me.rhunk.snapenhance.ui.AppMaterialTheme +import me.rhunk.snapenhance.common.ui.AppMaterialTheme import me.rhunk.snapenhance.ui.setup.screens.SetupScreen import me.rhunk.snapenhance.ui.setup.screens.impl.MappingsScreen import me.rhunk.snapenhance.ui.setup.screens.impl.PermissionsScreen diff --git a/common/build.gradle.kts b/common/build.gradle.kts @@ -10,6 +10,11 @@ android { buildFeatures { aidl = true buildConfig = true + compose = true + } + + composeOptions { + kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() } defaultConfig { @@ -38,5 +43,13 @@ dependencies { implementation(libs.androidx.documentfile) implementation(libs.rhino) + compileOnly(libs.androidx.activity.ktx) + compileOnly(platform(libs.androidx.compose.bom)) + compileOnly(libs.androidx.navigation.compose) + compileOnly(libs.androidx.material.icons.core) + compileOnly(libs.androidx.material.ripple) + compileOnly(libs.androidx.material.icons.extended) + compileOnly(libs.androidx.material3) + implementation(project(":mapper")) } \ No newline at end of file diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/ui/ComposeViewFactory.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/ui/ComposeViewFactory.kt @@ -0,0 +1,78 @@ +package me.rhunk.snapenhance.common.ui + +import android.content.Context +import android.os.Bundle +import androidx.activity.OnBackPressedDispatcher +import androidx.activity.OnBackPressedDispatcherOwner +import androidx.activity.setViewTreeOnBackPressedDispatcherOwner +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Recomposer +import androidx.compose.ui.platform.AndroidUiDispatcher +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.compose.ui.platform.compositionContext +import androidx.lifecycle.* +import androidx.savedstate.SavedStateRegistry +import androidx.savedstate.SavedStateRegistryController +import androidx.savedstate.SavedStateRegistryOwner +import androidx.savedstate.setViewTreeSavedStateRegistryOwner +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch + +// https://github.com/tberghuis/FloatingCountdownTimer/blob/master/app/src/main/java/xyz/tberghuis/floatingtimer/service/overlayViewFactory.kt +fun createComposeView(context: Context, content: @Composable () -> Unit) = ComposeView(context).apply { + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + val lifecycleOwner = OverlayLifecycleOwner().apply { + performRestore(null) + handleLifecycleEvent(Lifecycle.Event.ON_CREATE) + } + setViewTreeLifecycleOwner(lifecycleOwner) + setViewTreeSavedStateRegistryOwner(lifecycleOwner) + + val viewModelStore = ViewModelStore() + setViewTreeViewModelStoreOwner(object : ViewModelStoreOwner { + override val viewModelStore: ViewModelStore + get() = viewModelStore + }) + + val backPressedDispatcherOwner = OnBackPressedDispatcher() + setViewTreeOnBackPressedDispatcherOwner(object: OnBackPressedDispatcherOwner { + override val lifecycle: Lifecycle + get() = lifecycleOwner.lifecycle + override val onBackPressedDispatcher: OnBackPressedDispatcher + get() = backPressedDispatcherOwner + }) + + val coroutineContext = AndroidUiDispatcher.CurrentThread + val runRecomposeScope = CoroutineScope(coroutineContext) + val recomposer = Recomposer(coroutineContext) + compositionContext = recomposer + runRecomposeScope.launch { + recomposer.runRecomposeAndApplyChanges() + } + + setContent { + AppMaterialTheme { + content() + } + } +} + +private class OverlayLifecycleOwner : SavedStateRegistryOwner { + private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this) + private var mSavedStateRegistryController: SavedStateRegistryController = + SavedStateRegistryController.create(this) + override val lifecycle: Lifecycle + get() = mLifecycleRegistry + override val savedStateRegistry: SavedStateRegistry + get() = mSavedStateRegistryController.savedStateRegistry + fun handleLifecycleEvent(event: Lifecycle.Event) { + mLifecycleRegistry.handleLifecycleEvent(event) + } + fun performRestore(savedState: Bundle?) { + mSavedStateRegistryController.performRestore(savedState) + } + fun performSave(outBundle: Bundle) { + mSavedStateRegistryController.performSave(outBundle) + } +}+ \ No newline at end of file diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/ui/Theme.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/ui/Theme.kt @@ -0,0 +1,162 @@ +package me.rhunk.snapenhance.common.ui + +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext + +val md_theme_light_primary = Color(0xFF6750A4) +val md_theme_light_onPrimary = Color(0xFFFFFFFF) +val md_theme_light_primaryContainer = Color(0xFFE9DDFF) +val md_theme_light_onPrimaryContainer = Color(0xFF22005D) +val md_theme_light_secondary = Color(0xFF625B71) +val md_theme_light_onSecondary = Color(0xFFFFFFFF) +val md_theme_light_secondaryContainer = Color(0xFFE8DEF8) +val md_theme_light_onSecondaryContainer = Color(0xFF1E192B) +val md_theme_light_tertiary = Color(0xFF3C5BA9) +val md_theme_light_onTertiary = Color(0xFFFFFFFF) +val md_theme_light_tertiaryContainer = Color(0xFFDBE1FF) +val md_theme_light_onTertiaryContainer = Color(0xFF001849) +val md_theme_light_error = Color(0xFFBA1A1A) +val md_theme_light_errorContainer = Color(0xFFFFDAD6) +val md_theme_light_onError = Color(0xFFFFFFFF) +val md_theme_light_onErrorContainer = Color(0xFF410002) +val md_theme_light_background = Color(0xFFFFFBFF) +val md_theme_light_onBackground = Color(0xFF1C1B1E) +val md_theme_light_surface = Color(0xFFFFFBFF) +val md_theme_light_onSurface = Color(0xFF1C1B1E) +val md_theme_light_surfaceVariant = Color(0xFFE7E0EB) +val md_theme_light_onSurfaceVariant = Color(0xFF49454E) +val md_theme_light_outline = Color(0xFF7A757F) +val md_theme_light_inverseOnSurface = Color(0xFFF4EFF4) +val md_theme_light_inverseSurface = Color(0xFF313033) +val md_theme_light_inversePrimary = Color(0xFFCFBCFF) +val md_theme_light_surfaceTint = Color(0xFF6750A4) +val md_theme_light_outlineVariant = Color(0xFFCAC4CF) +val md_theme_light_scrim = Color(0xFF000000) + +val md_theme_dark_primary = Color(0xFFCFBCFF) +val md_theme_dark_onPrimary = Color(0xFF381E72) +val md_theme_dark_primaryContainer = Color(0xFF4F378A) +val md_theme_dark_onPrimaryContainer = Color(0xFFE9DDFF) +val md_theme_dark_secondary = Color(0xFFCBC2DB) +val md_theme_dark_onSecondary = Color(0xFF332D41) +val md_theme_dark_secondaryContainer = Color(0xFF4A4458) +val md_theme_dark_onSecondaryContainer = Color(0xFFE8DEF8) +val md_theme_dark_tertiary = Color(0xFFB3C5FF) +val md_theme_dark_onTertiary = Color(0xFF002B75) +val md_theme_dark_tertiaryContainer = Color(0xFF21428F) +val md_theme_dark_onTertiaryContainer = Color(0xFFDBE1FF) +val md_theme_dark_error = Color(0xFFFFB4AB) +val md_theme_dark_errorContainer = Color(0xFF93000A) +val md_theme_dark_onError = Color(0xFF690005) +val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) +val md_theme_dark_background = Color(0xFF1C1B1E) +val md_theme_dark_onBackground = Color(0xFFE6E1E6) +val md_theme_dark_surface = Color(0xFF1C1B1E) +val md_theme_dark_onSurface = Color(0xFFE6E1E6) +val md_theme_dark_surfaceVariant = Color(0xFF49454E) +val md_theme_dark_onSurfaceVariant = Color(0xFFCAC4CF) +val md_theme_dark_outline = Color(0xFF948F99) +val md_theme_dark_inverseOnSurface = Color(0xFF1C1B1E) +val md_theme_dark_inverseSurface = Color(0xFFE6E1E6) +val md_theme_dark_inversePrimary = Color(0xFF6750A4) +val md_theme_dark_surfaceTint = Color(0xFFCFBCFF) +val md_theme_dark_outlineVariant = Color(0xFF49454E) +val md_theme_dark_scrim = Color(0xFF000000) + + +val seed = Color(0xFF6750A4) + + +private val LightThemeColors = lightColorScheme( + primary = md_theme_light_primary, + onPrimary = md_theme_light_onPrimary, + primaryContainer = md_theme_light_primaryContainer, + onPrimaryContainer = md_theme_light_onPrimaryContainer, + secondary = md_theme_light_secondary, + onSecondary = md_theme_light_onSecondary, + secondaryContainer = md_theme_light_secondaryContainer, + onSecondaryContainer = md_theme_light_onSecondaryContainer, + tertiary = md_theme_light_tertiary, + onTertiary = md_theme_light_onTertiary, + tertiaryContainer = md_theme_light_tertiaryContainer, + onTertiaryContainer = md_theme_light_onTertiaryContainer, + error = md_theme_light_error, + onError = md_theme_light_onError, + errorContainer = md_theme_light_errorContainer, + onErrorContainer = md_theme_light_onErrorContainer, + background = md_theme_light_background, + onBackground = md_theme_light_onBackground, + surface = md_theme_light_surface, + onSurface = md_theme_light_onSurface, + surfaceVariant = md_theme_light_surfaceVariant, + onSurfaceVariant = md_theme_light_onSurfaceVariant, + outline = md_theme_light_outline, + inverseOnSurface = md_theme_light_inverseOnSurface, + inverseSurface = md_theme_light_inverseSurface, + inversePrimary = md_theme_light_inversePrimary, + surfaceTint = md_theme_light_surfaceTint, + outlineVariant = md_theme_light_outlineVariant, + scrim = md_theme_light_scrim +) + +private val DarkThemeColors = lightColorScheme( + primary = md_theme_dark_primary, + onPrimary = md_theme_dark_onPrimary, + primaryContainer = md_theme_dark_primaryContainer, + onPrimaryContainer = md_theme_dark_onPrimaryContainer, + secondary = md_theme_dark_secondary, + onSecondary = md_theme_dark_onSecondary, + secondaryContainer = md_theme_dark_secondaryContainer, + onSecondaryContainer = md_theme_dark_onSecondaryContainer, + tertiary = md_theme_dark_tertiary, + onTertiary = md_theme_dark_onTertiary, + tertiaryContainer = md_theme_dark_tertiaryContainer, + onTertiaryContainer = md_theme_dark_onTertiaryContainer, + error = md_theme_dark_error, + onError = md_theme_dark_onError, + errorContainer = md_theme_dark_errorContainer, + onErrorContainer = md_theme_dark_onErrorContainer, + background = md_theme_dark_background, + onBackground = md_theme_dark_onBackground, + surface = md_theme_dark_surface, + onSurface = md_theme_dark_onSurface, + surfaceVariant = md_theme_dark_surfaceVariant, + onSurfaceVariant = md_theme_dark_onSurfaceVariant, + outline = md_theme_dark_outline, + inverseOnSurface = md_theme_dark_inverseOnSurface, + inverseSurface = md_theme_dark_inverseSurface, + inversePrimary = md_theme_dark_inversePrimary, + surfaceTint = md_theme_dark_surfaceTint, + outlineVariant = md_theme_dark_outlineVariant, + scrim = md_theme_dark_scrim +) + +@Composable +fun AppMaterialTheme( + isDarkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable () -> Unit +) { + val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + val colorScheme = when { + dynamicColor && isDarkTheme -> { + dynamicDarkColorScheme(LocalContext.current) + } + dynamicColor && !isDarkTheme -> { + dynamicLightColorScheme(LocalContext.current) + } + !isDarkTheme -> LightThemeColors + else -> DarkThemeColors + } + + MaterialTheme( + colorScheme = colorScheme, + content = content + ) +}+ \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts @@ -11,6 +11,14 @@ android { minSdk = 28 } + buildFeatures { + compose = true + } + + composeOptions { + kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -33,4 +41,12 @@ dependencies { implementation(project(":common")) implementation(project(":mapper")) implementation(project(":native")) + + compileOnly(libs.androidx.activity.ktx) + compileOnly(platform(libs.androidx.compose.bom)) + compileOnly(libs.androidx.navigation.compose) + compileOnly(libs.androidx.material.icons.core) + compileOnly(libs.androidx.material.ripple) + compileOnly(libs.androidx.material.icons.extended) + compileOnly(libs.androidx.material3) } \ No newline at end of file