Skip to content

Commit 4108b08

Browse files
committed
Step 5 - SKIE
1 parent 3ab7b1b commit 4108b08

File tree

33 files changed

+1382
-0
lines changed

33 files changed

+1382
-0
lines changed

step5_skie/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
.idea
4+
.DS_Store
5+
build
6+
*/build
7+
captures
8+
.externalNativeBuild
9+
.cxx
10+
local.properties
11+
xcuserdata/
12+
Pods/
13+
/androidApp/key
14+
*.jks
15+
*yarn.lock
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
plugins {
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.kotlinAndroid)
4+
}
5+
6+
android {
7+
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
8+
compileSdk = 34
9+
defaultConfig {
10+
applicationId = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
11+
minSdk = 24
12+
targetSdk = 34
13+
versionCode = 1
14+
versionName = "1.0"
15+
}
16+
buildFeatures {
17+
compose = true
18+
}
19+
composeOptions {
20+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
21+
}
22+
packaging {
23+
resources {
24+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
25+
excludes += "META-INF/versions/9/previous-compilation-data.bin"
26+
}
27+
}
28+
buildTypes {
29+
getByName("release") {
30+
isMinifyEnabled = false
31+
}
32+
}
33+
compileOptions {
34+
sourceCompatibility = JavaVersion.VERSION_1_8
35+
targetCompatibility = JavaVersion.VERSION_1_8
36+
}
37+
kotlinOptions {
38+
jvmTarget = "1.8"
39+
}
40+
}
41+
42+
dependencies {
43+
implementation(projects.shared)
44+
implementation(libs.compose.ui)
45+
implementation(libs.compose.ui.tooling.preview)
46+
implementation(libs.compose.material3)
47+
implementation(libs.androidx.activity.compose)
48+
implementation(libs.androidx.lifecycle.runtime.compose)
49+
debugImplementation(libs.compose.ui.tooling)
50+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-permission android:name="android.permission.INTERNET"/>
4+
<application
5+
android:allowBackup="false"
6+
android:supportsRtl="true"
7+
android:theme="@style/AppTheme">
8+
<activity
9+
android:name="com.jetbrains.simplelogin.kotlinmultiplatformsandbox.MainActivity"
10+
android:exported="true">
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN" />
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
</application>
17+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.activity.viewModels
7+
import androidx.compose.foundation.layout.Arrangement
8+
import androidx.compose.foundation.layout.PaddingValues
9+
import androidx.compose.foundation.layout.fillMaxSize
10+
import androidx.compose.foundation.lazy.LazyColumn
11+
import androidx.compose.foundation.lazy.items
12+
import androidx.compose.material3.Divider
13+
import androidx.compose.material3.MaterialTheme
14+
import androidx.compose.material3.Surface
15+
import androidx.compose.material3.Text
16+
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.tooling.preview.Preview
19+
import androidx.compose.ui.unit.dp
20+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
21+
22+
class MainActivity : ComponentActivity() {
23+
private val mainViewModel: MainViewModel by viewModels()
24+
25+
override fun onCreate(savedInstanceState: Bundle?) {
26+
super.onCreate(savedInstanceState)
27+
setContent {
28+
MyApplicationTheme {
29+
Surface(
30+
modifier = Modifier.fillMaxSize(),
31+
color = MaterialTheme.colorScheme.background
32+
) {
33+
val greetings = mainViewModel.greetingList.collectAsStateWithLifecycle()
34+
GreetingView(phrases = greetings.value)
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
@Composable
42+
fun GreetingView(phrases: List<String>) {
43+
LazyColumn(
44+
contentPadding = PaddingValues(20.dp),
45+
verticalArrangement = Arrangement.spacedBy(8.dp),
46+
) {
47+
items(phrases) { phrase ->
48+
Text(phrase)
49+
Divider()
50+
}
51+
}
52+
}
53+
54+
55+
@Preview
56+
@Composable
57+
fun DefaultPreview() {
58+
MyApplicationTheme {
59+
GreetingView(listOf("Hello, Android!"))
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.viewModelScope
5+
import kotlinx.coroutines.flow.MutableStateFlow
6+
import kotlinx.coroutines.flow.SharingStarted
7+
import kotlinx.coroutines.flow.StateFlow
8+
import kotlinx.coroutines.flow.stateIn
9+
import kotlinx.coroutines.flow.update
10+
import kotlinx.coroutines.launch
11+
12+
class MainViewModel : ViewModel() {
13+
private val _greetingList = MutableStateFlow<List<String>>(listOf())
14+
val greetingList: StateFlow<List<String>> get() = _greetingList
15+
16+
init {
17+
viewModelScope.launch {
18+
Greeting().greet().collect { phrase ->
19+
_greetingList.update { list -> list + phrase }
20+
}
21+
}
22+
}
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.foundation.shape.RoundedCornerShape
5+
import androidx.compose.material3.MaterialTheme
6+
import androidx.compose.material3.Shapes
7+
import androidx.compose.material3.Typography
8+
import androidx.compose.material3.darkColorScheme
9+
import androidx.compose.material3.lightColorScheme
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.graphics.Color
12+
import androidx.compose.ui.text.TextStyle
13+
import androidx.compose.ui.text.font.FontFamily
14+
import androidx.compose.ui.text.font.FontWeight
15+
import androidx.compose.ui.unit.dp
16+
import androidx.compose.ui.unit.sp
17+
18+
@Composable
19+
fun MyApplicationTheme(
20+
darkTheme: Boolean = isSystemInDarkTheme(),
21+
content: @Composable () -> Unit
22+
) {
23+
val colors = if (darkTheme) {
24+
darkColorScheme(
25+
primary = Color(0xFFBB86FC),
26+
secondary = Color(0xFF03DAC5)
27+
)
28+
} else {
29+
lightColorScheme(
30+
primary = Color(0xFF6200EE),
31+
secondary = Color(0xFF03DAC5)
32+
)
33+
}
34+
val typography = Typography(
35+
bodyLarge = TextStyle(
36+
fontFamily = FontFamily.Default,
37+
fontWeight = FontWeight.Normal,
38+
fontSize = 16.sp
39+
)
40+
)
41+
val shapes = Shapes(
42+
small = RoundedCornerShape(4.dp),
43+
medium = RoundedCornerShape(4.dp),
44+
large = RoundedCornerShape(0.dp)
45+
)
46+
47+
MaterialTheme(
48+
colorScheme = colors,
49+
typography = typography,
50+
shapes = shapes,
51+
content = content
52+
)
53+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"/>
3+
</resources>

step5_skie/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
//trick: for the same plugin versions in all sub-modules
3+
alias(libs.plugins.androidApplication).apply(false)
4+
alias(libs.plugins.androidLibrary).apply(false)
5+
alias(libs.plugins.kotlinAndroid).apply(false)
6+
alias(libs.plugins.kotlinMultiplatform).apply(false)
7+
kotlin("plugin.serialization").version("1.9.20").apply(false)
8+
}
9+
10+
tasks.register("clean", Delete::class) {
11+
delete(rootProject.buildDir)
12+
}

step5_skie/gradle.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Gradle
2+
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
3+
org.gradle.caching=true
4+
5+
#Kotlin
6+
kotlin.code.style=official
7+
8+
#Android
9+
android.useAndroidX=true
10+
android.nonTransitiveRClass=true
11+
12+
org.gradle.configuration-cache=false

step5_skie/gradle/libs.versions.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[versions]
2+
agp = "8.2.0-rc03"
3+
kotlin = "1.9.20"
4+
compose = "1.5.4"
5+
compose-compiler = "1.5.4"
6+
compose-material3 = "1.1.2"
7+
androidx-activityCompose = "1.8.0"
8+
lifecycleRuntimeCompose = "2.6.2"
9+
10+
[libraries]
11+
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycleRuntimeCompose" }
12+
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
13+
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
14+
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
15+
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
16+
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
17+
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
18+
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
19+
20+
[plugins]
21+
androidApplication = { id = "com.android.application", version.ref = "agp" }
22+
androidLibrary = { id = "com.android.library", version.ref = "agp" }
23+
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
24+
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
25+
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }

0 commit comments

Comments
 (0)