├── .github
├── CODEOWNERS
└── workflows
│ └── Fruitties.yaml
├── .gitignore
├── CONTRIBUTING.md
├── Fruitties
├── .editorconfig
├── .gitignore
├── androidApp
│ ├── build.gradle.kts
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── fruitties
│ │ │ └── android
│ │ │ ├── MainActivity.kt
│ │ │ ├── MyApplicationTheme.kt
│ │ │ ├── di
│ │ │ └── App.kt
│ │ │ └── ui
│ │ │ └── ListScreen.kt
│ │ └── res
│ │ ├── values
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ ├── data_extraction_rules.xml
│ │ └── full_backup_content.xml
├── build.gradle.kts
├── gradle.properties
├── gradle
│ ├── libs.versions.toml
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── iosApp
│ ├── Podfile
│ ├── iosApp.xcodeproj
│ │ └── project.pbxproj
│ └── iosApp
│ │ ├── Assets.xcassets
│ │ ├── AccentColor.colorset
│ │ │ └── Contents.json
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── Contents.json
│ │ ├── CartView.swift
│ │ ├── ContentView.swift
│ │ ├── Info.plist
│ │ ├── Preview Content
│ │ └── Preview Assets.xcassets
│ │ │ └── Contents.json
│ │ └── iOSApp.swift
├── settings.gradle.kts
└── shared
│ ├── .gitignore
│ ├── build.gradle.kts
│ ├── schemas
│ └── com.example.fruitties.database.AppDatabase
│ │ └── 1.json
│ └── src
│ ├── androidMain
│ ├── AndroidManifest.xml
│ └── kotlin
│ │ └── com
│ │ └── example
│ │ └── fruitties
│ │ └── di
│ │ └── Factory.android.kt
│ ├── commonMain
│ └── kotlin
│ │ └── com
│ │ └── example
│ │ └── fruitties
│ │ ├── DataRepository.kt
│ │ ├── database
│ │ ├── AppDatabase.kt
│ │ ├── CartDataStore.kt
│ │ └── FruittieDao.kt
│ │ ├── di
│ │ ├── AppContainer.kt
│ │ └── Factory.kt
│ │ ├── model
│ │ ├── Fruittie.kt
│ │ └── FruittiesResponse.kt
│ │ ├── network
│ │ └── FruittieApi.kt
│ │ └── viewmodel
│ │ └── MainViewModel.kt
│ └── iosMain
│ └── kotlin
│ └── com
│ └── example
│ └── fruitties
│ └── di
│ ├── Factory.native.kt
│ └── viewmodel
│ └── IOSViewModelOwner.kt
├── LICENSE
├── README.md
└── renovate.json
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @android/kmp-devrel
2 |
--------------------------------------------------------------------------------
/.github/workflows/Fruitties.yaml:
--------------------------------------------------------------------------------
1 | name: Build Fruitties sample
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | branches:
7 | - main
8 | - feature/*
9 | pull_request:
10 |
11 | concurrency:
12 | group: build-${{ github.ref }}
13 | cancel-in-progress: true
14 |
15 | jobs:
16 | build_android:
17 | name: Build Android app
18 | runs-on: ubuntu-latest
19 | steps:
20 | - name: Checkout
21 | uses: actions/checkout@v4
22 |
23 | - name: Validate Gradle Wrapper
24 | uses: gradle/wrapper-validation-action@v3
25 |
26 | - name: Set up JDK 17
27 | uses: actions/setup-java@v4
28 | with:
29 | distribution: 'zulu'
30 | java-version: 17
31 |
32 | - name: Build app
33 | working-directory: ./Fruitties
34 | run: ./gradlew assemble --stacktrace
35 |
36 | build_ios:
37 | name: Build iOS app
38 | runs-on: macos-latest
39 | steps:
40 | - uses: maxim-lobanov/setup-xcode@v1
41 | with:
42 | xcode-version: latest-stable
43 |
44 | - name: Checkout
45 | uses: actions/checkout@v4
46 |
47 | - name: Validate Gradle Wrapper
48 | uses: gradle/wrapper-validation-action@v3
49 |
50 | - name: Set up JDK 17
51 | uses: actions/setup-java@v4
52 | with:
53 | distribution: 'zulu'
54 | java-version: 17
55 |
56 | - name: Build app
57 | working-directory: ./Fruitties
58 | run: xcodebuild -project iosApp/iosApp.xcodeproj -configuration Debug -scheme iosApp -sdk iphonesimulator
59 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Android Studio
2 | /*/build/
3 | /*/local.properties
4 | /*/out
5 | /*/*/build
6 | /*/*/production
7 | captures/
8 | .navigation/
9 | *.ipr
10 | *~
11 | *.swp
12 | *.iml
13 | .idea/caches/
14 | .idea/libraries/
15 | .idea/shelf/
16 | .idea/workspace.xml
17 | .idea/tasks.xml
18 | .idea/.name
19 | .idea/compiler.xml
20 | .idea/copyright/profiles_settings.xml
21 | .idea/encodings.xml
22 | .idea/misc.xml
23 | .idea/modules.xml
24 | .idea/scopes/scope_settings.xml
25 | .idea/dictionaries
26 | .idea/vcs.xml
27 | .idea/jsLibraryMappings.xml
28 | .idea/datasources.xml
29 | .idea/dataSources.ids
30 | .idea/sqlDataSources.xml
31 | .idea/dynamic.xml
32 | .idea/uiDesigner.xml
33 | .idea/assetWizardSettings.xml
34 | .idea/gradle.xml
35 | .idea/jarRepositories.xml
36 | .idea/navEditor.xml
37 | !/gradle/wrapper/gradle-wrapper.jar
38 |
39 | ### Xcode ###
40 | *.xcodeproj/*
41 | !*.xcodeproj/project.pbxproj
42 | !*.xcodeproj/xcshareddata/
43 | !*.xcworkspace/contents.xcworkspacedata/
44 | /*.gcno
45 | **/xcshareddata/WorkspaceSettings.xcsettings
46 | *.xcuserstate
47 | *.xcscheme
48 | *.xcworkspace
49 | xcuserdata/
50 |
51 | # CocoaPods
52 | Pods/
53 |
54 | ## iOS App packaging
55 | *.ipa
56 | *.dSYM.zip
57 | *.dSYM
58 |
59 | # Android App packaging
60 | *.apk
61 | *.ap_
62 | *.aab
63 |
64 | # macOs
65 | .DS_Store
66 |
67 | # Generated files
68 | bin/
69 | gen/
70 | *.class
71 | *.dex
72 |
73 | # Gradle files
74 | .gradle
75 | .gradle/
76 | build/
77 |
78 | # Local configuration file
79 | local.properties
80 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code Reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google/conduct/).
29 |
--------------------------------------------------------------------------------
/Fruitties/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.{kt,kts}]
2 | # Kotlin style typically requires functions to start with a lowercase letter.
3 | # Composable functions should start with a capital letter.
4 | ktlint_function_naming_ignore_when_annotated_with = Composable
5 |
6 | # ktlint always puts a new line after a multi-line assignment, like this:
7 | # val colors =
8 | # if (darkTheme) {
9 | # darkColorScheme(
10 | # primary = Color(0xFFBB86FC),
11 | # secondary = Color(0xFF03DAC5),
12 | # tertiary = Color(0xFF3700B3),
13 | # )
14 | # } else {
15 | # lightColorScheme(
16 | # primary = Color(0xFF6200EE),
17 | # secondary = Color(0xFF03DAC5),
18 | # tertiary = Color(0xFF3700B3),
19 | # )
20 | # }
21 | # But we actually prefer to keep some multi-line assignments on the same line, like this:
22 | # val colors = if (darkTheme) {
23 | # darkColorScheme(
24 | # primary = Color(0xFFBB86FC),
25 | # secondary = Color(0xFF03DAC5),
26 | # tertiary = Color(0xFF3700B3),
27 | # )
28 | # } else {
29 | # lightColorScheme(
30 | # primary = Color(0xFF6200EE),
31 | # secondary = Color(0xFF03DAC5),
32 | # tertiary = Color(0xFF3700B3),
33 | # )
34 | # }
35 | ktlint_standard_multiline-expression-wrapping = disabled
36 |
--------------------------------------------------------------------------------
/Fruitties/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | .DS_Store
5 | build
6 | captures
7 | .externalNativeBuild
8 | .cxx
9 | local.properties
10 | xcuserdata
11 | .kotlin
12 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | plugins {
17 | alias(libs.plugins.androidApplication)
18 | alias(libs.plugins.kotlinAndroid)
19 | alias(libs.plugins.compose.compiler)
20 | }
21 |
22 | android {
23 | namespace = "com.example.fruitties.android"
24 | compileSdk = 35
25 | defaultConfig {
26 | applicationId = "com.example.fruitties.android"
27 | minSdk = 26
28 | targetSdk = 35
29 | versionCode = 1
30 | versionName = "1.0"
31 | }
32 | buildFeatures {
33 | compose = true
34 | }
35 | packaging {
36 | resources {
37 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
38 | }
39 | }
40 | buildTypes {
41 | getByName("release") {
42 | // Enables code shrinking, obfuscation, and optimization for only
43 | // your project's release build type. Make sure to use a build
44 | // variant with `isDebuggable=false`.
45 | isMinifyEnabled = true
46 |
47 | // Enables resource shrinking, which is performed by the
48 | // Android Gradle plugin.
49 | isShrinkResources = true
50 |
51 | proguardFiles(
52 | // Includes the default ProGuard rules files that are packaged with
53 | // the Android Gradle plugin. To learn more, go to the section about
54 | // R8 configuration files.
55 | getDefaultProguardFile("proguard-android-optimize.txt"),
56 | // Includes a local, custom Proguard rules file
57 | "proguard-rules.pro",
58 | )
59 | }
60 | }
61 | compileOptions {
62 | sourceCompatibility = JavaVersion.VERSION_1_8
63 | targetCompatibility = JavaVersion.VERSION_1_8
64 | }
65 | kotlinOptions {
66 | jvmTarget = "1.8"
67 | }
68 | }
69 |
70 | dependencies {
71 | implementation(projects.shared)
72 |
73 | val composeBom = platform(libs.compose.bom)
74 | implementation(composeBom)
75 | implementation(libs.compose.ui)
76 | implementation(libs.compose.ui.tooling.preview)
77 | implementation(libs.compose.material3)
78 | implementation(libs.androidx.activity.compose)
79 | implementation(libs.androidx.paging.compose.android)
80 | implementation(libs.androidx.lifecycle.viewmodel.compose)
81 | debugImplementation(libs.compose.ui.tooling)
82 | }
83 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Please add these rules to your existing keep rules in order to suppress warnings.
2 | # This is generated automatically by the Android Gradle plugin.
3 | -dontwarn org.slf4j.impl.StaticLoggerBinder
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.fruitties.android
18 |
19 | import android.os.Bundle
20 | import androidx.activity.ComponentActivity
21 | import androidx.activity.compose.setContent
22 | import androidx.activity.enableEdgeToEdge
23 | import androidx.compose.foundation.layout.fillMaxSize
24 | import androidx.compose.material3.MaterialTheme
25 | import androidx.compose.material3.Surface
26 | import androidx.compose.ui.Modifier
27 | import com.example.fruitties.android.ui.ListScreen
28 |
29 | class MainActivity : ComponentActivity() {
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | enableEdgeToEdge()
33 | setContent {
34 | MyApplicationTheme {
35 | Surface(
36 | modifier = Modifier.fillMaxSize(),
37 | color = MaterialTheme.colorScheme.background,
38 | ) {
39 | ListScreen()
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/java/com/example/fruitties/android/MyApplicationTheme.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.android
17 |
18 | import androidx.compose.foundation.isSystemInDarkTheme
19 | import androidx.compose.foundation.shape.RoundedCornerShape
20 | import androidx.compose.material3.MaterialTheme
21 | import androidx.compose.material3.Shapes
22 | import androidx.compose.material3.Typography
23 | import androidx.compose.material3.darkColorScheme
24 | import androidx.compose.material3.lightColorScheme
25 | import androidx.compose.runtime.Composable
26 | import androidx.compose.ui.graphics.Color
27 | import androidx.compose.ui.text.TextStyle
28 | import androidx.compose.ui.text.font.FontFamily
29 | import androidx.compose.ui.text.font.FontWeight
30 | import androidx.compose.ui.unit.dp
31 | import androidx.compose.ui.unit.sp
32 |
33 | @Composable
34 | fun MyApplicationTheme(
35 | darkTheme: Boolean = isSystemInDarkTheme(),
36 | content: @Composable () -> Unit,
37 | ) {
38 | val colors = if (darkTheme) {
39 | darkColorScheme(
40 | primary = Color(0xFFBB86FC),
41 | secondary = Color(0xFF03DAC5),
42 | tertiary = Color(0xFF3700B3),
43 | )
44 | } else {
45 | lightColorScheme(
46 | primary = Color(0xFF6200EE),
47 | secondary = Color(0xFF03DAC5),
48 | tertiary = Color(0xFF3700B3),
49 | )
50 | }
51 | val typography = Typography(
52 | bodyMedium = TextStyle(
53 | fontFamily = FontFamily.Default,
54 | fontWeight = FontWeight.Normal,
55 | fontSize = 16.sp,
56 | ),
57 | )
58 | val shapes = Shapes(
59 | small = RoundedCornerShape(4.dp),
60 | medium = RoundedCornerShape(4.dp),
61 | large = RoundedCornerShape(0.dp),
62 | )
63 |
64 | MaterialTheme(
65 | colorScheme = colors,
66 | typography = typography,
67 | shapes = shapes,
68 | content = content,
69 | )
70 | }
71 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/java/com/example/fruitties/android/di/App.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.fruitties.android.di
18 |
19 | import android.app.Application
20 | import com.example.fruitties.di.AppContainer
21 | import com.example.fruitties.di.Factory
22 |
23 | class App : Application() {
24 | /** AppContainer instance used by the rest of classes to obtain dependencies */
25 | lateinit var container: AppContainer
26 |
27 | override fun onCreate() {
28 | super.onCreate()
29 | container = AppContainer(Factory(this))
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListScreen.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.fruitties.android.ui
18 |
19 | import androidx.compose.animation.AnimatedVisibility
20 | import androidx.compose.animation.core.tween
21 | import androidx.compose.animation.fadeIn
22 | import androidx.compose.animation.fadeOut
23 | import androidx.compose.foundation.layout.Arrangement
24 | import androidx.compose.foundation.layout.Column
25 | import androidx.compose.foundation.layout.Row
26 | import androidx.compose.foundation.layout.Spacer
27 | import androidx.compose.foundation.layout.WindowInsets
28 | import androidx.compose.foundation.layout.WindowInsetsSides
29 | import androidx.compose.foundation.layout.fillMaxWidth
30 | import androidx.compose.foundation.layout.heightIn
31 | import androidx.compose.foundation.layout.only
32 | import androidx.compose.foundation.layout.padding
33 | import androidx.compose.foundation.layout.safeDrawing
34 | import androidx.compose.foundation.layout.systemBars
35 | import androidx.compose.foundation.layout.windowInsetsBottomHeight
36 | import androidx.compose.foundation.lazy.LazyColumn
37 | import androidx.compose.foundation.lazy.items
38 | import androidx.compose.foundation.shape.RoundedCornerShape
39 | import androidx.compose.material3.Button
40 | import androidx.compose.material3.Card
41 | import androidx.compose.material3.CardDefaults
42 | import androidx.compose.material3.CenterAlignedTopAppBar
43 | import androidx.compose.material3.ExperimentalMaterial3Api
44 | import androidx.compose.material3.MaterialTheme
45 | import androidx.compose.material3.Scaffold
46 | import androidx.compose.material3.Text
47 | import androidx.compose.material3.TopAppBarColors
48 | import androidx.compose.runtime.Composable
49 | import androidx.compose.runtime.collectAsState
50 | import androidx.compose.runtime.getValue
51 | import androidx.compose.runtime.mutableStateOf
52 | import androidx.compose.runtime.remember
53 | import androidx.compose.runtime.setValue
54 | import androidx.compose.ui.Alignment
55 | import androidx.compose.ui.Modifier
56 | import androidx.compose.ui.draw.clip
57 | import androidx.compose.ui.platform.LocalContext
58 | import androidx.compose.ui.res.stringResource
59 | import androidx.compose.ui.text.style.TextOverflow
60 | import androidx.compose.ui.tooling.preview.Preview
61 | import androidx.compose.ui.unit.dp
62 | import androidx.lifecycle.viewmodel.compose.viewModel
63 | import com.example.fruitties.android.R
64 | import com.example.fruitties.android.di.App
65 | import com.example.fruitties.model.CartItemDetails
66 | import com.example.fruitties.model.Fruittie
67 | import com.example.fruitties.viewmodel.MainViewModel
68 |
69 | @OptIn(ExperimentalMaterial3Api::class)
70 | @Composable
71 | fun ListScreen() {
72 | // Instantiate a ViewModel with a dependency on the AppContainer.
73 | // To make ViewModel compatible with KMP, the ViewModel factory must
74 | // create an instance without referencing the Android Application.
75 | // Here we put the KMP-compatible AppContainer into the extras
76 | // so it can be passed to the ViewModel factory.
77 | val app = LocalContext.current.applicationContext as App
78 | val extras = remember(app) {
79 | val container = app.container
80 | MainViewModel.newCreationExtras(container)
81 | }
82 | val viewModel: MainViewModel = viewModel(
83 | factory = MainViewModel.Factory,
84 | extras = extras,
85 | )
86 |
87 | val uiState by viewModel.homeUiState.collectAsState()
88 | val cartState by viewModel.cartUiState.collectAsState()
89 |
90 | Scaffold(
91 | topBar = {
92 | CenterAlignedTopAppBar(
93 | title = {
94 | Text(text = stringResource(R.string.frutties))
95 | },
96 | colors = TopAppBarColors(
97 | containerColor = MaterialTheme.colorScheme.primary,
98 | scrolledContainerColor = MaterialTheme.colorScheme.primary,
99 | navigationIconContentColor = MaterialTheme.colorScheme.onPrimary,
100 | titleContentColor = MaterialTheme.colorScheme.onPrimary,
101 | actionIconContentColor = MaterialTheme.colorScheme.onPrimary,
102 | ),
103 | )
104 | },
105 | contentWindowInsets = WindowInsets.safeDrawing.only(
106 | // Do not include Bottom so scrolled content is drawn below system bars.
107 | // Include Horizontal because some devices have camera cutouts on the side.
108 | WindowInsetsSides.Top + WindowInsetsSides.Horizontal,
109 | ),
110 | ) { paddingValues ->
111 | Column(
112 | modifier = Modifier
113 | // Support edge-to-edge (required on Android 15)
114 | // https://developer.android.com/develop/ui/compose/layouts/insets#inset-size
115 | .padding(paddingValues),
116 | ) {
117 | var expanded by remember { mutableStateOf(false) }
118 | Row(modifier = Modifier.padding(16.dp)) {
119 | val total = cartState.cartDetails.sumOf { item -> item.count }
120 | Text(
121 | text = "Cart has $total items",
122 | modifier = Modifier.weight(1f).padding(12.dp),
123 | )
124 | Button(onClick = { expanded = !expanded }) {
125 | Text(text = if (expanded) "collapse" else "expand")
126 | }
127 | }
128 | AnimatedVisibility(
129 | visible = expanded,
130 | enter = fadeIn(animationSpec = tween(1000)),
131 | exit = fadeOut(animationSpec = tween(1000)),
132 | ) {
133 | CartDetailsView(cartState.cartDetails)
134 | }
135 |
136 | LazyColumn {
137 | items(items = uiState.fruitties, key = { it.id }) { item ->
138 | FruittieItem(
139 | item = item,
140 | onAddToCart = viewModel::addItemToCart,
141 | )
142 | }
143 | // Support edge-to-edge (required on Android 15)
144 | // https://developer.android.com/develop/ui/compose/layouts/insets#inset-size
145 | item {
146 | Spacer(
147 | Modifier.windowInsetsBottomHeight(
148 | WindowInsets.systemBars,
149 | ),
150 | )
151 | }
152 | }
153 | }
154 | }
155 | }
156 |
157 | @Composable
158 | fun FruittieItem(
159 | item: Fruittie,
160 | onAddToCart: (fruittie: Fruittie) -> Unit,
161 | modifier: Modifier = Modifier,
162 | ) {
163 | Card(
164 | modifier = modifier
165 | .padding(horizontal = 16.dp, vertical = 8.dp)
166 | .clip(RoundedCornerShape(8.dp)),
167 | shape = RoundedCornerShape(8.dp),
168 | colors = CardDefaults.cardColors(
169 | containerColor = MaterialTheme.colorScheme.surface,
170 | ),
171 | elevation = CardDefaults.cardElevation(
172 | defaultElevation = 8.dp,
173 | ),
174 | ) {
175 | Row(
176 | modifier = Modifier.fillMaxWidth(),
177 | verticalAlignment = Alignment.CenterVertically,
178 | ) {
179 | Column(
180 | modifier = Modifier
181 | .heightIn(min = 96.dp),
182 | verticalArrangement = Arrangement.Center,
183 | ) {
184 | Text(
185 | text = item.name,
186 | color = MaterialTheme.colorScheme.onBackground,
187 | style = MaterialTheme.typography.titleMedium,
188 | maxLines = 1,
189 | overflow = TextOverflow.Ellipsis,
190 | modifier = Modifier
191 | .padding(horizontal = 16.dp)
192 | .padding(top = 8.dp),
193 | )
194 | Text(
195 | text = item.fullName,
196 | modifier = Modifier
197 | .padding(horizontal = 16.dp)
198 | .padding(bottom = 8.dp),
199 | color = MaterialTheme.colorScheme.onSurface,
200 | maxLines = 2,
201 | overflow = TextOverflow.Ellipsis,
202 | )
203 | }
204 | Spacer(modifier = Modifier.weight(1f))
205 | Row(
206 | modifier = Modifier
207 | .padding(horizontal = 16.dp, vertical = 8.dp),
208 | verticalAlignment = Alignment.CenterVertically,
209 | ) {
210 | Button(onClick = { onAddToCart(item) }) {
211 | Text(stringResource(R.string.add))
212 | }
213 | }
214 | }
215 | }
216 | }
217 |
218 | @Composable
219 | fun CartDetailsView(
220 | cart: List,
221 | modifier: Modifier = Modifier,
222 | ) {
223 | Column(
224 | modifier.padding(horizontal = 32.dp),
225 | ) {
226 | cart.forEach { item ->
227 | Text(text = "${item.fruittie.name}: ${item.count}")
228 | }
229 | }
230 | }
231 |
232 | @Preview
233 | @Composable
234 | fun ItemPreview() {
235 | FruittieItem(
236 | Fruittie(name = "Fruit", fullName = "Fruitus Mangorus", calories = "240"),
237 | onAddToCart = {},
238 | )
239 | }
240 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | "Frutties"
19 | Add
20 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Fruitties/androidApp/src/main/res/xml/full_backup_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Fruitties/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | plugins {
17 | //trick: for the same plugin versions in all sub-modules
18 | alias(libs.plugins.androidApplication) apply false
19 | alias(libs.plugins.androidLibrary) apply false
20 | alias(libs.plugins.kotlinAndroid) apply false
21 | alias(libs.plugins.kotlinMultiplatform) apply false
22 | alias(libs.plugins.compose.compiler) apply false
23 | alias(libs.plugins.spotless) apply false
24 | alias(libs.plugins.androidKmpLibrary) apply false
25 | }
26 |
27 | subprojects {
28 | apply(plugin = "com.diffplug.spotless")
29 | configure {
30 | kotlin {
31 | target("**/*.kt")
32 | targetExclude("${layout.buildDirectory}/**/*.kt")
33 |
34 | ktlint()
35 | }
36 |
37 | kotlinGradle {
38 | target("*.gradle.kts")
39 | ktlint()
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Fruitties/gradle.properties:
--------------------------------------------------------------------------------
1 | #Gradle
2 | org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
3 | org.gradle.caching=true
4 | org.gradle.configuration-cache=false
5 |
6 | #Kotlin
7 | kotlin.code.style=official
8 |
9 | #Android
10 | android.useAndroidX=true
11 | android.nonTransitiveRClass=true
12 |
13 | #KMP
14 | # Disabled due to https://youtrack.jetbrains.com/issue/KT-74278/
15 | kotlin.native.toolchain.enabled=false
16 |
--------------------------------------------------------------------------------
/Fruitties/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | [versions]
16 | agp = "8.10.0"
17 | androidx-activityCompose = "1.10.1"
18 | androidx-paging = "3.3.6"
19 | androidx-room = "2.7.1"
20 | androidx-lifecycle = "2.9.0"
21 | atomicfu = "0.27.0"
22 | composeBom = "2025.05.00"
23 | dataStore = "1.1.6"
24 | kotlin = "2.1.10"
25 | kotlinx-coroutines = "1.10.2"
26 | kotlinxDatetime = "0.6.2"
27 | ksp = "2.1.10-1.0.31"
28 | ktorVersion = "3.1.3"
29 | pagingComposeAndroid = "3.3.6"
30 | skie = "0.10.1"
31 | sqlite = "2.5.1"
32 | spotless = "7.0.3"
33 | okio = "3.11.0"
34 | runner = "1.6.2"
35 | core = "1.6.1"
36 | junit = "1.2.1"
37 |
38 | [libraries]
39 | androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
40 | androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore-core-okio", version.ref = "dataStore" }
41 | androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "dataStore" }
42 | androidx-paging-common = { module = "androidx.paging:paging-common", version.ref = "androidx-paging" }
43 | androidx-paging-compose-android = { group = "androidx.paging", name = "paging-compose-android", version.ref = "pagingComposeAndroid" }
44 | androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "androidx-room" }
45 | androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "androidx-room" }
46 | androidx-room-paging = { group = "androidx.room", name = "room-paging", version.ref = "androidx-room" }
47 | androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "androidx-lifecycle" }
48 | androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
49 | compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" }
50 | compose-ui = { module = "androidx.compose.ui:ui" }
51 | compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
52 | compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
53 | compose-material3 = { module = "androidx.compose.material3:material3" }
54 | kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
55 | kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" }
56 | kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
57 | kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
58 | ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktorVersion" }
59 | ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorVersion" }
60 | ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktorVersion" }
61 | ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorVersion" }
62 | ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
63 | okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
64 | skie-annotations = { module = "co.touchlab.skie:configuration-annotations", version.ref = "skie" }
65 | sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
66 | kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
67 | androidx-runner = { group = "androidx.test", name = "runner", version.ref = "runner" }
68 | androidx-core = { group = "androidx.test", name = "core", version.ref = "core" }
69 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junit" }
70 |
71 | [plugins]
72 | androidApplication = { id = "com.android.application", version.ref = "agp" }
73 | androidLibrary = { id = "com.android.library", version.ref = "agp" }
74 | kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
75 | kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
76 | androidKmpLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
77 | kotlinxSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
78 | compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
79 | skie = { id = "co.touchlab.skie", version.ref = "skie" }
80 | ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
81 | room = { id = "androidx.room", version.ref = "androidx-room" }
82 | spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
83 |
--------------------------------------------------------------------------------
/Fruitties/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/kotlin-multiplatform-samples/a5c58bcd75cefff975fad0d6a27e5d05a4bbdb21/Fruitties/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Fruitties/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/Fruitties/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/Fruitties/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/Podfile:
--------------------------------------------------------------------------------
1 | target 'iosApp' do
2 | platform :ios, '14.1'
3 | end
4 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
11 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
12 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
13 | 2E8773602BC85C2400BF7C40 /* CartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E87735F2BC85C2400BF7C40 /* CartView.swift */; };
14 | 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
15 | /* End PBXBuildFile section */
16 |
17 | /* Begin PBXCopyFilesBuildPhase section */
18 | 7555FFB4242A642300829871 /* Embed Frameworks */ = {
19 | isa = PBXCopyFilesBuildPhase;
20 | buildActionMask = 2147483647;
21 | dstPath = "";
22 | dstSubfolderSpec = 10;
23 | files = (
24 | );
25 | name = "Embed Frameworks";
26 | runOnlyForDeploymentPostprocessing = 0;
27 | };
28 | /* End PBXCopyFilesBuildPhase section */
29 |
30 | /* Begin PBXFileReference section */
31 | 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
32 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; };
33 | 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; };
34 | 2E87735F2BC85C2400BF7C40 /* CartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CartView.swift; sourceTree = ""; };
35 | 7555FF7B242A565900829871 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
36 | 7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; };
37 | 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
38 | /* End PBXFileReference section */
39 |
40 | /* Begin PBXFrameworksBuildPhase section */
41 | 7555FF78242A565900829871 /* Frameworks */ = {
42 | isa = PBXFrameworksBuildPhase;
43 | buildActionMask = 2147483647;
44 | files = (
45 | );
46 | runOnlyForDeploymentPostprocessing = 0;
47 | };
48 | /* End PBXFrameworksBuildPhase section */
49 |
50 | /* Begin PBXGroup section */
51 | 058557D7273AAEEB004C7B11 /* Preview Content */ = {
52 | isa = PBXGroup;
53 | children = (
54 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */,
55 | );
56 | path = "Preview Content";
57 | sourceTree = "";
58 | };
59 | 7555FF72242A565900829871 = {
60 | isa = PBXGroup;
61 | children = (
62 | 7555FF7D242A565900829871 /* iosApp */,
63 | 7555FF7C242A565900829871 /* Products */,
64 | 7555FFB0242A642200829871 /* Frameworks */,
65 | );
66 | sourceTree = "";
67 | };
68 | 7555FF7C242A565900829871 /* Products */ = {
69 | isa = PBXGroup;
70 | children = (
71 | 7555FF7B242A565900829871 /* iosApp.app */,
72 | );
73 | name = Products;
74 | sourceTree = "";
75 | };
76 | 7555FF7D242A565900829871 /* iosApp */ = {
77 | isa = PBXGroup;
78 | children = (
79 | 058557BA273AAA24004C7B11 /* Assets.xcassets */,
80 | 7555FF82242A565900829871 /* ContentView.swift */,
81 | 7555FF8C242A565B00829871 /* Info.plist */,
82 | 2152FB032600AC8F00CF470E /* iOSApp.swift */,
83 | 058557D7273AAEEB004C7B11 /* Preview Content */,
84 | 2E87735F2BC85C2400BF7C40 /* CartView.swift */,
85 | );
86 | path = iosApp;
87 | sourceTree = "";
88 | };
89 | 7555FFB0242A642200829871 /* Frameworks */ = {
90 | isa = PBXGroup;
91 | children = (
92 | );
93 | name = Frameworks;
94 | sourceTree = "";
95 | };
96 | /* End PBXGroup section */
97 |
98 | /* Begin PBXNativeTarget section */
99 | 7555FF7A242A565900829871 /* iosApp */ = {
100 | isa = PBXNativeTarget;
101 | buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */;
102 | buildPhases = (
103 | 7555FFB5242A651A00829871 /* Compile Kotlin Multiplatform */,
104 | 7555FF77242A565900829871 /* Sources */,
105 | 7555FF78242A565900829871 /* Frameworks */,
106 | 7555FF79242A565900829871 /* Resources */,
107 | 7555FFB4242A642300829871 /* Embed Frameworks */,
108 | );
109 | buildRules = (
110 | );
111 | dependencies = (
112 | );
113 | name = iosApp;
114 | productName = iosApp;
115 | productReference = 7555FF7B242A565900829871 /* iosApp.app */;
116 | productType = "com.apple.product-type.application";
117 | };
118 | /* End PBXNativeTarget section */
119 |
120 | /* Begin PBXProject section */
121 | 7555FF73242A565900829871 /* Project object */ = {
122 | isa = PBXProject;
123 | attributes = {
124 | LastSwiftUpdateCheck = 1130;
125 | LastUpgradeCheck = 1130;
126 | ORGANIZATIONNAME = orgName;
127 | TargetAttributes = {
128 | 7555FF7A242A565900829871 = {
129 | CreatedOnToolsVersion = 11.3.1;
130 | };
131 | };
132 | };
133 | buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */;
134 | compatibilityVersion = "Xcode 9.3";
135 | developmentRegion = en;
136 | hasScannedForEncodings = 0;
137 | knownRegions = (
138 | en,
139 | Base,
140 | );
141 | mainGroup = 7555FF72242A565900829871;
142 | productRefGroup = 7555FF7C242A565900829871 /* Products */;
143 | projectDirPath = "";
144 | projectRoot = "";
145 | targets = (
146 | 7555FF7A242A565900829871 /* iosApp */,
147 | );
148 | };
149 | /* End PBXProject section */
150 |
151 | /* Begin PBXResourcesBuildPhase section */
152 | 7555FF79242A565900829871 /* Resources */ = {
153 | isa = PBXResourcesBuildPhase;
154 | buildActionMask = 2147483647;
155 | files = (
156 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */,
157 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */,
158 | );
159 | runOnlyForDeploymentPostprocessing = 0;
160 | };
161 | /* End PBXResourcesBuildPhase section */
162 |
163 | /* Begin PBXShellScriptBuildPhase section */
164 | 7555FFB5242A651A00829871 /* Compile Kotlin Multiplatform */ = {
165 | isa = PBXShellScriptBuildPhase;
166 | buildActionMask = 2147483647;
167 | files = (
168 | );
169 | inputFileListPaths = (
170 | );
171 | inputPaths = (
172 | );
173 | name = "Compile Kotlin Multiplatform";
174 | outputFileListPaths = (
175 | );
176 | outputPaths = (
177 | );
178 | runOnlyForDeploymentPostprocessing = 0;
179 | shellPath = /bin/sh;
180 | shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n";
181 | };
182 | /* End PBXShellScriptBuildPhase section */
183 |
184 | /* Begin PBXSourcesBuildPhase section */
185 | 7555FF77242A565900829871 /* Sources */ = {
186 | isa = PBXSourcesBuildPhase;
187 | buildActionMask = 2147483647;
188 | files = (
189 | 2E8773602BC85C2400BF7C40 /* CartView.swift in Sources */,
190 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
191 | 7555FF83242A565900829871 /* ContentView.swift in Sources */,
192 | );
193 | runOnlyForDeploymentPostprocessing = 0;
194 | };
195 | /* End PBXSourcesBuildPhase section */
196 |
197 | /* Begin XCBuildConfiguration section */
198 | 7555FFA3242A565B00829871 /* Debug */ = {
199 | isa = XCBuildConfiguration;
200 | buildSettings = {
201 | ALWAYS_SEARCH_USER_PATHS = NO;
202 | CLANG_ANALYZER_NONNULL = YES;
203 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
204 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
205 | CLANG_CXX_LIBRARY = "libc++";
206 | CLANG_ENABLE_MODULES = YES;
207 | CLANG_ENABLE_OBJC_ARC = YES;
208 | CLANG_ENABLE_OBJC_WEAK = YES;
209 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
210 | CLANG_WARN_BOOL_CONVERSION = YES;
211 | CLANG_WARN_COMMA = YES;
212 | CLANG_WARN_CONSTANT_CONVERSION = YES;
213 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
214 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
215 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
216 | CLANG_WARN_EMPTY_BODY = YES;
217 | CLANG_WARN_ENUM_CONVERSION = YES;
218 | CLANG_WARN_INFINITE_RECURSION = YES;
219 | CLANG_WARN_INT_CONVERSION = YES;
220 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
221 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
222 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
223 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
224 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
225 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
226 | CLANG_WARN_STRICT_PROTOTYPES = YES;
227 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
228 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
229 | CLANG_WARN_UNREACHABLE_CODE = YES;
230 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
231 | COPY_PHASE_STRIP = NO;
232 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
233 | ENABLE_STRICT_OBJC_MSGSEND = YES;
234 | ENABLE_TESTABILITY = YES;
235 | GCC_C_LANGUAGE_STANDARD = gnu11;
236 | GCC_DYNAMIC_NO_PIC = NO;
237 | GCC_NO_COMMON_BLOCKS = YES;
238 | GCC_OPTIMIZATION_LEVEL = 0;
239 | GCC_PREPROCESSOR_DEFINITIONS = (
240 | "DEBUG=1",
241 | "$(inherited)",
242 | );
243 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
244 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
245 | GCC_WARN_UNDECLARED_SELECTOR = YES;
246 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
247 | GCC_WARN_UNUSED_FUNCTION = YES;
248 | GCC_WARN_UNUSED_VARIABLE = YES;
249 | IPHONEOS_DEPLOYMENT_TARGET = 14.1;
250 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
251 | MTL_FAST_MATH = YES;
252 | ONLY_ACTIVE_ARCH = YES;
253 | SDKROOT = iphoneos;
254 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
255 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
256 | };
257 | name = Debug;
258 | };
259 | 7555FFA4242A565B00829871 /* Release */ = {
260 | isa = XCBuildConfiguration;
261 | buildSettings = {
262 | ALWAYS_SEARCH_USER_PATHS = NO;
263 | CLANG_ANALYZER_NONNULL = YES;
264 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
265 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
266 | CLANG_CXX_LIBRARY = "libc++";
267 | CLANG_ENABLE_MODULES = YES;
268 | CLANG_ENABLE_OBJC_ARC = YES;
269 | CLANG_ENABLE_OBJC_WEAK = YES;
270 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
271 | CLANG_WARN_BOOL_CONVERSION = YES;
272 | CLANG_WARN_COMMA = YES;
273 | CLANG_WARN_CONSTANT_CONVERSION = YES;
274 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
276 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
277 | CLANG_WARN_EMPTY_BODY = YES;
278 | CLANG_WARN_ENUM_CONVERSION = YES;
279 | CLANG_WARN_INFINITE_RECURSION = YES;
280 | CLANG_WARN_INT_CONVERSION = YES;
281 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
282 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
283 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
284 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
285 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
286 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
287 | CLANG_WARN_STRICT_PROTOTYPES = YES;
288 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
289 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
290 | CLANG_WARN_UNREACHABLE_CODE = YES;
291 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
292 | COPY_PHASE_STRIP = NO;
293 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
294 | ENABLE_NS_ASSERTIONS = NO;
295 | ENABLE_STRICT_OBJC_MSGSEND = YES;
296 | GCC_C_LANGUAGE_STANDARD = gnu11;
297 | GCC_NO_COMMON_BLOCKS = YES;
298 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
299 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
300 | GCC_WARN_UNDECLARED_SELECTOR = YES;
301 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
302 | GCC_WARN_UNUSED_FUNCTION = YES;
303 | GCC_WARN_UNUSED_VARIABLE = YES;
304 | IPHONEOS_DEPLOYMENT_TARGET = 14.1;
305 | MTL_ENABLE_DEBUG_INFO = NO;
306 | MTL_FAST_MATH = YES;
307 | SDKROOT = iphoneos;
308 | SWIFT_COMPILATION_MODE = wholemodule;
309 | SWIFT_OPTIMIZATION_LEVEL = "-O";
310 | VALIDATE_PRODUCT = YES;
311 | };
312 | name = Release;
313 | };
314 | 7555FFA6242A565B00829871 /* Debug */ = {
315 | isa = XCBuildConfiguration;
316 | buildSettings = {
317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
318 | CODE_SIGN_STYLE = Automatic;
319 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
320 | ENABLE_PREVIEWS = YES;
321 | FRAMEWORK_SEARCH_PATHS = (
322 | "$(inherited)",
323 | "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
324 | );
325 | INFOPLIST_FILE = iosApp/Info.plist;
326 | IPHONEOS_DEPLOYMENT_TARGET = 17.0;
327 | LD_RUNPATH_SEARCH_PATHS = (
328 | "$(inherited)",
329 | "@executable_path/Frameworks",
330 | );
331 | OTHER_LDFLAGS = (
332 | "$(inherited)",
333 | "-framework",
334 | shared,
335 | );
336 | PRODUCT_BUNDLE_IDENTIFIER = com.example.fruitties.ios;
337 | PRODUCT_NAME = "$(TARGET_NAME)";
338 | SWIFT_VERSION = 5.0;
339 | TARGETED_DEVICE_FAMILY = "1,2";
340 | };
341 | name = Debug;
342 | };
343 | 7555FFA7242A565B00829871 /* Release */ = {
344 | isa = XCBuildConfiguration;
345 | buildSettings = {
346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
347 | CODE_SIGN_STYLE = Automatic;
348 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
349 | ENABLE_PREVIEWS = YES;
350 | FRAMEWORK_SEARCH_PATHS = (
351 | "$(inherited)",
352 | "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
353 | );
354 | INFOPLIST_FILE = iosApp/Info.plist;
355 | IPHONEOS_DEPLOYMENT_TARGET = 17.0;
356 | LD_RUNPATH_SEARCH_PATHS = (
357 | "$(inherited)",
358 | "@executable_path/Frameworks",
359 | );
360 | OTHER_LDFLAGS = (
361 | "$(inherited)",
362 | "-framework",
363 | shared,
364 | );
365 | PRODUCT_BUNDLE_IDENTIFIER = com.example.fruitties.ios;
366 | PRODUCT_NAME = "$(TARGET_NAME)";
367 | SWIFT_VERSION = 5.0;
368 | TARGETED_DEVICE_FAMILY = "1,2";
369 | };
370 | name = Release;
371 | };
372 | /* End XCBuildConfiguration section */
373 |
374 | /* Begin XCConfigurationList section */
375 | 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */ = {
376 | isa = XCConfigurationList;
377 | buildConfigurations = (
378 | 7555FFA3242A565B00829871 /* Debug */,
379 | 7555FFA4242A565B00829871 /* Release */,
380 | );
381 | defaultConfigurationIsVisible = 0;
382 | defaultConfigurationName = Release;
383 | };
384 | 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */ = {
385 | isa = XCConfigurationList;
386 | buildConfigurations = (
387 | 7555FFA6242A565B00829871 /* Debug */,
388 | 7555FFA7242A565B00829871 /* Release */,
389 | );
390 | defaultConfigurationIsVisible = 0;
391 | defaultConfigurationName = Release;
392 | };
393 | /* End XCConfigurationList section */
394 | };
395 | rootObject = 7555FF73242A565900829871 /* Project object */;
396 | }
397 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "scale" : "1x",
46 | "size" : "20x20"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "scale" : "2x",
51 | "size" : "20x20"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "scale" : "1x",
56 | "size" : "29x29"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "scale" : "2x",
61 | "size" : "29x29"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "scale" : "1x",
66 | "size" : "40x40"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "scale" : "2x",
71 | "size" : "40x40"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "scale" : "1x",
76 | "size" : "76x76"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "scale" : "2x",
81 | "size" : "76x76"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "scale" : "2x",
86 | "size" : "83.5x83.5"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "scale" : "1x",
91 | "size" : "1024x1024"
92 | }
93 | ],
94 | "info" : {
95 | "author" : "xcode",
96 | "version" : 1
97 | }
98 | }
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/CartView.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import Foundation
18 | import SwiftUI
19 | import shared
20 |
21 | struct CartView : View {
22 | let mainViewModel: MainViewModel
23 |
24 | // The ViewModel exposes a StateFlow that we access in SwiftUI with SKIE Observing.
25 | // https://skie.touchlab.co/features/flows-in-swiftui
26 |
27 | @State
28 | private var expanded = false
29 |
30 | var body: some View {
31 | // https://skie.touchlab.co/features/flows-in-swiftui
32 | Observing(self.mainViewModel.cartUiState) { cartUIState in
33 | VStack {
34 | HStack {
35 | let total = cartUIState.cartDetails.reduce(0) { $0 + $1.count }
36 | Text("Cart has \(total) items").padding()
37 | Spacer()
38 | Button {
39 | expanded.toggle()
40 | } label: {
41 | if (expanded) {
42 | Text("collapse")
43 | } else {
44 | Text("expand")
45 | }
46 | }.padding()
47 | }
48 | if (expanded) {
49 | CartDetailsView(mainViewModel: mainViewModel)
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
56 | struct CartDetailsView: View {
57 | let mainViewModel: MainViewModel
58 |
59 | var body: some View {
60 |
61 | // https://skie.touchlab.co/features/flows-in-swiftui
62 | Observing(self.mainViewModel.cartUiState) { cartUIState in
63 | VStack {
64 | ForEach(cartUIState.cartDetails, id: \.fruittie.id) { item in
65 | Text("\(item.fruittie.name): \(item.count)")
66 | }
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/ContentView.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import SwiftUI
18 | import shared
19 | import Foundation
20 |
21 | struct ContentView: View {
22 | var mainViewModel: MainViewModel
23 |
24 | var body: some View {
25 | Text("Fruitties").font(.largeTitle).fontWeight(.bold)
26 | CartView(mainViewModel: mainViewModel)
27 | // https://skie.touchlab.co/features/flows-in-swiftui
28 | Observing(self.mainViewModel.homeUiState) { homeUIState in
29 | ScrollView {
30 | LazyVStack {
31 | ForEach(homeUIState.fruitties, id: \.self) { value in
32 | FruittieView(fruittie: value, addToCart: { fruittie in
33 | Task {
34 | self.mainViewModel.addItemToCart(fruittie: fruittie)
35 | }
36 | })
37 | }
38 | }
39 | }
40 | }
41 | }
42 | }
43 |
44 | struct FruittieView: View {
45 | var fruittie: Fruittie
46 | var addToCart: (Fruittie) -> Void
47 | var body: some View {
48 | HStack(alignment: .firstTextBaseline) {
49 | ZStack {
50 | RoundedRectangle(cornerRadius: 15).fill(Color(red: 0.8, green: 0.8, blue: 1.0))
51 | VStack {
52 | Text("\(fruittie.name)")
53 | .fontWeight(.bold)
54 | .frame(maxWidth: .infinity, alignment: .leading)
55 | Text("\(fruittie.fullName)")
56 | .frame(maxWidth: .infinity, alignment: .leading)
57 | }.padding()
58 | Spacer()
59 | Button(action: { addToCart(fruittie) }, label: {
60 | Text("Add")
61 | }).padding().frame(maxWidth: .infinity, alignment: .trailing)
62 | }.padding([.leading, .trailing])
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UIApplicationSceneManifest
24 |
25 | UIApplicationSupportsMultipleScenes
26 |
27 |
28 | UILaunchScreen
29 |
30 | UIRequiredDeviceCapabilities
31 |
32 | armv7
33 |
34 | UISupportedInterfaceOrientations
35 |
36 | UIInterfaceOrientationPortrait
37 | UIInterfaceOrientationLandscapeLeft
38 | UIInterfaceOrientationLandscapeRight
39 |
40 | UISupportedInterfaceOrientations~ipad
41 |
42 | UIInterfaceOrientationPortrait
43 | UIInterfaceOrientationPortraitUpsideDown
44 | UIInterfaceOrientationLandscapeLeft
45 | UIInterfaceOrientationLandscapeRight
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
--------------------------------------------------------------------------------
/Fruitties/iosApp/iosApp/iOSApp.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import SwiftUI
18 | import shared
19 | @main
20 | struct iOSApp: App {
21 | let appContainer = AppContainer(factory: Factory())
22 | var body: some Scene {
23 | WindowGroup {
24 | let iosViewModelOwner = IOSViewModelOwner(appContainer: appContainer)
25 | ContentView(mainViewModel: iosViewModelOwner.mainViewModel)
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Fruitties/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
17 | pluginManagement {
18 | repositories {
19 | google()
20 | gradlePluginPortal()
21 | mavenCentral()
22 | }
23 | }
24 |
25 | dependencyResolutionManagement {
26 | repositories {
27 | google()
28 | mavenCentral()
29 | }
30 | }
31 |
32 | rootProject.name = "Fruitties"
33 | include(":androidApp")
34 | include(":shared")
--------------------------------------------------------------------------------
/Fruitties/shared/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/Fruitties/shared/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | plugins {
18 | alias(libs.plugins.kotlinMultiplatform)
19 | alias(libs.plugins.androidKmpLibrary)
20 | alias(libs.plugins.kotlinxSerialization)
21 | alias(libs.plugins.skie)
22 | alias(libs.plugins.ksp)
23 | alias(libs.plugins.room)
24 | }
25 |
26 | kotlin {
27 |
28 | // Target declarations - add or remove as needed below. These define
29 | // which platforms this KMP module supports.
30 | // See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets
31 | androidLibrary {
32 | namespace = "com.example.fruitties"
33 | compileSdk = 35
34 | minSdk = 26
35 |
36 | withHostTestBuilder {
37 | }
38 |
39 | withDeviceTestBuilder {
40 | sourceSetTreeName = "test"
41 | }.configure {
42 | instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
43 | }
44 | }
45 |
46 | // For iOS targets, this is also where you should
47 | // configure native binary output. For more information, see:
48 | // https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks
49 |
50 | // A step-by-step guide on how to include this library in an XCode
51 | // project can be found here:
52 | // https://developer.android.com/kotlin/multiplatform/migrate
53 | val xcfName = "shared"
54 |
55 | iosX64 {
56 | binaries.framework {
57 | baseName = xcfName
58 | }
59 | }
60 |
61 | iosArm64 {
62 | binaries.framework {
63 | baseName = xcfName
64 | }
65 | }
66 |
67 | iosSimulatorArm64 {
68 | binaries.framework {
69 | baseName = xcfName
70 | }
71 | }
72 |
73 | // Source set declarations.
74 | // Declaring a target automatically creates a source set with the same name. By default, the
75 | // Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is
76 | // common to share sources between related targets.
77 | // See: https://kotlinlang.org/docs/multiplatform-hierarchy.html
78 | sourceSets {
79 | all {
80 | languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
81 | }
82 |
83 | commonMain {
84 | dependencies {
85 | implementation(libs.kotlin.stdlib)
86 | // Add KMP dependencies here
87 | implementation(libs.kotlinx.datetime)
88 | implementation(libs.kotlinx.coroutines.core)
89 | implementation(libs.ktor.client.core)
90 | implementation(libs.ktor.client.content.negotiation)
91 | implementation(libs.ktor.serialization.kotlinx.json)
92 | implementation(libs.skie.annotations)
93 | implementation(libs.androidx.lifecycle.viewmodel)
94 | implementation(libs.androidx.paging.common)
95 | implementation(libs.androidx.room.runtime)
96 | implementation(libs.sqlite.bundled)
97 | implementation(libs.kotlinx.atomicfu)
98 | api(libs.androidx.datastore.preferences.core)
99 | api(libs.androidx.datastore.core.okio)
100 | implementation(libs.okio)
101 | }
102 | }
103 |
104 | commonTest {
105 | dependencies {
106 | implementation(libs.kotlin.test)
107 | }
108 | }
109 |
110 | androidMain {
111 | dependencies {
112 | // Add Android-specific dependencies here. Note that this source set depends on
113 | // commonMain by default and will correctly pull the Android artifacts of any KMP
114 | // dependencies declared in commonMain.
115 | implementation(libs.ktor.client.okhttp)
116 | implementation(libs.androidx.room.paging)
117 | }
118 | }
119 |
120 | getByName("androidDeviceTest") {
121 | dependencies {
122 | implementation(libs.androidx.runner)
123 | implementation(libs.androidx.core)
124 | implementation(libs.androidx.junit)
125 | }
126 | }
127 |
128 | iosMain {
129 | dependencies {
130 | // Add iOS-specific dependencies here. This a source set created by Kotlin Gradle
131 | // Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as
132 | // part of KMP’s default source set hierarchy. Note that this source set depends
133 | // on common by default and will correctly pull the iOS artifacts of any
134 | // KMP dependencies declared in commonMain.
135 | implementation(libs.ktor.client.darwin)
136 | }
137 | }
138 | }
139 | }
140 |
141 | dependencies {
142 | add("kspAndroid", libs.androidx.room.compiler)
143 | add("kspIosSimulatorArm64", libs.androidx.room.compiler)
144 | add("kspIosX64", libs.androidx.room.compiler)
145 | add("kspIosArm64", libs.androidx.room.compiler)
146 | }
147 |
148 | room {
149 | schemaDirectory("$projectDir/schemas")
150 | }
151 |
152 | skie {
153 | features {
154 | // https://skie.touchlab.co/features/flows-in-swiftui
155 | enableSwiftUIObservingPreview = true
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/Fruitties/shared/schemas/com.example.fruitties.database.AppDatabase/1.json:
--------------------------------------------------------------------------------
1 | {
2 | "formatVersion": 1,
3 | "database": {
4 | "version": 1,
5 | "identityHash": "88d6cb8637e50e45bdb804b3cba6b273",
6 | "entities": [
7 | {
8 | "tableName": "Fruittie",
9 | "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)",
10 | "fields": [
11 | {
12 | "fieldPath": "id",
13 | "columnName": "id",
14 | "affinity": "INTEGER",
15 | "notNull": true
16 | },
17 | {
18 | "fieldPath": "name",
19 | "columnName": "name",
20 | "affinity": "TEXT",
21 | "notNull": true
22 | },
23 | {
24 | "fieldPath": "fullName",
25 | "columnName": "fullName",
26 | "affinity": "TEXT",
27 | "notNull": true
28 | },
29 | {
30 | "fieldPath": "calories",
31 | "columnName": "calories",
32 | "affinity": "TEXT",
33 | "notNull": true
34 | }
35 | ],
36 | "primaryKey": {
37 | "autoGenerate": true,
38 | "columnNames": [
39 | "id"
40 | ]
41 | }
42 | }
43 | ],
44 | "setupQueries": [
45 | "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
46 | "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '88d6cb8637e50e45bdb804b3cba6b273')"
47 | ]
48 | }
49 | }
--------------------------------------------------------------------------------
/Fruitties/shared/src/androidMain/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/androidMain/kotlin/com/example/fruitties/di/Factory.android.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.di
17 |
18 | import android.app.Application
19 | import androidx.room.Room
20 | import androidx.sqlite.driver.bundled.BundledSQLiteDriver
21 | import com.example.fruitties.database.AppDatabase
22 | import com.example.fruitties.database.CartDataStore
23 | import com.example.fruitties.database.DB_FILE_NAME
24 | import com.example.fruitties.network.FruittieApi
25 | import kotlinx.coroutines.Dispatchers
26 |
27 | actual class Factory(
28 | private val app: Application,
29 | ) {
30 | actual fun createRoomDatabase(): AppDatabase {
31 | val dbFile = app.getDatabasePath(DB_FILE_NAME)
32 | return Room
33 | .databaseBuilder(
34 | context = app,
35 | name = dbFile.absolutePath,
36 | ).setDriver(BundledSQLiteDriver())
37 | .setQueryCoroutineContext(Dispatchers.IO)
38 | .build()
39 | }
40 |
41 | actual fun createCartDataStore(): CartDataStore =
42 | CartDataStore {
43 | app.filesDir
44 | .resolve(
45 | "cart.json",
46 | ).absolutePath
47 | }
48 |
49 | actual fun createApi(): FruittieApi = commonCreateApi()
50 | }
51 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/DataRepository.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties
17 |
18 | import com.example.fruitties.database.AppDatabase
19 | import com.example.fruitties.database.CartDataStore
20 | import com.example.fruitties.model.CartItemDetails
21 | import com.example.fruitties.model.Fruittie
22 | import com.example.fruitties.network.FruittieApi
23 | import kotlinx.coroutines.CoroutineScope
24 | import kotlinx.coroutines.ExperimentalCoroutinesApi
25 | import kotlinx.coroutines.flow.Flow
26 | import kotlinx.coroutines.flow.mapLatest
27 | import kotlinx.coroutines.launch
28 |
29 | class DataRepository(
30 | private val api: FruittieApi,
31 | private var database: AppDatabase,
32 | private val cartDataStore: CartDataStore,
33 | private val scope: CoroutineScope,
34 | ) {
35 | @OptIn(ExperimentalCoroutinesApi::class)
36 | val cartDetails: Flow>
37 | get() = cartDataStore.cart.mapLatest {
38 | val ids = it.items.map { it.id }
39 | val fruitties = database.fruittieDao().loadMapped(ids)
40 | it.items.mapNotNull {
41 | fruitties[it.id]?.let { fruittie ->
42 | CartItemDetails(fruittie, it.count)
43 | }
44 | }
45 | }
46 |
47 | suspend fun addToCart(fruittie: Fruittie) {
48 | cartDataStore.add(fruittie)
49 | }
50 |
51 | fun getData(): Flow> {
52 | scope.launch {
53 | if (database.fruittieDao().count() < 1) {
54 | refreshData()
55 | }
56 | }
57 | return loadData()
58 | }
59 |
60 | fun loadData(): Flow> = database.fruittieDao().getAllAsFlow()
61 |
62 | suspend fun refreshData() {
63 | val response = api.getData()
64 | database.fruittieDao().insert(response.feed)
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.database
17 |
18 | import androidx.room.ConstructedBy
19 | import androidx.room.Database
20 | import androidx.room.RoomDatabase
21 | import androidx.room.RoomDatabaseConstructor
22 | import com.example.fruitties.model.Fruittie
23 |
24 | @Database(entities = [Fruittie::class], version = 1)
25 | @ConstructedBy(AppDatabaseConstructor::class)
26 | abstract class AppDatabase : RoomDatabase() {
27 | abstract fun fruittieDao(): FruittieDao
28 | }
29 |
30 | // The Room compiler generates the `actual` implementations.
31 | @Suppress("NO_ACTUAL_FOR_EXPECT")
32 | expect object AppDatabaseConstructor : RoomDatabaseConstructor {
33 | override fun initialize(): AppDatabase
34 | }
35 |
36 | internal const val DB_FILE_NAME = "fruits.db"
37 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/CartDataStore.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.database
17 |
18 | import androidx.datastore.core.DataStoreFactory
19 | import androidx.datastore.core.okio.OkioSerializer
20 | import androidx.datastore.core.okio.OkioStorage
21 | import com.example.fruitties.di.json
22 | import com.example.fruitties.model.Fruittie
23 | import kotlinx.coroutines.flow.Flow
24 | import kotlinx.serialization.Serializable
25 | import okio.BufferedSink
26 | import okio.BufferedSource
27 | import okio.FileSystem
28 | import okio.Path.Companion.toPath
29 | import okio.SYSTEM
30 | import okio.use
31 |
32 | @Serializable
33 | data class Cart(
34 | val items: List,
35 | )
36 |
37 | @Serializable
38 | data class CartItem(
39 | val id: Long,
40 | val count: Int,
41 | )
42 |
43 | internal object CartJsonSerializer : OkioSerializer {
44 | override val defaultValue: Cart = Cart(emptyList())
45 |
46 | override suspend fun readFrom(source: BufferedSource): Cart = json.decodeFromString(source.readUtf8())
47 |
48 | override suspend fun writeTo(
49 | t: Cart,
50 | sink: BufferedSink,
51 | ) {
52 | sink.use {
53 | it.writeUtf8(json.encodeToString(Cart.serializer(), t))
54 | }
55 | }
56 | }
57 |
58 | class CartDataStore(
59 | private val produceFilePath: () -> String,
60 | ) {
61 | private val db = DataStoreFactory.create(
62 | storage = OkioStorage(
63 | fileSystem = FileSystem.SYSTEM,
64 | serializer = CartJsonSerializer,
65 | producePath = {
66 | produceFilePath().toPath()
67 | },
68 | ),
69 | )
70 | val cart: Flow
71 | get() = db.data
72 |
73 | suspend fun add(fruittie: Fruittie) = update(fruittie, 1)
74 |
75 | suspend fun remove(fruittie: Fruittie) = update(fruittie, -1)
76 |
77 | suspend fun update(
78 | fruittie: Fruittie,
79 | diff: Int,
80 | ) {
81 | db.updateData { prevCart ->
82 | val newItems = mutableListOf()
83 | var found = false
84 | prevCart.items.forEach {
85 | if (it.id == fruittie.id) {
86 | found = true
87 | newItems.add(
88 | it.copy(
89 | count = it.count + diff,
90 | ),
91 | )
92 | } else {
93 | newItems.add(it)
94 | }
95 | }
96 | if (!found) {
97 | newItems.add(
98 | CartItem(id = fruittie.id, count = diff),
99 | )
100 | }
101 | newItems.removeAll {
102 | it.count <= 0
103 | }
104 | Cart(
105 | items = newItems,
106 | )
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/FruittieDao.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.database
17 |
18 | import androidx.room.Dao
19 | import androidx.room.Insert
20 | import androidx.room.MapColumn
21 | import androidx.room.OnConflictStrategy
22 | import androidx.room.Query
23 | import com.example.fruitties.model.Fruittie
24 | import kotlinx.coroutines.flow.Flow
25 |
26 | @Dao
27 | interface FruittieDao {
28 | @Insert(onConflict = OnConflictStrategy.REPLACE)
29 | suspend fun insert(fruittie: Fruittie)
30 |
31 | @Insert(onConflict = OnConflictStrategy.REPLACE)
32 | suspend fun insert(fruitties: List)
33 |
34 | @Query("SELECT * FROM Fruittie")
35 | fun getAllAsFlow(): Flow>
36 |
37 | @Query("SELECT COUNT(*) as count FROM Fruittie")
38 | suspend fun count(): Int
39 |
40 | @Query("SELECT * FROM Fruittie WHERE id in (:ids)")
41 | suspend fun loadAll(ids: List): List
42 |
43 | @Query("SELECT * FROM Fruittie WHERE id in (:ids)")
44 | suspend fun loadMapped(ids: List): Map<
45 | @MapColumn(columnName = "id")
46 | Long,
47 | Fruittie,
48 | >
49 | }
50 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/AppContainer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.di
17 |
18 | import com.example.fruitties.DataRepository
19 | import kotlinx.coroutines.CoroutineScope
20 | import kotlinx.coroutines.Dispatchers
21 | import kotlinx.coroutines.SupervisorJob
22 |
23 | class AppContainer(
24 | private val factory: Factory,
25 | ) {
26 | val dataRepository: DataRepository by lazy {
27 | DataRepository(
28 | api = factory.createApi(),
29 | database = factory.createRoomDatabase(),
30 | cartDataStore = factory.createCartDataStore(),
31 | scope = CoroutineScope(Dispatchers.Default + SupervisorJob()),
32 | )
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/Factory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.di
17 |
18 | import com.example.fruitties.database.AppDatabase
19 | import com.example.fruitties.database.CartDataStore
20 | import com.example.fruitties.network.FruittieApi
21 | import com.example.fruitties.network.FruittieNetworkApi
22 | import io.ktor.client.HttpClient
23 | import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
24 | import io.ktor.http.ContentType
25 | import io.ktor.serialization.kotlinx.json.json
26 | import kotlinx.serialization.json.Json
27 |
28 | expect class Factory {
29 | fun createRoomDatabase(): AppDatabase
30 |
31 | fun createApi(): FruittieApi
32 |
33 | fun createCartDataStore(): CartDataStore
34 | }
35 |
36 | internal fun commonCreateApi(): FruittieApi =
37 | FruittieNetworkApi(
38 | client = HttpClient {
39 | install(ContentNegotiation) {
40 | json(json, contentType = ContentType.Any)
41 | }
42 | },
43 | apiUrl = "https://android.github.io/kotlin-multiplatform-samples/fruitties-api",
44 | )
45 |
46 | val json = Json { ignoreUnknownKeys = true }
47 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/Fruittie.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.model
17 |
18 | import androidx.room.Entity
19 | import androidx.room.PrimaryKey
20 | import kotlinx.serialization.SerialName
21 | import kotlinx.serialization.Serializable
22 |
23 | @Serializable
24 | @Entity
25 | data class Fruittie(
26 | @PrimaryKey(autoGenerate = true) val id: Long = 0,
27 | @SerialName("name")
28 | val name: String,
29 | @SerialName("full_name")
30 | val fullName: String,
31 | @SerialName("calories")
32 | val calories: String,
33 | )
34 |
35 | data class CartItemDetails(
36 | val fruittie: Fruittie,
37 | val count: Int,
38 | )
39 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/model/FruittiesResponse.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.model
17 |
18 | import kotlinx.serialization.SerialName
19 | import kotlinx.serialization.Serializable
20 |
21 | @Serializable
22 | data class FruittiesResponse(
23 | @SerialName("feed")
24 | val feed: List,
25 | @SerialName("totalPages")
26 | val totalPages: Int,
27 | @SerialName("currentPage")
28 | val currentPage: Int,
29 | )
30 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/network/FruittieApi.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.network
17 |
18 | import com.example.fruitties.model.FruittiesResponse
19 | import io.ktor.client.HttpClient
20 | import io.ktor.client.call.body
21 | import io.ktor.client.request.get
22 | import kotlin.coroutines.cancellation.CancellationException
23 |
24 | interface FruittieApi {
25 | suspend fun getData(pageNumber: Int = 0): FruittiesResponse
26 | }
27 |
28 | class FruittieNetworkApi(
29 | private val client: HttpClient,
30 | private val apiUrl: String,
31 | ) : FruittieApi {
32 | override suspend fun getData(pageNumber: Int): FruittiesResponse {
33 | val url = "$apiUrl/$pageNumber.json"
34 | return try {
35 | client.get(url).body()
36 | } catch (e: Exception) {
37 | if (e is CancellationException) throw e
38 | e.printStackTrace()
39 |
40 | FruittiesResponse(emptyList(), 0, 0)
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/viewmodel/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.fruitties.viewmodel
18 |
19 | import androidx.lifecycle.ViewModel
20 | import androidx.lifecycle.ViewModelProvider
21 | import androidx.lifecycle.viewModelScope
22 | import androidx.lifecycle.viewmodel.CreationExtras
23 | import androidx.lifecycle.viewmodel.MutableCreationExtras
24 | import androidx.lifecycle.viewmodel.initializer
25 | import androidx.lifecycle.viewmodel.viewModelFactory
26 | import com.example.fruitties.DataRepository
27 | import com.example.fruitties.di.AppContainer
28 | import com.example.fruitties.model.CartItemDetails
29 | import com.example.fruitties.model.Fruittie
30 | import kotlinx.coroutines.flow.SharingStarted
31 | import kotlinx.coroutines.flow.StateFlow
32 | import kotlinx.coroutines.flow.map
33 | import kotlinx.coroutines.flow.stateIn
34 | import kotlinx.coroutines.launch
35 |
36 | class MainViewModel(
37 | private val repository: DataRepository,
38 | ) : ViewModel() {
39 | val homeUiState: StateFlow =
40 | repository
41 | .getData()
42 | .map { HomeUiState(it) }
43 | .stateIn(
44 | scope = viewModelScope,
45 | started = SharingStarted.WhileSubscribed(TIMEOUT_MILLIS),
46 | initialValue = HomeUiState(),
47 | )
48 |
49 | val cartUiState: StateFlow =
50 | repository.cartDetails
51 | .map { CartUiState(it) }
52 | .stateIn(
53 | scope = viewModelScope,
54 | started = SharingStarted.WhileSubscribed(TIMEOUT_MILLIS),
55 | initialValue = CartUiState(),
56 | )
57 |
58 | fun addItemToCart(fruittie: Fruittie) {
59 | viewModelScope.launch {
60 | repository.addToCart(fruittie)
61 | }
62 | }
63 |
64 | companion object {
65 | val APP_CONTAINER_KEY = CreationExtras.Key()
66 |
67 | val Factory: ViewModelProvider.Factory = viewModelFactory {
68 | initializer {
69 | val appContainer = this[APP_CONTAINER_KEY] as AppContainer
70 | val repository = appContainer.dataRepository
71 | MainViewModel(repository = repository)
72 | }
73 | }
74 |
75 | /**
76 | * Helper function to prepare CreationExtras.
77 | *
78 | * USAGE:
79 | *
80 | * val mainViewModel: MainViewModel = ViewModelProvider.create(
81 | * owner = this as ViewModelStoreOwner,
82 | * factory = MainViewModel.Factory,
83 | * extras = MainViewModel.newCreationExtras(appContainer),
84 | * )[MainViewModel::class]
85 | */
86 | fun newCreationExtras(appContainer: AppContainer): CreationExtras =
87 | MutableCreationExtras().apply {
88 | set(APP_CONTAINER_KEY, appContainer)
89 | }
90 | }
91 | }
92 |
93 | /**
94 | * Ui State for the home screen
95 | */
96 | data class HomeUiState(
97 | val fruitties: List = listOf(),
98 | )
99 |
100 | /**
101 | * Ui State for the cart
102 | */
103 | data class CartUiState(
104 | val cartDetails: List = listOf(),
105 | )
106 |
107 | private const val TIMEOUT_MILLIS = 5_000L
108 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/Factory.native.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.fruitties.di
17 |
18 | import androidx.room.Room
19 | import androidx.sqlite.driver.bundled.BundledSQLiteDriver
20 | import com.example.fruitties.database.AppDatabase
21 | import com.example.fruitties.database.CartDataStore
22 | import com.example.fruitties.database.DB_FILE_NAME
23 | import com.example.fruitties.network.FruittieApi
24 | import kotlinx.cinterop.ExperimentalForeignApi
25 | import kotlinx.coroutines.Dispatchers
26 | import kotlinx.coroutines.IO
27 | import platform.Foundation.NSDocumentDirectory
28 | import platform.Foundation.NSFileManager
29 | import platform.Foundation.NSURL
30 | import platform.Foundation.NSUserDomainMask
31 |
32 | actual class Factory {
33 | actual fun createRoomDatabase(): AppDatabase {
34 | val dbFile = "${fileDirectory()}/$DB_FILE_NAME"
35 | return Room
36 | .databaseBuilder(
37 | name = dbFile,
38 | ).setDriver(BundledSQLiteDriver())
39 | .setQueryCoroutineContext(Dispatchers.IO)
40 | .build()
41 | }
42 |
43 | actual fun createCartDataStore(): CartDataStore =
44 | CartDataStore {
45 | "${fileDirectory()}/cart.json"
46 | }
47 |
48 | @OptIn(ExperimentalForeignApi::class)
49 | private fun fileDirectory(): String {
50 | val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(
51 | directory = NSDocumentDirectory,
52 | inDomain = NSUserDomainMask,
53 | appropriateForURL = null,
54 | create = false,
55 | error = null,
56 | )
57 | return requireNotNull(documentDirectory).path!!
58 | }
59 |
60 | actual fun createApi(): FruittieApi = commonCreateApi()
61 | }
62 |
--------------------------------------------------------------------------------
/Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt:
--------------------------------------------------------------------------------
1 | package com.example.fruitties.di.viewmodel
2 |
3 | import androidx.lifecycle.ViewModelProvider
4 | import androidx.lifecycle.ViewModelStore
5 | import androidx.lifecycle.ViewModelStoreOwner
6 | import com.example.fruitties.di.AppContainer
7 | import com.example.fruitties.viewmodel.MainViewModel
8 |
9 | /**
10 | * A ViewModelStoreOwner specifically for iOS.
11 | * This is used with from iOS with Kotlin Multiplatform (KMP).
12 | */
13 | @Suppress("unused") // Android Studio is not aware of iOS usage.
14 | class IOSViewModelOwner(
15 | appContainer: AppContainer,
16 | ) : ViewModelStoreOwner {
17 | override val viewModelStore: ViewModelStore = ViewModelStore()
18 |
19 | // Create an instance of MainViewModel with the CreationExtras.
20 | val mainViewModel: MainViewModel = ViewModelProvider.create(
21 | owner = this as ViewModelStoreOwner,
22 | factory = MainViewModel.Factory,
23 | extras = MainViewModel.newCreationExtras(appContainer),
24 | )[MainViewModel::class]
25 |
26 | // To add more ViewModel types, add new properties for each ViewModel.
27 | // If we need to add a very large number of ViewModel types,
28 | // we could consider creating a generic retrieval implementation with reflection.
29 |
30 | // If the ViewModelStoreOwner will go out of scope, we should clear the ViewModelStore.
31 | fun clear() {
32 | viewModelStore.clear()
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kotlin Multiplatform Samples
2 |
3 | ## [Fruitties](./Fruitties)
4 |
5 | Fruitties is a sample app using the Kotlin Multiplatform ViewModel, Room, DataStore and Ktor libraries to fetch, store and display data.
6 |
7 | ## ~DiceRoller~ (Deprecated)
8 |
9 | DiceRoller is a sample app using the Kotlin Multiplatform DataStore library to store and observe preferences.
10 |
11 | #### This sample was deprecated and removed, but you can still access it [in the history](https://github.com/android/kotlin-multiplatform-samples/tree/36d62a15d6e476e0f0ee4102b881aa40806bb8dd/DiceRoller).
12 |
13 |
14 | ## License
15 |
16 | ```
17 | Copyright 2022 The Android Open Source Project
18 |
19 | Licensed under the Apache License, Version 2.0 (the "License");
20 | you may not use this file except in compliance with the License.
21 | You may obtain a copy of the License at
22 |
23 | https://www.apache.org/licenses/LICENSE-2.0
24 |
25 | Unless required by applicable law or agreed to in writing, software
26 | distributed under the License is distributed on an "AS IS" BASIS,
27 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | See the License for the specific language governing permissions and
29 | limitations under the License.
30 | ```
31 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "local>android/.github:renovate-config"
5 | ],
6 |
7 | "baseBranches": [
8 | "main"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------