Skip to content
Open
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
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ compass = "1.2.4"
ksensor = "2.0.4"
kmp-zip = "0.8.0"
vico = "3.1.0"
skiko = "0.8.18" # aligned with compose

[libraries]
multiplatform-settings = { module = "com.russhwolf:multiplatform-settings-no-arg", version.ref = "multiplatform-settings" }
Expand Down Expand Up @@ -49,6 +50,7 @@ ksensor = { module = "io.github.shadmanadman:KSensor", version.ref = "ksensor" }
kmp-zip = { module = "no.synth:kmp-zip", version.ref = "kmp-zip" }
vico-compose = { module = "com.patrykandpatrick.vico:compose", version.ref = "vico" }
vico-compose-m3 = { module = "com.patrykandpatrick.vico:compose-m3", version.ref = "vico" }
skiko = { module = "org.jetbrains.skiko:skiko", version.ref = "skiko" }

[plugins]
app-cash-sqldelight = { id = "app.cash.sqldelight", version = "2.1.0" }
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ kotlin {
// KMP dependencies declared in commonMain.
implementation(libs.ktor.client.darwin)
implementation("app.cash.sqldelight:native-driver:2.1.0")
implementation(libs.skiko)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions shared/docs/kmp-migration-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@
| Media keycode events | | |
| | | |
| **Statistics** | | |
| Total | :white_check_mark: | :white_check_mark: |
| Year | :white_check_mark: | :white_check_mark: |
| Month | :white_check_mark: | :white_check_mark: |
| Share image | :white_check_mark: | |
| Heatmap | :white_check_mark: | :white_check_mark: |
| Heatmap/DatePicker | :white_check_mark: | |
| | | |
| ... | | |
| | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fieldbook.shared.screens.statistics

import android.graphics.Bitmap
import android.os.Build
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import java.io.ByteArrayOutputStream

actual fun encodePng(image: ImageBitmap): ByteArray? {
return runCatching {
val source = image.asAndroidBitmap()
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && source.config == Bitmap.Config.HARDWARE) {
source.copy(Bitmap.Config.ARGB_8888, false)
} else {
source
}

ByteArrayOutputStream().use { output ->
val encoded = bitmap.compress(Bitmap.CompressFormat.PNG, 100, output)
if (bitmap !== source) {
bitmap.recycle()
}
if (encoded) output.toByteArray() else null
}
}.getOrNull()
}
8 changes: 8 additions & 0 deletions shared/src/commonMain/kotlin/com/fieldbook/shared/KmpApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.fieldbook.shared.screens.preferences.LanguageScreen
import com.fieldbook.shared.screens.preferences.PreferencesScreen
import com.fieldbook.shared.screens.preferences.StorageDefinerScreen
import com.fieldbook.shared.screens.preferences.StoragePreferencesScreen
import com.fieldbook.shared.screens.statistics.StatisticsScreen
import com.fieldbook.shared.screens.trait.TraitEditorScreen
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -229,6 +230,13 @@ fun KmpApp(
)
}

composable(KmpHostScreenType.STATISTICS.route) {
StatisticsScreen(
onBack = { navController.navigateBackOrExit(onExit) },
onSnackbarMessage = onSnackbarMessage,
)
}

composable(KmpHostScreenType.ABOUT.route) {
AboutScreen(
onBack = { navController.navigateBackOrExit(onExit) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class KmpHostScreenType(val value: String) {
BRAPI_FILTER("brapi_filter"),
COLLECT("collect"),
EXPORT("export"),
STATISTICS("statistics"),
ABOUT("about"),
PREFERENCES("preferences"),
BRAPI_PREFERENCES("brapi_preferences"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ fun ConfigScreen(
),
ConfigItem(
title = Res.string.settings_statistics,
icon = Res.drawable.ic_nav_drawer_statistics
icon = Res.drawable.ic_nav_drawer_statistics,
destination = KmpHostScreenType.STATISTICS
),
ConfigItem(
title = Res.string.about_title,
Expand Down
Loading