feat: 날씨각 워치 스킨(WFF) — 1~7위 링, 구름·비·눈 애니메이션, 귀여운 해
- watchface 모듈: 큰 원 1위 + 둘레 링 2~7위, 시간대 하늘, 구름 흐름, 비·눈 오버레이 - 앱: 순위별 컴플리케이션(1~7위), 비·눈 컴플리케이션, 히어로 장 비·눈·해 광선 - 백엔드: /v1/watch/summary top 을 7개로 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f806f9955
commit
8c7fbdaac7
47 files changed
+1119
-32
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Icon
|
||||
import androidx.wear.watchface.complications.data.ComplicationData
|
||||
import androidx.wear.watchface.complications.data.ComplicationType
|
||||
@@ -23,9 +26,9 @@ class GakComplicationService : SuspendingTimelineComplicationDataSourceService()
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationDataTimeline? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@GakComplicationService) } ?: return null
|
||||
val type = request.complicationType
|
||||
val sunset = s.sunset?.let { data(type, hhmm(it.bestAt), "노을", it.score, "sunset") }
|
||||
val sunset = s.sunset?.let { gakData(this, type, hhmm(it.bestAt), "노을", it.score, "sunset") }
|
||||
// 각 점수를 못 받았으면 노을이라도
|
||||
val default = s.myGak?.let { data(type, it.score.toString(), it.name.removeSuffix("각"), it.score, it.icon) } ?: sunset ?: return null
|
||||
val default = s.myGak?.let { gakData(this, type, it.score.toString(), it.name.removeSuffix("각"), it.score, it.icon) } ?: sunset ?: return null
|
||||
val entries = if (sunset == null) emptyList() else s.timeline.withIndex().filter { it.value.kind == "sunset" }.map { (i, p) ->
|
||||
val end = s.timeline.getOrNull(i + 1)?.startAt ?: p.startAt.plus(Duration.ofHours(3))
|
||||
TimelineEntry(TimeInterval(p.startAt, end), sunset)
|
||||
@@ -33,18 +36,19 @@ class GakComplicationService : SuspendingTimelineComplicationDataSourceService()
|
||||
return ComplicationDataTimeline(default, entries)
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = data(type, "82", "야장", 82, "yajang")
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = gakData(this, type, "82", "야장", 82, "yajang")
|
||||
}
|
||||
|
||||
/** 3D 아이콘은 작은 이미지로 함께 보낸다. 그릴지 말지는 시계 화면이 정한다. */
|
||||
private fun data(type: ComplicationType, text: String, title: String, score: Int, icon: String): ComplicationData {
|
||||
val img = SmallImage.Builder(Icon.createWithResource(this, iconRes(icon)), SmallImageType.ICON).build()
|
||||
val t = PlainComplicationText.Builder(text).build()
|
||||
val ti = PlainComplicationText.Builder(title).build()
|
||||
val desc = PlainComplicationText.Builder("$title $text").build()
|
||||
return if (type == ComplicationType.RANGED_VALUE) {
|
||||
RangedValueComplicationData.Builder(score.toFloat(), 0f, 100f, desc).setText(t).setTitle(ti).setSmallImage(img).build()
|
||||
} else {
|
||||
ShortTextComplicationData.Builder(t, desc).setTitle(ti).setSmallImage(img).build()
|
||||
}
|
||||
/** 3D 아이콘은 작은 이미지로 함께 보낸다. 그릴지 말지는 시계 화면이 정한다. 누르면 날씨각 앱이 열린다. */
|
||||
fun gakData(context: Context, type: ComplicationType, text: String, title: String, score: Int, icon: String): ComplicationData {
|
||||
val img = SmallImage.Builder(Icon.createWithResource(context, iconRes(icon)), SmallImageType.ICON).build()
|
||||
val t = PlainComplicationText.Builder(text).build()
|
||||
val ti = PlainComplicationText.Builder(title).build()
|
||||
val desc = PlainComplicationText.Builder("$title $text").build()
|
||||
val open = PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||
return if (type == ComplicationType.RANGED_VALUE) {
|
||||
RangedValueComplicationData.Builder(score.toFloat(), 0f, 100f, desc).setText(t).setTitle(ti).setSmallImage(img).setTapAction(open).build()
|
||||
} else {
|
||||
ShortTextComplicationData.Builder(t, desc).setTitle(ti).setSmallImage(img).setTapAction(open).build()
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ private fun App(s: Summary?, loading: Boolean, onRetry: () -> Unit) {
|
||||
VerticalPager(state = state, modifier = Modifier.fillMaxSize()) { i ->
|
||||
when (pages[i]) {
|
||||
Page.HERO -> HeroPage(s, now)
|
||||
Page.TOP -> GakListPage("오늘의 각", s.top, bgButter, medals = true, now)
|
||||
Page.TOP -> GakListPage("오늘의 각", s.top.take(3), bgButter, medals = true, now)
|
||||
Page.PICKS -> GakListPage("내 각", s.picks, bgMint, medals = false, now)
|
||||
Page.SUNSET -> SunsetPage(s.sunset!!, now)
|
||||
Page.HOURS -> HoursPage(s, now)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import androidx.wear.watchface.complications.data.ComplicationData
|
||||
import androidx.wear.watchface.complications.data.ComplicationType
|
||||
import androidx.wear.watchface.complications.data.PlainComplicationText
|
||||
import androidx.wear.watchface.complications.data.ShortTextComplicationData
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationRequest
|
||||
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/** 워치 스킨의 숨은 칸용: 지금 비·눈 여부("rain" | "snow" | "none"). 스킨이 이 값을 보고 빗줄기·눈송이를 그린다. */
|
||||
class RainComplicationService : SuspendingComplicationDataSourceService() {
|
||||
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@RainComplicationService) } ?: return null
|
||||
return data(s.precip ?: "none")
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = data("none")
|
||||
|
||||
private fun data(kind: String) = ShortTextComplicationData.Builder(
|
||||
PlainComplicationText.Builder(kind).build(),
|
||||
PlainComplicationText.Builder(mapOf("rain" to "비", "snow" to "눈").getOrDefault(kind, "맑음")).build(),
|
||||
).build()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import androidx.wear.watchface.complications.data.ComplicationData
|
||||
import androidx.wear.watchface.complications.data.ComplicationType
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationRequest
|
||||
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/** 워치 스킨용 N위 각. 칸 하나에 공급원 하나라 순위마다 서비스를 하나씩 둔다 (큰 원 1위, 둘레 링 2~7위). */
|
||||
open class RankComplicationService(private val rank: Int) : SuspendingComplicationDataSourceService() {
|
||||
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@RankComplicationService) } ?: return null
|
||||
val g = s.top.getOrNull(rank - 1) ?: return null
|
||||
return gakData(this, request.complicationType, g.score.toString(), g.name, g.score, g.icon)
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = gakData(this, type, "${90 - rank * 2}", "${rank}위", 90 - rank * 2, "sun_cloud")
|
||||
}
|
||||
|
||||
class Rank1ComplicationService : RankComplicationService(1)
|
||||
class Rank2ComplicationService : RankComplicationService(2)
|
||||
class Rank3ComplicationService : RankComplicationService(3)
|
||||
class Rank4ComplicationService : RankComplicationService(4)
|
||||
class Rank5ComplicationService : RankComplicationService(5)
|
||||
class Rank6ComplicationService : RankComplicationService(6)
|
||||
class Rank7ComplicationService : RankComplicationService(7)
|
||||
@@ -1,6 +1,7 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
@@ -27,6 +28,9 @@ 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.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -104,27 +108,31 @@ private val STARS = listOf(0.22f to 0.20f, 0.70f to 0.14f, 0.84f to 0.40f, 0.14f
|
||||
|
||||
@Composable
|
||||
fun HeroPage(s: Summary, now: Instant) {
|
||||
val precip = s.precip
|
||||
val dark = isDark(s.mode)
|
||||
val night = s.mode == "night"
|
||||
val fg = if (dark) Color.White else Tok.ink
|
||||
val top = s.top.firstOrNull()
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(skyBrush(s.mode))) {
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(if (precip != null) precipBrush(precip, s.mode) else skyBrush(s.mode))) {
|
||||
val w = maxWidth
|
||||
if (night) Canvas(Modifier.fillMaxSize()) {
|
||||
if (night && precip == null) Canvas(Modifier.fillMaxSize()) {
|
||||
STARS.forEach { (x, y) -> drawCircle(Color.White, 1.4.dp.toPx(), Offset(size.width * x, size.height * y)) }
|
||||
}
|
||||
Clock(now, fg)
|
||||
val day = now.atZone(KST).dayOfWeek.getDisplayName(DateTextStyle.FULL, Locale.KOREAN)
|
||||
T("$day · ${s.regionName.substringAfterLast(' ')}", 12.sp, color = fg, modifier = Modifier.fillMaxWidth().padding(top = 26.dp))
|
||||
|
||||
Cloud(night, 7000, 16f, Modifier.offset(w * 0.09f, w * 0.34f).size(w * 0.19f, w * 0.07f))
|
||||
Cloud(night, 9000, -20f, Modifier.offset(w * 0.6f, w * 0.74f).size(w * 0.22f, w * 0.075f))
|
||||
Orb(night, Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.4f)) {
|
||||
T(top?.score?.toString() ?: "-", 36.sp, Tok.bagel, if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
T(top?.name ?: "날씨각", 11.sp, color = if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
val cloudColor = when { precip == "rain" -> Color(0xFFDCE2EB); night -> Color(0xFFC9CDF0); else -> Color.White }
|
||||
Cloud(cloudColor, 7000, 16f, Modifier.offset(w * 0.09f, w * 0.34f).size(w * 0.19f, w * 0.07f))
|
||||
Cloud(cloudColor, 9000, -20f, Modifier.offset(w * 0.6f, w * 0.74f).size(w * 0.22f, w * 0.075f))
|
||||
precip?.let { Precip(it, Modifier.fillMaxSize()) }
|
||||
if (!night) SunRays(Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.5f))
|
||||
Orb(night, Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.36f)) {
|
||||
T(top?.score?.toString() ?: "-", 32.sp, Tok.bagel, if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
T(top?.name ?: "날씨각", 10.sp, color = if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
}
|
||||
// 큰 원 둘레에 나머지 각 점수 링 (1위는 큰 원에 있으니 빼고)
|
||||
val rings = (s.top + s.picks).distinctBy { it.code }.filter { it.code != top?.code }.take(RING_ANGLES.size)
|
||||
// 큰 원 둘레에 2~7위 점수 링 (워치 스킨과 같은 배치)
|
||||
val rings = s.top.drop(1).take(RING_ANGLES.size)
|
||||
rings.forEachIndexed { i, g ->
|
||||
val rad = Math.toRadians(RING_ANGLES[i])
|
||||
val size = w * 0.15f
|
||||
@@ -132,7 +140,13 @@ fun HeroPage(s: Summary, now: Instant) {
|
||||
}
|
||||
Row(Modifier.align(Alignment.BottomCenter).padding(bottom = w * 0.1f), horizontalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Stat("thermo", s.tempC?.let { "${it.roundToInt()}°" } ?: "-°", dark)
|
||||
Stat("umbrella", when (s.rain2h) { true -> "곧 비"; false -> "비 없음"; null -> "-" }, dark)
|
||||
Stat("umbrella", when {
|
||||
precip == "snow" -> "눈 와요"
|
||||
s.nowIcon == "rain" -> "비 와요"
|
||||
s.rain2h == true -> "곧 비"
|
||||
s.rain2h == false -> "비 없음"
|
||||
else -> "-"
|
||||
}, dark)
|
||||
}
|
||||
s.warning?.let {
|
||||
T("⚠ $it", 10.sp, color = fg, modifier = Modifier.align(Alignment.BottomCenter).padding(bottom = w * 0.03f), maxLines = 1)
|
||||
@@ -166,6 +180,23 @@ private fun ScoreRing(g: Gak, dark: Boolean, modifier: Modifier) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 구슬 둘레의 끝이 둥근 햇살 12개. 1분에 한 바퀴 천천히 돈다 */
|
||||
@Composable
|
||||
private fun SunRays(modifier: Modifier) {
|
||||
val t = rememberInfiniteTransition(label = "rays")
|
||||
val turn by t.animateFloat(0f, 360f, infiniteRepeatable(tween(60_000, easing = LinearEasing)), label = "turn")
|
||||
Canvas(modifier.graphicsLayer { rotationZ = turn }) {
|
||||
val c = Offset(size.width / 2, size.height / 2)
|
||||
val r1 = size.width * 0.4f
|
||||
val r2 = size.width * 0.462f
|
||||
repeat(12) { i ->
|
||||
val a = Math.toRadians(i * 30.0)
|
||||
val dir = Offset(cos(a).toFloat(), sin(a).toFloat())
|
||||
drawLine(Color(0xFFFFB347), c + dir * r1, c + dir * r2, size.width * 0.044f, StrokeCap.Round)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 말랑 3D 해 구슬 (웹 .b-sun). 밤에는 달빛 보라 */
|
||||
@Composable
|
||||
private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> Unit) {
|
||||
@@ -181,6 +212,10 @@ private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> U
|
||||
// 오른쪽 아래 그늘, 왼쪽 위 빛 (웹 inset 그림자 두 개)
|
||||
drawCircle(Brush.linearGradient(listOf(Color.Transparent, Color(if (night) 0x4D3C328C else 0x57AA3214)), Offset(size.width * 0.45f, size.height * 0.45f), Offset(size.width, size.height)))
|
||||
drawCircle(Brush.radialGradient(listOf(Color.White.copy(alpha = 0.45f), Color.Transparent), Offset(size.width * 0.28f, size.height * 0.25f), size.width * 0.35f))
|
||||
// 해에만 볼터치
|
||||
if (!night) listOf(0.18f, 0.82f).forEach { x ->
|
||||
drawOval(Color(0x73FF7A8A), Offset(size.width * x - size.width * 0.07f, size.height * 0.68f), Size(size.width * 0.14f, size.width * 0.08f))
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) { Column(horizontalAlignment = Alignment.CenterHorizontally) { content() } }
|
||||
@@ -188,8 +223,7 @@ private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> U
|
||||
|
||||
/** 구름은 좌우로 천천히 오간다. distance 부호로 방향, ms 로 속도 */
|
||||
@Composable
|
||||
private fun Cloud(night: Boolean, ms: Int, distance: Float, modifier: Modifier) {
|
||||
val c = if (night) Color(0xFFC9CDF0) else Color.White
|
||||
private fun Cloud(c: Color, ms: Int, distance: Float, modifier: Modifier) {
|
||||
val t = rememberInfiniteTransition(label = "cloud")
|
||||
val p by t.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "drift")
|
||||
Canvas(modifier.graphicsLayer { translationX = distance.dp.toPx() * p }) {
|
||||
@@ -199,6 +233,43 @@ private fun Cloud(night: Boolean, ms: Int, distance: Float, modifier: Modifier)
|
||||
}
|
||||
}
|
||||
|
||||
// 빗줄기·눈송이 하나: 가로 위치, 시작 위상, 한 번 떨어지는 데 걸리는 초, 크기 (모두 고정값이라 매번 같은 자리)
|
||||
private class Drop(val x: Float, val phase: Float, val sec: Float, val size: Float)
|
||||
|
||||
private val DROPS = java.util.Random(7).let { r -> List(42) { Drop(r.nextFloat(), r.nextFloat(), 0.7f + r.nextFloat() * 0.5f, 0.6f + r.nextFloat() * 0.4f) } }
|
||||
|
||||
/** 비는 추적추적 비스듬히, 눈은 천천히 흔들리며. 화면이 켜져 있는 동안만 그린다 */
|
||||
@Composable
|
||||
private fun Precip(kind: String, modifier: Modifier) {
|
||||
var time by remember { mutableFloatStateOf(0f) }
|
||||
LaunchedEffect(Unit) {
|
||||
val start = withFrameNanos { it }
|
||||
while (true) withFrameNanos { time = (it - start) / 1e9f }
|
||||
}
|
||||
val snow = kind == "snow"
|
||||
Canvas(modifier) {
|
||||
val h = size.height
|
||||
DROPS.forEachIndexed { i, d ->
|
||||
val period = if (snow) d.sec * 7f else d.sec
|
||||
val p = (time / period + d.phase) % 1f
|
||||
val y = p * (h + 40.dp.toPx()) - 20.dp.toPx()
|
||||
if (snow) {
|
||||
val x = d.x * size.width + sin((time / 2f + d.phase) * 2f * Math.PI.toFloat()) * 6.dp.toPx()
|
||||
drawCircle(Color.White.copy(alpha = 0.9f), (1.5f + 2f * d.size).dp.toPx(), Offset(x, y))
|
||||
} else {
|
||||
val len = 14.dp.toPx() * d.size
|
||||
val x = d.x * size.width + y * 0.12f
|
||||
drawLine(Color(0xCCEAF2FF), Offset(x, y), Offset(x - len * 0.12f, y - len), 1.5.dp.toPx(), StrokeCap.Round)
|
||||
// 셋 중 하나는 바닥에서 톡 튄다
|
||||
if (i % 3 == 0 && p > 0.86f) {
|
||||
val k = (p - 0.86f) / 0.14f
|
||||
drawCircle(Color(0x99EAF2FF), (2f + 6f * k).dp.toPx(), Offset(x, h * (0.8f + 0.12f * d.x)), style = Stroke(1.dp.toPx()), alpha = 1f - k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Stat(icon: String, text: String, dark: Boolean) {
|
||||
Row(
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.LocationManager
|
||||
import android.util.Log
|
||||
import androidx.wear.tiles.TileService
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationDataSourceUpdateRequester
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
@@ -26,6 +29,8 @@ data class Summary(
|
||||
/** morning | day | evening | night (서버 slot_of) */
|
||||
val mode: String,
|
||||
val tempC: Double?,
|
||||
/** 지금 3시간 칸 아이콘 (sun, rain, snow …) */
|
||||
val nowIcon: String?,
|
||||
val rainText: String?,
|
||||
val rain2h: Boolean?,
|
||||
val warning: String?,
|
||||
@@ -37,6 +42,13 @@ data class Summary(
|
||||
) {
|
||||
/** 컴플리케이션·타일에 올릴 각: 내 각 첫 번째, 없으면 오늘 1위 */
|
||||
val myGak: Gak? get() = picks.firstOrNull() ?: top.firstOrNull()
|
||||
|
||||
/** 비·눈 화면: "rain" | "snow" | null. 지금 칸이 눈이면 눈, 지금 칸이 비거나 2시간 안에 비 소식이면 비 */
|
||||
val precip: String? get() = when {
|
||||
nowIcon == "snow" -> "snow"
|
||||
nowIcon == "rain" || rain2h == true -> "rain"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val KST: ZoneId = ZoneId.of("Asia/Seoul")
|
||||
@@ -63,6 +75,7 @@ fun parseSummary(json: String): Summary {
|
||||
refreshAt = time(o.getString("refresh_at")),
|
||||
mode = o.optString("mode", "day"),
|
||||
tempC = now?.dbl("temp_c"),
|
||||
nowIcon = now?.str("icon"),
|
||||
rainText = now?.str("text"),
|
||||
rain2h = now?.takeIf { it.has("rain_2h") }?.getBoolean("rain_2h"),
|
||||
warning = o.str("warning"),
|
||||
@@ -84,7 +97,13 @@ object SummaryRepo {
|
||||
private const val DEFAULT_REGION = "1111000000"
|
||||
|
||||
/** 캐시가 refresh_at 전이면 캐시, 아니면 새로 받는다. 받기 실패하면 지난 캐시라도. 네트워크를 쓰니 메인 스레드에서 부르지 않는다. */
|
||||
fun load(context: Context, force: Boolean = false): Summary? {
|
||||
fun load(context: Context, force: Boolean = false): Summary? = fetch(context, force)?.let { s ->
|
||||
// 디버그 빌드 확인용: shared_prefs/debug.xml 의 precip(rain|snow)로 비·눈 화면을 강제로 띄운다
|
||||
val forced = if (BuildConfig.DEBUG) context.getSharedPreferences("debug", Context.MODE_PRIVATE).getString("precip", null) else null
|
||||
if (forced == null) s else s.copy(nowIcon = forced, rain2h = forced == "rain")
|
||||
}
|
||||
|
||||
private fun fetch(context: Context, force: Boolean): Summary? {
|
||||
val prefs = context.getSharedPreferences("summary", Context.MODE_PRIVATE)
|
||||
val cached = prefs.getString("json", null)?.let { runCatching { parseSummary(it) }.getOrNull() }
|
||||
if (!force && cached != null && Instant.now() < cached.refreshAt) return cached
|
||||
@@ -93,6 +112,7 @@ object SummaryRepo {
|
||||
val json = get("/v1/watch/summary?region=$region&pick=$PICKS")
|
||||
val fresh = parseSummary(json)
|
||||
prefs.edit().putString("json", json).apply()
|
||||
refreshSurfaces(context)
|
||||
fresh
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "summary 받기 실패, 캐시 사용", e)
|
||||
@@ -100,6 +120,16 @@ object SummaryRepo {
|
||||
}
|
||||
}
|
||||
|
||||
/** 새 값을 받으면 시계 화면 칸·타일을 모두 다시 그리게 한다. 칸마다 갱신 시점이 달라 순위가 섞이는 걸 막는다.
|
||||
* 다시 불린 칸들은 방금 저장한 캐시를 읽으니 서버를 또 부르지 않는다. */
|
||||
private fun refreshSurfaces(context: Context) {
|
||||
val sources = listOf(GakComplicationService::class.java, RainComplicationService::class.java, Rank1ComplicationService::class.java,
|
||||
Rank2ComplicationService::class.java, Rank3ComplicationService::class.java, Rank4ComplicationService::class.java,
|
||||
Rank5ComplicationService::class.java, Rank6ComplicationService::class.java, Rank7ComplicationService::class.java)
|
||||
sources.forEach { ComplicationDataSourceUpdateRequester.create(context, ComponentName(context, it)).requestUpdateAll() }
|
||||
TileService.getUpdater(context).requestUpdate(GakTileService::class.java)
|
||||
}
|
||||
|
||||
private fun nearestRegion(context: Context): String? {
|
||||
if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) return null
|
||||
val lm = context.getSystemService(LocationManager::class.java)
|
||||
|
||||
@@ -34,6 +34,13 @@ fun skyBrush(mode: String): Brush = when (mode) {
|
||||
else -> v(0f to 0xFF9FD3FF, 0.55f to 0xFFCFE9FF, 1f to 0xFFF1F8FF)
|
||||
}
|
||||
|
||||
/** 비·눈 오는 날 하늘. 밤에는 어두운 회청색 */
|
||||
fun precipBrush(kind: String, mode: String): Brush = when {
|
||||
mode == "night" -> v(0f to 0xFF1C2238, 0.6f to 0xFF2E3650, 1f to 0xFF434B66)
|
||||
kind == "snow" -> v(0f to 0xFFB8C4D6, 0.55f to 0xFFDFE6F0, 1f to 0xFFF4F7FB)
|
||||
else -> v(0f to 0xFF7F93AD, 0.55f to 0xFFA9B7C9, 1f to 0xFFD5DDE8)
|
||||
}
|
||||
|
||||
/** 하늘 위 글자가 흰색이어야 하는 시간대 */
|
||||
fun isDark(mode: String) = mode == "evening" || mode == "night"
|
||||
|
||||
|
||||
Reference in new issue
Block a user