feat: 워치에 주변 축제 표시 (앱 축제 장, 스킨 날짜 밑 한 줄)
- /v1/watch/summary 에 events 2개: 진행 중 먼저, 이름 앞 [주최] 괄호 제거, 4초 넘으면 축제만 빼고 응답 - 앱: 내 각 다음에 근처 축제 장 (이름 · 상태 · 장소와 그날 날씨) - 스킨: 날짜 밑 "🎉 주변 축제 · 이름" 한 줄 (EventComplicationService, LONG_TEXT, 행사 없으면 숨김) - 스킨 배치: 해 구슬 162→136, 해·링 묶음 24px 아래로, 기온·비 칩 y 366 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6a738ae61
commit
b4d028a91b
10 files changed
+208
-46
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import androidx.wear.watchface.complications.data.ComplicationData
|
||||
import androidx.wear.watchface.complications.data.ComplicationType
|
||||
import androidx.wear.watchface.complications.data.LongTextComplicationData
|
||||
import androidx.wear.watchface.complications.data.NoDataComplicationData
|
||||
import androidx.wear.watchface.complications.data.PlainComplicationText
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationRequest
|
||||
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/** 워치 스킨 아래 축제 한 줄: 글자 = 이름, 제목 = 상태("진행 중"·"D-3"). 서버가 진행 중인 행사를 앞에 둔다. 누르면 앱이 열린다. */
|
||||
class EventComplicationService : SuspendingComplicationDataSourceService() {
|
||||
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@EventComplicationService) } ?: return null
|
||||
// 행사가 끝나 목록이 비면 지난 줄이 남지 않게 "데이터 없음"으로 (공급원은 EMPTY 를 보낼 수 없다)
|
||||
val e = s.events.firstOrNull() ?: return NoDataComplicationData()
|
||||
return data(e.name, e.status)
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = data("불꽃축제", "진행 중")
|
||||
|
||||
private fun data(name: String, status: String): ComplicationData {
|
||||
val open = PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||
return LongTextComplicationData.Builder(PlainComplicationText.Builder(name).build(), PlainComplicationText.Builder("$name $status").build())
|
||||
.setTitle(PlainComplicationText.Builder(status).build()).setTapAction(open).build()
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private enum class Page { DETAIL, SKY, TOP, PICKS, SUNSET, HOURS }
|
||||
private enum class Page { DETAIL, SKY, TOP, PICKS, EVENTS, SUNSET, HOURS }
|
||||
|
||||
@Composable
|
||||
private fun App(s: Summary?, loading: Boolean, opened: String?, onRetry: () -> Unit) {
|
||||
@@ -72,6 +72,7 @@ private fun App(s: Summary?, loading: Boolean, opened: String?, onRetry: () -> U
|
||||
add(Page.SKY)
|
||||
if (s.top.isNotEmpty()) add(Page.TOP)
|
||||
if (s.picks.isNotEmpty()) add(Page.PICKS)
|
||||
if (s.events.isNotEmpty()) add(Page.EVENTS)
|
||||
if (s.sunset != null) add(Page.SUNSET)
|
||||
if (s.slots.isNotEmpty()) add(Page.HOURS)
|
||||
}
|
||||
@@ -83,6 +84,7 @@ private fun App(s: Summary?, loading: Boolean, opened: String?, onRetry: () -> U
|
||||
Page.SKY -> SkyPage(s, now)
|
||||
Page.TOP -> GakListPage("오늘의 각", s.top.take(3), bgButter, medals = true, now)
|
||||
Page.PICKS -> GakListPage("내 각", s.picks, bgMint, medals = false, now)
|
||||
Page.EVENTS -> EventsPage(s.events, now)
|
||||
Page.SUNSET -> SunsetPage(s.sunset!!, now)
|
||||
Page.HOURS -> HoursPage(s, now)
|
||||
}
|
||||
|
||||
@@ -335,6 +335,30 @@ private fun GakRow(g: Gak, medal: String?, open: Boolean, modifier: Modifier, on
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EventsPage(events: List<Event>, now: Instant) {
|
||||
Box(Modifier.fillMaxSize().background(bgButter)) {
|
||||
Clock(now, Tok.ink)
|
||||
Column(
|
||||
Modifier.fillMaxSize().padding(start = 22.dp, end = 22.dp, top = 34.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
T("근처 축제", 14.sp, color = Tok.ink)
|
||||
events.forEach { e ->
|
||||
Column(Modifier.fillMaxWidth().mallang().padding(start = 10.dp, end = 10.dp, top = 5.dp, bottom = 8.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
T(e.name, 13.sp, color = Tok.ink, modifier = Modifier.weight(1f), align = TextAlign.Start, maxLines = 1)
|
||||
T(e.status, 9.sp, FontFamily.Default, Color.White, Modifier.padding(start = 4.dp).background(Tok.orange, CircleShape).padding(horizontal = 5.dp),
|
||||
weight = FontWeight.ExtraBold, maxLines = 1)
|
||||
}
|
||||
T(listOfNotNull(e.place.takeIf { it.isNotBlank() }, e.fit).joinToString(" · "), 9.sp, FontFamily.Default, Tok.ink2, align = TextAlign.Start, weight = FontWeight.Bold, maxLines = 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ───────────── 4. 노을 ─────────────
|
||||
|
||||
// 웹 .b-skyline::after 의 건물 윤곽 (x%, y%)
|
||||
|
||||
@@ -22,6 +22,8 @@ data class Gak(val code: String, val name: String, val icon: String, val score:
|
||||
data class Sunset(val isToday: Boolean, val score: Int, val grade: String, val sunsetAt: Instant, val bestAt: Instant)
|
||||
data class Slot(val at: Instant, val icon: String, val tempC: Double?, val rainProb: Int?)
|
||||
data class Phase(val startAt: Instant, val kind: String)
|
||||
/** 근처 축제·행사. status 는 "진행 중", "이번 토요일", "D-12" */
|
||||
data class Event(val name: String, val place: String, val status: String, val fit: String?)
|
||||
|
||||
data class Summary(
|
||||
val regionName: String,
|
||||
@@ -39,6 +41,7 @@ data class Summary(
|
||||
val sunset: Sunset?,
|
||||
val slots: List<Slot>,
|
||||
val timeline: List<Phase>,
|
||||
val events: List<Event>,
|
||||
) {
|
||||
/** 컴플리케이션·타일에 올릴 각: 내 각 첫 번째, 없으면 오늘 1위 */
|
||||
val myGak: Gak? get() = picks.firstOrNull() ?: top.firstOrNull()
|
||||
@@ -95,6 +98,7 @@ fun parseSummary(json: String): Summary {
|
||||
},
|
||||
slots = o.list("slots") { Slot(time(it.getString("at")), it.getString("icon"), it.dbl("temp_c"), it.int("rain_prob")) },
|
||||
timeline = o.list("timeline") { Phase(time(it.getString("start_at")), it.getString("kind")) },
|
||||
events = o.list("events") { Event(it.getString("name"), it.getString("place_name"), it.getString("status_label"), it.str("fit")) },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -134,7 +138,7 @@ 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)
|
||||
Rank5ComplicationService::class.java, Rank6ComplicationService::class.java, Rank7ComplicationService::class.java, EventComplicationService::class.java)
|
||||
sources.forEach { ComplicationDataSourceUpdateRequester.create(context, ComponentName(context, it)).requestUpdateAll() }
|
||||
TileService.getUpdater(context).requestUpdate(GakTileService::class.java)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user