- 스킨 아래 기온·비 소식 칩, 날짜는 시계 밑으로. 빗줄기·눈송이는 비 소식 문구 기준 - 링·가운데 1위 탭 → 앱이 새로 열리며 그 각 상세 장부터 - 앱 첫 장(해 구슬·링)은 스킨과 겹쳐 삭제, 앱은 오늘의 각부터 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
272 lines
13 KiB
Kotlin
272 lines
13 KiB
Kotlin
package kr.o2o.nalssigak
|
|
|
|
import androidx.compose.animation.core.FastOutSlowInEasing
|
|
import androidx.compose.animation.core.RepeatMode
|
|
import androidx.compose.animation.core.animateFloat
|
|
import androidx.compose.animation.core.infiniteRepeatable
|
|
import androidx.compose.animation.core.rememberInfiniteTransition
|
|
import androidx.compose.animation.core.tween
|
|
import androidx.compose.foundation.Canvas
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.offset
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.foundation.layout.widthIn
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.draw.drawBehind
|
|
import androidx.compose.ui.geometry.Offset
|
|
import androidx.compose.ui.geometry.Size
|
|
import androidx.compose.ui.graphics.Brush
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.graphicsLayer
|
|
import androidx.compose.ui.graphics.Path
|
|
import androidx.compose.ui.graphics.StrokeCap
|
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
|
import androidx.compose.ui.res.painterResource
|
|
import androidx.compose.ui.text.TextStyle
|
|
import androidx.compose.ui.text.font.FontFamily
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
import androidx.compose.ui.unit.Dp
|
|
import androidx.compose.ui.unit.TextUnit
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import androidx.wear.compose.material3.Text
|
|
import java.time.Duration
|
|
import java.time.Instant
|
|
import kotlin.math.roundToInt
|
|
|
|
// 시안 크기는 큰 원형(227dp) 기준. 작은 원형(192dp)에서도 넘치지 않게 비율과 여백으로 잡는다.
|
|
|
|
/** 말랑 카드: 반투명 흰 바탕 + 아래쪽 안쪽 그림자 4dp (웹 inset 0 -5px 0 var(--shade)) */
|
|
fun Modifier.mallang(color: Color = Tok.card, shade: Color = Tok.shade, radius: Dp = 18.dp): Modifier =
|
|
clip(RoundedCornerShape(radius)).drawBehind {
|
|
drawRect(color)
|
|
val h = 4.dp.toPx()
|
|
drawRect(shade, topLeft = Offset(0f, size.height - h), size = Size(size.width, h))
|
|
}
|
|
|
|
@Composable
|
|
private fun T(text: String, size: TextUnit, family: FontFamily = Tok.jua, color: Color = Color.Unspecified, modifier: Modifier = Modifier,
|
|
weight: FontWeight? = null, align: TextAlign = TextAlign.Center, maxLines: Int = Int.MAX_VALUE) {
|
|
Text(text, modifier = modifier, color = color, maxLines = maxLines, overflow = TextOverflow.Ellipsis, textAlign = align,
|
|
style = TextStyle(fontFamily = family, fontSize = size, fontWeight = weight, lineHeight = size * 1.15))
|
|
}
|
|
|
|
@Composable
|
|
private fun Ic(name: String, size: Dp, modifier: Modifier = Modifier) =
|
|
Image(painterResource(iconRes(name)), contentDescription = null, modifier = modifier.size(size))
|
|
|
|
/** 3D 아이콘이 둥둥 (웹 b-float 4.4s) */
|
|
@Composable
|
|
private fun Floating(content: @Composable () -> Unit) {
|
|
val t = rememberInfiniteTransition(label = "float")
|
|
val p by t.animateFloat(0f, 1f, infiniteRepeatable(tween(2200, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "bob")
|
|
Box(Modifier.graphicsLayer { translationY = -6.dp.toPx() * p; rotationZ = 1.2f * p }) { content() }
|
|
}
|
|
|
|
@Composable
|
|
fun Clock(now: Instant, color: Color) {
|
|
T(hhmm(now), 11.sp, FontFamily.Default, color.copy(alpha = 0.8f), Modifier.fillMaxWidth().padding(top = 8.dp), weight = FontWeight.Bold)
|
|
}
|
|
|
|
// ───────────── 워치 스킨에서 누른 각 ─────────────
|
|
|
|
@Composable
|
|
fun DetailPage(g: Gak, now: Instant) {
|
|
Box(Modifier.fillMaxSize().background(bgButter)) {
|
|
Clock(now, Tok.ink)
|
|
Column(Modifier.fillMaxSize().padding(horizontal = 30.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
|
|
Box(
|
|
Modifier.size(96.dp).drawBehind {
|
|
val stroke = 6.dp.toPx()
|
|
val arc = Size(size.width - stroke, size.height - stroke)
|
|
val tl = Offset(stroke / 2, stroke / 2)
|
|
drawCircle(Tok.stat)
|
|
drawArc(Tok.shade, -90f, 360f, false, tl, arc, style = Stroke(stroke))
|
|
drawArc(Tok.orange, -90f, 360f * g.score / 100f, false, tl, arc, style = Stroke(stroke, cap = StrokeCap.Round))
|
|
},
|
|
contentAlignment = Alignment.Center,
|
|
) {
|
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
Ic(g.icon, 36.dp)
|
|
T(g.score.toString(), 24.sp, Tok.bagel, Tok.ink)
|
|
}
|
|
}
|
|
Spacer(Modifier.height(6.dp))
|
|
T(g.name, 17.sp, color = Tok.ink)
|
|
T("오늘 ${g.rank}위", 10.sp, FontFamily.Default, Tok.ink.copy(alpha = 0.7f), weight = FontWeight.Bold)
|
|
g.summary?.let {
|
|
Spacer(Modifier.height(6.dp))
|
|
T(it, 11.sp, FontFamily.Default, Tok.ink, Modifier.mallang().padding(horizontal = 10.dp, vertical = 6.dp), maxLines = 3)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ───────────── 2·3. 오늘의 각 · 내 각 ─────────────
|
|
|
|
@Composable
|
|
fun GakListPage(title: String, items: List<Gak>, bg: Brush, medals: Boolean, now: Instant) {
|
|
var open by remember { mutableStateOf<String?>(null) }
|
|
Box(Modifier.fillMaxSize().background(bg)) {
|
|
Clock(now, Tok.ink)
|
|
Column(
|
|
Modifier.fillMaxSize().padding(start = 20.dp, end = 20.dp, top = 30.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
verticalArrangement = Arrangement.spacedBy(5.dp),
|
|
) {
|
|
T(title, 14.sp, color = Tok.ink)
|
|
items.forEachIndexed { i, g ->
|
|
// 원 위아래가 좁아 가운데 줄만 꽉 채운다
|
|
val width = if (i == 1) 1f else 0.88f
|
|
GakRow(g, if (medals) MEDALS.getOrNull(i) else null, open == g.code, Modifier.fillMaxWidth(width)) {
|
|
open = if (open == g.code) null else g.code
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun GakRow(g: Gak, medal: String?, open: Boolean, modifier: Modifier, onClick: () -> Unit) {
|
|
Row(
|
|
modifier.mallang().clickable(onClick = onClick).padding(start = 6.dp, end = 10.dp, top = 5.dp, bottom = 8.dp),
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
) {
|
|
Box {
|
|
Ic(g.icon, 28.dp)
|
|
medal?.let { Ic(it, 12.dp, Modifier.offset((-4).dp, (-3).dp)) }
|
|
}
|
|
Column(Modifier.weight(1f)) {
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
T(g.name, 13.sp, color = Tok.ink, align = TextAlign.Start, maxLines = 1)
|
|
if (medal == null) {
|
|
T("${g.rank}위", 8.sp, FontFamily.Default, Tok.ink2, Modifier.padding(start = 3.dp).background(Color(0xFFEEF3FA), CircleShape).padding(horizontal = 4.dp),
|
|
weight = FontWeight.ExtraBold)
|
|
}
|
|
}
|
|
g.summary?.let {
|
|
// 누르면 근거 한 줄을 크게
|
|
T(it, if (open) 11.sp else 8.5.sp, FontFamily.Default, Tok.ink2, align = TextAlign.Start, weight = FontWeight.Bold, maxLines = if (open) 3 else 1)
|
|
}
|
|
}
|
|
T(g.score.toString(), 18.sp, Tok.bagel, Tok.orange)
|
|
}
|
|
}
|
|
|
|
// ───────────── 4. 노을 ─────────────
|
|
|
|
// 웹 .b-skyline::after 의 건물 윤곽 (x%, y%)
|
|
private val SKYLINE = listOf(0 to 55, 8 to 55, 8 to 30, 15 to 30, 15 to 50, 22 to 50, 22 to 10, 28 to 10, 28 to 45, 36 to 45, 36 to 25, 44 to 25, 44 to 55,
|
|
52 to 55, 52 to 35, 60 to 35, 60 to 5, 66 to 5, 66 to 40, 74 to 40, 74 to 20, 82 to 20, 82 to 50, 90 to 50, 90 to 30, 100 to 30, 100 to 100, 0 to 100)
|
|
|
|
@Composable
|
|
fun SunsetPage(sun: Sunset, now: Instant) {
|
|
Box(Modifier.fillMaxSize().background(bgDusk)) {
|
|
Canvas(Modifier.fillMaxSize()) {
|
|
val h = size.height * 0.26f
|
|
val top = size.height - h
|
|
val path = Path().apply {
|
|
SKYLINE.forEachIndexed { i, (x, y) ->
|
|
val px = size.width * x / 100f
|
|
val py = top + h * y / 100f
|
|
if (i == 0) moveTo(px, py) else lineTo(px, py)
|
|
}
|
|
close()
|
|
}
|
|
drawPath(path, Color(0xFF2D2440))
|
|
}
|
|
Clock(now, Color.White)
|
|
Column(Modifier.fillMaxSize().padding(top = 32.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
T(if (sun.isToday) "오늘 노을" else "내일 노을", 13.sp, color = Color.White.copy(alpha = 0.9f))
|
|
T(sun.score.toString(), 52.sp, Tok.bagel, Color.White)
|
|
T(sun.grade, 12.sp, color = Color.White,
|
|
modifier = Modifier.mallang(Color.White.copy(alpha = 0.2f), Color.White.copy(alpha = 0.12f), 99.dp).padding(start = 10.dp, end = 10.dp, top = 2.dp, bottom = 5.dp))
|
|
Spacer(Modifier.height(8.dp))
|
|
T("가장 붉을 때 ${hhmm(sun.bestAt)}", 14.sp, color = Color.White)
|
|
val left = Duration.between(now, sun.sunsetAt)
|
|
val tail = if (sun.isToday && !left.isNegative) " · ${left.toHours()}시간 ${left.toMinutes() % 60}분 남음" else ""
|
|
T("해 지는 ${hhmm(sun.sunsetAt)}$tail", 9.5.sp, FontFamily.Default, Color.White.copy(alpha = 0.85f), weight = FontWeight.Bold)
|
|
}
|
|
}
|
|
}
|
|
|
|
// ───────────── 5. 오늘 남은 시간 ─────────────
|
|
|
|
@Composable
|
|
fun HoursPage(s: Summary, now: Instant) {
|
|
Box(Modifier.fillMaxSize().background(bgSky)) {
|
|
Clock(now, Tok.ink)
|
|
Column(Modifier.fillMaxSize().padding(top = 40.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
T("오늘 남은 시간", 14.sp, color = Tok.ink)
|
|
Spacer(Modifier.height(10.dp))
|
|
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
s.slots.take(4).forEachIndexed { i, slot -> HourCol(slot, i == 0) }
|
|
}
|
|
s.rainText?.let {
|
|
Spacer(Modifier.height(10.dp))
|
|
Row(verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.spacedBy(3.dp)) {
|
|
Ic(if (s.mode == "night") "bear" else "rabbit", 26.dp)
|
|
T(it, 10.5.sp, color = Tok.ink, align = TextAlign.Start,
|
|
modifier = Modifier.widthIn(max = 120.dp).background(Color.White, RoundedCornerShape(12.dp, 12.dp, 12.dp, 4.dp)).padding(horizontal = 8.dp, vertical = 4.dp))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun HourCol(slot: Slot, first: Boolean) {
|
|
val fg = if (first) Color.White else Tok.ink
|
|
Column(
|
|
Modifier.width(40.dp).then(if (first) Modifier.background(Tok.ink, RoundedCornerShape(15.dp)) else Modifier.mallang(Tok.stat, radius = 15.dp))
|
|
.padding(top = 6.dp, bottom = 8.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
|
) {
|
|
T("${slot.at.atZone(KST).hour}시", 8.5.sp, FontFamily.Default, fg.copy(alpha = 0.75f), weight = FontWeight.ExtraBold)
|
|
Ic(slot.icon, 22.dp)
|
|
T(slot.tempC?.let { "${it.roundToInt()}°" } ?: "-", 14.sp, Tok.bagel, fg)
|
|
T("${slot.rainProb ?: "-"}%", 8.sp, FontFamily.Default, if (first) Tok.rainLight else Tok.rain, weight = FontWeight.ExtraBold)
|
|
}
|
|
}
|
|
|
|
// ───────────── 불러오는 중 · 실패 ─────────────
|
|
|
|
@Composable
|
|
fun StatePage(loading: Boolean, onRetry: () -> Unit) {
|
|
Column(Modifier.fillMaxSize().background(skyBrush("day")), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
|
|
Floating { Ic("rabbit", 54.dp) }
|
|
Spacer(Modifier.height(6.dp))
|
|
T(if (loading) "날씨 보러 가는 중" else "날씨를 못 불러왔어요", 14.sp, color = Tok.ink)
|
|
if (!loading) {
|
|
Spacer(Modifier.height(10.dp))
|
|
T("다시 시도", 12.sp, FontFamily.Default, Color.White, Modifier.clip(CircleShape).background(Tok.ink).clickable(onClick = onRetry).padding(horizontal = 14.dp, vertical = 6.dp),
|
|
weight = FontWeight.Bold)
|
|
}
|
|
}
|
|
}
|