Skip to content

Commit a02e870

Browse files
author
vadim
committed
application init
1 parent 76614a9 commit a02e870

File tree

34 files changed

+833
-0
lines changed

34 files changed

+833
-0
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Default ignored files
2+
/shelf/
3+
/workspace.xml
4+
# Datasource local storage ignored files
5+
/dataSources/
6+
/dataSources.local.xml
7+
# Editor-based HTTP Client requests
8+
/httpRequests/
9+
/build
10+
/android/build
11+
/buildSrc/build
12+
/common/build
13+
/desktop/build
14+
/.idea
15+
/.gradle
16+
local.properties
17+
/buildSrc/.gradle/
18+
/gradlew
19+
/gradlew.bat

android/build.gradle.kts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
plugins {
2+
id("org.jetbrains.compose")
3+
id("com.android.application")
4+
kotlin("android")
5+
id("kotlin-parcelize")
6+
}
7+
8+
group = AppConfig.PACKAGE
9+
version = AppConfig.VERSION
10+
11+
repositories {
12+
google()
13+
}
14+
15+
dependencies {
16+
implementation(project(":common"))
17+
}
18+
19+
android {
20+
compileSdkVersion(AppConfig.Android.TARGET_SDK)
21+
defaultConfig {
22+
applicationId = "com.notes.android"
23+
minSdkVersion(AppConfig.Android.MIN_SDK)
24+
targetSdkVersion(AppConfig.Android.TARGET_SDK)
25+
versionCode = AppConfig.VERSION_CODE
26+
versionName = AppConfig.VERSION
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+
}

android/src/main/AndroidManifest.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.notes.android">
3+
<application
4+
android:allowBackup="false"
5+
android:supportsRtl="true"
6+
android:label="Notes"
7+
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
8+
<activity android:name=".MainActivity" android:exported="true">
9+
<intent-filter>
10+
<action android:name="android.intent.action.MAIN"/>
11+
<category android:name="android.intent.category.LAUNCHER"/>
12+
</intent-filter>
13+
</activity>
14+
</application>
15+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.notes.android
2+
3+
import android.os.Bundle
4+
import androidx.activity.compose.setContent
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.compose.material.MaterialTheme
7+
import androidx.compose.material.Surface
8+
import com.arkivanov.decompose.defaultComponentContext
9+
import com.notes.common.DriverFactory
10+
import com.notes.navigation.NavHostComponent
11+
12+
class MainActivity : AppCompatActivity() {
13+
override fun onCreate(savedInstanceState: Bundle?) {
14+
super.onCreate(savedInstanceState)
15+
val componentContext = defaultComponentContext()
16+
setContent {
17+
MaterialTheme {
18+
Surface {
19+
NavHostComponent(DriverFactory(this), componentContext).render()
20+
}
21+
}
22+
}
23+
}
24+
}

build.gradle.kts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
buildscript {
2+
repositories {
3+
gradlePluginPortal()
4+
google()
5+
mavenCentral()
6+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev/")
7+
}
8+
dependencies {
9+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
10+
classpath("com.android.tools.build:gradle:4.2.2")
11+
classpath("com.squareup.sqldelight:gradle-plugin:1.5.1")
12+
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha3")
13+
}
14+
}
15+
16+
group = "com.notes"
17+
version = "1.0"
18+
19+
allprojects {
20+
repositories {
21+
mavenCentral()
22+
google()
23+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
24+
}
25+
}

buildSrc/build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}

buildSrc/src/main/kotlin/AppConfig.kt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object AppConfig {
2+
const val PACKAGE = "com.notes"
3+
const val VERSION = "1.0"
4+
const val VERSION_CODE = 1
5+
6+
object Android {
7+
const val MIN_SDK = 24
8+
const val TARGET_SDK = 31
9+
}
10+
}

buildSrc/src/main/kotlin/Deps.kt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
object Deps {
2+
object Plugins {
3+
object Jetbrains {
4+
object Compose {
5+
const val Id = "org.jetbrains.compose"
6+
}
7+
8+
object Kotlin {
9+
object Multiplatform {
10+
const val Id = "org.jetbrains.kotlin.multiplatform"
11+
}
12+
13+
object Parcelize {
14+
const val Id = "kotlin-parcelize"
15+
}
16+
}
17+
}
18+
19+
object Android {
20+
object Library {
21+
const val Id = "com.android.library"
22+
}
23+
}
24+
25+
object SQDelight {
26+
const val Id = "com.squareup.sqldelight"
27+
}
28+
}
29+
30+
object Libs {
31+
object Androidx {
32+
private const val Version = "1.3.1"
33+
const val Activity = "androidx.activity:activity-compose:$Version"
34+
const val AppCompat = "androidx.appcompat:appcompat:$Version"
35+
const val CoreKtx = "androidx.core:core-ktx:1.6.0"
36+
}
37+
38+
const val JUnit = "junit:junit:4.13.2"
39+
40+
object SQLDelight {
41+
private const val Version = "1.5.1"
42+
const val Runtime = "com.squareup.sqldelight:runtime:$Version"
43+
const val AndroidDriver = "com.squareup.sqldelight:android-driver:$Version"
44+
const val SqliteDriver = "com.squareup.sqldelight:sqlite-driver:$Version"
45+
}
46+
47+
object Decompose {
48+
private const val Version = "0.3.1"
49+
const val Decompose = "com.arkivanov.decompose:decompose:$Version"
50+
const val JetbrainsComposeExtensions = "com.arkivanov.decompose:extensions-compose-jetbrains:$Version"
51+
}
52+
}
53+
}

common/build.gradle.kts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import org.jetbrains.compose.compose
2+
3+
plugins {
4+
id(Deps.Plugins.Jetbrains.Kotlin.Multiplatform.Id)
5+
id(Deps.Plugins.Jetbrains.Compose.Id)
6+
id(Deps.Plugins.Android.Library.Id)
7+
id(Deps.Plugins.SQDelight.Id)
8+
id(Deps.Plugins.Jetbrains.Kotlin.Parcelize.Id)
9+
}
10+
11+
group = AppConfig.PACKAGE
12+
version = AppConfig.VERSION
13+
14+
repositories {
15+
google()
16+
}
17+
18+
kotlin {
19+
android()
20+
jvm("desktop") {
21+
compilations.all {
22+
kotlinOptions.jvmTarget = "11"
23+
}
24+
}
25+
sourceSets {
26+
val commonMain by getting {
27+
dependencies {
28+
api(compose.runtime)
29+
api(compose.foundation)
30+
api(compose.material)
31+
api(Deps.Libs.SQLDelight.Runtime)
32+
api(Deps.Libs.Decompose.Decompose)
33+
api(Deps.Libs.Decompose.JetbrainsComposeExtensions)
34+
}
35+
}
36+
val commonTest by getting {
37+
dependencies {
38+
//implementation(kotlin("test"))
39+
}
40+
}
41+
val androidMain by getting {
42+
dependencies {
43+
api(Deps.Libs.Androidx.AppCompat)
44+
api(Deps.Libs.Androidx.CoreKtx)
45+
api(Deps.Libs.Androidx.Activity)
46+
api(Deps.Libs.SQLDelight.AndroidDriver)
47+
}
48+
}
49+
val androidTest by getting {
50+
dependencies {
51+
implementation(Deps.Libs.JUnit)
52+
}
53+
}
54+
val desktopMain by getting {
55+
dependencies {
56+
api(Deps.Libs.SQLDelight.SqliteDriver)
57+
}
58+
}
59+
val desktopTest by getting
60+
}
61+
}
62+
63+
android {
64+
compileSdkVersion(AppConfig.Android.TARGET_SDK)
65+
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
66+
defaultConfig {
67+
minSdkVersion(AppConfig.Android.MIN_SDK)
68+
targetSdkVersion(AppConfig.Android.TARGET_SDK)
69+
}
70+
}
71+
72+
sqldelight {
73+
database("NoteDatabase") {
74+
packageName = "${AppConfig.PACKAGE}.database"
75+
sourceFolders = listOf("sqldelight")
76+
schemaOutputDirectory = file("build/dbs")
77+
dialect = "sqlite:3.25"
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.notes.database
2+
3+
data class Note(
4+
val id: Long,
5+
val name: String,
6+
val text: String
7+
) {
8+
override fun toString(): String = """
9+
|Note [
10+
| id: $id
11+
| name: $name
12+
| text: $text
13+
|]
14+
""".trimMargin()
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.notes.common"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.notes.common
2+
3+
import android.content.Context
4+
import com.notes.database.NoteDatabase
5+
import com.squareup.sqldelight.android.AndroidSqliteDriver
6+
import com.squareup.sqldelight.db.SqlDriver
7+
8+
actual class DriverFactory(private val context: Context) {
9+
actual fun createDriver(): SqlDriver {
10+
return AndroidSqliteDriver(NoteDatabase.Schema, context, "notes.db")
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.notes.common
2+
3+
actual fun getPlatformName(): String {
4+
return "Android"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.notes.common
2+
3+
import com.notes.database.NoteDatabase
4+
import com.squareup.sqldelight.db.SqlDriver
5+
6+
expect class DriverFactory {
7+
fun createDriver(): SqlDriver
8+
}
9+
10+
fun createDatabase(driverFactory: DriverFactory): NoteDatabase {
11+
val driver = driverFactory.createDriver()
12+
NoteDatabase.Schema.create(driver)
13+
return NoteDatabase(driver)
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.notes.common
2+
3+
expect fun getPlatformName(): String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.notes.components
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.rememberCoroutineScope
5+
import kotlinx.coroutines.CoroutineScope
6+
7+
interface Component {
8+
/**
9+
* Default components [CoroutineScope]'s.
10+
*/
11+
val coroutineScope: CoroutineScope
12+
@Composable
13+
get() = rememberCoroutineScope()
14+
15+
@Composable
16+
fun render()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.notes.components
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.State
5+
6+
interface NoteEditor : Component {
7+
val isSaving: State<Boolean>
8+
9+
val title: State<String>
10+
val text: State<String>
11+
12+
fun processTitle(input: String)
13+
fun processText(input: String)
14+
15+
@Composable
16+
fun save()
17+
}

0 commit comments

Comments
 (0)