Skip to content

Spotless updates and lint #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Fruitties/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[*.{kt,kts}]
# Kotlin style typically requires functions to start with a lowercase letter.
# Composable functions should start with a capital letter.
ktlint_function_naming_ignore_when_annotated_with = Composable

# ktlint always puts a new line after a multi-line assignment, like this:
# val colors =
# if (darkTheme) {
# darkColorScheme(
# primary = Color(0xFFBB86FC),
# secondary = Color(0xFF03DAC5),
# tertiary = Color(0xFF3700B3),
# )
# } else {
# lightColorScheme(
# primary = Color(0xFF6200EE),
# secondary = Color(0xFF03DAC5),
# tertiary = Color(0xFF3700B3),
# )
# }
# But we actually prefer to keep some multi-line assignments on the same line, like this:
# val colors = if (darkTheme) {
# darkColorScheme(
# primary = Color(0xFFBB86FC),
# secondary = Color(0xFF03DAC5),
# tertiary = Color(0xFF3700B3),
# )
# } else {
# lightColorScheme(
# primary = Color(0xFF6200EE),
# secondary = Color(0xFF03DAC5),
# tertiary = Color(0xFF3700B3),
# )
# }
ktlint_standard_multiline-expression-wrapping = disabled
2 changes: 2 additions & 0 deletions Fruitties/androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="false"
android:fullBackupContent="@xml/full_backup_content"
android:dataExtractionRules="@xml/data_extraction_rules"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".di.App">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.example.fruitties.di.Factory
class App : Application() {
/** AppContainer instance used by the rest of classes to obtain dependencies */
lateinit var container: AppContainer

override fun onCreate() {
super.onCreate()
container = AppContainer(Factory(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fun ListScreen() {
topBar = {
CenterAlignedTopAppBar(
title = {
Text(text = stringResource(R.string.frutties),)
Text(text = stringResource(R.string.frutties))
},
colors = TopAppBarColors(
containerColor = MaterialTheme.colorScheme.primary,
Expand All @@ -105,7 +105,7 @@ fun ListScreen() {
contentWindowInsets = WindowInsets.safeDrawing.only(
// Do not include Bottom so scrolled content is drawn below system bars.
// Include Horizontal because some devices have camera cutouts on the side.
WindowInsetsSides.Top + WindowInsetsSides.Horizontal
WindowInsetsSides.Top + WindowInsetsSides.Horizontal,
),
) { paddingValues ->
Column(
Expand Down Expand Up @@ -145,8 +145,8 @@ fun ListScreen() {
item {
Spacer(
Modifier.windowInsetsBottomHeight(
WindowInsets.systemBars
)
WindowInsets.systemBars,
),
)
}
}
Expand Down Expand Up @@ -216,7 +216,10 @@ fun FruittieItem(
}

@Composable
fun CartDetailsView(cart: List<CartItemDetails>, modifier: Modifier = Modifier) {
fun CartDetailsView(
cart: List<CartItemDetails>,
modifier: Modifier = Modifier,
) {
Column(
modifier.padding(horizontal = 32.dp),
) {
Expand Down
3 changes: 0 additions & 3 deletions Fruitties/androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@
-->
<resources>
<string name="frutties">"Frutties"</string>
<string name="save">Save</string>
<string name="add">Add</string>
<string name="loading">Loading</string>
<string name="retry">Retry</string>
</resources>
40 changes: 40 additions & 0 deletions Fruitties/androidApp/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2025 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<data-extraction-rules>
<cloud-backup>
<exclude domain="file" />
<exclude domain="database" />
<exclude domain="sharedpref" />
<exclude domain="external" />
<exclude domain="root" />
<exclude domain="device_file" />
<exclude domain="device_database" />
<exclude domain="device_sharedpref" />
<exclude domain="device_root" />
</cloud-backup>
<device-transfer>
<exclude domain="file" />
<exclude domain="database" />
<exclude domain="sharedpref" />
<exclude domain="external" />
<exclude domain="root" />
<exclude domain="device_file" />
<exclude domain="device_database" />
<exclude domain="device_sharedpref" />
<exclude domain="device_root" />
</device-transfer>
</data-extraction-rules>
23 changes: 23 additions & 0 deletions Fruitties/androidApp/src/main/res/xml/full_backup_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2025 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<full-backup-content>
<exclude domain="root" />
<exclude domain="file" />
<exclude domain="database" />
<exclude domain="sharedpref" />
<exclude domain="external" />
</full-backup-content>
14 changes: 5 additions & 9 deletions Fruitties/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
agp = "8.9.1"
androidx-activityCompose = "1.10.1"
androidx-paging = "3.3.6"
androidx-room = "2.7.0-rc03"
androidx-lifecycle = "2.9.0-alpha13"
androidx-room = "2.7.0"
androidx-lifecycle = "2.9.0-beta01"
atomicfu = "0.27.0"
compose = "1.7.8"
compose-material3 = "1.3.1"
compose-material3 = "1.3.2"
dataStore = "1.1.4"
kotlin = "2.1.10"
kotlinx-coroutines = "1.10.1"
kotlinxDatetime = "0.6.1"
ksp = "2.1.10-1.0.29"
ksp = "2.1.10-1.0.30"
ktorVersion = "3.0.3"
pagingComposeAndroid = "3.3.6"
skie = "0.10.1"
sqlite = "2.5.0-rc03"
sqlite = "2.5.0"
spotless = "7.0.2"
okio = "3.10.2"
runner = "1.6.2"
Expand All @@ -54,10 +54,7 @@ compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-core-iosarm64 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-iossimulatorarm64", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-core-iossimulatorarm64 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-iossimulatorarm64", version.ref = "kotlinx-coroutines" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "ktorVersion" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktorVersion" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorVersion" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktorVersion" }
Expand All @@ -77,7 +74,6 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
androidKmpLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
kotlinxSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
skie = { id = "co.touchlab.skie", version.ref = "skie" }
Expand Down
4 changes: 2 additions & 2 deletions Fruitties/iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
"-framework",
shared,
);
PRODUCT_BUNDLE_IDENTIFIER = orgIdentifier.iosApp;
PRODUCT_BUNDLE_IDENTIFIER = com.example.fruitties.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -362,7 +362,7 @@
"-framework",
shared,
);
PRODUCT_BUNDLE_IDENTIFIER = orgIdentifier.iosApp;
PRODUCT_BUNDLE_IDENTIFIER = com.example.fruitties.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
6 changes: 3 additions & 3 deletions Fruitties/iosApp/iosApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
</dict>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand All @@ -42,7 +44,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UILaunchScreen</key>
<dict/>
</dict>
</plist>
</plist>
3 changes: 0 additions & 3 deletions Fruitties/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand Down Expand Up @@ -138,7 +136,6 @@ kotlin {
}
}
}

}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@ import androidx.room.Room
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import com.example.fruitties.database.AppDatabase
import com.example.fruitties.database.CartDataStore
import com.example.fruitties.database.dbFileName
import com.example.fruitties.database.DB_FILE_NAME
import com.example.fruitties.network.FruittieApi
import kotlinx.coroutines.Dispatchers

actual class Factory(private val app: Application) {
actual class Factory(
private val app: Application,
) {
actual fun createRoomDatabase(): AppDatabase {
val dbFile = app.getDatabasePath(dbFileName)
return Room.databaseBuilder<AppDatabase>(
context = app,
name = dbFile.absolutePath,
)
.setDriver(BundledSQLiteDriver())
val dbFile = app.getDatabasePath(DB_FILE_NAME)
return Room
.databaseBuilder<AppDatabase>(
context = app,
name = dbFile.absolutePath,
).setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
}

actual fun createCartDataStore(): CartDataStore {
return CartDataStore {
app.filesDir.resolve(
"cart.json",
).absolutePath
actual fun createCartDataStore(): CartDataStore =
CartDataStore {
app.filesDir
.resolve(
"cart.json",
).absolutePath
}
}

actual fun createApi(): FruittieApi = commonCreateApi()
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class DataRepository(
return loadData()
}

fun loadData(): Flow<List<Fruittie>> {
return database.fruittieDao().getAllAsFlow()
}
fun loadData(): Flow<List<Fruittie>> = database.fruittieDao().getAllAsFlow()

suspend fun refreshData() {
val response = api.getData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ abstract class AppDatabase : RoomDatabase() {
expect object AppDatabaseConstructor : RoomDatabaseConstructor<AppDatabase> {
override fun initialize(): AppDatabase
}
internal const val dbFileName = "fruits.db"

internal const val DB_FILE_NAME = "fruits.db"
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,28 @@ import okio.use
data class Cart(
val items: List<CartItem>,
)

@Serializable
data class CartItem(
val id: Long,
val count: Int,
)

internal object CartJsonSerializer : OkioSerializer<Cart> {
override val defaultValue: Cart = Cart(emptyList())
override suspend fun readFrom(source: BufferedSource): Cart {
return json.decodeFromString<Cart>(source.readUtf8())
}
override suspend fun writeTo(t: Cart, sink: BufferedSink) {

override suspend fun readFrom(source: BufferedSource): Cart = json.decodeFromString<Cart>(source.readUtf8())

override suspend fun writeTo(
t: Cart,
sink: BufferedSink,
) {
sink.use {
it.writeUtf8(json.encodeToString(Cart.serializer(), t))
}
}
}

class CartDataStore(
private val produceFilePath: () -> String,
) {
Expand All @@ -63,9 +69,15 @@ class CartDataStore(
)
val cart: Flow<Cart>
get() = db.data

suspend fun add(fruittie: Fruittie) = update(fruittie, 1)

suspend fun remove(fruittie: Fruittie) = update(fruittie, -1)
suspend fun update(fruittie: Fruittie, diff: Int) {

suspend fun update(
fruittie: Fruittie,
diff: Int,
) {
db.updateData { prevCart ->
val newItems = mutableListOf<CartItem>()
var found = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.Flow

@Dao
interface FruittieDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(fruittie: Fruittie)

Expand All @@ -46,5 +45,5 @@ interface FruittieDao {
@MapColumn(columnName = "id")
Long,
Fruittie,
>
>
}
Loading
Loading