Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpeapsUnterstrichHD committed Jul 13, 2024
1 parent 1ce8e5e commit e1cdec4
Show file tree
Hide file tree
Showing 30 changed files with 3,331 additions and 220 deletions.
7 changes: 1 addition & 6 deletions .fleet/receipt.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
"ui": [
"compose"
]
},
"server": {
"engine": [
"ktor"
]
}
}
},
"timestamp": "2024-07-12T21:59:47.449382473Z"
"timestamp": "2024-07-13T08:27:56.900120496Z"
}
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop, Server.
This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop.

* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
It contains several subfolders:
Expand All @@ -10,11 +10,6 @@ This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop, Ser
* `/iosApp` contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform,
you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.

* `/server` is for the Ktor server application.

* `/shared` is for the code that will be shared between all targets in the project.
The most important subfolder is `commonMain`. If preferred, you can add code to the platform-specific folders here too.


Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html),
[Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform),
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ plugins {
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
}
33 changes: 23 additions & 10 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ kotlin {
}
binaries.executable()
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

jvm("desktop")

listOf(
iosX64(),
iosArm64(),
Expand All @@ -48,13 +48,14 @@ kotlin {
isStatic = true
}
}

sourceSets {
val desktopMain by getting

androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.navigation.compose)
}
commonMain.dependencies {
implementation(compose.runtime)
Expand All @@ -63,7 +64,8 @@ kotlin {
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(projects.shared)


}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
Expand All @@ -73,16 +75,16 @@ kotlin {

android {
namespace = "comboom.sucht.app"
compileSdk = libs.versions.android.compileSdk.get().toInt()
compileSdk = 35

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
applicationId = "comboom.sucht.app"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
minSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"
}
Expand All @@ -103,18 +105,29 @@ android {
buildFeatures {
compose = true
}
buildToolsVersion = "35.0.0"

dependencies {
debugImplementation(compose.uiTooling)
}
}
dependencies {
implementation(libs.androidx.foundation.android)
implementation(libs.androidx.ui.graphics.android)
implementation(libs.androidx.material3.android)
implementation(libs.androidx.ui.android)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.ui.tooling.preview.android)

}

compose.desktop {
application {
mainClass = "MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "comboom.sucht.app"
packageName = "comboom.sucht"
packageVersion = "1.0.0"
}
}
Expand Down
6 changes: 0 additions & 6 deletions composeApp/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

2 changes: 1 addition & 1 deletion composeApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">comboom_sucht_App</string>
<string name="app_name">comboom_sucht_app</string>
</resources>
218 changes: 173 additions & 45 deletions composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -1,64 +1,192 @@
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.*
import kotlinx.coroutines.delay

import comboom_sucht_app.composeapp.generated.resources.Res
import comboom_sucht_app.composeapp.generated.resources.compose_multiplatform
enum class ColorMode {
SYSTEM, LIGHT, DARK
}

val DarkColorPalette = darkColors(
primary = Color(0xFF00FF00),
primaryVariant = Color(0xFF00AA00),
onPrimary = Color(0xFF000000),
secondary = Color(0xFF0000FF),
secondaryVariant = Color(0xFFAA0000),
onSecondary = Color(0xFF000000),
background = Color(0xFF000000),
onBackground = Color(0xFFFFFFFF),
surface = Color(0xFF000000),
onSurface = Color(0xFFFFFFFF),
error = Color(0xFFFF0000),
onError = Color(0xFFFFFFFF)
)

val LightColorPalette = lightColors(
primary = Color(0xFF00FF00),
primaryVariant = Color(0xFF00AA00),
onPrimary = Color(0xFF000000),
secondary = Color(0xFF0000FF),
secondaryVariant = Color(0xFFAA0000),
onSecondary = Color(0xFF000000),
background = Color(0xFFFFFFFF),
onBackground = Color(0xFF000000),
surface = Color(0xFFFFFFFF),
onSurface = Color(0xFF000000),
error = Color(0xFFFF0000),
onError = Color(0xFF000000)
)

@Composable
@Preview
fun App() {
val darkColors = darkColors(
primary = Color(0xFF00FF00),
primaryVariant = Color(0xFF00AA00),
onPrimary = Color(0xFF000000),
secondary = Color(0xFF0000FF),
secondaryVariant = Color(0xFFAA0000),
onSecondary = Color(0xFF000000),
background = Color(0xFF000000),
onBackground = Color(0xFFFFFFFF),
surface = Color(0xFF000000),
onSurface = Color(0xFFFFFFFF),
onError = Color(0xFFFF0000)
)
fun rememberColorMode(): MutableState<ColorMode> {
return remember { mutableStateOf(ColorMode.SYSTEM) }
}

@Composable
fun MyAppTheme(colorMode: ColorMode, content: @Composable () -> Unit) {
val colors = when (colorMode) {
ColorMode.SYSTEM -> if (isSystemInDarkTheme()) DarkColorPalette else LightColorPalette
ColorMode.LIGHT -> LightColorPalette
ColorMode.DARK -> DarkColorPalette
}

val lightColors = lightColors(
primary = Color(0xFF00FF00),
primaryVariant = Color(0xFF00AA00),
onPrimary = Color(0xFF000000),
secondary = Color(0xFF0000FF),
secondaryVariant = Color(0xFFAA0000),
onSecondary = Color(0xFF000000),
background = Color(0xFF000000),
onBackground = Color(0xFFFFFFFF),
surface = Color(0xFF000000),
onSurface = Color(0xFFFFFFFF),
onError = Color(0xFFFF0000)
MaterialTheme(
colors = colors,
typography = Typography(),
shapes = Shapes(),
content = content
)
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun SettingsPage(colorMode: MutableState<ColorMode>, openDrawer: () -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Settings", style = MaterialTheme.typography.h4)
Spacer(modifier = Modifier.height(16.dp))

Button(onClick = { colorMode.value = ColorMode.SYSTEM }) {
Text("System")
}
Spacer(modifier = Modifier.height(8.dp))

Button(onClick = { colorMode.value = ColorMode.LIGHT }) {
Text("Light")
}
Spacer(modifier = Modifier.height(8.dp))

Button(onClick = { colorMode.value = ColorMode.DARK }) {
Text("Dark")
}
Spacer(modifier = Modifier.height(32.dp))

val colors = if (isSystemInDarkTheme()) darkColors else lightColors
Button(
onClick = openDrawer,
modifier = Modifier.align(Alignment.CenterHorizontally)
) {
Text("Menu")
}
}
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomePage(openDrawer: () -> Unit) {
val currentTime = remember { mutableStateOf("") }

LaunchedEffect(Unit) {
while (true) {
currentTime.value = java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.getDefault()).format(java.util.Date())
delay(1000L)
}
}

Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text("Home", style = MaterialTheme.typography.h4)
Spacer(modifier = Modifier.height(16.dp))
Text("Current Time:", style = MaterialTheme.typography.h6)
Spacer(modifier = Modifier.height(8.dp))
Text(currentTime.value, style = MaterialTheme.typography.h3)
}
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
@Preview
fun App() {
val colorMode = rememberColorMode()
val scaffoldState = rememberScaffoldState()

MyAppTheme(colorMode.value) {
val navController = rememberNavController()

MaterialTheme(colors = colors) {
Scaffold(
scaffoldState = scaffoldState,
drawerBackgroundColor = MaterialTheme.colors.background,
drawerContent = {
Column {
Text(
text = "Menu",
style = MaterialTheme.typography.h4,
modifier = Modifier.padding(16.dp),
color = MaterialTheme.colors.onPrimary
)
Divider()
TextButton(onClick = { navController.navigate("home") }) {
Text("Home", color = MaterialTheme.colors.onPrimary)
}
TextButton(onClick = { navController.navigate("settings") }) {
Text("Settings", color = MaterialTheme.colors.onPrimary)
}
}
},
topBar = {
TopAppBar(
title = { Text("comboom.sucht", color = MaterialTheme.colors.onBackground) },
backgroundColor = MaterialTheme.colors.background,
navigationIcon = {
TextButton(onClick = {
scope.launch {
scaffoldState.drawerState.snapTo(DrawerValue.Open)
}
}) {
Text("Menu", color = MaterialTheme.colors.onBackground)
}
}

var showContent by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { showContent = !showContent }, colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colors.primary)) {
Text("Click me!", color = MaterialTheme.colors.onPrimary)
)
}
AnimatedVisibility(showContent) {
val greeting = remember { Greeting().greet() }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Image(painterResource(Res.drawable.compose_multiplatform), null)
Text("Compose: $greeting")
) {
NavHost(navController, startDestination = "home") {
composable("home") {
HomePage{ scope.launch {
scaffoldState.drawerState.snapTo(DrawerValue.Open)
} }
}
composable("settings") {
SettingsPage(colorMode, openDrawer = { scope.launch {
scaffoldState.drawerState.snapTo(DrawerValue.Open)
} })
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion composeApp/src/desktopMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fun main() = application {
onCloseRequest = ::exitApplication,
title = "comboom.sucht",
focusable = true,
undecorated = true
undecorated = false
) {
App()
}
Expand Down
File renamed without changes.
Loading

0 comments on commit e1cdec4

Please sign in to comment.