From 6b4c307aaac4e29918924ea7c43a38b831af7677 Mon Sep 17 00:00:00 2001 From: Adit Lal Date: Sun, 23 Jun 2024 13:53:30 +0530 Subject: [PATCH] Adds step 4 - adds sql build fixes --- composeApp/build.gradle.kts | 62 +++++++++---------- .../src/androidMain/AndroidManifest.xml | 4 +- .../academy}/NotesAppApplication.kt | 4 +- .../NotesDatabaseDriverFactory.android.kt | 15 +++++ .../app/academy/di/AppModule.android.kt | 41 ++++++++++++ .../academy/di/DispatchersProvider.android.kt | 8 +++ .../app/academy/notes/MainActivity.kt | 18 ++---- .../academy/utils/NativeStateFlow.android.kt | 8 +++ .../app/academy/utils/Platform.android.kt | 10 +++ .../kotlin/app/academy/utils/UUID.android.kt | 8 +++ .../app/academy/components/NoteItems.kt | 4 +- .../app/academy/components/NoteListCard.kt | 4 +- .../components/SwipeableNoteListCard.kt | 4 +- .../academy}/data/DefaultNotesRepository.kt | 13 ++-- .../app/academy}/data/NotesRepository.kt | 4 +- .../data/local/NotesDatabaseDriverFactory.kt | 2 +- .../datasource/DefaultLocalNotesDataSource.kt | 14 ++--- .../local/datasource/LocalNotesDataSource.kt | 10 +-- .../kotlin/app/academy/di/AppModule.kt | 16 +++++ .../app/academy/di/DispatchersProvider.kt | 17 +++++ .../app/academy/domain/HomeViewModel.kt | 6 ++ .../kotlin/app/academy}/model/Note.kt | 57 +++++++++-------- .../app/academy/theme/NotesAppTheme.kt | 2 +- .../commonMain/kotlin/app/academy/ui/App.kt | 14 +++++ .../academy => app/academy/ui}/DemoScreen.kt | 2 +- .../academy => app/academy/ui}/HomeScreen.kt | 6 +- .../academy/ui}/NotesNavigation.kt | 7 ++- .../kotlin/app/academy}/utils/Constants.kt | 0 .../kotlin/app/academy}/utils/Greeting.kt | 2 + .../app/academy}/utils/NativeStateFlow.kt | 2 +- .../kotlin/app/academy}/utils/Platform.kt | 2 +- .../kotlin/app/academy}/utils/UUID.kt | 2 +- .../commonMain/kotlin/com/app/academy/App.kt | 31 ---------- .../academy/notes/database/NotesDatabase.sq | 33 ++++++++++ .../app/academy/di/AppModule.desktop.kt | 20 ++++++ .../academy/di/DispatchersProvider.desktop.kt | 8 +++ composeApp/src/desktopMain/kotlin/main.kt | 12 ---- .../src/iosMain/kotlin/MainViewController.kt | 2 +- .../local/NotesDatabaseDriverFactory.ios.kt | 13 ++++ .../kotlin/app/academy/di/AppModule.ios.kt | 31 ++++++++++ .../app/academy/di/DispatchersProvider.ios.kt | 8 +++ .../app/academy/utils/NativeStateFlow.ios.kt | 21 +++++++ .../kotlin/app/academy/utils/Platform.ios.kt | 10 +++ .../kotlin/app/academy/utils/UUID.ios.kt | 10 +++ .../kotlin/app/academy/di/AppModule.wasmJs.kt | 20 ++++++ .../academy/di/DispatchersProvider.wasmJs.kt | 8 +++ composeApp/src/wasmJsMain/kotlin/main.kt | 11 ---- .../src/wasmJsMain/resources/index.html | 12 ---- .../src/wasmJsMain/resources/styles.css | 7 --- server/build.gradle.kts | 21 ------- .../com/app/academy/notes/Application.kt | 22 ------- server/src/main/resources/logback.xml | 12 ---- settings.gradle.kts | 2 - shared/build.gradle.kts | 7 --- .../NotesDatabaseDriverFactory.android.kt | 2 + 55 files changed, 441 insertions(+), 250 deletions(-) rename composeApp/src/androidMain/kotlin/{com/app/academy/notes => app/academy}/NotesAppApplication.kt (58%) create mode 100644 composeApp/src/androidMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.android.kt create mode 100644 composeApp/src/androidMain/kotlin/app/academy/di/AppModule.android.kt create mode 100644 composeApp/src/androidMain/kotlin/app/academy/di/DispatchersProvider.android.kt rename composeApp/src/androidMain/kotlin/{com => }/app/academy/notes/MainActivity.kt (56%) create mode 100644 composeApp/src/androidMain/kotlin/app/academy/utils/NativeStateFlow.android.kt create mode 100644 composeApp/src/androidMain/kotlin/app/academy/utils/Platform.android.kt create mode 100644 composeApp/src/androidMain/kotlin/app/academy/utils/UUID.android.kt rename composeApp/src/commonMain/kotlin/{com => }/app/academy/components/NoteItems.kt (92%) rename composeApp/src/commonMain/kotlin/{com => }/app/academy/components/NoteListCard.kt (96%) rename composeApp/src/commonMain/kotlin/{com => }/app/academy/components/SwipeableNoteListCard.kt (94%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/data/DefaultNotesRepository.kt (66%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/data/NotesRepository.kt (86%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/data/local/NotesDatabaseDriverFactory.kt (83%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/data/local/datasource/DefaultLocalNotesDataSource.kt (82%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/data/local/datasource/LocalNotesDataSource.kt (84%) create mode 100644 composeApp/src/commonMain/kotlin/app/academy/di/AppModule.kt create mode 100644 composeApp/src/commonMain/kotlin/app/academy/di/DispatchersProvider.kt create mode 100644 composeApp/src/commonMain/kotlin/app/academy/domain/HomeViewModel.kt rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/model/Note.kt (94%) rename composeApp/src/commonMain/kotlin/{com => }/app/academy/theme/NotesAppTheme.kt (87%) create mode 100644 composeApp/src/commonMain/kotlin/app/academy/ui/App.kt rename composeApp/src/commonMain/kotlin/{com/app/academy => app/academy/ui}/DemoScreen.kt (98%) rename composeApp/src/commonMain/kotlin/{com/app/academy => app/academy/ui}/HomeScreen.kt (80%) rename composeApp/src/commonMain/kotlin/{com/app/academy => app/academy/ui}/NotesNavigation.kt (69%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/utils/Constants.kt (100%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/utils/Greeting.kt (86%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/utils/NativeStateFlow.kt (89%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/utils/Platform.kt (70%) rename {shared/src/commonMain/kotlin/app/architect/notes => composeApp/src/commonMain/kotlin/app/academy}/utils/UUID.kt (82%) delete mode 100644 composeApp/src/commonMain/kotlin/com/app/academy/App.kt create mode 100644 composeApp/src/commonMain/sqldelight/app/academy/notes/database/NotesDatabase.sq create mode 100644 composeApp/src/desktopMain/kotlin/app/academy/di/AppModule.desktop.kt create mode 100644 composeApp/src/desktopMain/kotlin/app/academy/di/DispatchersProvider.desktop.kt delete mode 100644 composeApp/src/desktopMain/kotlin/main.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.ios.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/di/AppModule.ios.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/di/DispatchersProvider.ios.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/utils/NativeStateFlow.ios.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/utils/Platform.ios.kt create mode 100644 composeApp/src/iosMain/kotlin/app/academy/utils/UUID.ios.kt create mode 100644 composeApp/src/wasmJsMain/kotlin/app/academy/di/AppModule.wasmJs.kt create mode 100644 composeApp/src/wasmJsMain/kotlin/app/academy/di/DispatchersProvider.wasmJs.kt delete mode 100644 composeApp/src/wasmJsMain/kotlin/main.kt delete mode 100644 composeApp/src/wasmJsMain/resources/index.html delete mode 100644 composeApp/src/wasmJsMain/resources/styles.css delete mode 100644 server/build.gradle.kts delete mode 100644 server/src/main/kotlin/com/app/academy/notes/Application.kt delete mode 100644 server/src/main/resources/logback.xml diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index e7df99f..03928af 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,58 +1,40 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat -import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) + id("app.cash.sqldelight") version "2.0.2" } kotlin { - @OptIn(ExperimentalWasmDsl::class) - wasmJs { - moduleName = "composeApp" - browser { - commonWebpackConfig { - outputFileName = "composeApp.js" - devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { - static = (static ?: mutableListOf()).apply { - // Serve sources to debug inside browser - add(project.projectDir.path) - } - } + android { + compilations.all { + kotlinOptions { + jvmTarget = "11" } } - binaries.executable() } - androidTarget { - @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) - } - } - - jvm("desktop") - listOf( iosX64(), iosArm64(), iosSimulatorArm64() - ).forEach { iosTarget -> - iosTarget.binaries.framework { + ).forEach { + it.binaries.framework { baseName = "ComposeApp" isStatic = true + if (System.getenv("XCODE_VERSION_MAJOR") == "1500") { + linkerOpts += "-ld64" + } } } sourceSets { - val desktopMain by getting - androidMain.dependencies { + // sql-delight driver - Android + implementation(libs.android.driver) implementation(compose.preview) implementation(libs.androidx.activity.compose) } @@ -63,13 +45,19 @@ kotlin { implementation(compose.ui) implementation(compose.components.resources) implementation(compose.components.uiToolingPreview) - implementation(projects.shared) implementation(libs.voyager.navigator) implementation(libs.voyager.navigator.transitions) implementation(libs.voyager.screenmodel) + // sql-delight runtime + implementation(libs.runtime.v200) + // flows support for sql-delight + implementation(libs.coroutines.extensions) + // date-time + implementation(libs.kotlinx.datetime.v041) } - desktopMain.dependencies { - implementation(compose.desktop.currentOs) + + iosMain.dependencies { + implementation(libs.native.driver.v200) } } } @@ -125,3 +113,11 @@ compose.desktop { } } } + +sqldelight { + databases { + create("NotesDatabase") { + packageName.set("com.app.academy.notes.database") + } + } +} diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml index ff9ccec..b7b1c53 100644 --- a/composeApp/src/androidMain/AndroidManifest.xml +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -2,7 +2,7 @@ diff --git a/composeApp/src/androidMain/kotlin/com/app/academy/notes/NotesAppApplication.kt b/composeApp/src/androidMain/kotlin/app/academy/NotesAppApplication.kt similarity index 58% rename from composeApp/src/androidMain/kotlin/com/app/academy/notes/NotesAppApplication.kt rename to composeApp/src/androidMain/kotlin/app/academy/NotesAppApplication.kt index ada24db..4371d2b 100644 --- a/composeApp/src/androidMain/kotlin/com/app/academy/notes/NotesAppApplication.kt +++ b/composeApp/src/androidMain/kotlin/app/academy/NotesAppApplication.kt @@ -1,8 +1,10 @@ -package app.architect.notes +package app.academy import android.app.Application +import app.academy.di.AppModule class NotesAppApplication : Application() { + val appModule by lazy { AppModule(this) } override fun onCreate() { super.onCreate() diff --git a/composeApp/src/androidMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.android.kt b/composeApp/src/androidMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.android.kt new file mode 100644 index 0000000..aee6d8a --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.android.kt @@ -0,0 +1,15 @@ +package app.academy.data.local + +import android.content.Context +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.driver.android.AndroidSqliteDriver +import com.app.academy.notes.database.NotesDatabase + +actual class NotesDatabaseDriverFactory(private val context: Context) { + actual fun createDriver(): SqlDriver = AndroidSqliteDriver( + schema = NotesDatabase.Schema, + context = context, + name = DatabaseDriverConstants.DATABASE_NAME + ) + +} diff --git a/composeApp/src/androidMain/kotlin/app/academy/di/AppModule.android.kt b/composeApp/src/androidMain/kotlin/app/academy/di/AppModule.android.kt new file mode 100644 index 0000000..64a08ee --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/di/AppModule.android.kt @@ -0,0 +1,41 @@ +package app.academy.di + +import android.content.Context +import app.academy.data.DefaultNotesRepository +import app.academy.data.NotesRepository +import app.academy.data.local.NotesDatabaseDriverFactory +import app.academy.data.local.datasource.DefaultLocalNotesDataSource +import com.app.academy.notes.database.NotesDatabase +import kotlinx.coroutines.Dispatchers + +actual class AppModule(context: Context) { + + private val database by lazy { + val driver = NotesDatabaseDriverFactory(context).createDriver() + NotesDatabase(driver) + } + + /** + * Provides an implementation of [NotesRepository] + */ + actual fun provideNotesRepository(): NotesRepository { + val localNotesDataSource = DefaultLocalNotesDataSource( + database = database, + ioDispatcher = Dispatchers.IO + ) + return DefaultNotesRepository(localNotesDataSource = localNotesDataSource) + } + + + /** + * Used to provide an instance of [DispatchersProvider] + */ + actual fun provideDispatchersProvider(): DispatchersProviderList { + return DispatchersProviderList( + ioDispatcher = Dispatchers.IO, + defaultDispatcher = Dispatchers.Default, + mainDispatcher = Dispatchers.Main + ) + } + +} diff --git a/composeApp/src/androidMain/kotlin/app/academy/di/DispatchersProvider.android.kt b/composeApp/src/androidMain/kotlin/app/academy/di/DispatchersProvider.android.kt new file mode 100644 index 0000000..ac4ed7b --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/di/DispatchersProvider.android.kt @@ -0,0 +1,8 @@ +package app.academy.di + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +actual object DispatchersProvider { + actual val io: CoroutineDispatcher = Dispatchers.IO +} diff --git a/composeApp/src/androidMain/kotlin/com/app/academy/notes/MainActivity.kt b/composeApp/src/androidMain/kotlin/app/academy/notes/MainActivity.kt similarity index 56% rename from composeApp/src/androidMain/kotlin/com/app/academy/notes/MainActivity.kt rename to composeApp/src/androidMain/kotlin/app/academy/notes/MainActivity.kt index eb4b60f..bcd172a 100644 --- a/composeApp/src/androidMain/kotlin/com/app/academy/notes/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/app/academy/notes/MainActivity.kt @@ -1,24 +1,18 @@ -package com.app.academy.notes +package app.academy.notes -import com.app.academy.App import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.runtime.Composable -import androidx.compose.ui.tooling.preview.Preview +import app.academy.NotesAppApplication +import app.academy.ui.App class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - + val application = this.application as NotesAppApplication + val appModule = application.appModule setContent { - App() + App(appModule) } } } - -@Preview -@Composable -fun AppAndroidPreview() { - App() -} diff --git a/composeApp/src/androidMain/kotlin/app/academy/utils/NativeStateFlow.android.kt b/composeApp/src/androidMain/kotlin/app/academy/utils/NativeStateFlow.android.kt new file mode 100644 index 0000000..f7adf3f --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/utils/NativeStateFlow.android.kt @@ -0,0 +1,8 @@ +package app.academy.utils + +import kotlinx.coroutines.flow.StateFlow + +/** + * A cross platform implementation of [StateFlow]. + */ +actual class NativeStateFlow actual constructor(source: StateFlow) : StateFlow by source diff --git a/composeApp/src/androidMain/kotlin/app/academy/utils/Platform.android.kt b/composeApp/src/androidMain/kotlin/app/academy/utils/Platform.android.kt new file mode 100644 index 0000000..0f57b4b --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/utils/Platform.android.kt @@ -0,0 +1,10 @@ +package app.academy.utils + +class AndroidPlatform : Platform { + override val name: String + get() = "Android" +} + +actual fun getPlatform(): Platform { + return AndroidPlatform() +} diff --git a/composeApp/src/androidMain/kotlin/app/academy/utils/UUID.android.kt b/composeApp/src/androidMain/kotlin/app/academy/utils/UUID.android.kt new file mode 100644 index 0000000..663efab --- /dev/null +++ b/composeApp/src/androidMain/kotlin/app/academy/utils/UUID.android.kt @@ -0,0 +1,8 @@ +package app.academy.utils + +/** + * A class that is used to generate a unique UUID (Universally Unique Identifier) string. + */ +actual object UUID { + actual fun randomUUIDString(): String = java.util.UUID.randomUUID().toString() +} diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/components/NoteItems.kt b/composeApp/src/commonMain/kotlin/app/academy/components/NoteItems.kt similarity index 92% rename from composeApp/src/commonMain/kotlin/com/app/academy/components/NoteItems.kt rename to composeApp/src/commonMain/kotlin/app/academy/components/NoteItems.kt index b788fed..73b91ff 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/components/NoteItems.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/components/NoteItems.kt @@ -1,4 +1,4 @@ -package com.app.academy.components +package app.academy.components import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.fillMaxWidth @@ -7,7 +7,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.items import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import app.architect.notes.model.Note +import app.academy.model.Note @OptIn(ExperimentalFoundationApi::class) fun LazyListScope.NoteItems( diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/components/NoteListCard.kt b/composeApp/src/commonMain/kotlin/app/academy/components/NoteListCard.kt similarity index 96% rename from composeApp/src/commonMain/kotlin/com/app/academy/components/NoteListCard.kt rename to composeApp/src/commonMain/kotlin/app/academy/components/NoteListCard.kt index 562cfa2..5b882af 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/components/NoteListCard.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/components/NoteListCard.kt @@ -1,4 +1,4 @@ -package com.app.academy.components +package app.academy.components import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -14,7 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import app.architect.notes.model.Note +import app.academy.model.Note /** * A composable that displays the information of a [Note], in a card. Some of the contents diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/components/SwipeableNoteListCard.kt b/composeApp/src/commonMain/kotlin/app/academy/components/SwipeableNoteListCard.kt similarity index 94% rename from composeApp/src/commonMain/kotlin/com/app/academy/components/SwipeableNoteListCard.kt rename to composeApp/src/commonMain/kotlin/app/academy/components/SwipeableNoteListCard.kt index 9f597fa..6c398ba 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/components/SwipeableNoteListCard.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/components/SwipeableNoteListCard.kt @@ -1,4 +1,4 @@ -package com.app.academy.components +package app.academy.components import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.DismissDirection @@ -9,7 +9,7 @@ import androidx.compose.material.SwipeToDismiss import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import app.architect.notes.model.Note +import app.academy.model.Note @OptIn(ExperimentalMaterialApi::class) @Composable diff --git a/shared/src/commonMain/kotlin/app/architect/notes/data/DefaultNotesRepository.kt b/composeApp/src/commonMain/kotlin/app/academy/data/DefaultNotesRepository.kt similarity index 66% rename from shared/src/commonMain/kotlin/app/architect/notes/data/DefaultNotesRepository.kt rename to composeApp/src/commonMain/kotlin/app/academy/data/DefaultNotesRepository.kt index d360dc9..8a2d3d0 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/data/DefaultNotesRepository.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/data/DefaultNotesRepository.kt @@ -1,9 +1,10 @@ -package app.architect.notes.data +package app.academy.data -import app.architect.notes.data.local.datasource.LocalNotesDataSource -import app.architect.notes.model.Note -import app.architect.notes.model.toNote -import app.architect.notes.model.toSavedNoteEntity +import app.academy.data.local.datasource.LocalNotesDataSource +import app.academy.model.Note +import app.academy.model.toNote +import app.academy.model.toSavedNoteEntity +import app.academy.notes.database.SavedNoteEntity import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -13,7 +14,7 @@ class DefaultNotesRepository( override val savedNotesStream: Flow> = localNotesDataSource.savedNotesStream.map { savedNoteEntities -> - savedNoteEntities.map { savedNoteEntity -> savedNoteEntity.toNote() } + savedNoteEntities.map { savedNoteEntity: SavedNoteEntity -> savedNoteEntity.toNote() } } override suspend fun saveNote(note: Note) { diff --git a/shared/src/commonMain/kotlin/app/architect/notes/data/NotesRepository.kt b/composeApp/src/commonMain/kotlin/app/academy/data/NotesRepository.kt similarity index 86% rename from shared/src/commonMain/kotlin/app/architect/notes/data/NotesRepository.kt rename to composeApp/src/commonMain/kotlin/app/academy/data/NotesRepository.kt index 67f2564..7dc4ace 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/data/NotesRepository.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/data/NotesRepository.kt @@ -1,6 +1,6 @@ -package app.architect.notes.data +package app.academy.data -import app.architect.notes.model.Note +import app.academy.model.Note import kotlinx.coroutines.flow.Flow interface NotesRepository { diff --git a/shared/src/commonMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.kt b/composeApp/src/commonMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.kt similarity index 83% rename from shared/src/commonMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.kt rename to composeApp/src/commonMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.kt index ef3ff34..eeda38c 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.kt @@ -1,4 +1,4 @@ -package app.architect.notes.data.local +package app.academy.data.local import app.cash.sqldelight.db.SqlDriver diff --git a/shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/DefaultLocalNotesDataSource.kt b/composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/DefaultLocalNotesDataSource.kt similarity index 82% rename from shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/DefaultLocalNotesDataSource.kt rename to composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/DefaultLocalNotesDataSource.kt index 0063757..298e501 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/DefaultLocalNotesDataSource.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/DefaultLocalNotesDataSource.kt @@ -1,10 +1,9 @@ -package app.architect.notes.data.local.datasource +package app.academy.data.local.datasource -import app.architect.notes.data.local.datasource.LocalNotesDataSource +import app.academy.notes.database.SavedNoteEntity import app.cash.sqldelight.coroutines.asFlow import app.cash.sqldelight.coroutines.mapToList -import com.example.notes.database.NotesDatabase -import com.example.notes.database.SavedNoteEntity +import com.app.academy.notes.database.NotesDatabase import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.withContext @@ -15,9 +14,10 @@ class DefaultLocalNotesDataSource( ) : LocalNotesDataSource { private val queries = database.notesDatabaseQueries - override val savedNotesStream: Flow> = queries.getAllSavedNotes() - .asFlow() - .mapToList(ioDispatcher) + override val savedNotesStream: Flow> = + queries.getAllSavedNotes() + .asFlow() + .mapToList(ioDispatcher) override suspend fun saveNote(noteEntity: SavedNoteEntity) = withContext(ioDispatcher) { queries.insertNote( diff --git a/shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/LocalNotesDataSource.kt b/composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/LocalNotesDataSource.kt similarity index 84% rename from shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/LocalNotesDataSource.kt rename to composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/LocalNotesDataSource.kt index 62cf782..230dfbc 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/data/local/datasource/LocalNotesDataSource.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/data/local/datasource/LocalNotesDataSource.kt @@ -1,7 +1,6 @@ -package app.architect.notes.data.local.datasource - -import com.example.notes.database.SavedNoteEntity +package app.academy.data.local.datasource +import app.academy.notes.database.SavedNoteEntity import kotlinx.coroutines.flow.Flow /** @@ -9,13 +8,14 @@ import kotlinx.coroutines.flow.Flow */ interface LocalNotesDataSource { /** - * A [Flow] of all saved notes. + * A [Flow] of all saved notes. */ val savedNotesStream: Flow> /** * Used to save a note. - */ + * */ + suspend fun saveNote(noteEntity: SavedNoteEntity) /** diff --git a/composeApp/src/commonMain/kotlin/app/academy/di/AppModule.kt b/composeApp/src/commonMain/kotlin/app/academy/di/AppModule.kt new file mode 100644 index 0000000..9e6330d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/app/academy/di/AppModule.kt @@ -0,0 +1,16 @@ +package app.academy.di + +import app.academy.data.NotesRepository + +expect class AppModule { + /** + * Provides an implementation of [NotesRepository] + */ + fun provideNotesRepository(): NotesRepository + + /** + * Used to provide an instance of [DispatchersProviderList] + */ + fun provideDispatchersProvider(): DispatchersProviderList + +} diff --git a/composeApp/src/commonMain/kotlin/app/academy/di/DispatchersProvider.kt b/composeApp/src/commonMain/kotlin/app/academy/di/DispatchersProvider.kt new file mode 100644 index 0000000..ac2f774 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/app/academy/di/DispatchersProvider.kt @@ -0,0 +1,17 @@ +package app.academy.di + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +expect object DispatchersProvider { + val io: CoroutineDispatcher +} + +/** + * A class that contains all required [CoroutineDispatcher]'s. + */ +data class DispatchersProviderList( + val ioDispatcher: CoroutineDispatcher = DispatchersProvider.io, + val defaultDispatcher: CoroutineDispatcher = Dispatchers.Default, + val mainDispatcher: CoroutineDispatcher = Dispatchers.Main +) diff --git a/composeApp/src/commonMain/kotlin/app/academy/domain/HomeViewModel.kt b/composeApp/src/commonMain/kotlin/app/academy/domain/HomeViewModel.kt new file mode 100644 index 0000000..0b1329f --- /dev/null +++ b/composeApp/src/commonMain/kotlin/app/academy/domain/HomeViewModel.kt @@ -0,0 +1,6 @@ +package app.academy.domain + +import cafe.adriel.voyager.core.model.ScreenModel + +class HomeViewModel : ScreenModel { +} diff --git a/shared/src/commonMain/kotlin/app/architect/notes/model/Note.kt b/composeApp/src/commonMain/kotlin/app/academy/model/Note.kt similarity index 94% rename from shared/src/commonMain/kotlin/app/architect/notes/model/Note.kt rename to composeApp/src/commonMain/kotlin/app/academy/model/Note.kt index 7d800da..bc6e3e5 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/model/Note.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/model/Note.kt @@ -1,6 +1,7 @@ -package app.architect.notes.model +package app.academy.model + +import app.academy.notes.database.SavedNoteEntity -import com.example.notes.database.SavedNoteEntity /** * Data class representing a note. @@ -18,8 +19,34 @@ data class Note( val isDeleted: Boolean ) +val dummyNotes = listOf( + Note( + id = "id1", + title = "Dummy note 1", + content = "This is a test note 1", + createdAtTimestampMillis = 0L, + isDeleted = false + ), + Note( + id = "id2", + title = "Dummy note 2", + content = "This is a test note 2", + createdAtTimestampMillis = 1L, + isDeleted = false + ), + Note( + id = "id3", + title = "Dummy note 3", + content = "This is a test note 3", + createdAtTimestampMillis = 2L, + isDeleted = false + ) +) + + /** * Used to convert a [SavedNoteEntity] to a [Note]. + */ fun SavedNoteEntity.toNote(): Note { return Note( @@ -31,7 +58,7 @@ fun SavedNoteEntity.toNote(): Note { ) } -/** +/* * Used to convert a [Note] to a [SavedNoteEntity]. */ fun Note.toSavedNoteEntity(): SavedNoteEntity { @@ -43,27 +70,3 @@ fun Note.toSavedNoteEntity(): SavedNoteEntity { isDeleted = if (this.isDeleted) 1 else 0 ) } - -val dummyNotes = listOf( - Note( - id = "id1", - title = "Dummy note 1", - content = "This is a test note 1", - createdAtTimestampMillis = 0L, - isDeleted = false - ), - Note( - id = "id2", - title = "Dummy note 2", - content = "This is a test note 2", - createdAtTimestampMillis = 1L, - isDeleted = false - ), - Note( - id = "id3", - title = "Dummy note 3", - content = "This is a test note 3", - createdAtTimestampMillis = 2L, - isDeleted = false - ) -) diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/theme/NotesAppTheme.kt b/composeApp/src/commonMain/kotlin/app/academy/theme/NotesAppTheme.kt similarity index 87% rename from composeApp/src/commonMain/kotlin/com/app/academy/theme/NotesAppTheme.kt rename to composeApp/src/commonMain/kotlin/app/academy/theme/NotesAppTheme.kt index b8500b3..aa72831 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/theme/NotesAppTheme.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/theme/NotesAppTheme.kt @@ -1,4 +1,4 @@ -package com.app.academy.theme +package app.academy.theme import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable diff --git a/composeApp/src/commonMain/kotlin/app/academy/ui/App.kt b/composeApp/src/commonMain/kotlin/app/academy/ui/App.kt new file mode 100644 index 0000000..b807047 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/app/academy/ui/App.kt @@ -0,0 +1,14 @@ +package app.academy.ui + +import androidx.compose.runtime.Composable +import app.academy.di.AppModule +import app.academy.theme.NotesAppTheme +import org.jetbrains.compose.ui.tooling.preview.Preview + +@Composable +@Preview +fun App(appModule: AppModule) { + NotesAppTheme { + NotesAppNavigation(appModule) + } +} diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/DemoScreen.kt b/composeApp/src/commonMain/kotlin/app/academy/ui/DemoScreen.kt similarity index 98% rename from composeApp/src/commonMain/kotlin/com/app/academy/DemoScreen.kt rename to composeApp/src/commonMain/kotlin/app/academy/ui/DemoScreen.kt index d496f58..ffc4485 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/DemoScreen.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/ui/DemoScreen.kt @@ -1,4 +1,4 @@ -package com.app.academy +package app.academy.ui import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.Image diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/HomeScreen.kt b/composeApp/src/commonMain/kotlin/app/academy/ui/HomeScreen.kt similarity index 80% rename from composeApp/src/commonMain/kotlin/com/app/academy/HomeScreen.kt rename to composeApp/src/commonMain/kotlin/app/academy/ui/HomeScreen.kt index 96e9c5d..60e91a6 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/ui/HomeScreen.kt @@ -1,12 +1,12 @@ -package com.app.academy +package app.academy.ui import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import app.architect.notes.model.dummyNotes +import app.academy.components.NoteItems +import app.academy.model.dummyNotes import cafe.adriel.voyager.core.screen.Screen -import com.app.academy.components.NoteItems object HomeScreen : Screen { @Composable diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/NotesNavigation.kt b/composeApp/src/commonMain/kotlin/app/academy/ui/NotesNavigation.kt similarity index 69% rename from composeApp/src/commonMain/kotlin/com/app/academy/NotesNavigation.kt rename to composeApp/src/commonMain/kotlin/app/academy/ui/NotesNavigation.kt index 569eea6..263a302 100644 --- a/composeApp/src/commonMain/kotlin/com/app/academy/NotesNavigation.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/ui/NotesNavigation.kt @@ -1,11 +1,14 @@ -package com.app.academy +package app.academy.ui import androidx.compose.runtime.Composable +import app.academy.di.AppModule import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.transitions.SlideTransition @Composable -fun NotesAppNavigation() { +fun NotesAppNavigation( + appModule: AppModule, +) { Navigator(screen = HomeScreen) { SlideTransition(navigator = it) } diff --git a/shared/src/commonMain/kotlin/app/architect/notes/utils/Constants.kt b/composeApp/src/commonMain/kotlin/app/academy/utils/Constants.kt similarity index 100% rename from shared/src/commonMain/kotlin/app/architect/notes/utils/Constants.kt rename to composeApp/src/commonMain/kotlin/app/academy/utils/Constants.kt diff --git a/shared/src/commonMain/kotlin/app/architect/notes/utils/Greeting.kt b/composeApp/src/commonMain/kotlin/app/academy/utils/Greeting.kt similarity index 86% rename from shared/src/commonMain/kotlin/app/architect/notes/utils/Greeting.kt rename to composeApp/src/commonMain/kotlin/app/academy/utils/Greeting.kt index 8641bd8..35db35e 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/utils/Greeting.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/utils/Greeting.kt @@ -1,5 +1,7 @@ package app.architect.notes.utils +import app.academy.utils.getPlatform + class Greeting { private val platform = getPlatform() diff --git a/shared/src/commonMain/kotlin/app/architect/notes/utils/NativeStateFlow.kt b/composeApp/src/commonMain/kotlin/app/academy/utils/NativeStateFlow.kt similarity index 89% rename from shared/src/commonMain/kotlin/app/architect/notes/utils/NativeStateFlow.kt rename to composeApp/src/commonMain/kotlin/app/academy/utils/NativeStateFlow.kt index 4c05dbd..6eb781e 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/utils/NativeStateFlow.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/utils/NativeStateFlow.kt @@ -1,4 +1,4 @@ -package app.architect.notes.utils +package app.academy.utils import kotlinx.coroutines.flow.StateFlow diff --git a/shared/src/commonMain/kotlin/app/architect/notes/utils/Platform.kt b/composeApp/src/commonMain/kotlin/app/academy/utils/Platform.kt similarity index 70% rename from shared/src/commonMain/kotlin/app/architect/notes/utils/Platform.kt rename to composeApp/src/commonMain/kotlin/app/academy/utils/Platform.kt index eb8f08d..552c953 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/utils/Platform.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/utils/Platform.kt @@ -1,4 +1,4 @@ -package app.architect.notes.utils +package app.academy.utils interface Platform { val name: String diff --git a/shared/src/commonMain/kotlin/app/architect/notes/utils/UUID.kt b/composeApp/src/commonMain/kotlin/app/academy/utils/UUID.kt similarity index 82% rename from shared/src/commonMain/kotlin/app/architect/notes/utils/UUID.kt rename to composeApp/src/commonMain/kotlin/app/academy/utils/UUID.kt index cbcaa8d..1c20503 100644 --- a/shared/src/commonMain/kotlin/app/architect/notes/utils/UUID.kt +++ b/composeApp/src/commonMain/kotlin/app/academy/utils/UUID.kt @@ -1,4 +1,4 @@ -package app.architect.notes.utils +package app.academy.utils /** * A class that is used to generate a unique UUID (Universally Unique Identifier) string. diff --git a/composeApp/src/commonMain/kotlin/com/app/academy/App.kt b/composeApp/src/commonMain/kotlin/com/app/academy/App.kt deleted file mode 100644 index ff6da52..0000000 --- a/composeApp/src/commonMain/kotlin/com/app/academy/App.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.app.academy - -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.material.Button -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import app.architect.notes.utils.Greeting -import com.app.academy.theme.NotesAppTheme -import kmpnotes.composeapp.generated.resources.Res -import kmpnotes.composeapp.generated.resources.compose_multiplatform -import org.jetbrains.compose.resources.painterResource -import org.jetbrains.compose.ui.tooling.preview.Preview - -@Composable -@Preview -fun App() { - NotesAppTheme { - NotesAppNavigation() - } -} diff --git a/composeApp/src/commonMain/sqldelight/app/academy/notes/database/NotesDatabase.sq b/composeApp/src/commonMain/sqldelight/app/academy/notes/database/NotesDatabase.sq new file mode 100644 index 0000000..9f2923e --- /dev/null +++ b/composeApp/src/commonMain/sqldelight/app/academy/notes/database/NotesDatabase.sq @@ -0,0 +1,33 @@ +import kotlin.Int; + +CREATE TABLE savedNoteEntity ( + id TEXT NOT NULL PRIMARY KEY, + title TEXT NOT NULL, + content TEXT NOT NULL, + createdAtTimestamp INTEGER NOT NULL, + isDeleted INTEGER NOT NULL DEFAULT 0 +); + +insertNote: +INSERT OR REPLACE INTO savedNoteEntity(id,title,content,createdAtTimestamp,isDeleted) +VALUES (?,?,?,?,?); + +markNoteAsDeleted: +UPDATE savedNoteEntity SET isDeleted = 1 WHERE id == :id; + +markNoteAsNotDeleted: +UPDATE savedNoteEntity SET isDeleted = 0 WHERE id == :id; + +getAllSavedNotes: +SELECT * +FROM savedNoteEntity +WHERE savedNoteEntity.isDeleted == 0 +ORDER BY savedNoteEntity.createdAtTimestamp DESC; + +deleteNote: +DELETE FROM savedNoteEntity WHERE id == :id; + +deleteAllNotesMarkedAsDeleted: +DELETE FROM savedNoteEntity WHERE savedNoteEntity.isDeleted == 1; + + diff --git a/composeApp/src/desktopMain/kotlin/app/academy/di/AppModule.desktop.kt b/composeApp/src/desktopMain/kotlin/app/academy/di/AppModule.desktop.kt new file mode 100644 index 0000000..d245052 --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/app/academy/di/AppModule.desktop.kt @@ -0,0 +1,20 @@ +package app.academy.di + +import app.academy.data.NotesRepository + +actual class AppModule { + /** + * Provides an implementation of [NotesRepository] + */ + actual fun provideNotesRepository(): NotesRepository { + return TODO() + } + + /** + * Used to provide an instance of [DispatchersProviderList] + */ + actual fun provideDispatchersProvider(): DispatchersProviderList { + return TODO() + } + +} diff --git a/composeApp/src/desktopMain/kotlin/app/academy/di/DispatchersProvider.desktop.kt b/composeApp/src/desktopMain/kotlin/app/academy/di/DispatchersProvider.desktop.kt new file mode 100644 index 0000000..f26a08d --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/app/academy/di/DispatchersProvider.desktop.kt @@ -0,0 +1,8 @@ +package app.academy.di + +import kotlinx.coroutines.CoroutineDispatcher + +actual object DispatchersProvider { + actual val io: CoroutineDispatcher + get() = TODO("Not yet implemented") +} diff --git a/composeApp/src/desktopMain/kotlin/main.kt b/composeApp/src/desktopMain/kotlin/main.kt deleted file mode 100644 index b495c5f..0000000 --- a/composeApp/src/desktopMain/kotlin/main.kt +++ /dev/null @@ -1,12 +0,0 @@ -import androidx.compose.ui.window.Window -import androidx.compose.ui.window.application -import com.app.academy.App - -fun main() = application { - Window( - onCloseRequest = ::exitApplication, - title = "KMPNotes", - ) { - App() - } -} diff --git a/composeApp/src/iosMain/kotlin/MainViewController.kt b/composeApp/src/iosMain/kotlin/MainViewController.kt index f3b94c5..dfbb34a 100644 --- a/composeApp/src/iosMain/kotlin/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/MainViewController.kt @@ -1,4 +1,4 @@ import androidx.compose.ui.window.ComposeUIViewController -import com.app.academy.App +import com.app.academy.ui.App fun MainViewController() = ComposeUIViewController { App() } diff --git a/composeApp/src/iosMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.ios.kt new file mode 100644 index 0000000..80b71d1 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/data/local/NotesDatabaseDriverFactory.ios.kt @@ -0,0 +1,13 @@ +package app.academy.data.local + +import app.cash.sqldelight.db.SqlDriver +import app.cash.sqldelight.driver.native.NativeSqliteDriver +import com.app.academy.notes.database.NotesDatabase + +actual class NotesDatabaseDriverFactory { + + actual fun createDriver(): SqlDriver = NativeSqliteDriver( + schema = NotesDatabase.Schema, + name = DatabaseDriverConstants.DATABASE_NAME + ) +} diff --git a/composeApp/src/iosMain/kotlin/app/academy/di/AppModule.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/di/AppModule.ios.kt new file mode 100644 index 0000000..4b7a6a7 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/di/AppModule.ios.kt @@ -0,0 +1,31 @@ +package app.academy.di + +import app.academy.data.DefaultNotesRepository +import app.academy.data.NotesRepository +import app.academy.data.local.NotesDatabaseDriverFactory +import app.academy.data.local.datasource.DefaultLocalNotesDataSource +import com.example.notes.database.NotesDatabase +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.IO + +actual class AppModule { + + private val database by lazy { + val driver = NotesDatabaseDriverFactory().createDriver() + NotesDatabase(driver) + } + + actual fun provideNotesRepository(): NotesRepository { + val localNotesDataSource = DefaultLocalNotesDataSource( + database = database, + ioDispatcher = Dispatchers.IO + ) + return DefaultNotesRepository(localNotesDataSource = localNotesDataSource) + } + + actual fun provideDispatchersProvider(): DispatchersProviderList = DispatchersProviderList( + ioDispatcher = Dispatchers.Default, + defaultDispatcher = Dispatchers.Default, + mainDispatcher = Dispatchers.Main + ) +} diff --git a/composeApp/src/iosMain/kotlin/app/academy/di/DispatchersProvider.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/di/DispatchersProvider.ios.kt new file mode 100644 index 0000000..5d4c8fc --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/di/DispatchersProvider.ios.kt @@ -0,0 +1,8 @@ +package app.academy.di + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +actual object DispatchersProvider { + actual val io: CoroutineDispatcher = Dispatchers.Default +} diff --git a/composeApp/src/iosMain/kotlin/app/academy/utils/NativeStateFlow.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/utils/NativeStateFlow.ios.kt new file mode 100644 index 0000000..948358c --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/utils/NativeStateFlow.ios.kt @@ -0,0 +1,21 @@ +package app.academy.utils + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.DisposableHandle +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch + +/** + * A cross platform implementation of [StateFlow]. + */ +actual class NativeStateFlow actual constructor(source: StateFlow) : StateFlow by source { + + fun subscribe(onCollect: (T) -> Unit): DisposableHandle { + val scope = MainScope().apply { + launch(Dispatchers.Main) { collect(onCollect) } + } + return DisposableHandle { scope.cancel() } + } +} diff --git a/composeApp/src/iosMain/kotlin/app/academy/utils/Platform.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/utils/Platform.ios.kt new file mode 100644 index 0000000..35ed782 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/utils/Platform.ios.kt @@ -0,0 +1,10 @@ +package app.academy.utils + +class IOSPlatform : Platform { + override val name: String + get() = "iOS" +} + +actual fun getPlatform(): Platform { + return IOSPlatform() +} diff --git a/composeApp/src/iosMain/kotlin/app/academy/utils/UUID.ios.kt b/composeApp/src/iosMain/kotlin/app/academy/utils/UUID.ios.kt new file mode 100644 index 0000000..f4a5b5d --- /dev/null +++ b/composeApp/src/iosMain/kotlin/app/academy/utils/UUID.ios.kt @@ -0,0 +1,10 @@ +package app.academy.utils + +import platform.Foundation.NSUUID + +/** + * A class that is used to generate a unique UUID (Universally Unique Identifier) string. + */ +actual object UUID { + actual fun randomUUIDString(): String = NSUUID().UUIDString +} diff --git a/composeApp/src/wasmJsMain/kotlin/app/academy/di/AppModule.wasmJs.kt b/composeApp/src/wasmJsMain/kotlin/app/academy/di/AppModule.wasmJs.kt new file mode 100644 index 0000000..d245052 --- /dev/null +++ b/composeApp/src/wasmJsMain/kotlin/app/academy/di/AppModule.wasmJs.kt @@ -0,0 +1,20 @@ +package app.academy.di + +import app.academy.data.NotesRepository + +actual class AppModule { + /** + * Provides an implementation of [NotesRepository] + */ + actual fun provideNotesRepository(): NotesRepository { + return TODO() + } + + /** + * Used to provide an instance of [DispatchersProviderList] + */ + actual fun provideDispatchersProvider(): DispatchersProviderList { + return TODO() + } + +} diff --git a/composeApp/src/wasmJsMain/kotlin/app/academy/di/DispatchersProvider.wasmJs.kt b/composeApp/src/wasmJsMain/kotlin/app/academy/di/DispatchersProvider.wasmJs.kt new file mode 100644 index 0000000..f26a08d --- /dev/null +++ b/composeApp/src/wasmJsMain/kotlin/app/academy/di/DispatchersProvider.wasmJs.kt @@ -0,0 +1,8 @@ +package app.academy.di + +import kotlinx.coroutines.CoroutineDispatcher + +actual object DispatchersProvider { + actual val io: CoroutineDispatcher + get() = TODO("Not yet implemented") +} diff --git a/composeApp/src/wasmJsMain/kotlin/main.kt b/composeApp/src/wasmJsMain/kotlin/main.kt deleted file mode 100644 index b2f0a13..0000000 --- a/composeApp/src/wasmJsMain/kotlin/main.kt +++ /dev/null @@ -1,11 +0,0 @@ -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.window.ComposeViewport -import com.app.academy.App -import kotlinx.browser.document - -@OptIn(ExperimentalComposeUiApi::class) -fun main() { - ComposeViewport(document.body!!) { - App() - } -} diff --git a/composeApp/src/wasmJsMain/resources/index.html b/composeApp/src/wasmJsMain/resources/index.html deleted file mode 100644 index 320a400..0000000 --- a/composeApp/src/wasmJsMain/resources/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - KMPNotes - - - - - - \ No newline at end of file diff --git a/composeApp/src/wasmJsMain/resources/styles.css b/composeApp/src/wasmJsMain/resources/styles.css deleted file mode 100644 index 0549b10..0000000 --- a/composeApp/src/wasmJsMain/resources/styles.css +++ /dev/null @@ -1,7 +0,0 @@ -html, body { - width: 100%; - height: 100%; - margin: 0; - padding: 0; - overflow: hidden; -} \ No newline at end of file diff --git a/server/build.gradle.kts b/server/build.gradle.kts deleted file mode 100644 index 2d87023..0000000 --- a/server/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - alias(libs.plugins.kotlinJvm) - alias(libs.plugins.ktor) - application -} - -group = "com.app.academy.notes" -version = "1.0.0" -application { - mainClass.set("com.app.academy.notes.ApplicationKt") - applicationDefaultJvmArgs = listOf("-Dio.ktor.development=${extra["io.ktor.development"] ?: "false"}") -} - -dependencies { - implementation(projects.shared) - implementation(libs.logback) - implementation(libs.ktor.server.core) - implementation(libs.ktor.server.netty) - testImplementation(libs.ktor.server.tests) - testImplementation(libs.kotlin.test.junit) -} \ No newline at end of file diff --git a/server/src/main/kotlin/com/app/academy/notes/Application.kt b/server/src/main/kotlin/com/app/academy/notes/Application.kt deleted file mode 100644 index abed22b..0000000 --- a/server/src/main/kotlin/com/app/academy/notes/Application.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.app.academy.notes - -import Greeting -import SERVER_PORT -import io.ktor.server.application.* -import io.ktor.server.engine.* -import io.ktor.server.netty.* -import io.ktor.server.response.* -import io.ktor.server.routing.* - -fun main() { - embeddedServer(Netty, port = SERVER_PORT, host = "0.0.0.0", module = Application::module) - .start(wait = true) -} - -fun Application.module() { - routing { - get("/") { - call.respondText("Ktor: ${Greeting().greet()}") - } - } -} \ No newline at end of file diff --git a/server/src/main/resources/logback.xml b/server/src/main/resources/logback.xml deleted file mode 100644 index 3e11d78..0000000 --- a/server/src/main/resources/logback.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 535a1b3..a3c0cd4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,5 +29,3 @@ dependencyResolutionManagement { } include(":composeApp") -include(":server") -include(":shared") diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 1211136..f47464e 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -80,10 +80,3 @@ android { } } -sqldelight { - databases { - create("NotesDatabase") { - packageName.set("com.example.notes.database") - } - } -} diff --git a/shared/src/androidMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.android.kt b/shared/src/androidMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.android.kt index a5f3bd3..3ba1f9e 100644 --- a/shared/src/androidMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.android.kt +++ b/shared/src/androidMain/kotlin/app/architect/notes/data/local/NotesDatabaseDriverFactory.android.kt @@ -1,3 +1,4 @@ +/* package app.architect.notes.data.local import android.content.Context @@ -14,3 +15,4 @@ actual class NotesDatabaseDriverFactory(private val context: Context) { ) } +*/