diff --git a/Fruitties/.gitignore b/Fruitties/.gitignore
new file mode 100644
index 0000000..e510fa9
--- /dev/null
+++ b/Fruitties/.gitignore
@@ -0,0 +1,10 @@
+*.iml
+.gradle
+.idea
+.DS_Store
+build
+captures
+.externalNativeBuild
+.cxx
+local.properties
+xcuserdata
\ No newline at end of file
diff --git a/Fruitties/androidApp/build.gradle.kts b/Fruitties/androidApp/build.gradle.kts
new file mode 100644
index 0000000..cd5351b
--- /dev/null
+++ b/Fruitties/androidApp/build.gradle.kts
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+plugins {
+ alias(libs.plugins.androidApplication)
+ alias(libs.plugins.kotlinAndroid)
+}
+
+android {
+ namespace = "com.example.fruitties.android"
+ compileSdk = 34
+ defaultConfig {
+ applicationId = "com.example.fruitties.android"
+ minSdk = 26
+ targetSdk = 34
+ versionCode = 1
+ versionName = "1.0"
+ }
+ buildFeatures {
+ compose = true
+ }
+ composeOptions {
+ kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
+ }
+ packaging {
+ resources {
+ excludes += "/META-INF/{AL2.0,LGPL2.1}"
+ }
+ }
+ buildTypes {
+ getByName("release") {
+ isMinifyEnabled = false
+ }
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+dependencies {
+ implementation(projects.shared)
+ implementation(libs.compose.ui)
+ implementation(libs.compose.ui.tooling.preview)
+ implementation(libs.compose.material3)
+ implementation(libs.androidx.activity.compose)
+ implementation(libs.androidx.paging.compose.android)
+ implementation(libs.androidx.viewmodel.compose)
+ debugImplementation(libs.compose.ui.tooling)
+}
diff --git a/Fruitties/androidApp/src/main/AndroidManifest.xml b/Fruitties/androidApp/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..b5a5e47
--- /dev/null
+++ b/Fruitties/androidApp/src/main/AndroidManifest.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MainActivity.kt b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MainActivity.kt
new file mode 100644
index 0000000..30e6778
--- /dev/null
+++ b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MainActivity.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.fruitties.android
+
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.ui.Modifier
+import com.example.fruitties.android.ui.ListScreen
+
+class MainActivity : ComponentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContent {
+ MyApplicationTheme {
+ Surface(
+ modifier = Modifier.fillMaxSize(),
+ color = MaterialTheme.colorScheme.background,
+ ) {
+ ListScreen()
+ }
+ }
+ }
+ }
+}
diff --git a/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MyApplicationTheme.kt b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MyApplicationTheme.kt
new file mode 100644
index 0000000..2181632
--- /dev/null
+++ b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MyApplicationTheme.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.android
+
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Shapes
+import androidx.compose.material3.Typography
+import androidx.compose.material3.darkColorScheme
+import androidx.compose.material3.lightColorScheme
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+@Composable
+fun MyApplicationTheme(
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ content: @Composable () -> Unit,
+) {
+ val colors = if (darkTheme) {
+ darkColorScheme(
+ primary = Color(0xFFBB86FC),
+ secondary = Color(0xFF03DAC5),
+ tertiary = Color(0xFF3700B3),
+ )
+ } else {
+ lightColorScheme(
+ primary = Color(0xFF6200EE),
+ secondary = Color(0xFF03DAC5),
+ tertiary = Color(0xFF3700B3),
+ )
+ }
+ val typography = Typography(
+ bodyMedium = TextStyle(
+ fontFamily = FontFamily.Default,
+ fontWeight = FontWeight.Normal,
+ fontSize = 16.sp,
+ ),
+ )
+ val shapes = Shapes(
+ small = RoundedCornerShape(4.dp),
+ medium = RoundedCornerShape(4.dp),
+ large = RoundedCornerShape(0.dp),
+ )
+
+ MaterialTheme(
+ colorScheme = colors,
+ typography = typography,
+ shapes = shapes,
+ content = content,
+ )
+}
diff --git a/Fruitties/androidApp/src/main/java/com/example/fruitties/android/di/App.kt b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/di/App.kt
new file mode 100644
index 0000000..fcc8383
--- /dev/null
+++ b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/di/App.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.fruitties.android.di
+
+import android.app.Application
+import com.example.fruitties.di.AppContainer
+import com.example.fruitties.di.Factory
+
+class App : Application() {
+ /** AppContainer instance used by the rest of classes to obtain dependencies */
+ lateinit var container: AppContainer
+ override fun onCreate() {
+ super.onCreate()
+ container = AppContainer(Factory(this))
+ }
+}
diff --git a/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListScreen.kt b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListScreen.kt
new file mode 100644
index 0000000..060afa5
--- /dev/null
+++ b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListScreen.kt
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.fruitties.android.ui
+
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.core.tween
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.wrapContentHeight
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.Card
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+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 androidx.compose.ui.draw.clip
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.viewmodel.compose.viewModel
+import com.example.fruitties.android.R
+import com.example.fruitties.database.CartItemDetails
+import com.example.fruitties.model.Fruittie
+
+@Composable
+fun ListScreen(viewModel: MainViewModel = viewModel(factory = MainViewModel.Factory)) {
+ val uiState by viewModel.uiState.collectAsState()
+ val cartState by viewModel.cartUiState.collectAsState()
+
+ Scaffold(
+ topBar = {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .wrapContentHeight()
+ .background(MaterialTheme.colorScheme.primary),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(
+ text = stringResource(R.string.frutties),
+ color = MaterialTheme.colorScheme.onPrimary,
+ modifier = Modifier
+ .padding(vertical = 16.dp, horizontal = 16.dp)
+ .weight(1.0f),
+ textAlign = TextAlign.Center,
+ )
+ }
+ },
+ ) {
+ Column(
+ modifier = Modifier.padding(it),
+ ) {
+ var expanded by remember { mutableStateOf(false) }
+ Row (modifier = Modifier.padding(16.dp)) {
+ Text(
+ text = "Cart has ${cartState.itemList.count()} items",
+ modifier = Modifier.weight(1f).padding(12.dp)
+ )
+ Button(onClick = { expanded = !expanded } ) {
+ Text(text = if (expanded) "collapse" else "expand")
+ }
+ }
+ AnimatedVisibility(
+ visible = expanded,
+ enter = fadeIn(animationSpec = tween(1000)),
+ exit = fadeOut(animationSpec = tween(1000))
+ ) {
+ CardDetailsView(cartState.itemList)
+ }
+
+ LazyColumn {
+ items(items = uiState.itemList, key = { it.id }) { item ->
+ FruittieItem(
+ item = item,
+ onAddToCart = viewModel::addItemToCart,
+ )
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun FruittieItem(
+ item: Fruittie,
+ onAddToCart: (fruittie: Fruittie) -> Unit,
+ modifier: Modifier = Modifier
+) {
+ Card(
+ modifier = modifier
+ .padding(horizontal = 16.dp, vertical = 8.dp)
+ .clip(RoundedCornerShape(8.dp)),
+ shape = RoundedCornerShape(8.dp),
+ colors = CardDefaults.cardColors(
+ containerColor = MaterialTheme.colorScheme.surface,
+ ),
+ elevation = CardDefaults.cardElevation(
+ defaultElevation = 8.dp,
+ ),
+ ) {
+ Column {
+ Text(
+ text = item.name,
+ color = MaterialTheme.colorScheme.onBackground,
+ style = MaterialTheme.typography.titleMedium,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 16.dp)
+ .padding(top = 8.dp),
+ )
+ Row {
+ Text(
+ text = item.fullName,
+ modifier = Modifier
+ .padding(horizontal = 16.dp)
+ .padding(bottom = 8.dp),
+ color = MaterialTheme.colorScheme.onSurface,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ )
+ Spacer(modifier = Modifier.padding(vertical = 4.dp))
+ Box(
+ modifier = Modifier
+ .height(50.dp)
+ .fillMaxWidth(),
+ ) {
+ Row(
+ modifier = Modifier
+ .padding(horizontal = 16.dp, vertical = 8.dp)
+ .align(Alignment.TopEnd),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Button(onClick = { onAddToCart(item) }) {
+ Text(stringResource(R.string.add))
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+fun CardDetailsView(cart: List, modifier: Modifier = Modifier) {
+ Column (
+ modifier.padding(horizontal = 32.dp)
+ ){
+ cart.forEach { item ->
+ Text(text = "${item.fruittie.name} : ${item.count}")
+ }
+ }
+}
+
+@Preview
+@Composable
+fun ItemPreview() {
+ FruittieItem(
+ Fruittie(name = "Fruit", fullName = "Fruitus Mangorus", calories = "240"),
+ onAddToCart = {},
+ )
+}
diff --git a/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListViewModel.kt b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListViewModel.kt
new file mode 100644
index 0000000..405e017
--- /dev/null
+++ b/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListViewModel.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.fruitties.android.ui
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY
+import androidx.lifecycle.viewModelScope
+import androidx.lifecycle.viewmodel.initializer
+import androidx.lifecycle.viewmodel.viewModelFactory
+import com.example.fruitties.DataRepository
+import com.example.fruitties.android.di.App
+import com.example.fruitties.database.CartItemDetails
+import com.example.fruitties.model.Fruittie
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.launch
+
+class MainViewModel(private val repository: DataRepository) : ViewModel() {
+
+ val uiState: StateFlow =
+ repository.getData().map { HomeUiState(it) }
+ .stateIn(
+ scope = viewModelScope,
+ started = SharingStarted.WhileSubscribed(TIMEOUT_MILLIS),
+ initialValue = HomeUiState()
+ )
+
+ val cartUiState: StateFlow =
+ repository.cartDetails.map { CartUiState(it.items) }
+ .stateIn(
+ scope = viewModelScope,
+ started = SharingStarted.WhileSubscribed(TIMEOUT_MILLIS),
+ initialValue = CartUiState()
+ )
+
+ fun addItemToCart(fruittie: Fruittie) {
+ viewModelScope.launch {
+ repository.addToCart(fruittie)
+ }
+ }
+
+ companion object {
+ val Factory: ViewModelProvider.Factory = viewModelFactory {
+ initializer {
+ val application = (this[APPLICATION_KEY] as App)
+ val repository = application.container.dataRepository
+ MainViewModel(repository = repository)
+ }
+ }
+ }
+}
+
+/**
+ * Ui State for ListScreen
+ */
+data class HomeUiState(val itemList: List = listOf())
+
+/**
+ * Ui State for Cart
+ */
+data class CartUiState(val itemList: List = listOf())
+
+private const val TIMEOUT_MILLIS = 5_000L
diff --git a/Fruitties/androidApp/src/main/res/values/strings.xml b/Fruitties/androidApp/src/main/res/values/strings.xml
new file mode 100644
index 0000000..3cdffa3
--- /dev/null
+++ b/Fruitties/androidApp/src/main/res/values/strings.xml
@@ -0,0 +1,23 @@
+
+
+
+ "Frutties "
+ Save
+ Add
+ Loading
+ Retry
+
\ No newline at end of file
diff --git a/Fruitties/androidApp/src/main/res/values/styles.xml b/Fruitties/androidApp/src/main/res/values/styles.xml
new file mode 100644
index 0000000..89e4abf
--- /dev/null
+++ b/Fruitties/androidApp/src/main/res/values/styles.xml
@@ -0,0 +1,18 @@
+
+
+
+
\ No newline at end of file
diff --git a/Fruitties/build.gradle.kts b/Fruitties/build.gradle.kts
new file mode 100644
index 0000000..c55db8b
--- /dev/null
+++ b/Fruitties/build.gradle.kts
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+plugins {
+ //trick: for the same plugin versions in all sub-modules
+ alias(libs.plugins.androidApplication).apply(false)
+ alias(libs.plugins.androidLibrary).apply(false)
+ alias(libs.plugins.kotlinAndroid).apply(false)
+ alias(libs.plugins.kotlinMultiplatform).apply(false)
+ alias(libs.plugins.spotless).apply(false)
+}
+
+subprojects {
+ apply(plugin = "com.diffplug.spotless")
+ configure {
+ kotlin {
+ target("**/*.kt")
+ targetExclude("$buildDir/**/*.kt")
+
+ ktlint()
+ //licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
+ }
+
+ kotlinGradle {
+ target("*.gradle.kts")
+ ktlint()
+ }
+ }
+}
diff --git a/Fruitties/gradle.properties b/Fruitties/gradle.properties
new file mode 100644
index 0000000..2869189
--- /dev/null
+++ b/Fruitties/gradle.properties
@@ -0,0 +1,16 @@
+#Gradle
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
+org.gradle.caching=true
+org.gradle.configuration-cache=false
+
+#Kotlin
+kotlin.code.style=official
+
+#Android
+android.useAndroidX=true
+android.nonTransitiveRClass=true
+
+#KMP
+kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
+# Disabled due to https://youtrack.jetbrains.com/issue/KT-65761
+kotlin.native.disableCompilerDaemon = true
diff --git a/Fruitties/gradle/libs.versions.toml b/Fruitties/gradle/libs.versions.toml
new file mode 100644
index 0000000..9d17c0b
--- /dev/null
+++ b/Fruitties/gradle/libs.versions.toml
@@ -0,0 +1,67 @@
+[versions]
+agp = "8.4.0"
+androidx-activityCompose = "1.8.2"
+androidx-paging = "3.3.0-rc01"
+androidx-room = "2.7.0-alpha01"
+androidx-viewmodelCompose = "2.7.0"
+atomicfu = "0.23.1"
+compose = "1.6.5"
+compose-compiler = "1.5.11"
+compose-material3 = "1.2.1"
+compose-plugin = "1.6.0"
+dataStoreVersion = "1.1.1"
+kotlin = "1.9.23"
+kotlinx-coroutines = "1.8.0"
+kotlinxDatetime = "0.6.0-RC.2"
+ksp = "1.9.23-1.0.19"
+ktorVersion = "2.3.8"
+material3Android = "1.2.1"
+pagingComposeAndroid = "3.3.0-beta01"
+roomKtx = "2.6.1"
+skie = "0.6.2"
+sqlite = "2.5.0-SNAPSHOT"
+spotless = "6.19.0"
+
+[libraries]
+androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
+androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore-core-okio", version.ref = "dataStoreVersion" }
+androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "dataStoreVersion" }
+androidx-paging-common = { module = "androidx.paging:paging-common", version.ref = "androidx-paging" }
+androidx-paging-compose-android = { group = "androidx.paging", name = "paging-compose-android", version.ref = "pagingComposeAndroid" }
+androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "androidx-room" }
+androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "androidx-room" }
+androidx-room-paging = { group = "androidx.room", name = "room-paging", version.ref = "androidx-room" }
+androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "androidx-room" }
+androidx-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-viewmodelCompose" }
+compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
+compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
+compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
+compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
+compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
+kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
+kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" }
+kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
+kotlinx-coroutines-core-iosarm64 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-iossimulatorarm64", version.ref = "kotlinx-coroutines" }
+kotlinx-coroutines-core-iossimulatorarm64 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-iossimulatorarm64", version.ref = "kotlinx-coroutines" }
+kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
+ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "ktorVersion" }
+ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktorVersion" }
+ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorVersion" }
+ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktorVersion" }
+ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorVersion" }
+ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
+okio = "com.squareup.okio:okio:3.9.0"
+skie-annotations = { module = "co.touchlab.skie:configuration-annotations", version.ref = "skie" }
+sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
+
+[plugins]
+androidApplication = { id = "com.android.application", version.ref = "agp" }
+androidLibrary = { id = "com.android.library", version.ref = "agp" }
+kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
+kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
+kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
+kotlinxSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
+skie = { id = "co.touchlab.skie", version.ref = "skie" }
+ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
+room = { id = "androidx.room", version.ref = "androidx-room" }
+spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
diff --git a/Fruitties/gradle/wrapper/gradle-wrapper.jar b/Fruitties/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..e708b1c
Binary files /dev/null and b/Fruitties/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/Fruitties/gradle/wrapper/gradle-wrapper.properties b/Fruitties/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..54c9221
--- /dev/null
+++ b/Fruitties/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Apr 10 15:24:21 PDT 2024
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/Fruitties/gradlew b/Fruitties/gradlew
new file mode 100755
index 0000000..4f906e0
--- /dev/null
+++ b/Fruitties/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/Fruitties/gradlew.bat b/Fruitties/gradlew.bat
new file mode 100644
index 0000000..ac1b06f
--- /dev/null
+++ b/Fruitties/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj b/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..260968a
--- /dev/null
+++ b/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj
@@ -0,0 +1,387 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 50;
+ objects = {
+/* Begin PBXBuildFile section */
+ 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
+ 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
+ 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
+ 2E8773602BC85C2400BF7C40 /* CartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E87735F2BC85C2400BF7C40 /* CartView.swift */; };
+ 2E8773622BCD904A00BF7C40 /* StateHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8773612BCD904A00BF7C40 /* StateHelper.swift */; };
+ 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
+/* End PBXBuildFile section */
+/* Begin PBXCopyFilesBuildPhase section */
+ 7555FFB4242A642300829871 /* Embed Frameworks */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = "";
+ dstSubfolderSpec = 10;
+ files = (
+ );
+ name = "Embed Frameworks";
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXCopyFilesBuildPhase section */
+/* Begin PBXFileReference section */
+ 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
+ 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; };
+ 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; };
+ 2E87735F2BC85C2400BF7C40 /* CartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CartView.swift; sourceTree = ""; };
+ 2E8773612BCD904A00BF7C40 /* StateHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateHelper.swift; sourceTree = ""; };
+ 7555FF7B242A565900829871 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; };
+ 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
+/* End PBXFileReference section */
+/* Begin PBXFrameworksBuildPhase section */
+ 7555FF78242A565900829871 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+/* Begin PBXGroup section */
+ 058557D7273AAEEB004C7B11 /* Preview Content */ = {
+ isa = PBXGroup;
+ children = (
+ 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */,
+ );
+ path = "Preview Content";
+ sourceTree = "";
+ };
+ 7555FF72242A565900829871 = {
+ isa = PBXGroup;
+ children = (
+ 7555FF7D242A565900829871 /* iosApp */,
+ 7555FF7C242A565900829871 /* Products */,
+ 7555FFB0242A642200829871 /* Frameworks */,
+ );
+ sourceTree = "";
+ };
+ 7555FF7C242A565900829871 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 7555FF7B242A565900829871 /* iosApp.app */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+ 7555FF7D242A565900829871 /* iosApp */ = {
+ isa = PBXGroup;
+ children = (
+ 058557BA273AAA24004C7B11 /* Assets.xcassets */,
+ 7555FF82242A565900829871 /* ContentView.swift */,
+ 7555FF8C242A565B00829871 /* Info.plist */,
+ 2152FB032600AC8F00CF470E /* iOSApp.swift */,
+ 058557D7273AAEEB004C7B11 /* Preview Content */,
+ 2E87735F2BC85C2400BF7C40 /* CartView.swift */,
+ 2E8773612BCD904A00BF7C40 /* StateHelper.swift */,
+ );
+ path = iosApp;
+ sourceTree = "";
+ };
+ 7555FFB0242A642200829871 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
+/* End PBXGroup section */
+/* Begin PBXNativeTarget section */
+ 7555FF7A242A565900829871 /* iosApp */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */;
+ buildPhases = (
+ 7555FFB5242A651A00829871 /* ShellScript */,
+ 7555FF77242A565900829871 /* Sources */,
+ 7555FF78242A565900829871 /* Frameworks */,
+ 7555FF79242A565900829871 /* Resources */,
+ 7555FFB4242A642300829871 /* Embed Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = iosApp;
+ productName = iosApp;
+ productReference = 7555FF7B242A565900829871 /* iosApp.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+/* Begin PBXProject section */
+ 7555FF73242A565900829871 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastSwiftUpdateCheck = 1130;
+ LastUpgradeCheck = 1130;
+ ORGANIZATIONNAME = orgName;
+ TargetAttributes = {
+ 7555FF7A242A565900829871 = {
+ CreatedOnToolsVersion = 11.3.1;
+ };
+ };
+ };
+ buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */;
+ compatibilityVersion = "Xcode 9.3";
+ developmentRegion = en;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = 7555FF72242A565900829871;
+ productRefGroup = 7555FF7C242A565900829871 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 7555FF7A242A565900829871 /* iosApp */,
+ );
+ };
+/* End PBXProject section */
+/* Begin PBXResourcesBuildPhase section */
+ 7555FF79242A565900829871 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */,
+ 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+/* Begin PBXShellScriptBuildPhase section */
+ 7555FFB5242A651A00829871 /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ );
+ inputPaths = (
+ );
+ outputFileListPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n";
+ };
+/* End PBXShellScriptBuildPhase section */
+/* Begin PBXSourcesBuildPhase section */
+ 7555FF77242A565900829871 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2E8773602BC85C2400BF7C40 /* CartView.swift in Sources */,
+ 2E8773622BCD904A00BF7C40 /* StateHelper.swift in Sources */,
+ 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
+ 7555FF83242A565900829871 /* ContentView.swift in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+/* Begin XCBuildConfiguration section */
+ 7555FFA3242A565B00829871 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 14.1;
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+ MTL_FAST_MATH = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ };
+ name = Debug;
+ };
+ 7555FFA4242A565B00829871 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 14.1;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ MTL_FAST_MATH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_COMPILATION_MODE = wholemodule;
+ SWIFT_OPTIMIZATION_LEVEL = "-O";
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ 7555FFA6242A565B00829871 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CODE_SIGN_STYLE = Automatic;
+ DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
+ ENABLE_PREVIEWS = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
+ );
+ INFOPLIST_FILE = iosApp/Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 16.0;
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-framework",
+ shared,
+ );
+ PRODUCT_BUNDLE_IDENTIFIER = orgIdentifier.iosApp;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ 7555FFA7242A565B00829871 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CODE_SIGN_STYLE = Automatic;
+ DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
+ ENABLE_PREVIEWS = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
+ );
+ INFOPLIST_FILE = iosApp/Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 16.0;
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ OTHER_LDFLAGS = (
+ "$(inherited)",
+ "-framework",
+ shared,
+ );
+ PRODUCT_BUNDLE_IDENTIFIER = orgIdentifier.iosApp;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+/* Begin XCConfigurationList section */
+ 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7555FFA3242A565B00829871 /* Debug */,
+ 7555FFA4242A565B00829871 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7555FFA6242A565B00829871 /* Debug */,
+ 7555FFA7242A565B00829871 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 7555FF73242A565900829871 /* Project object */;
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json b/Fruitties/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json
new file mode 100644
index 0000000..ee7e3ca
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json
@@ -0,0 +1,11 @@
+{
+ "colors" : [
+ {
+ "idiom" : "universal"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/Fruitties/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..fb88a39
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,98 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "20x20"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "20x20"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "29x29"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "29x29"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "40x40"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "40x40"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "60x60"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "60x60"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "20x20"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "20x20"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "29x29"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "29x29"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "40x40"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "40x40"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "76x76"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "76x76"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "83.5x83.5"
+ },
+ {
+ "idiom" : "ios-marketing",
+ "scale" : "1x",
+ "size" : "1024x1024"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/Assets.xcassets/Contents.json b/Fruitties/iosApp/iosApp/Assets.xcassets/Contents.json
new file mode 100644
index 0000000..4aa7c53
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/CartView.swift b/Fruitties/iosApp/iosApp/CartView.swift
new file mode 100644
index 0000000..81aca6d
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/CartView.swift
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Foundation
+import SwiftUI
+import shared
+
+struct CartView : View {
+ let cart: Cart
+ let dataRepository: DataRepository
+ @State
+ private var expanded = false
+
+ var body: some View {
+ if (cart.items.isEmpty) {
+ Text("Cart is empty, add some items").padding()
+ } else {
+ HStack {
+ Text("Cart has \(cart.items.count) items").padding()
+ Spacer()
+ Button {
+ expanded.toggle()
+ } label: {
+ if (expanded) {
+ Text("collapse")
+ } else {
+ Text("expand")
+ }
+ }.padding()
+ }
+ if (expanded) {
+ CartDetailsView(dataRepository: dataRepository)
+ }
+ }
+ }
+}
+
+struct CartDetailsView: View {
+ let dataRepository: DataRepository
+ @State
+ private var details: CartDetails = CartDetails(items: [])
+
+ var body: some View {
+ VStack {
+ ForEach(details.items, id: \.fruittie.id) { item in
+ Text("\(item.fruittie.name): \(item.count)")
+ }
+ }.collectWithLifecycle(dataRepository.cartDetails, binding: $details)
+ }
+}
diff --git a/Fruitties/iosApp/iosApp/ContentView.swift b/Fruitties/iosApp/iosApp/ContentView.swift
new file mode 100644
index 0000000..c3d723a
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/ContentView.swift
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import SwiftUI
+import shared
+import Foundation
+
+struct ContentView: View {
+ @ObservedObject var uiModel: UIModel
+ init(appContainer: AppContainer) {
+ self.uiModel = UIModel(dataRepository: appContainer.dataRepository)
+ }
+
+ var body: some View {
+ Text("Fruitties").font(.largeTitle).fontWeight(.bold)
+ CartView(cart: uiModel.cart, dataRepository: uiModel.dataRepository)
+ ScrollView {
+ LazyVStack {
+ ForEach(uiModel.fruitties, id: \.self) { value in
+ FruittieView(fruittie: value, addToCart: { fruittie in
+ Task {
+ await uiModel.addToCart(fruittie: fruittie)
+ }
+ })
+ }
+ }
+ }.task {
+ await uiModel.activate()
+ }
+ }
+}
+
+struct FruittieView: View {
+ var fruittie: Fruittie
+ var addToCart: (Fruittie) -> Void
+ var body: some View {
+ HStack(alignment: .firstTextBaseline) {
+ ZStack {
+ RoundedRectangle(cornerRadius: 15).fill(Color(red: 0.8, green: 0.8, blue: 1.0))
+ VStack {
+ Text("\(fruittie.name)")
+ .fontWeight(.bold)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ Text("\(fruittie.fullName)")
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }.padding()
+ Spacer()
+ Button(action: { addToCart(fruittie) }, label: {
+ Text("Add")
+ }).padding().frame(maxWidth: .infinity, alignment: .trailing)
+ }.padding([.leading, .trailing])
+ }
+ }
+}
+
+class UIModel: ObservableObject {
+ let dataRepository : DataRepository
+ init(dataRepository: DataRepository) {
+ self.dataRepository = dataRepository
+ }
+ @Published
+ private(set) var fruitties: [Fruittie] = []
+ @Published
+ private(set) var cart: Cart = Cart(items: [])
+
+ @MainActor
+ func observeDatabase() async {
+ for await fruitties in dataRepository.getData() {
+ self.fruitties = fruitties
+ }
+ }
+
+ @MainActor
+ func watchCart() async {
+ for await cart in dataRepository.getCart() {
+ self.cart = cart
+ }
+ }
+
+ func addToCart(fruittie: Fruittie) async {
+ try? await dataRepository.addToCart(fruittie: fruittie)
+ }
+
+ @MainActor
+ func activate() async {
+ async let db: () = observeDatabase()
+ async let cartUpdate: () = watchCart()
+ await (db, cartUpdate)
+ }
+}
diff --git a/Fruitties/iosApp/iosApp/Info.plist b/Fruitties/iosApp/iosApp/Info.plist
new file mode 100644
index 0000000..8044709
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/Info.plist
@@ -0,0 +1,48 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ $(DEVELOPMENT_LANGUAGE)
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIdentifier
+ $(PRODUCT_BUNDLE_IDENTIFIER)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ $(PRODUCT_BUNDLE_PACKAGE_TYPE)
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+ LSRequiresIPhoneOS
+
+ UIApplicationSceneManifest
+
+ UIApplicationSupportsMultipleScenes
+
+
+ UIRequiredDeviceCapabilities
+
+ armv7
+
+ UISupportedInterfaceOrientations
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+ UISupportedInterfaceOrientations~ipad
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+ UILaunchScreen
+
+
+
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json b/Fruitties/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json
new file mode 100644
index 0000000..4aa7c53
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/StateHelper.swift b/Fruitties/iosApp/iosApp/StateHelper.swift
new file mode 100644
index 0000000..98346e5
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/StateHelper.swift
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import SwiftUI
+
+extension View {
+ @MainActor
+ func collectWithLifecycle(_ sequence: S, binding: Binding) -> some View where S.Element == T {
+ task {
+ do {
+ for try await item in sequence {
+ binding.wrappedValue = item
+ }
+ }catch {
+ print("error while collecting async sequence")
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/iosApp/iosApp/iOSApp.swift b/Fruitties/iosApp/iosApp/iOSApp.swift
new file mode 100644
index 0000000..4c9b10c
--- /dev/null
+++ b/Fruitties/iosApp/iosApp/iOSApp.swift
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import SwiftUI
+import shared
+@main
+struct iOSApp: App {
+ let appContainer = AppContainer(factory: Factory())
+ var body: some Scene {
+ WindowGroup {
+ ContentView(appContainer: appContainer)
+ }
+ }
+}
diff --git a/Fruitties/settings.gradle.kts b/Fruitties/settings.gradle.kts
new file mode 100644
index 0000000..7e069cc
--- /dev/null
+++ b/Fruitties/settings.gradle.kts
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
+pluginManagement {
+ repositories {
+ google()
+ gradlePluginPortal()
+ mavenCentral()
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+rootProject.name = "Fruitties"
+include(":androidApp")
+include(":shared")
\ No newline at end of file
diff --git a/Fruitties/shared/build.gradle.kts b/Fruitties/shared/build.gradle.kts
new file mode 100644
index 0000000..3295e90
--- /dev/null
+++ b/Fruitties/shared/build.gradle.kts
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+plugins {
+ alias(libs.plugins.kotlinMultiplatform)
+ alias(libs.plugins.androidLibrary)
+ alias(libs.plugins.kotlinxSerialization)
+ alias(libs.plugins.skie)
+ alias(libs.plugins.ksp)
+ alias(libs.plugins.room)
+}
+
+kotlin {
+ androidTarget {
+ compilations.all {
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+ }
+ }
+ listOf(
+ iosX64(),
+ iosArm64(),
+ iosSimulatorArm64(),
+ ).forEach {
+ it.binaries.framework {
+ baseName = "shared"
+ isStatic = true
+ }
+ }
+ sourceSets.all {
+ languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
+ }
+ sourceSets {
+ commonMain.dependencies {
+ // put your multiplatform dependencies here
+ implementation(libs.kotlinx.datetime)
+ implementation(libs.kotlinx.coroutines.core)
+ implementation(libs.ktor.client.core)
+ implementation(libs.ktor.client.content.negotiation)
+ implementation(libs.ktor.serialization.kotlinx.json)
+ implementation(libs.skie.annotations)
+ implementation(libs.androidx.paging.common)
+ implementation(libs.androidx.room.runtime)
+ implementation(libs.sqlite.bundled)
+ implementation(libs.kotlinx.atomicfu)
+ api(libs.androidx.datastore.preferences.core)
+ api(libs.androidx.datastore.core.okio)
+ implementation(libs.okio)
+ }
+ commonTest.dependencies {
+ implementation(libs.kotlin.test)
+ }
+ androidMain.dependencies {
+ implementation(libs.ktor.client.okhttp)
+ implementation(libs.androidx.room.paging)
+ }
+ iosMain.dependencies {
+ implementation(libs.ktor.client.darwin)
+ }
+ }
+}
+
+android {
+ namespace = "com.example.fruitties"
+ compileSdk = 34
+ defaultConfig {
+ minSdk = 26
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+}
+
+dependencies {
+ add("kspAndroid", libs.androidx.room.compiler)
+ add("kspIosSimulatorArm64", libs.androidx.room.compiler)
+ add("kspIosX64", libs.androidx.room.compiler)
+ add("kspIosArm64", libs.androidx.room.compiler)
+}
+
+room {
+ schemaDirectory("$projectDir/schemas")
+}
diff --git a/Fruitties/shared/schemas/com.example.fruitties.database.AppDatabase/1.json b/Fruitties/shared/schemas/com.example.fruitties.database.AppDatabase/1.json
new file mode 100644
index 0000000..992ed42
--- /dev/null
+++ b/Fruitties/shared/schemas/com.example.fruitties.database.AppDatabase/1.json
@@ -0,0 +1,49 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 1,
+ "identityHash": "88d6cb8637e50e45bdb804b3cba6b273",
+ "entities": [
+ {
+ "tableName": "Fruittie",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `fullName` TEXT NOT NULL, `calories` TEXT NOT NULL)",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "name",
+ "columnName": "name",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "fullName",
+ "columnName": "fullName",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "calories",
+ "columnName": "calories",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ }
+ }
+ ],
+ "setupQueries": [
+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '88d6cb8637e50e45bdb804b3cba6b273')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/Fruitties/shared/src/androidMain/kotlin/com/example/fruitties/di/Factory.android.kt b/Fruitties/shared/src/androidMain/kotlin/com/example/fruitties/di/Factory.android.kt
new file mode 100644
index 0000000..4f75a1e
--- /dev/null
+++ b/Fruitties/shared/src/androidMain/kotlin/com/example/fruitties/di/Factory.android.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.di
+
+import android.app.Application
+import androidx.room.Room
+import androidx.sqlite.driver.bundled.BundledSQLiteDriver
+import com.example.fruitties.database.AppDatabase
+import com.example.fruitties.database.CartDataStore
+import com.example.fruitties.database.dbFileName
+import com.example.fruitties.network.FruittieApi
+import kotlinx.coroutines.Dispatchers
+
+actual class Factory(private val app: Application) {
+ actual fun createRoomDatabase(): AppDatabase {
+ val dbFile = app.getDatabasePath(dbFileName)
+ return Room.databaseBuilder(app, dbFile.absolutePath)
+ .setDriver(BundledSQLiteDriver())
+ .setQueryCoroutineContext(Dispatchers.IO)
+ .build()
+ }
+
+ actual fun createCartDataStore(): CartDataStore {
+ return CartDataStore {
+ app.filesDir.resolve(
+ "cart.json",
+ ).absolutePath
+ }
+ }
+
+ actual fun createApi(): FruittieApi = commonCreateApi()
+}
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/DataRepository.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/DataRepository.kt
new file mode 100644
index 0000000..1edd4fe
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/DataRepository.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties
+
+import com.example.fruitties.database.AppDatabase
+import com.example.fruitties.database.Cart
+import com.example.fruitties.database.CartDataStore
+import com.example.fruitties.database.CartDetails
+import com.example.fruitties.database.CartItemDetails
+import com.example.fruitties.model.Fruittie
+import com.example.fruitties.network.FruittieApi
+import io.ktor.utils.io.errors.IOException
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.count
+import kotlinx.coroutines.flow.mapLatest
+import kotlinx.coroutines.flow.update
+import kotlinx.coroutines.launch
+
+class DataRepository(
+ private val api: FruittieApi,
+ private var database: AppDatabase,
+ private val cartDataStore: CartDataStore,
+ private val scope: CoroutineScope,
+) {
+ @OptIn(ExperimentalCoroutinesApi::class)
+ val cartDetails: Flow
+ get() = cartDataStore.cart.mapLatest {
+ val ids = it.items.map { it.id }
+ val fruitties = database.fruittieDao().loadMapped(ids)
+ CartDetails(
+ items = it.items.mapNotNull {
+ fruitties[it.id]?.let { fruittie ->
+ CartItemDetails(fruittie, it.count)
+ }
+ },
+ )
+ }
+
+ suspend fun addToCart(fruittie: Fruittie) {
+ cartDataStore.add(fruittie)
+ }
+
+ fun getCart(): Flow {
+ return cartDataStore.cart
+ }
+
+ fun getData(): Flow> {
+ scope.launch {
+ if (database.fruittieDao().count() < 1) {
+ refreshData()
+ }
+ }
+ return loadData()
+ }
+
+ fun loadData(): Flow> {
+ return database.fruittieDao().getAllAsFlow()
+ }
+
+ suspend fun refreshData(){
+ val response = api.getData()
+ database.fruittieDao().insert(response.feed)
+ }
+
+}
+
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/AppDatabase.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/AppDatabase.kt
new file mode 100644
index 0000000..176e3d6
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/AppDatabase.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.database
+
+import androidx.room.Database
+import androidx.room.RoomDatabase
+import com.example.fruitties.model.Fruittie
+
+@Database(entities = [Fruittie::class], version = 1)
+abstract class AppDatabase : RoomDatabase() {
+ abstract fun fruittieDao(): FruittieDao
+}
+
+internal const val dbFileName = "fruits.db"
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/CartDataStore.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/CartDataStore.kt
new file mode 100644
index 0000000..8a32ca0
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/CartDataStore.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.database
+
+import androidx.datastore.core.DataStoreFactory
+import androidx.datastore.core.okio.OkioSerializer
+import androidx.datastore.core.okio.OkioStorage
+import com.example.fruitties.di.json
+import com.example.fruitties.model.Fruittie
+import kotlinx.coroutines.flow.Flow
+import kotlinx.serialization.Serializable
+import okio.BufferedSink
+import okio.BufferedSource
+import okio.FileSystem
+import okio.Path.Companion.toPath
+import okio.SYSTEM
+import okio.use
+
+@Serializable
+data class Cart(
+ val items: List,
+)
+class CartDetails(
+ val items: List,
+)
+
+@Serializable
+data class CartItem(
+ val id: Long,
+ val count: Int,
+)
+data class CartItemDetails(
+ val fruittie: Fruittie,
+ val count: Int,
+)
+internal object CartJsonSerializer : OkioSerializer {
+ override val defaultValue: Cart = Cart(emptyList())
+ override suspend fun readFrom(source: BufferedSource): Cart {
+ return json.decodeFromString(source.readUtf8())
+ }
+ override suspend fun writeTo(t: Cart, sink: BufferedSink) {
+ sink.use {
+ it.writeUtf8(json.encodeToString(Cart.serializer(), t))
+ }
+ }
+}
+class CartDataStore(
+ private val produceFilePath: () -> String,
+) {
+ private val db = DataStoreFactory.create(
+ storage = OkioStorage(
+ fileSystem = FileSystem.SYSTEM,
+ serializer = CartJsonSerializer,
+ producePath = {
+ produceFilePath().toPath()
+ },
+ ),
+ )
+ val cart: Flow
+ get() = db.data
+ suspend fun add(fruittie: Fruittie) = update(fruittie, 1)
+ suspend fun remove(fruittie: Fruittie) = update(fruittie, -1)
+ suspend fun update(fruittie: Fruittie, diff: Int) {
+ db.updateData { prevCart ->
+ val newItems = mutableListOf()
+ var found = false
+ prevCart.items.forEach {
+ if (it.id == fruittie.id) {
+ found = true
+ newItems.add(
+ it.copy(
+ count = it.count + diff,
+ ),
+ )
+ } else {
+ newItems.add(it)
+ }
+ }
+ if (!found) {
+ newItems.add(
+ CartItem(id = fruittie.id, count = diff),
+ )
+ }
+ newItems.removeAll {
+ it.count <= 0
+ }
+ Cart(
+ items = newItems,
+ )
+ }
+ }
+}
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/FruittieDao.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/FruittieDao.kt
new file mode 100644
index 0000000..7ec8ac5
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/FruittieDao.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.database
+
+import androidx.room.Dao
+import androidx.room.Insert
+import androidx.room.MapColumn
+import androidx.room.OnConflictStrategy
+import androidx.room.Query
+import com.example.fruitties.model.Fruittie
+import kotlinx.coroutines.flow.Flow
+
+@Dao
+interface FruittieDao {
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ suspend fun insert(fruittie: Fruittie)
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ suspend fun insert(fruggie: List)
+
+ @Query("SELECT * FROM Fruittie")
+ fun getAllAsFlow(): Flow>
+
+ @Query("SELECT COUNT(*) as count FROM Fruittie")
+ suspend fun count(): Int
+
+ @Query("SELECT * FROM Fruittie WHERE id in (:ids)")
+ suspend fun loadAll(ids: List): List
+
+ @Query("SELECT * FROM Fruittie WHERE id in (:ids)")
+ suspend fun loadMapped(ids: List): Map<
+ @MapColumn(columnName = "id")
+ Long,
+ Fruittie,
+ >
+}
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/AppContainer.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/AppContainer.kt
new file mode 100644
index 0000000..4b6bfd7
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/AppContainer.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.di
+
+import com.example.fruitties.DataRepository
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.SupervisorJob
+
+class AppContainer(
+ private val factory: Factory,
+) {
+ val dataRepository: DataRepository by lazy {
+ DataRepository(
+ api = factory.createApi(),
+ database = factory.createRoomDatabase(),
+ cartDataStore = factory.createCartDataStore(),
+ scope = CoroutineScope(Dispatchers.Default + SupervisorJob()),
+ )
+ }
+}
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/Factory.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/Factory.kt
new file mode 100644
index 0000000..342d1fd
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/Factory.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.di
+
+import com.example.fruitties.database.AppDatabase
+import com.example.fruitties.database.CartDataStore
+import com.example.fruitties.network.FruittieApi
+import com.example.fruitties.network.FruittieNetworkApi
+import io.ktor.client.HttpClient
+import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
+import io.ktor.http.ContentType
+import io.ktor.serialization.kotlinx.json.json
+import kotlinx.serialization.json.Json
+
+expect class Factory {
+ fun createRoomDatabase(): AppDatabase
+ fun createApi(): FruittieApi
+ fun createCartDataStore(): CartDataStore
+}
+
+internal fun commonCreateApi(): FruittieApi = FruittieNetworkApi(
+ client = HttpClient {
+ install(ContentNegotiation) {
+ json(json, contentType = ContentType.Any)
+ }
+ },
+ apiUrl = "https://yenerm.github.io/frutties/",
+)
+
+val json = Json { ignoreUnknownKeys = true }
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/Fruittie.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/Fruittie.kt
new file mode 100644
index 0000000..922f5cd
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/Fruittie.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.model
+
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+import kotlinx.serialization.SerialName
+import kotlinx.serialization.Serializable
+
+@Serializable
+@Entity
+data class Fruittie(
+ @PrimaryKey(autoGenerate = true) val id: Long = 0,
+ @SerialName("name")
+ val name: String,
+ @SerialName("full_name")
+ val fullName: String,
+ @SerialName("calories")
+ val calories: String,
+)
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/FruittiesResponse.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/FruittiesResponse.kt
new file mode 100644
index 0000000..32b3161
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/FruittiesResponse.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.model
+
+import kotlinx.serialization.SerialName
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class FruittiesResponse(
+ @SerialName("feed")
+ val feed: List,
+ @SerialName("totalPages")
+ val totalPages: Int,
+ @SerialName("currentPage")
+ val currentPage: Int,
+)
diff --git a/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/network/FruittieApi.kt b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/network/FruittieApi.kt
new file mode 100644
index 0000000..3f8d460
--- /dev/null
+++ b/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/network/FruittieApi.kt
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.network
+
+import com.example.fruitties.model.FruittiesResponse
+import io.ktor.client.HttpClient
+import io.ktor.client.call.body
+import io.ktor.client.request.get
+import kotlin.coroutines.cancellation.CancellationException
+
+interface FruittieApi {
+ suspend fun getData(pageNumber: Int = 0): FruittiesResponse
+}
+class FruittieNetworkApi(private val client: HttpClient, private val apiUrl: String) : FruittieApi {
+
+ override suspend fun getData(pageNumber: Int): FruittiesResponse {
+ val url = apiUrl + "api/$pageNumber"
+ return try {
+ client.get(url).body()
+ } catch (e: Exception) {
+ if (e is CancellationException) throw e
+ e.printStackTrace()
+
+ FruittiesResponse(emptyList(), 0, 0)
+ }
+ }
+}
diff --git a/Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/Factory.native.kt b/Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/Factory.native.kt
new file mode 100644
index 0000000..4b3bf9c
--- /dev/null
+++ b/Fruitties/shared/src/nativeMain/kotlin/com/example/fruitties/di/Factory.native.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.fruitties.di
+
+import androidx.room.Room
+import androidx.sqlite.driver.bundled.BundledSQLiteDriver
+import com.example.fruitties.database.AppDatabase
+import com.example.fruitties.database.CartDataStore
+import com.example.fruitties.database.dbFileName
+import com.example.fruitties.database.instantiateImpl
+import com.example.fruitties.network.FruittieApi
+import kotlinx.cinterop.ExperimentalForeignApi
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.IO
+import platform.Foundation.NSDocumentDirectory
+import platform.Foundation.NSFileManager
+import platform.Foundation.NSURL
+import platform.Foundation.NSUserDomainMask
+
+actual class Factory {
+ actual fun createRoomDatabase(): AppDatabase {
+ val dbFile = "${fileDirectory()}/$dbFileName"
+ return Room.databaseBuilder(
+ name = dbFile,
+ factory = { AppDatabase::class.instantiateImpl() }
+ ).setDriver(BundledSQLiteDriver())
+ .setQueryCoroutineContext(Dispatchers.IO)
+ .build()
+ }
+
+ actual fun createCartDataStore(): CartDataStore {
+ return CartDataStore {
+ "${fileDirectory()}/cart.json"
+ }
+ }
+
+ @OptIn(ExperimentalForeignApi::class)
+ private fun fileDirectory(): String {
+ val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(
+ directory = NSDocumentDirectory,
+ inDomain = NSUserDomainMask,
+ appropriateForURL = null,
+ create = false,
+ error = null,
+ )
+ return requireNotNull(documentDirectory).path!!
+ }
+
+ actual fun createApi(): FruittieApi = commonCreateApi()
+}
diff --git a/README.md b/README.md
index 57a4e54..e07354c 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,10 @@
DiceRoller is a sample app using the Kotlin Multiplatform DataStore library to store and observe preferences.
+## [Fruitties](./Fruitties)
+
+Fruitties is a sample app using the Kotlin Multiplatform Room, DataStore and Ktor libraries to fetch, store and display data.
+
## License
```