Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiebe committed May 7, 2023
1 parent c30df6c commit 2828d49
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation(Compose.activity)
implementation(Compose.runtime)
implementation(Compose.ui)
implementation(Compose.material3)
implementation(Compose.foundationLayout)
implementation(Compose.material)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package nl.tiebe.otarium.androidApp

import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import com.arkivanov.decompose.defaultComponentContext
import nl.tiebe.otarium.RootView
import nl.tiebe.otarium.ui.theme.DarkColorScheme
import nl.tiebe.otarium.ui.theme.LightColorScheme
import nl.tiebe.otarium.utils.refreshGradesBackground
import nl.tiebe.otarium.utils.reloadTokensBackground
import nl.tiebe.otarium.utils.ui.Android
Expand Down Expand Up @@ -35,8 +41,25 @@ class MainActivity : AppCompatActivity() {

val rootComponentContext = defaultComponentContext()

val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val darkMode = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES

val colorScheme =
when {
dynamicColor && darkMode -> {
dynamicDarkColorScheme(Android.context)
}

dynamicColor && !darkMode -> {
dynamicLightColorScheme(Android.context)
}

darkMode -> DarkColorScheme
else -> LightColorScheme
}

setContent {
RootView(rootComponentContext)
RootView(rootComponentContext, colorScheme)
}
}

Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Version {
const val appcompat = "1.6.1"
const val material = "1.4.0"
const val compose = "1.4.0"
const val compose_android = "1.4.0"
const val compose_android = "1.4.3"
const val compose_compiler = "1.4.0"
const val ktor = "2.3.0"
const val decompose = "2.0.0-compose-experimental-alpha-02"
Expand All @@ -30,6 +30,7 @@ object Compose {
const val ui = "androidx.compose.ui:ui:${Version.compose_android}"
const val foundationLayout = "androidx.compose.foundation:foundation-layout:${Version.compose_android}"
const val material = "androidx.compose.material:material:${Version.compose_android}"
const val material3 = "androidx.compose.material3:material3:1.0.1"
}


Expand Down
22 changes: 2 additions & 20 deletions shared/src/androidMain/kotlin/nl/tiebe/otarium/RootViewAndroid.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
package nl.tiebe.otarium

import android.os.Build
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.arkivanov.decompose.DefaultComponentContext
import nl.tiebe.otarium.ui.theme.DarkColorScheme
import nl.tiebe.otarium.ui.theme.LightColorScheme

@Composable
fun RootView(rootComponentContext: DefaultComponentContext) {
fun RootView(rootComponentContext: DefaultComponentContext, colorScheme: ColorScheme) {
ProvideComponentContext(rootComponentContext) {
setup()

val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S

val colorScheme = when {
dynamicColor && darkModeState.value -> {
dynamicDarkColorScheme(LocalContext.current)
}
dynamicColor && !darkModeState.value -> {
dynamicLightColorScheme(LocalContext.current)
}
darkModeState.value -> DarkColorScheme
else -> LightColorScheme
}

Content(componentContext = rootComponentContext, colorScheme = colorScheme)
}
}
8 changes: 2 additions & 6 deletions shared/src/commonMain/kotlin/nl/tiebe/otarium/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package nl.tiebe.otarium

import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
Expand All @@ -30,6 +25,7 @@ lateinit var darkModeState: MutableState<Boolean>
val safeAreaState = mutableStateOf(PaddingValues())

fun setup() {

val oldVersion = settings.getInt("version", 1000)

runVersionCheck(oldVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import nl.tiebe.otarium.utils.icons.bottombar.*
interface HomeComponent {
val dialog: Value<ChildSlot<MenuItem, MenuItemComponent>>

val visibleItems: List<MenuItem> get() = listOf(MenuItem.Timetable, MenuItem.Grades, MenuItem.Settings)
val visibleItems: List<MenuItem> get() = listOf(MenuItem.Timetable, MenuItem.Grades, MenuItem.Messages, MenuItem.Settings)

@Parcelize
sealed class MenuItem(val resourceId: StringResource, val icon: @Composable () -> Unit, val iconSelected: @Composable () -> Unit): Parcelable {
Expand Down Expand Up @@ -70,7 +70,8 @@ class DefaultHomeComponent(componentContext: ComponentContext, override val navi

override val dialog: Value<ChildSlot<HomeComponent.MenuItem, MenuItemComponent>> = childSlot<HomeComponent.MenuItem, MenuItemComponent>(
dialogNavigation,
"DefaultChildOverlay", { HomeComponent.MenuItem.Timetable },
"HomeComponentChildOverlay",
{ HomeComponent.MenuItem.Timetable },
persistent = true,
handleBackButton = false
) { config, componentContext ->
Expand Down Expand Up @@ -113,6 +114,10 @@ class DefaultHomeComponent(componentContext: ComponentContext, override val navi

private var clickCount: Pair<HomeComponent.MenuItem, Int> = HomeComponent.MenuItem.Timetable to 0

init {
println("init")
}

override fun navigate(item: HomeComponent.MenuItem) {
dialogNavigation.activate(item)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ class DefaultRootComponent(componentContext: ComponentContext): RootComponent, C
}
)

private fun homeComponent(componentContext: ComponentContext): HomeComponent =
DefaultHomeComponent(
private fun homeComponent(componentContext: ComponentContext): HomeComponent {
println("HomeComponent")
return DefaultHomeComponent(
componentContext = componentContext,
navigateRootComponent = { screen ->
currentScreen.value = screen
}
)
}

private fun loginComponent(componentContext: ComponentContext): DefaultLoginComponent =
DefaultLoginComponent(
Expand Down

0 comments on commit 2828d49

Please sign in to comment.