diff --git a/androidApp/src/main/java/com/makeevrserg/empireprojekt/mobile/MainActivity.kt b/androidApp/src/main/java/com/makeevrserg/empireprojekt/mobile/MainActivity.kt index 4630191e..b22fed90 100644 --- a/androidApp/src/main/java/com/makeevrserg/empireprojekt/mobile/MainActivity.kt +++ b/androidApp/src/main/java/com/makeevrserg/empireprojekt/mobile/MainActivity.kt @@ -8,16 +8,15 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ModalBottomSheetLayout -import androidx.compose.runtime.getValue import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.core.view.WindowCompat import com.arkivanov.decompose.defaultComponentContext import com.makeevrserg.empireprojekt.mobile.core.ui.rememberSlotModalBottomSheetState import com.makeevrserg.empireprojekt.mobile.core.ui.theme.AppTheme -import com.makeevrserg.empireprojekt.mobile.features.root.DefaultRootBottomSheetComponent import com.makeevrserg.empireprojekt.mobile.features.root.DefaultRootComponent import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule +import com.makeevrserg.empireprojekt.mobile.features.root.modal.DefaultRootBottomSheetComponent import com.makeevrserg.empireprojekt.mobile.features.ui.info.InfoScreen import com.makeevrserg.empireprojekt.mobile.features.ui.root.ApplicationContent import com.makeevrserg.empireprojekt.mobile.features.ui.root.ComposeApplication @@ -37,7 +36,7 @@ class MainActivity : ComponentActivity() { WindowCompat.setDecorFitsSystemWindows(window, false) setTheme(R.style.AppTheme) val componentContext = defaultComponentContext() - val rootComponent = DefaultRootComponent(componentContext, rootModule, servicesModule) + val rootComponent = DefaultRootComponent(componentContext, rootModule) val rootBottomSheetComponent = rootComponent.rootBottomSheetComponent setContent { @@ -51,7 +50,7 @@ class MainActivity : ComponentActivity() { } } } - ComposeApplication(rootModule.themeSwitcher.value) { + ComposeApplication(rootModule.themeSwitcherComponent.value) { ModalBottomSheetLayout( sheetState = bottomSheetState.sheetState, sheetContent = bottomSheetState.sheetContent.value, @@ -60,7 +59,6 @@ class MainActivity : ComponentActivity() { ) { ApplicationContent( rootComponent = rootComponent, - rootBottomSheetComponent = rootBottomSheetComponent, modifier = Modifier ) } diff --git a/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt b/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt similarity index 98% rename from modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt rename to modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt index 73466728..497a1536 100644 --- a/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt +++ b/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.makeevrserg.empireprojekt.mobile.services.core.AndroidLinkBrowser import com.makeevrserg.empireprojekt.mobile.services.core.LinkBrowser diff --git a/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt b/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt similarity index 98% rename from modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt rename to modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt index 8cfbb9dd..c387bc1b 100644 --- a/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt +++ b/modules/features/root/src/androidMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.russhwolf.settings.Settings import com.russhwolf.settings.SharedPreferencesSettings diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootComponent.kt index 6853ac33..07ec88db 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootComponent.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootComponent.kt @@ -2,85 +2,20 @@ package com.makeevrserg.empireprojekt.mobile.features.root import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.childContext -import com.arkivanov.decompose.router.stack.ChildStack -import com.arkivanov.decompose.router.stack.StackNavigation -import com.arkivanov.decompose.router.stack.childStack -import com.arkivanov.decompose.router.stack.pop -import com.arkivanov.decompose.router.stack.push -import com.arkivanov.decompose.router.stack.replaceAll -import com.arkivanov.decompose.router.stack.replaceCurrent -import com.arkivanov.decompose.value.Value -import com.makeevrserg.empireprojekt.mobile.features.logic.splash.SplashComponent -import com.makeevrserg.empireprojekt.mobile.features.logic.splash.SplashComponentImpl import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule -import com.makeevrserg.empireprojekt.mobile.features.root.di.ServicesModule -import com.makeevrserg.empireprojekt.mobile.features.root.di.impl.splash.SplashComponentModuleImpl -import com.makeevrserg.empireprojekt.mobile.features.status.root.RootStatusComponent -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.root.modal.DefaultRootBottomSheetComponent +import com.makeevrserg.empireprojekt.mobile.features.root.screen.DefaultRootScreenComponent class DefaultRootComponent( componentContext: ComponentContext, - rootModule: RootModule, - servicesModule: ServicesModule + rootModule: RootModule ) : RootComponent, ComponentContext by componentContext { - override val rootBottomSheetComponent: RootBottomSheetComponent = - DefaultRootBottomSheetComponent( - componentContext = childContext("RootBottomSheetComponent"), - servicesModule = servicesModule, - ) - private val navigation = StackNavigation() - - override val childStack: Value> = childStack( - source = navigation, - initialConfiguration = RootComponent.Child.Splash, - handleBackButton = true, - childFactory = { config, context -> - when (config) { - RootComponent.Child.Splash -> Configuration.Splash( - splashComponent = SplashComponentImpl( - context = context, - module = SplashComponentModuleImpl( - rootModule = rootModule, - servicesModule = servicesModule - ) - ) - ) - - RootComponent.Child.Status -> { - Configuration.Status( - themeSwitcher = rootModule.themeSwitcher.value, - rootStatusComponent = rootModule.rootStatusComponent.value - ) - } - } - } + override val rootBottomSheetComponent = DefaultRootBottomSheetComponent( + componentContext = childContext("RootBottomSheetComponent"), + servicesModule = rootModule.servicesModule, + ) + override val rootScreenComponent = DefaultRootScreenComponent( + componentContext = childContext("RootScreenComponent"), + rootModule = rootModule, ) - - override fun push(screen: RootComponent.Child) { - navigation.push(screen) - } - - override fun replaceCurrent(screen: RootComponent.Child) { - navigation.replaceCurrent(screen) - } - - override fun replaceAll(screen: RootComponent.Child) { - navigation.replaceAll(screen) - } - - override fun pop() { - navigation.pop() - } - - sealed interface Configuration { - - class Splash( - val splashComponent: SplashComponent - ) : Configuration - - class Status( - val rootStatusComponent: RootStatusComponent, - val themeSwitcher: ThemeSwitcher - ) : Configuration - } } diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootComponent.kt index d1bdb149..28a304f3 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootComponent.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootComponent.kt @@ -1,25 +1,9 @@ package com.makeevrserg.empireprojekt.mobile.features.root -import com.arkivanov.decompose.router.stack.ChildStack -import com.arkivanov.decompose.value.Value -import com.arkivanov.essenty.backhandler.BackHandlerOwner -import com.arkivanov.essenty.parcelable.Parcelable -import com.arkivanov.essenty.parcelable.Parcelize +import com.makeevrserg.empireprojekt.mobile.features.root.modal.RootBottomSheetComponent +import com.makeevrserg.empireprojekt.mobile.features.root.screen.RootScreenComponent -interface RootComponent : BackHandlerOwner { +interface RootComponent { + val rootScreenComponent: RootScreenComponent val rootBottomSheetComponent: RootBottomSheetComponent - val childStack: Value> - - fun push(screen: Child) - fun replaceCurrent(screen: Child) - fun replaceAll(screen: Child) - fun pop() - - sealed interface Child : Parcelable { - @Parcelize - object Splash : Child - - @Parcelize - object Status : Child - } } diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/RootModule.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/RootModule.kt index ebfafa52..1738d9cd 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/RootModule.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/RootModule.kt @@ -2,7 +2,7 @@ package com.makeevrserg.empireprojekt.mobile.features.root.di import com.makeevrserg.empireprojekt.mobile.features.root.di.impl.root.RootModuleImpl import com.makeevrserg.empireprojekt.mobile.features.status.root.RootStatusComponent -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import com.russhwolf.settings.Settings import kotlinx.coroutines.CoroutineScope import ru.astrainteractive.klibs.kdi.Module @@ -15,7 +15,7 @@ interface RootModule : Module { val settings: Single val dispatchers: Single val mainScope: Single - val themeSwitcher: Single + val themeSwitcherComponent: Single val rootStatusComponent: Single companion object : RootModule by RootModuleImpl } diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt similarity index 97% rename from modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt rename to modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt index be66437e..83fe86ca 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.makeevrserg.empireprojekt.mobile.services.core.LinkBrowser import ru.astrainteractive.klibs.kdi.Factory diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt similarity index 97% rename from modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt rename to modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt index f933ce85..da0ece6a 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.russhwolf.settings.Settings import ru.astrainteractive.klibs.kdi.Factory diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/RootModuleImpl.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/RootModuleImpl.kt index 0197e08d..c172f96c 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/RootModuleImpl.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/RootModuleImpl.kt @@ -1,11 +1,11 @@ package com.makeevrserg.empireprojekt.mobile.features.root.di.impl.root import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule -import com.makeevrserg.empireprojekt.mobile.features.root.di.factories.SettingsFactory +import com.makeevrserg.empireprojekt.mobile.features.root.di.factory.SettingsFactory import com.makeevrserg.empireprojekt.mobile.features.root.di.impl.status.StatusModuleImpl import com.makeevrserg.empireprojekt.mobile.features.status.root.DefaultRootStatusComponent import com.makeevrserg.empireprojekt.mobile.features.status.root.RootStatusComponent -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.DefaultThemeSwitcherComponentComponent import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import kotlinx.coroutines.MainScope import ru.astrainteractive.klibs.kdi.Single @@ -30,8 +30,8 @@ internal object RootModuleImpl : RootModule { override val mainScope = Single { MainScope() } - override val themeSwitcher: Single = Single { - ThemeSwitcherComponent(settings.value) + override val themeSwitcherComponent: Single = Single { + DefaultThemeSwitcherComponentComponent(settings.value) } override val rootStatusComponent: Single = Single { DefaultRootStatusComponent(StatusModuleImpl(this)) diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/ServicesModuleImpl.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/ServicesModuleImpl.kt index 91961cd9..a81b897d 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/ServicesModuleImpl.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/root/ServicesModuleImpl.kt @@ -1,7 +1,7 @@ package com.makeevrserg.empireprojekt.mobile.features.root.di.impl.root import com.makeevrserg.empireprojekt.mobile.features.root.di.ServicesModule -import com.makeevrserg.empireprojekt.mobile.features.root.di.factories.LinkBrowserFactory +import com.makeevrserg.empireprojekt.mobile.features.root.di.factory.LinkBrowserFactory import com.makeevrserg.empireprojekt.mobile.services.core.LinkBrowser import io.ktor.client.HttpClient import io.ktor.client.plugins.contentnegotiation.ContentNegotiation diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/splash/SplashComponentModuleImpl.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/splash/SplashComponentModuleImpl.kt index 60535685..39df9de4 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/splash/SplashComponentModuleImpl.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/impl/splash/SplashComponentModuleImpl.kt @@ -1,6 +1,7 @@ package com.makeevrserg.empireprojekt.mobile.features.root.di.impl.splash import com.makeevrserg.empireprojekt.mobile.features.logic.splash.data.SplashComponentRepository +import com.makeevrserg.empireprojekt.mobile.features.logic.splash.data.SplashComponentRepositoryImpl import com.makeevrserg.empireprojekt.mobile.features.logic.splash.di.SplashComponentModule import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule import com.makeevrserg.empireprojekt.mobile.features.root.di.ServicesModule @@ -18,6 +19,6 @@ class SplashComponentModuleImpl( override val scope: CoroutineScope by rootModule.mainScope override val dispatchers: KotlinDispatchers by rootModule.dispatchers override val repository: SplashComponentRepository = Provider { - SplashComponentRepository.Default() + SplashComponentRepositoryImpl() }.provide() } diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootBottomSheetComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/DefaultRootBottomSheetComponent.kt similarity index 95% rename from modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootBottomSheetComponent.kt rename to modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/DefaultRootBottomSheetComponent.kt index 813f2c18..60038c3e 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/DefaultRootBottomSheetComponent.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/DefaultRootBottomSheetComponent.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root +package com.makeevrserg.empireprojekt.mobile.features.root.modal import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.router.slot.ChildSlot diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootBottomSheetComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/RootBottomSheetComponent.kt similarity index 81% rename from modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootBottomSheetComponent.kt rename to modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/RootBottomSheetComponent.kt index 59380d83..98f8012f 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/RootBottomSheetComponent.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/modal/RootBottomSheetComponent.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root +package com.makeevrserg.empireprojekt.mobile.features.root.modal import com.arkivanov.decompose.router.slot.ChildSlot import com.arkivanov.decompose.value.Value @@ -12,6 +12,6 @@ interface RootBottomSheetComponent { sealed interface Child : Parcelable { @Parcelize - object Settings : Child + data object Settings : Child } } diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/DefaultRootScreenComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/DefaultRootScreenComponent.kt new file mode 100644 index 00000000..213b9221 --- /dev/null +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/DefaultRootScreenComponent.kt @@ -0,0 +1,65 @@ +package com.makeevrserg.empireprojekt.mobile.features.root.screen + +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.decompose.router.stack.ChildStack +import com.arkivanov.decompose.router.stack.StackNavigation +import com.arkivanov.decompose.router.stack.childStack +import com.arkivanov.decompose.router.stack.pop +import com.arkivanov.decompose.router.stack.push +import com.arkivanov.decompose.router.stack.replaceAll +import com.arkivanov.decompose.router.stack.replaceCurrent +import com.arkivanov.decompose.value.Value +import com.makeevrserg.empireprojekt.mobile.features.logic.splash.SplashComponent +import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule +import com.makeevrserg.empireprojekt.mobile.features.root.screen.di.factory.RootScreenComponentChildFactory +import com.makeevrserg.empireprojekt.mobile.features.status.root.RootStatusComponent +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent + +class DefaultRootScreenComponent( + componentContext: ComponentContext, + rootModule: RootModule, +) : RootScreenComponent, ComponentContext by componentContext { + + private val navigation = StackNavigation() + + override val childStack: Value> = childStack( + source = navigation, + initialConfiguration = RootScreenComponent.Child.Splash, + handleBackButton = true, + childFactory = { config, context -> + RootScreenComponentChildFactory( + config = config, + context = context, + rootModule = rootModule + ).create() + } + ) + + override fun push(screen: RootScreenComponent.Child) { + navigation.push(screen) + } + + override fun replaceCurrent(screen: RootScreenComponent.Child) { + navigation.replaceCurrent(screen) + } + + override fun replaceAll(screen: RootScreenComponent.Child) { + navigation.replaceAll(screen) + } + + override fun pop() { + navigation.pop() + } + + sealed interface Configuration { + + class Splash( + val splashComponent: SplashComponent + ) : Configuration + + class Status( + val rootStatusComponent: RootStatusComponent, + val themeSwitcherComponent: ThemeSwitcherComponent + ) : Configuration + } +} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/RootScreenComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/RootScreenComponent.kt new file mode 100644 index 00000000..bd6c5fb4 --- /dev/null +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/RootScreenComponent.kt @@ -0,0 +1,24 @@ +package com.makeevrserg.empireprojekt.mobile.features.root.screen + +import com.arkivanov.decompose.router.stack.ChildStack +import com.arkivanov.decompose.value.Value +import com.arkivanov.essenty.backhandler.BackHandlerOwner +import com.arkivanov.essenty.parcelable.Parcelable +import com.arkivanov.essenty.parcelable.Parcelize + +interface RootScreenComponent : BackHandlerOwner { + val childStack: Value> + + fun push(screen: Child) + fun replaceCurrent(screen: Child) + fun replaceAll(screen: Child) + fun pop() + + sealed interface Child : Parcelable { + @Parcelize + object Splash : Child + + @Parcelize + object Status : Child + } +} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/di/factory/RootScreenComponentChildFactory.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/di/factory/RootScreenComponentChildFactory.kt new file mode 100644 index 00000000..af744d33 --- /dev/null +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/screen/di/factory/RootScreenComponentChildFactory.kt @@ -0,0 +1,36 @@ +package com.makeevrserg.empireprojekt.mobile.features.root.screen.di.factory + +import com.arkivanov.decompose.ComponentContext +import com.makeevrserg.empireprojekt.mobile.features.logic.splash.DefaultSplashComponent +import com.makeevrserg.empireprojekt.mobile.features.root.di.RootModule +import com.makeevrserg.empireprojekt.mobile.features.root.di.impl.splash.SplashComponentModuleImpl +import com.makeevrserg.empireprojekt.mobile.features.root.screen.DefaultRootScreenComponent +import com.makeevrserg.empireprojekt.mobile.features.root.screen.RootScreenComponent +import ru.astrainteractive.klibs.kdi.Factory + +class RootScreenComponentChildFactory( + private val config: RootScreenComponent.Child, + private val context: ComponentContext, + private val rootModule: RootModule +) : Factory { + override fun create(): DefaultRootScreenComponent.Configuration { + return when (config) { + RootScreenComponent.Child.Splash -> DefaultRootScreenComponent.Configuration.Splash( + splashComponent = DefaultSplashComponent( + context = context, + module = SplashComponentModuleImpl( + rootModule = rootModule, + servicesModule = rootModule.servicesModule + ) + ) + ) + + RootScreenComponent.Child.Status -> { + DefaultRootScreenComponent.Configuration.Status( + themeSwitcherComponent = rootModule.themeSwitcherComponent.value, + rootStatusComponent = rootModule.rootStatusComponent.value + ) + } + } + } +} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/DefaultThemeSwitcherComponentComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/DefaultThemeSwitcherComponentComponent.kt new file mode 100644 index 00000000..84722115 --- /dev/null +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/DefaultThemeSwitcherComponentComponent.kt @@ -0,0 +1,42 @@ +package com.makeevrserg.empireprojekt.mobile.features.theme + +import com.russhwolf.settings.Settings +import kotlinx.coroutines.flow.StateFlow +import ru.astrainteractive.klibs.kstorage.StateFlowMutableStorageValue +import ru.astrainteractive.klibs.mikro.core.util.next + +class DefaultThemeSwitcherComponentComponent(private val settings: Settings) : ThemeSwitcherComponent { + private val key = "THEME" + private val default = ThemeSwitcherComponent.Theme.DARK + private val themeFlowStorageValue = StateFlowMutableStorageValue( + default = default, + loadSettingsValue = { + val ordinal = settings.getInt(key, ThemeSwitcherComponent.Theme.LIGHT.ordinal) + ThemeSwitcherComponent.Theme.values().getOrNull(ordinal) ?: default + }, + saveSettingsValue = { + settings.putInt(key, it.ordinal) + } + ) + override val theme: StateFlow = themeFlowStorageValue.stateFlow + + override fun selectDarkTheme() { + themeFlowStorageValue.save(ThemeSwitcherComponent.Theme.DARK) + } + + override fun selectLightTheme() { + themeFlowStorageValue.save(ThemeSwitcherComponent.Theme.LIGHT) + } + + override fun selectTheme(theme: ThemeSwitcherComponent.Theme) { + themeFlowStorageValue.save(theme) + } + + override fun next() { + selectTheme(theme.value.next(ThemeSwitcherComponent.Theme.values())) + } + + init { + themeFlowStorageValue.load() + } +} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcher.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcher.kt deleted file mode 100644 index 69ed4228..00000000 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcher.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.makeevrserg.empireprojekt.mobile.features.theme - -import kotlinx.coroutines.flow.MutableStateFlow -import ru.astrainteractive.klibs.mikro.core.util.next - -class PreviewThemeSwitcher : ThemeSwitcher { - override val theme: MutableStateFlow = - MutableStateFlow(ThemeSwitcher.Theme.LIGHT) - - override fun selectDarkTheme() { - selectTheme(ThemeSwitcher.Theme.DARK) - } - - override fun selectLightTheme() { - selectTheme(ThemeSwitcher.Theme.LIGHT) - } - - override fun selectTheme(theme: ThemeSwitcher.Theme) { - this.theme.value = theme - } - - override fun next() { - theme.value.next(ThemeSwitcher.Theme.values()).run(::selectTheme) - } -} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcherComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcherComponent.kt new file mode 100644 index 00000000..7a15d321 --- /dev/null +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/PreviewThemeSwitcherComponent.kt @@ -0,0 +1,25 @@ +package com.makeevrserg.empireprojekt.mobile.features.theme + +import kotlinx.coroutines.flow.MutableStateFlow +import ru.astrainteractive.klibs.mikro.core.util.next + +class PreviewThemeSwitcherComponent : ThemeSwitcherComponent { + override val theme: MutableStateFlow = + MutableStateFlow(ThemeSwitcherComponent.Theme.LIGHT) + + override fun selectDarkTheme() { + selectTheme(ThemeSwitcherComponent.Theme.DARK) + } + + override fun selectLightTheme() { + selectTheme(ThemeSwitcherComponent.Theme.LIGHT) + } + + override fun selectTheme(theme: ThemeSwitcherComponent.Theme) { + this.theme.value = theme + } + + override fun next() { + theme.value.next(ThemeSwitcherComponent.Theme.values()).run(::selectTheme) + } +} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcher.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcher.kt deleted file mode 100644 index 4cd49c17..00000000 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcher.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.makeevrserg.empireprojekt.mobile.features.theme - -import kotlinx.coroutines.flow.StateFlow - -interface ThemeSwitcher { - val theme: StateFlow - - enum class Theme { - DARK, LIGHT - } - - fun selectDarkTheme() - fun selectLightTheme() - fun selectTheme(theme: Theme) - fun next() -} diff --git a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcherComponent.kt b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcherComponent.kt index 9fa9e3d1..4bb7e468 100644 --- a/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcherComponent.kt +++ b/modules/features/root/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/theme/ThemeSwitcherComponent.kt @@ -1,42 +1,16 @@ package com.makeevrserg.empireprojekt.mobile.features.theme -import com.russhwolf.settings.Settings import kotlinx.coroutines.flow.StateFlow -import ru.astrainteractive.klibs.kstorage.StateFlowMutableStorageValue -import ru.astrainteractive.klibs.mikro.core.util.next -class ThemeSwitcherComponent(private val settings: Settings) : ThemeSwitcher { - private val key = "THEME" - private val default = ThemeSwitcher.Theme.DARK - private val themeFlowStorageValue = StateFlowMutableStorageValue( - default = default, - loadSettingsValue = { - val ordinal = settings.getInt(key, ThemeSwitcher.Theme.LIGHT.ordinal) - ThemeSwitcher.Theme.values().getOrNull(ordinal) ?: default - }, - saveSettingsValue = { - settings.putInt(key, it.ordinal) - } - ) - override val theme: StateFlow = themeFlowStorageValue.stateFlow +interface ThemeSwitcherComponent { + val theme: StateFlow - override fun selectDarkTheme() { - themeFlowStorageValue.save(ThemeSwitcher.Theme.DARK) + enum class Theme { + DARK, LIGHT } - override fun selectLightTheme() { - themeFlowStorageValue.save(ThemeSwitcher.Theme.LIGHT) - } - - override fun selectTheme(theme: ThemeSwitcher.Theme) { - themeFlowStorageValue.save(theme) - } - - override fun next() { - selectTheme(theme.value.next(ThemeSwitcher.Theme.values())) - } - - init { - themeFlowStorageValue.load() - } + fun selectDarkTheme() + fun selectLightTheme() + fun selectTheme(theme: Theme) + fun next() } diff --git a/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt b/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt similarity index 98% rename from modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt rename to modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt index be41b2da..1dcab638 100644 --- a/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/LinkBrowserFactory.kt +++ b/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/LinkBrowserFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.makeevrserg.empireprojekt.mobile.services.core.LinkBrowser import ru.astrainteractive.klibs.kdi.Factory diff --git a/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt b/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt similarity index 98% rename from modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt rename to modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt index 240aea4f..21370679 100644 --- a/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factories/SettingsFactory.kt +++ b/modules/features/root/src/iosMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/root/di/factory/SettingsFactory.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.features.root.di.factories +package com.makeevrserg.empireprojekt.mobile.features.root.di.factory import com.russhwolf.settings.NSUserDefaultsSettings import com.russhwolf.settings.Settings diff --git a/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentImpl.kt b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/DefaultSplashComponent.kt similarity index 96% rename from modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentImpl.kt rename to modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/DefaultSplashComponent.kt index 3a62bc3f..ff240c06 100644 --- a/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentImpl.kt +++ b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/DefaultSplashComponent.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.launch -class SplashComponentImpl( +class DefaultSplashComponent( context: ComponentContext, module: SplashComponentModule ) : SplashComponent, diff --git a/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepository.kt b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepository.kt index 1baba25c..472ff68f 100644 --- a/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepository.kt +++ b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepository.kt @@ -2,13 +2,4 @@ package com.makeevrserg.empireprojekt.mobile.features.logic.splash.data interface SplashComponentRepository { fun isInitialLaunch(): Boolean - - /** - * Default implementation for this interface from [LocalPreferenceSource] - */ - class Default : SplashComponentRepository { - override fun isInitialLaunch(): Boolean { - return true - } - } } diff --git a/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepositoryImpl.kt b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepositoryImpl.kt new file mode 100644 index 00000000..0e09947b --- /dev/null +++ b/modules/features/splash/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/data/SplashComponentRepositoryImpl.kt @@ -0,0 +1,7 @@ +package com.makeevrserg.empireprojekt.mobile.features.logic.splash.data + +class SplashComponentRepositoryImpl : SplashComponentRepository { + override fun isInitialLaunch(): Boolean { + return true + } +} diff --git a/modules/features/splash/src/commonTest/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentTest.kt b/modules/features/splash/src/commonTest/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentTest.kt index 8c9d4e9b..9bdbe979 100644 --- a/modules/features/splash/src/commonTest/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentTest.kt +++ b/modules/features/splash/src/commonTest/kotlin/com/makeevrserg/empireprojekt/mobile/features/logic/splash/SplashComponentTest.kt @@ -29,7 +29,7 @@ class SplashComponentTest { fun TEST_initial_launch_true(): Unit = runBlocking { val expectInitialLaunchValue = true val splashComponent = - SplashComponentImpl(componentContext, buildModule(expectInitialLaunchValue)) + DefaultSplashComponent(componentContext, buildModule(expectInitialLaunchValue)) splashComponent.screenChannelFlow.test { val item = awaitItem() assertTrue(item is SplashComponent.Label.InitialLaunch) @@ -41,7 +41,7 @@ class SplashComponentTest { fun TEST_initial_launch_false(): Unit = runBlocking { val expectInitialLaunchValue = false val splashComponent = - SplashComponentImpl(componentContext, buildModule(expectInitialLaunchValue)) + DefaultSplashComponent(componentContext, buildModule(expectInitialLaunchValue)) splashComponent.screenChannelFlow.test { val item = awaitItem() assertTrue(item is SplashComponent.Label.InitialLaunch) diff --git a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ApplicationContent.kt b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ApplicationContent.kt index 87709fe4..b7aa4b4d 100644 --- a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ApplicationContent.kt +++ b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ApplicationContent.kt @@ -8,18 +8,17 @@ import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.slide import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState -import com.makeevrserg.empireprojekt.mobile.features.root.DefaultRootComponent -import com.makeevrserg.empireprojekt.mobile.features.root.RootBottomSheetComponent +import com.makeevrserg.empireprojekt.mobile.features.root.RootComponent +import com.makeevrserg.empireprojekt.mobile.features.root.screen.DefaultRootScreenComponent import com.makeevrserg.empireprojekt.mobile.features.ui.splash.SplashScreenComponent import com.makeevrserg.empireprojekt.mobile.features.ui.status.StatusScreen @Composable fun ApplicationContent( - rootComponent: DefaultRootComponent, - rootBottomSheetComponent: RootBottomSheetComponent, + rootComponent: RootComponent, modifier: Modifier = Modifier ) { - val childStack by rootComponent.childStack.subscribeAsState() + val childStack by rootComponent.rootScreenComponent.childStack.subscribeAsState() Children( stack = childStack, modifier = modifier.fillMaxSize(), @@ -27,15 +26,14 @@ fun ApplicationContent( ) { configuration -> when (val screen = configuration.instance) { - is DefaultRootComponent.Configuration.Splash -> SplashScreenComponent( + is DefaultRootScreenComponent.Configuration.Splash -> SplashScreenComponent( rootComponent = rootComponent, splashComponent = screen.splashComponent ) - is DefaultRootComponent.Configuration.Status -> StatusScreen( + is DefaultRootScreenComponent.Configuration.Status -> StatusScreen( rootComponent = rootComponent, - rootBottomSheetComponent = rootBottomSheetComponent, - themeSwitcher = screen.themeSwitcher, + themeSwitcherComponent = screen.themeSwitcherComponent, rootStatusComponent = screen.rootStatusComponent ) } diff --git a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ComposeApplication.kt b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ComposeApplication.kt index ba620871..70d1d3ac 100644 --- a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ComposeApplication.kt +++ b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/root/ComposeApplication.kt @@ -8,17 +8,20 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import com.makeevrserg.empireprojekt.mobile.core.ui.theme.AppTheme import com.makeevrserg.empireprojekt.mobile.core.ui.theme.LocalAppTheme -import com.makeevrserg.empireprojekt.mobile.features.theme.PreviewThemeSwitcher -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.PreviewThemeSwitcherComponent +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent -fun ThemeSwitcher.Theme.toComposeTheme() = when (this) { - ThemeSwitcher.Theme.DARK -> AppTheme.DefaultDarkTheme - ThemeSwitcher.Theme.LIGHT -> AppTheme.DefaultLightTheme +fun ThemeSwitcherComponent.Theme.toComposeTheme() = when (this) { + ThemeSwitcherComponent.Theme.DARK -> AppTheme.DefaultDarkTheme + ThemeSwitcherComponent.Theme.LIGHT -> AppTheme.DefaultLightTheme } @Composable -fun ComposeApplication(themeSwitcher: ThemeSwitcher = PreviewThemeSwitcher(), content: @Composable () -> Unit) { - val theme by themeSwitcher.theme.collectAsState() +fun ComposeApplication( + themeSwitcherComponent: ThemeSwitcherComponent = PreviewThemeSwitcherComponent(), + content: @Composable () -> Unit +) { + val theme by themeSwitcherComponent.theme.collectAsState() val appTheme = theme.toComposeTheme() TransparentBars(appTheme.isDark) diff --git a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/splash/SplashScreen.kt b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/splash/SplashScreen.kt index df572811..0b53a831 100644 --- a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/splash/SplashScreen.kt +++ b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/splash/SplashScreen.kt @@ -16,21 +16,21 @@ import com.makeevrserg.empireprojekt.mobile.core.ui.asPainter import com.makeevrserg.empireprojekt.mobile.core.ui.components.navBarsPadding import com.makeevrserg.empireprojekt.mobile.core.ui.theme.AppTheme import com.makeevrserg.empireprojekt.mobile.features.logic.splash.SplashComponent -import com.makeevrserg.empireprojekt.mobile.features.root.DefaultRootComponent import com.makeevrserg.empireprojekt.mobile.features.root.RootComponent +import com.makeevrserg.empireprojekt.mobile.features.root.screen.RootScreenComponent import com.makeevrserg.empireprojekt.mobile.resources.MR import kotlinx.coroutines.flow.collectLatest @Composable fun SplashScreenComponent( splashComponent: SplashComponent, - rootComponent: DefaultRootComponent + rootComponent: RootComponent ) { LaunchedEffect(key1 = Unit) { splashComponent.screenChannelFlow.collectLatest { when (it) { is SplashComponent.Label.InitialLaunch -> { - rootComponent.replaceCurrent(RootComponent.Child.Status) + rootComponent.rootScreenComponent.replaceCurrent(RootScreenComponent.Child.Status) } } } diff --git a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/status/StatusScreen.kt b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/status/StatusScreen.kt index 17a4024a..70379aef 100644 --- a/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/status/StatusScreen.kt +++ b/modules/features/ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/features/ui/status/StatusScreen.kt @@ -18,19 +18,18 @@ import androidx.compose.ui.draw.clip import com.makeevrserg.empireprojekt.mobile.core.ui.asComposableString import com.makeevrserg.empireprojekt.mobile.core.ui.components.navBarsPadding import com.makeevrserg.empireprojekt.mobile.core.ui.theme.AppTheme -import com.makeevrserg.empireprojekt.mobile.features.root.DefaultRootComponent -import com.makeevrserg.empireprojekt.mobile.features.root.RootBottomSheetComponent +import com.makeevrserg.empireprojekt.mobile.features.root.RootComponent +import com.makeevrserg.empireprojekt.mobile.features.root.modal.RootBottomSheetComponent import com.makeevrserg.empireprojekt.mobile.features.status.root.RootStatusComponent -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import com.makeevrserg.empireprojekt.mobile.features.ui.status.widget.StatusWidget import com.makeevrserg.empireprojekt.mobile.resources.MR import ru.astrainteractive.klibs.mikro.core.util.next @Composable fun StatusScreen( - rootComponent: DefaultRootComponent, - rootBottomSheetComponent: RootBottomSheetComponent, - themeSwitcher: ThemeSwitcher, + rootComponent: RootComponent, + themeSwitcherComponent: ThemeSwitcherComponent, rootStatusComponent: RootStatusComponent, ) { Scaffold( @@ -40,7 +39,7 @@ fun StatusScreen( modifier = Modifier.navBarsPadding(), backgroundColor = AppTheme.materialColor.secondaryVariant, onClick = { - rootBottomSheetComponent.pushSlot(RootBottomSheetComponent.Child.Settings) + rootComponent.rootBottomSheetComponent.pushSlot(RootBottomSheetComponent.Child.Settings) }, ) { Icon( @@ -65,9 +64,10 @@ fun StatusScreen( modifier = Modifier .clip(CircleShape) .clickable { - val nextTheme = - themeSwitcher.theme.value.next(ThemeSwitcher.Theme.values()) - themeSwitcher.selectTheme(nextTheme) + val nextTheme = themeSwitcherComponent.theme.value.next( + ThemeSwitcherComponent.Theme.values() + ) + themeSwitcherComponent.selectTheme(nextTheme) } ) } diff --git a/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/ComposeUtils.kt b/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/ComposeUtils.kt similarity index 88% rename from modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/ComposeUtils.kt rename to modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/ComposeUtils.kt index 9141f2f0..b2707540 100644 --- a/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/ComposeUtils.kt +++ b/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/ComposeUtils.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.utils +package com.makeevrserg.empireprojekt.mobile.util import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.LinearOutSlowInEasing diff --git a/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/SharedBackHandler.kt b/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/SharedBackHandler.kt similarity index 90% rename from modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/SharedBackHandler.kt rename to modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/SharedBackHandler.kt index b234aebe..08088c79 100644 --- a/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/utils/SharedBackHandler.kt +++ b/modules/services/core-ui/src/commonMain/kotlin/com/makeevrserg/empireprojekt/mobile/util/SharedBackHandler.kt @@ -1,4 +1,4 @@ -package com.makeevrserg.empireprojekt.mobile.utils +package com.makeevrserg.empireprojekt.mobile.util import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect diff --git a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/MainActivity.kt b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/MainActivity.kt index acddb54a..095e3a3e 100644 --- a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/MainActivity.kt +++ b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/MainActivity.kt @@ -20,7 +20,7 @@ class MainActivity : ComponentActivity() { setContent { val navController = rememberSwipeDismissableNavController() val navHostRootComponent = NavHostRootComponent(navController) - ComposeApplication(rootModule.themeSwitcher.value) { + ComposeApplication(rootModule.themeSwitcherComponent.value) { NavigationScreen(navHostRootComponent) } } diff --git a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/WearRootModule.kt b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/WearRootModule.kt index 111d233e..65f45d9e 100644 --- a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/WearRootModule.kt +++ b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/WearRootModule.kt @@ -1,6 +1,6 @@ package com.makeevrserg.empireprojekt.mobile.wear.di -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import com.makeevrserg.empireprojekt.mobile.wear.di.impl.WearRootModuleImpl import com.makeevrserg.empireprojekt.mobile.wear.features.status.WearStatusComponent import com.russhwolf.settings.Settings @@ -12,7 +12,7 @@ import ru.astrainteractive.klibs.mikro.platform.PlatformConfiguration interface WearRootModule : Module { val platformConfiguration: Lateinit val settings: Single - val themeSwitcher: Single + val themeSwitcherComponent: Single val wearStatusComponent: Single companion object : WearRootModule by WearRootModuleImpl diff --git a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/impl/WearRootModuleImpl.kt b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/impl/WearRootModuleImpl.kt index d4298384..6c02bb5c 100644 --- a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/impl/WearRootModuleImpl.kt +++ b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/di/impl/WearRootModuleImpl.kt @@ -1,7 +1,7 @@ package com.makeevrserg.empireprojekt.mobile.wear.di.impl -import com.makeevrserg.empireprojekt.mobile.features.root.di.factories.SettingsFactory -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.root.di.factory.SettingsFactory +import com.makeevrserg.empireprojekt.mobile.features.theme.DefaultThemeSwitcherComponentComponent import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import com.makeevrserg.empireprojekt.mobile.wear.di.WearRootModule import com.makeevrserg.empireprojekt.mobile.wear.features.status.WearStatusComponent @@ -16,8 +16,8 @@ object WearRootModuleImpl : WearRootModule { val configuration by platformConfiguration SettingsFactory(configuration).create() } - override val themeSwitcher: Single = Single { - ThemeSwitcherComponent(settings.value) + override val themeSwitcherComponent: Single = Single { + DefaultThemeSwitcherComponentComponent(settings.value) } override val wearStatusComponent: Single = Single { WearStatusComponent.Stub() diff --git a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/MainScreen.kt b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/MainScreen.kt index 8c651732..60336f3d 100644 --- a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/MainScreen.kt +++ b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/MainScreen.kt @@ -25,7 +25,7 @@ fun MainScreen( wearRootModule: WearRootModule, rootComponent: NavHostRootComponent ) { - val themeSwitcher by wearRootModule.themeSwitcher + val themeSwitcher by wearRootModule.themeSwitcherComponent Scaffold( modifier = Modifier.background(AppTheme.materialColor.primaryVariant), vignette = { @@ -42,7 +42,7 @@ fun MainScreen( horizontalAlignment = Alignment.CenterHorizontally ) { Spacer(modifier = Modifier.height(AppTheme.dimens.S)) - ThemeChip(themeSwitcher = themeSwitcher) + ThemeChip(themeSwitcherComponent = themeSwitcher) Spacer(modifier = Modifier.height(AppTheme.dimens.S)) NavChip( text = "Statuses", diff --git a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/components/ThemeChip.kt b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/components/ThemeChip.kt index 6a931776..25b0cd85 100644 --- a/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/components/ThemeChip.kt +++ b/wearApp/src/main/java/com/makeevrserg/empireprojekt/mobile/wear/features/main/components/ThemeChip.kt @@ -17,20 +17,20 @@ import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Icon import androidx.wear.compose.material.Text import com.makeevrserg.empireprojekt.mobile.core.ui.theme.AppTheme -import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcher +import com.makeevrserg.empireprojekt.mobile.features.theme.ThemeSwitcherComponent import com.makeevrserg.empireprojekt.mobile.wear.features.components.AstraChip @Composable -fun ThemeChip(themeSwitcher: ThemeSwitcher) { - val theme by themeSwitcher.theme.collectAsState() +fun ThemeChip(themeSwitcherComponent: ThemeSwitcherComponent) { + val theme by themeSwitcherComponent.theme.collectAsState() val icon = when (theme) { - ThemeSwitcher.Theme.DARK -> Icons.Filled.Bedtime - ThemeSwitcher.Theme.LIGHT -> Icons.Filled.WbSunny + ThemeSwitcherComponent.Theme.DARK -> Icons.Filled.Bedtime + ThemeSwitcherComponent.Theme.LIGHT -> Icons.Filled.WbSunny } val color by animateColorAsState( targetValue = when (theme) { - ThemeSwitcher.Theme.DARK -> AppTheme.materialColor.onPrimary - ThemeSwitcher.Theme.LIGHT -> AppTheme.materialColor.onPrimary + ThemeSwitcherComponent.Theme.DARK -> AppTheme.materialColor.onPrimary + ThemeSwitcherComponent.Theme.LIGHT -> AppTheme.materialColor.onPrimary }, label = "LABEL" ) @@ -43,7 +43,7 @@ fun ThemeChip(themeSwitcher: ThemeSwitcher) { color = AppTheme.materialColor.onPrimary ) }, - onClick = themeSwitcher::next, + onClick = themeSwitcherComponent::next, icon = { Crossfade(targetState = icon, label = "LABEL") { Icon(