85 lines · 5.8 KB · KotlinRaw
package com.cottondb.android.ui.homeimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.clickableimport androidx.compose.foundation.Canvasimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.sizeimport androidx.compose.material3.ExperimentalMaterial3Apiimport androidx.compose.material3.ModalBottomSheetimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.StrokeCapimport androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.semantics.Roleimport androidx.compose.ui.semantics.contentDescriptionimport androidx.compose.ui.semantics.semanticsimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.unit.dpimport com.cottondb.android.design.CottonFontsimport com.cottondb.android.design.CottonTextStylesimport com.cottondb.android.generated.CottonPalette/** The deterministic creation lane from Home's plus circle. */@OptIn(ExperimentalMaterial3Api::class)@Composableinternal fun HomeAddFan(today: String, onDismiss: () -> Unit, onChoose: (String) -> Unit) { ModalBottomSheet(onDismissRequest = onDismiss, containerColor = CottonPalette.ground) { Column(Modifier.padding(horizontal = 24.dp, vertical = 8.dp)) { Text("Make something", style = CottonTextStyles.screenTitle.copy(fontFamily = CottonFonts.display), color = CottonPalette.ink) fanActions(today).chunked(3).forEach { row -> Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceAround) { row.forEach { action -> Column( Modifier.weight(1f).clickable(role = Role.Button) { onChoose(action.path) } .padding(vertical = 12.dp).semantics { contentDescription = action.label }, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp), ) { FanDisc(action.kind) Text(action.label, style = CottonTextStyles.caption, color = CottonPalette.ink, textAlign = TextAlign.Center) } } repeat(3 - row.size) { Column(Modifier.weight(1f)) {} } } } } }}@Composableprivate fun FanDisc(kind: FanKind) = androidx.compose.foundation.layout.Box( Modifier.size(48.dp).background(CottonPalette.chipGround, androidx.compose.foundation.shape.CircleShape), contentAlignment = Alignment.Center,) { Canvas(Modifier.size(20.dp)) { val ink = CottonPalette.inkSecondary val w = size.width; val h = size.height when (kind) { FanKind.Todo -> { drawLine(ink, Offset(w*.15f,h*.52f), Offset(w*.40f,h*.78f), 2.dp.toPx(), StrokeCap.Round); drawLine(ink, Offset(w*.40f,h*.78f), Offset(w*.85f,h*.20f), 2.dp.toPx(), StrokeCap.Round) } FanKind.Event -> { drawRect(ink, Offset(w*.15f,h*.2f), androidx.compose.ui.geometry.Size(w*.7f,h*.65f), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())); drawLine(ink, Offset(w*.15f,h*.4f), Offset(w*.85f,h*.4f), 1.7.dp.toPx()) } FanKind.Note -> { drawLine(ink, Offset(w*.2f,h*.25f), Offset(w*.8f,h*.25f), 1.7.dp.toPx()); drawLine(ink, Offset(w*.2f,h*.5f), Offset(w*.8f,h*.5f), 1.7.dp.toPx()); drawLine(ink, Offset(w*.2f,h*.75f), Offset(w*.65f,h*.75f), 1.7.dp.toPx()) } FanKind.Contact -> { drawCircle(ink, w*.18f, Offset(w*.5f,h*.33f), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())); drawArc(ink, 200f, 140f, false, Offset(w*.2f,h*.42f), androidx.compose.ui.geometry.Size(w*.6f,h*.45f), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())) } FanKind.Document -> { drawRect(ink, Offset(w*.23f,h*.12f), androidx.compose.ui.geometry.Size(w*.54f,h*.76f), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())); drawLine(ink, Offset(w*.5f,h*.32f), Offset(w*.5f,h*.68f), 1.7.dp.toPx(), StrokeCap.Round); drawLine(ink, Offset(w*.33f,h*.54f), Offset(w*.5f,h*.72f), 1.7.dp.toPx(), StrokeCap.Round); drawLine(ink, Offset(w*.67f,h*.54f), Offset(w*.5f,h*.72f), 1.7.dp.toPx(), StrokeCap.Round) } FanKind.Meeting, FanKind.Recording -> { drawCircle(ink, w*.25f, Offset(w*.5f,h*.42f), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())); drawLine(ink, Offset(w*.5f,h*.67f), Offset(w*.5f,h*.88f), 1.7.dp.toPx()); drawLine(ink, Offset(w*.3f,h*.88f), Offset(w*.7f,h*.88f), 1.7.dp.toPx()) } FanKind.Chat -> { drawRoundRect(ink, Offset(w*.12f,h*.2f), androidx.compose.ui.geometry.Size(w*.76f,h*.55f), androidx.compose.ui.geometry.CornerRadius(4.dp.toPx()), style = androidx.compose.ui.graphics.drawscope.Stroke(1.7.dp.toPx())); drawLine(ink, Offset(w*.3f,h*.75f), Offset(w*.22f,h*.9f), 1.7.dp.toPx()) } }} }private enum class FanKind { Todo, Event, Note, Contact, Document, Meeting, Recording, Chat }private data class FanAction(val label: String, val kind: FanKind, val path: String)private fun fanActions(today: String) = listOf( FanAction("Todo", FanKind.Todo, "/todos?new=1"), FanAction("Event", FanKind.Event, "/calendar/event/edit?date=$today"), FanAction("Note", FanKind.Note, "/notes/note/new"), FanAction("Contact", FanKind.Contact, "/people/import"), FanAction("Document", FanKind.Document, "/documents/import"), FanAction("Meeting", FanKind.Meeting, "/meetings/record"), FanAction("Recording", FanKind.Recording, "/meetings?import=1"), FanAction("WhatsApp chat", FanKind.Chat, "/messages/import"),)