Cotton code
135 lines · 4.5 KB · KotlinRaw
package com.cottondb.android.ui.legalimport com.cottondb.android.legal.LegalDocumentimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.PaddingValuesimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.safeDrawingPaddingimport androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.material3.HorizontalDividerimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.semantics.contentDescriptionimport androidx.compose.ui.semantics.semanticsimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport com.cottondb.android.design.CottonFontsimport com.cottondb.android.design.CottonMetricsimport com.cottondb.android.design.CottonTextStylesimport com.cottondb.android.generated.CottonPaletteimport com.cottondb.android.ui.paper.MemoryPaperDyeimport com.cottondb.android.ui.paper.PaperEdgeimport com.cottondb.android.ui.paper.TornPaper/** A read-less legal sheet. The document title belongs only on the paper, never in the top bar. */@Composablefun LegalScreen(    document: LegalDocument,    onBack: () -> Unit,    modifier: Modifier = Modifier,) {    Column(        modifier = modifier            .fillMaxSize()            .background(CottonPalette.groundMuted)            .safeDrawingPadding(),    ) {        TextButton(            onClick = onBack,            modifier = Modifier                .padding(start = 8.dp, top = 4.dp)                .semantics { contentDescription = "Back" },        ) {            Text("Back")        }        LazyColumn(            modifier = Modifier.fillMaxSize(),            contentPadding = PaddingValues(                start = CottonMetrics.contentMargin,                top = 8.dp,                end = CottonMetrics.contentMargin,                bottom = 24.dp,            ),        ) {            item(key = document.identifier) {                TornPaper(                    id = document.identifier,                    dye = MemoryPaperDye.Cream,                    modifier = Modifier.fillMaxWidth(),                    edge = PaperEdge.Cut,                ) {                    LegalSheet(document)                }            }        }    }}@Composableprivate fun LegalSheet(document: LegalDocument) {    Column(        modifier = Modifier.padding(24.dp),        verticalArrangement = Arrangement.spacedBy(0.dp),    ) {        Text(            text = document.title,            style = CottonTextStyles.screenTitle.copy(                fontFamily = CottonFonts.serif,                fontSize = 30.sp,                lineHeight = 37.sp,            ),            color = CottonPalette.ink,        )        Text(            text = document.updated,            modifier = Modifier.padding(top = 6.dp),            style = CottonTextStyles.caption.copy(fontFamily = CottonFonts.type),            color = CottonPalette.inkSecondary,        )        HorizontalDivider(            modifier = Modifier.padding(top = 16.dp),            thickness = CottonMetrics.hairline,            color = CottonPalette.hairline,        )        LegalParagraph(            text = document.intro,            modifier = Modifier.padding(top = 18.dp),        )        document.sections.forEach { section ->            Column(modifier = Modifier.padding(top = 26.dp)) {                Text(                    text = section.heading,                    style = CottonTextStyles.rowTitle.copy(fontFamily = CottonFonts.serif, fontSize = 20.sp),                    color = CottonPalette.ink,                )                section.body.forEach { paragraph ->                    LegalParagraph(                        text = paragraph,                        modifier = Modifier.padding(top = 10.dp),                    )                }            }        }    }}@Composableprivate fun LegalParagraph(text: String, modifier: Modifier = Modifier) {    Text(        text = text,        modifier = modifier,        style = CottonTextStyles.preview.copy(            fontFamily = CottonFonts.type,            fontSize = 15.sp,            lineHeight = 19.sp,        ),        color = CottonPalette.ink,    )}