feat: 워치 페이스 푸시로 앱 설치 때 날씨각 스킨 같이 적용(Wear OS 6+), 앱 첫 장을 오늘 남은 시간→주변 축제 순으로

Play 스토어 심사에 낸 1(0.1) 빌드와 같은 코드

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5.5 committed 2026-10-13 15:36:50 +09:00
1 parent ee46a101db
commit e270261e32
9 files changed
+203 -87

No files matched your search

@@ -1,27 +1,45 @@
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.PlainComplicationText
import androidx.wear.watchface.complications.data.ShortTextComplicationData
import androidx.wear.watchface.complications.data.RangedValueComplicationData
import androidx.wear.watchface.complications.datasource.ComplicationRequest
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.math.roundToInt
/** 워치 스킨 아래 칩: 글자 = 지금 기온, 제목 = 비 소식. 스킨은 제목("비 와요"·"곧 비"·"천둥 쳐요"·"눈 와요")을 보고 빗줄기·눈송이와 가운데 구름도 그린다. */
/**
* 워치 스킨 날씨 칸 + 가운데 1위. 스킨 칸이 8개까지라 한 칸에 몰아 준다.
* 값 = 날씨 코드(0 맑음·1 비·2 천둥·3 눈) × 1000 + 1위 점수, 글자 = 지금 기온, 제목 = 1위 이름(없으면 빈 글자).
*/
class RainComplicationService : SuspendingComplicationDataSourceService() {
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@RainComplicationService) } ?: return null
return data(s.tempC?.let { "${it.roundToInt()}°" } ?: "-°", s.rainLabel)
val code = when (s.rainLabel) {
"비 와요", "곧 비" -> 1
"천둥 쳐요" -> 2
"눈 와요" -> 3
else -> 0
}
val top = s.top.firstOrNull()
return data(code, top?.score ?: 0, s.tempC?.let { "${it.roundToInt()}°" } ?: "-°", top?.name ?: "")
}
override fun getPreviewData(type: ComplicationType): ComplicationData = data("20°", "비 없음")
override fun getPreviewData(type: ComplicationType): ComplicationData = data(0, 88, "20°", "산책각")
private fun data(temp: String, rain: String) = ShortTextComplicationData.Builder(
PlainComplicationText.Builder(temp).build(),
PlainComplicationText.Builder("$temp $rain").build(),
).setTitle(PlainComplicationText.Builder(rain).build()).build()
private fun data(code: Int, score: Int, temp: String, name: String): ComplicationData {
// 가운데 구슬을 누르면 앱 첫 장
val open = PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
return RangedValueComplicationData.Builder(code * 1000f + score, 0f, 3100f, PlainComplicationText.Builder("$name $score, $temp").build())
.setText(PlainComplicationText.Builder(temp).build())
.setTitle(PlainComplicationText.Builder(name).build())
.setTapAction(open)
.build()
}
}