Skip to content

Commit

Permalink
Adds step 4
Browse files Browse the repository at this point in the history
  • Loading branch information
aldefy committed Jun 23, 2024
1 parent fb70cd5 commit 3f0283a
Show file tree
Hide file tree
Showing 51 changed files with 383 additions and 250 deletions.
63 changes: 30 additions & 33 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -125,3 +113,12 @@ compose.desktop {
}
}
}


sqldelight {
databases {
create("NotesDatabase") {
packageName.set("com.app.academy.notes.database")
}
}
}
4 changes: 2 additions & 2 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name="app.architect.notes.NotesAppApplication"
android:name="app.academy.NotesAppApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:name=".MainActivity"
android:name="app.academy.notes.MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package app.academy.di

import android.content.Context
import app.academy.data.DefaultNotesRepository
import app.academy.data.local.NotesDatabaseDriverFactory
import app.academy.data.local.datasource.DefaultLocalNotesDataSource
import app.architect.notes.data.NotesRepository
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
)
}

}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package app.academy.utils

import kotlinx.coroutines.flow.StateFlow

/**
* A cross platform implementation of [StateFlow].
*/
actual class NativeStateFlow<T> actual constructor(source: StateFlow<T>) : StateFlow<T> by source
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.academy.utils

class AndroidPlatform : Platform {
override val name: String
get() = "Android"
}

actual fun getPlatform(): Platform {
return AndroidPlatform()
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.app.academy.components
package app.academy.components

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.app.academy.components
package app.academy.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.DismissDirection
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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.architect.notes.data.NotesRepository
import app.academy.data.local.datasource.LocalNotesDataSource
import app.academy.model.Note
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class DefaultNotesRepository(
private val localNotesDataSource: LocalNotesDataSource
) : NotesRepository {

override val savedNotesStream: Flow<List<Note>> =
override val savedNotesStream: Flow<List<Note>> = TODO()/*
localNotesDataSource.savedNotesStream.map { savedNoteEntities ->
savedNoteEntities.map { savedNoteEntity -> savedNoteEntity.toNote() }
}
}*/

override suspend fun saveNote(note: Note) {
localNotesDataSource.saveNote(note.toSavedNoteEntity())
TODO()
/* localNotesDataSource.saveNote(note.toSavedNoteEntity())*/
}

override suspend fun deleteNote(note: Note) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.architect.notes.data

import app.architect.notes.model.Note
import app.academy.model.Note
import kotlinx.coroutines.flow.Flow

interface NotesRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.architect.notes.data.local
package app.academy.data.local

import app.cash.sqldelight.db.SqlDriver

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package app.architect.notes.data.local.datasource
package app.academy.data.local.datasource

import app.architect.notes.data.local.datasource.LocalNotesDataSource
import app.academy.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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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

/**
* Interface that handles the DAO operations for [SavedNoteEntity].
*/
interface LocalNotesDataSource {
/**
* A [Flow] of all saved notes.
* A [Flow] of all saved notes.
*/
val savedNotesStream: Flow<List<SavedNoteEntity>>

/**
* Used to save a note.
*/
* */

suspend fun saveNote(noteEntity: SavedNoteEntity)

/**
Expand Down
Loading

0 comments on commit 3f0283a

Please sign in to comment.