spike(desktop): Phase 0 feasibility probes + findings
Adds the throwaway Phase-0 spike (Development Plan §6.3) that answers
whether Incido can become a Compose Multiplatform desktop app without
abandoning ObjectBox, its crypto layer, or its UI layer. All six
questions came back PASS; findings live in tools/DESKTOP_FEASIBILITY.md.
:spike:data-jvm ObjectBox kapt codegen + native runtime on a plain
JVM, DataStore Preferences without a Context, and
the app's own EncryptedKeyCodec round-tripping.
:spike:compose-jvm Compose Desktop rendering the app's real theme
layer + core:domain, plus jpackage packaging.
Additive only: nothing outside spike/ depends on these, and the Android
build is untouched (assembleDebug verified green).
This commit is contained in:
1 parent
f87ca17ded
commit
8b66e82acb
20 files changed
+1822
No files matched your search
@@ -0,0 +1,70 @@
|
||||
// spike/compose-jvm — THROWAWAY probe, not shipped. Desktop feasibility S2/S3/S5
|
||||
// (Development Plan §6.3). Answers Q1 (does a Compose Multiplatform window
|
||||
// build + render on this KDE/Wayland box?), Q4 (do the app's existing
|
||||
// `androidx.compose.*` imports — the real theme layer — compile for the JVM?)
|
||||
// and Q6 (does jpackage produce a runnable Linux image?).
|
||||
//
|
||||
// spike/compose-jvm — THROWAWAY probe, not shipped. Desktop feasibility S2/S3/S5
|
||||
// (Development Plan §6.3). Answers Q1 (does a Compose Multiplatform window
|
||||
// build + render on this KDE/Wayland box?), Q4 (do the app's existing
|
||||
// `androidx.compose.*` imports — the real theme layer — compile for the JVM?)
|
||||
// and Q6 (does jpackage produce a runnable Linux image?).
|
||||
//
|
||||
// Delete with the rest of `spike/`. Findings: tools/DESKTOP_FEASIBILITY.md
|
||||
|
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlinJvm)
|
||||
alias(libs.plugins.compose)
|
||||
alias(libs.plugins.kotlinCompose)
|
||||
// SPIKE FINDING: do NOT apply the `application` plugin explicitly here.
|
||||
// org.jetbrains.compose applies it itself as part of the desktop
|
||||
// packaging support; applying it first collides on task registration
|
||||
// ("Cannot add task 'run' as a task with that name already exists").
|
||||
// `compose.desktop { application { } }` below is what provides `run`.
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Everything below resolves through the org.jetbrains.compose plugin's
|
||||
// `compose.*` accessors, whose version comes from the catalog's
|
||||
// composeMultiplatform entry — no hardcoded versions here (§8).
|
||||
implementation(compose.desktop.currentOs)
|
||||
implementation(compose.ui)
|
||||
implementation(compose.foundation)
|
||||
implementation(compose.material3)
|
||||
implementation(compose.materialIconsExtended)
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
|
||||
// The real domain models + the real theme layer (copied verbatim) —
|
||||
// Q4: prove the app's own UI-facing types compile on the JVM.
|
||||
implementation(project(":core:domain"))
|
||||
|
||||
// S5: the packaged app-image must also carry ObjectBox and its
|
||||
// objectbox-linux native lib, so the data spike rides along here.
|
||||
implementation(project(":spike:data-jvm"))
|
||||
}
|
||||
|
||||
// S5: can jpackage build a runnable Linux distribution here?
|
||||
// `packageDistributionForCurrentOS` (image/tar.gz) is the guaranteed path;
|
||||
// Deb/Rpm/AppImage need dpkg / rpmbuild / appimagetool, which this box may
|
||||
// not have — a failure there is a finding for the CI job, not a bug.
|
||||
compose.desktop {
|
||||
application {
|
||||
mainClass = "org.incido.spike.compose.MainKt"
|
||||
nativeDistributions {
|
||||
targetFormats(TargetFormat.Deb, TargetFormat.Rpm, TargetFormat.AppImage)
|
||||
packageName = "incido-spike"
|
||||
packageVersion = "0.0.1"
|
||||
vendor = "Incido (desktop spike)"
|
||||
description = "Throwaway desktop feasibility spike — not shipped."
|
||||
linux {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.incido.compose.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
// Brand-neutral palette in v0.1 (per Development Plan §5.3). All colors
|
||||
// here are fallbacks for devices that don't support Material You dynamic
|
||||
// color (i.e. Android < 12 or pre-Tiramisu).
|
||||
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650A4)
|
||||
val PurpleGrey40 = Color(0xFF625B71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.incido.compose.ui.theme
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import org.incido.domain.model.NoteColor
|
||||
|
||||
/**
|
||||
* Maps a [NoteColor] enum to a Compose [Color]. Values are chosen to
|
||||
* stay readable against both light and dark surfaces.
|
||||
*/
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun NoteColor.toComposeColor(): Color = when (this) {
|
||||
NoteColor.NONE -> Color.Transparent
|
||||
NoteColor.BLUE -> Color(0xFF4A6FA5)
|
||||
NoteColor.GREEN -> Color(0xFF4F8A5B)
|
||||
NoteColor.AMBER -> Color(0xFFB8862B)
|
||||
NoteColor.RED -> Color(0xFFB14B4B)
|
||||
NoteColor.PURPLE -> Color(0xFF7B5BA6)
|
||||
}
|
||||
|
||||
/** All selectable colours, including [NoteColor.NONE]. */
|
||||
val AllNoteColors: List<NoteColor> = listOf(
|
||||
NoteColor.NONE,
|
||||
NoteColor.BLUE,
|
||||
NoteColor.GREEN,
|
||||
NoteColor.AMBER,
|
||||
NoteColor.RED,
|
||||
NoteColor.PURPLE,
|
||||
)
|
||||
|
||||
/** Outline colour used to highlight the selected swatch. */
|
||||
val swatchBorderColor: Color
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = MaterialTheme.colorScheme.outline
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.incido.compose.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
/**
|
||||
* SPIKE COPY of composeApp/.../ui/theme/Theme.kt — the only differences are
|
||||
* the two Android-only branches (dynamic colour via LocalContext +
|
||||
* Build.VERSION.SDK_INT >= S) removed. Everything else is character-identical.
|
||||
*
|
||||
* This is the whole of Q4: the app's theme layer needs ONE expect/actual seam
|
||||
* (dynamic colour available or not) — `Color.kt`, `Type.kt` and `NoteColors.kt`
|
||||
* were copied in untouched and compile for the JVM as-is.
|
||||
*/
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80,
|
||||
)
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun IncidoTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
@Suppress("UNUSED_PARAMETER") dynamicColor: Boolean = false,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
// Desktop has no Material You wallpaper sampling; Phase 2 keeps this
|
||||
// branch behind an expect/actual `dynamicColorSchemeOrNull()`.
|
||||
val colorScheme = if (darkTheme) DarkColorScheme else LightColorScheme
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = IncidoTypography,
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.incido.compose.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Default Material 3 typography. Custom fonts can be added in a future
|
||||
// version when brand decisions are made.
|
||||
val IncidoTypography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp,
|
||||
),
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp,
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp,
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,114 @@
|
||||
package org.incido.spike.compose
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.toComposeImageBitmap
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import androidx.compose.ui.window.rememberWindowState
|
||||
import java.io.File
|
||||
import kotlin.system.exitProcess
|
||||
import org.incido.compose.ui.theme.IncidoTheme
|
||||
import org.jetbrains.skia.Image as SkiaImage
|
||||
|
||||
/**
|
||||
* spike/compose-jvm — THROWAWAY probe (desktop feasibility S2/S3/S5, §6.3).
|
||||
*
|
||||
* Q1: does a Compose Multiplatform 1.7.3 window build AND render on this
|
||||
* KDE Plasma / Wayland box?
|
||||
* Q4: does the app's own theme layer + domain models compile and drive real
|
||||
* Material3 UI on the JVM? (Color.kt / Type.kt / NoteColors.kt are verbatim
|
||||
* copies from :composeApp; Theme.kt differs only by its two Android-only
|
||||
* lines — see the spike copy in org.incido.compose.ui.theme.)
|
||||
* Q5: can attachment bytes be decoded to an ImageBitmap on the JVM?
|
||||
* Q6: packaging — see the nativeDistributions block in build.gradle.kts.
|
||||
*
|
||||
* The UI covers the Material3 surface set Incido actually uses: Scaffold + top
|
||||
* bar, NavigationRail (the desktop answer to the drawer), a note-card list with
|
||||
* colour stripe + title/body split + hashtag chips, favourites, the colour
|
||||
* filter chip strip, an overflow menu, a confirm dialog, a snackbar, an editor
|
||||
* text field, and a wide-window two-pane layout.
|
||||
*
|
||||
* Args: `--exit-after <seconds>` auto-closes for CI; `--image <file>` decodes
|
||||
* and renders that file as if it were a note attachment.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
val exitAfter = args.argAfter("--exit-after")?.toLongOrNull()
|
||||
val imagePath = args.argAfter("--image")
|
||||
|
||||
// S5 extra: does ObjectBox's native lib load from INSIDE a jpackage image?
|
||||
// (objectbox-linux.jar carries native/libobjectbox-jni-linux-x64.so and
|
||||
// self-extracts it at runtime — that extraction must work in the image.)
|
||||
if ("--probe-db" in args) {
|
||||
runCatching {
|
||||
val dir = File("build/spike-packaged-db").also { it.mkdirs() }
|
||||
val store = org.incido.data.entity.MyObjectBox.builder().directory(dir).build()
|
||||
val count = store.boxFor(org.incido.data.entity.NoteEntity::class.java).count()
|
||||
println("SPIKE-DB : PASS — BoxStore built inside the image, notes=$count")
|
||||
store.close()
|
||||
}.onFailure { println("SPIKE-DB : FAIL ${it::class.java.simpleName}: ${it.message}") }
|
||||
}
|
||||
|
||||
println("=== Incido desktop spike S2: Compose Multiplatform on the JVM ===")
|
||||
println("JVM : ${System.getProperty("java.vendor")} ${System.getProperty("java.version")}")
|
||||
println("OS : ${System.getProperty("os.name")} ${System.getProperty("os.arch")}")
|
||||
println(
|
||||
"AWT toolkit : " + runCatching { java.awt.Toolkit.getDefaultToolkit().javaClass.name }
|
||||
.getOrElse { "unavailable (${it::class.java.simpleName})" },
|
||||
)
|
||||
println(
|
||||
"Skiko : " + runCatching {
|
||||
Class.forName("org.jetbrains.skiko.Library").simpleName + " resolved"
|
||||
}.getOrElse { "FAILED to load — ${it::class.java.simpleName}: ${it.message}" },
|
||||
)
|
||||
println("Check : a window must appear; blank/black window = Skia/GL failure")
|
||||
println()
|
||||
|
||||
val decoded = imagePath?.let { decodeAttachment(File(it)) } ?: ("no --image arg" to null)
|
||||
println("image decode: ${decoded.first}")
|
||||
|
||||
application {
|
||||
Window(
|
||||
onCloseRequest = { exitApplication() },
|
||||
state = rememberWindowState(width = 1180.dp, height = 760.dp),
|
||||
title = "Incido — desktop spike (throwaway)",
|
||||
) {
|
||||
IncidoTheme {
|
||||
SpikeApp(
|
||||
decodedImage = decoded.second,
|
||||
exitAfterSeconds = exitAfter,
|
||||
onHardExit = { exitProcess(0) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Array<String>.argAfter(flag: String): String? {
|
||||
val i = indexOf(flag)
|
||||
return if (i in 0 until size - 1) this[i + 1] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Q5: the two JVM decode paths for the `ByteArray` columns ObjectBox hands
|
||||
* back. ImageIO covers the JDK codecs (PNG/JPEG/GIF/BMP); Skia is the decoder
|
||||
* Compose itself renders with. Whichever fails tells us what a
|
||||
* `PlatformImageDecoder` seam must do per format.
|
||||
*/
|
||||
private fun decodeAttachment(file: File): Pair<String, ImageBitmap?> {
|
||||
val bytes = runCatching { file.readBytes() }
|
||||
.getOrElse { return "could not read ${file.absolutePath}: ${it.message}" to null }
|
||||
|
||||
val imageIo = runCatching {
|
||||
javax.imageio.ImageIO.read(java.io.ByteArrayInputStream(bytes))
|
||||
?.let { "ImageIO ${it.width}x${it.height}" } ?: "ImageIO: no registered reader"
|
||||
}.getOrElse { "ImageIO threw ${it::class.java.simpleName}" }
|
||||
println(" ImageIO : $imageIo")
|
||||
|
||||
return runCatching {
|
||||
SkiaImage.makeFromEncoded(bytes).use { img ->
|
||||
val bmp = img.toComposeImageBitmap()
|
||||
"Skia ${bmp.width}x${bmp.height} (bytes=${bytes.size})" to bmp
|
||||
}
|
||||
}.getOrElse { "Skia threw ${it::class.java.simpleName}: ${it.message}" to null }
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
package org.incido.spike.compose
|
||||
|
||||
// Throwaway spike file: wildcard imports to keep the probe small. Production
|
||||
// modules keep explicit imports per the repo style.
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
// `Dialog` is a ui.window API — material3 only ships AlertDialog/
|
||||
// BasicAlertDialog, so the app's own AlertDialogs port fine but a raw Dialog
|
||||
// needs this explicit import (spike finding for Phase 1).
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.ui.theme.AllNoteColors
|
||||
import org.incido.compose.ui.theme.toComposeColor
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.model.NoteColor
|
||||
|
||||
/** The UI half of the spike — see Main.kt for what it proves. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SpikeApp(
|
||||
decodedImage: ImageBitmap?,
|
||||
exitAfterSeconds: Long?,
|
||||
onHardExit: () -> Unit,
|
||||
) {
|
||||
val notes = remember { sampleNotes() }
|
||||
val destinations = listOf("Home", "Favorites", "Drafts", "Untagged", "Trash", "Settings")
|
||||
var selected by remember { mutableStateOf(0) }
|
||||
var colorFilter by remember { mutableStateOf<NoteColor?>(null) }
|
||||
var search by remember { mutableStateOf("") }
|
||||
var showConfirm by remember { mutableStateOf(false) }
|
||||
var menuOpenFor by remember { mutableStateOf<Long?>(null) }
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
val clipboard = LocalClipboardManager.current
|
||||
// CompositionLocals can't be read from inside LaunchedEffect's coroutine —
|
||||
// capture at composition time.
|
||||
val density = LocalDensity.current.density
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
println(
|
||||
"WINDOW-READY density=$density notes=${notes.size} " +
|
||||
"— first composition succeeded",
|
||||
)
|
||||
// Q5: clipboard write/read (Android reaches for ClipboardManager).
|
||||
runCatching {
|
||||
clipboard.setText(AnnotatedString("incido-spike-clipboard"))
|
||||
val back = clipboard.getText()?.text
|
||||
println(
|
||||
"clipboard : ${if (back == "incido-spike-clipboard") "PASS" else "FAIL"} " +
|
||||
"(read back: $back)",
|
||||
)
|
||||
}.onFailure { println("clipboard : FAIL — ${it::class.java.simpleName}: ${it.message}") }
|
||||
|
||||
exitAfterSeconds?.let {
|
||||
println("auto-closing in ${it}s")
|
||||
delay(it * 1000)
|
||||
onHardExit()
|
||||
}
|
||||
}
|
||||
|
||||
val visible = notes
|
||||
.filter { colorFilter == null || it.color == colorFilter }
|
||||
.filter { search.isBlank() || it.content.contains(search, ignoreCase = true) }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbar) },
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text("Incido — ${destinations[selected]}") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { scope.say(snackbar, "drawer toggle") }) {
|
||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Menu")
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { scope.say(snackbar, "search focus") }) {
|
||||
Icon(Icons.Default.Search, contentDescription = "Search")
|
||||
}
|
||||
IconButton(onClick = { scope.say(snackbar, "overflow") }) {
|
||||
Icon(Icons.Default.MoreVert, contentDescription = "More")
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
Row(Modifier.padding(padding).fillMaxSize()) {
|
||||
NavigationRail {
|
||||
destinations.forEachIndexed { index, label ->
|
||||
NavigationRailItem(
|
||||
selected = selected == index,
|
||||
onClick = { selected = index },
|
||||
icon = { Icon(Icons.Default.Check, contentDescription = null) },
|
||||
label = { Text(label, maxLines = 1) },
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(Modifier.width(360.dp).fillMaxHeight()) {
|
||||
OutlinedTextField(
|
||||
value = search,
|
||||
onValueChange = { search = it },
|
||||
placeholder = { Text("Search notes") },
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
) {
|
||||
// The real colour-swatch strip from the drawer.
|
||||
AllNoteColors.forEach { color ->
|
||||
FilterChip(
|
||||
selected = colorFilter == color,
|
||||
onClick = { colorFilter = if (colorFilter == color) null else color },
|
||||
label = { Text(color.label.take(3)) },
|
||||
leadingIcon = {
|
||||
Box(
|
||||
Modifier.size(10.dp)
|
||||
.background(color.toComposeColor(), RoundedCornerShape(2.dp)),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
HorizontalDivider(Modifier.padding(vertical = 8.dp))
|
||||
LazyColumn(Modifier.fillMaxWidth().weight(1f)) {
|
||||
items(visible, key = { it.id }) { note ->
|
||||
NoteCard(
|
||||
note = note,
|
||||
menuOpen = menuOpenFor == note.id,
|
||||
onMenu = { menuOpenFor = if (menuOpenFor == note.id) null else note.id },
|
||||
onMenuDismiss = { menuOpenFor = null },
|
||||
onTrash = { showConfirm = true },
|
||||
onCopy = {
|
||||
clipboard.setText(AnnotatedString(note.content))
|
||||
scope.say(snackbar, "Copied to clipboard")
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
ExtendedFloatingActionButton(
|
||||
onClick = { scope.say(snackbar, "New note") },
|
||||
icon = { Icon(Icons.Default.Add, contentDescription = null) },
|
||||
text = { Text("New note") },
|
||||
modifier = Modifier.padding(12.dp),
|
||||
)
|
||||
}
|
||||
|
||||
VerticalDivider(Modifier.fillMaxHeight())
|
||||
|
||||
// Wide-window second pane — the editor surface.
|
||||
Column(Modifier.fillMaxHeight().weight(1f).padding(16.dp)) {
|
||||
Text("Editor pane", style = MaterialTheme.typography.titleMedium)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
if (decodedImage != null) {
|
||||
Text(
|
||||
"Attachment decoded on the JVM: ${decodedImage.width}x${decodedImage.height}",
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
Image(
|
||||
bitmap = decodedImage,
|
||||
contentDescription = "decoded attachment",
|
||||
modifier = Modifier.padding(vertical = 8.dp).size(200.dp),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(12.dp))
|
||||
OutlinedTextField(
|
||||
value = "",
|
||||
onValueChange = {},
|
||||
placeholder = { Text("Type here — keyboard / IME check") },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The Trash confirm dialog — Material3 dialogs on desktop behave
|
||||
// differently to Android (scrim + window focus), so it is exercised here.
|
||||
if (showConfirm) {
|
||||
Dialog(onDismissRequest = { showConfirm = false }) {
|
||||
Surface(shape = MaterialTheme.shapes.extraLarge) {
|
||||
Column(Modifier.padding(24.dp)) {
|
||||
Text("Move to Trash?", style = MaterialTheme.typography.titleMedium)
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Text(
|
||||
"You can restore it from Trash later.",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
Spacer(Modifier.height(20.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = { showConfirm = false }) { Text("Cancel") }
|
||||
TextButton(onClick = {
|
||||
showConfirm = false
|
||||
scope.say(snackbar, "Moved to Trash")
|
||||
}) { Text("Move") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The list card — colour stripe, title/body split via the real domain
|
||||
* helper, favourite marker, overflow menu, hashtag chips. */
|
||||
@Composable
|
||||
private fun NoteCard(
|
||||
note: Note,
|
||||
menuOpen: Boolean,
|
||||
onMenu: () -> Unit,
|
||||
onMenuDismiss: () -> Unit,
|
||||
onTrash: () -> Unit,
|
||||
onCopy: () -> Unit,
|
||||
) {
|
||||
val (title, body) = Note.titleAndBody(note.content)
|
||||
Card(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 6.dp)) {
|
||||
Row {
|
||||
Box(
|
||||
Modifier.width(4.dp).fillMaxHeight().background(note.color.toComposeColor()),
|
||||
)
|
||||
Column(Modifier.padding(12.dp).fillMaxWidth()) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
title,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = if (note.isFavorite) FontWeight.Bold else FontWeight.Normal,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
if (note.isFavorite) {
|
||||
Icon(Icons.Default.Favorite, contentDescription = "Favourite")
|
||||
}
|
||||
Box {
|
||||
IconButton(onClick = onMenu) {
|
||||
Icon(Icons.Default.MoreVert, contentDescription = "More")
|
||||
}
|
||||
DropdownMenu(expanded = menuOpen, onDismissRequest = onMenuDismiss) {
|
||||
DropdownMenuItem(
|
||||
text = { Text("Copy") },
|
||||
onClick = { onCopy(); onMenuDismiss() },
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("Move to Trash") },
|
||||
onClick = { onTrash(); onMenuDismiss() },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (body.isNotBlank()) {
|
||||
Text(
|
||||
body,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = 3,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
note.hashtags.forEach { tag ->
|
||||
Box(
|
||||
Modifier
|
||||
.background(
|
||||
MaterialTheme.colorScheme.secondaryContainer,
|
||||
RoundedCornerShape(8.dp),
|
||||
)
|
||||
.padding(horizontal = 8.dp, vertical = 2.dp),
|
||||
) { Text("#$tag", style = MaterialTheme.typography.labelSmall) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun CoroutineScope.say(host: SnackbarHostState, message: String) {
|
||||
launch { host.showSnackbar(message) }
|
||||
}
|
||||
|
||||
/** Fake data shaped exactly like what NoteRepository hands the ViewModels. */
|
||||
private fun sampleNotes(): List<Note> {
|
||||
val base = System.currentTimeMillis()
|
||||
return listOf(
|
||||
Note(1, "Groceries\nmilk, bread, coffee", base - 5000, base,
|
||||
isFavorite = true, color = NoteColor.GREEN, hashtags = listOf("home", "shopping")),
|
||||
Note(2, "Desktop spike\nRendered from the real Note domain model",
|
||||
base - 4000, base, color = NoteColor.BLUE, hashtags = listOf("work")),
|
||||
Note(3, "Voice note idea", base - 3000, base, color = NoteColor.AMBER),
|
||||
Note(4, "Untitled draft", base - 2000, base, isDraft = true),
|
||||
Note(5, "Delete me\nexercises the confirm dialog", base - 1000, base,
|
||||
color = NoteColor.RED, hashtags = listOf("test")),
|
||||
Note(6, "Purple note", base, base, color = NoteColor.PURPLE,
|
||||
hashtags = listOf("ideas", "work")),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user