feat: 워치 스킨 가운데를 날씨 따라 비구름·천둥 구름·눈구름으로 — 초단기예보 낙뢰(LGT)로 2시간 안 천둥을 워치에 알림
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a74e3b49d0
commit
c0e0363759
10 files changed
+236
-37
No files matched your search
@@ -10,7 +10,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** 워치 스킨 아래 칩: 글자 = 지금 기온, 제목 = 비 소식. 스킨은 제목("비 와요"·"곧 비"·"눈 와요")을 보고 빗줄기·눈송이도 그린다. */
|
||||
/** 워치 스킨 아래 칩: 글자 = 지금 기온, 제목 = 비 소식. 스킨은 제목("비 와요"·"곧 비"·"천둥 쳐요"·"눈 와요")을 보고 빗줄기·눈송이와 가운데 구름도 그린다. */
|
||||
class RainComplicationService : SuspendingComplicationDataSourceService() {
|
||||
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
|
||||
@@ -40,6 +40,8 @@ data class Summary(
|
||||
val nowIcon: String?,
|
||||
val rainText: String?,
|
||||
val rain2h: Boolean?,
|
||||
/** 2시간 안에 낙뢰 예보 */
|
||||
val thunder: Boolean?,
|
||||
val warning: String?,
|
||||
val top: List<Gak>,
|
||||
val picks: List<Gak>,
|
||||
@@ -51,16 +53,17 @@ data class Summary(
|
||||
/** 컴플리케이션·타일에 올릴 각: 내 각 첫 번째, 없으면 오늘 1위 */
|
||||
val myGak: Gak? get() = picks.firstOrNull() ?: top.firstOrNull()
|
||||
|
||||
/** 비·눈 화면: "rain" | "snow" | null. 지금 칸이 눈이면 눈, 지금 칸이 비거나 2시간 안에 비 소식이면 비 */
|
||||
/** 비·눈: "rain" | "snow" | null. 지금 칸이 눈이면 눈, 지금 칸이 비거나 2시간 안에 비 소식이면 비 */
|
||||
val precip: String? get() = when {
|
||||
nowIcon == "snow" -> "snow"
|
||||
nowIcon == "rain" || rain2h == true -> "rain"
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** 스킨 칩의 비 소식. 비·눈 화면과 어긋나지 않게 precip 을 따른다 */
|
||||
/** 스킨 칩의 비 소식. 스킨은 이 글자를 보고 가운데를 비구름·천둥 구름·눈구름으로 바꾼다 */
|
||||
val rainLabel: String get() = when {
|
||||
precip == "snow" -> "눈 와요"
|
||||
thunder == true -> "천둥 쳐요"
|
||||
nowIcon == "rain" -> "비 와요"
|
||||
precip == "rain" -> "곧 비"
|
||||
rain2h == false -> "비 없음"
|
||||
@@ -95,6 +98,7 @@ fun parseSummary(json: String): Summary {
|
||||
nowIcon = now?.str("icon"),
|
||||
rainText = now?.str("text"),
|
||||
rain2h = now?.takeIf { it.has("rain_2h") }?.getBoolean("rain_2h"),
|
||||
thunder = now?.takeIf { it.has("thunder") }?.getBoolean("thunder"),
|
||||
warning = o.str("warning"),
|
||||
top = o.list("top", ::gak),
|
||||
picks = o.list("picks", ::gak),
|
||||
@@ -117,9 +121,9 @@ object SummaryRepo {
|
||||
|
||||
/** 캐시가 refresh_at 전이면 캐시, 아니면 새로 받는다. 받기 실패하면 지난 캐시라도. 네트워크를 쓰니 메인 스레드에서 부르지 않는다. */
|
||||
fun load(context: Context, force: Boolean = false): Summary? = fetch(context, force)?.let { s ->
|
||||
// 디버그 빌드 확인용: shared_prefs/debug.xml 의 precip(rain|snow)로 비·눈 화면을 강제로 띄운다
|
||||
// 디버그 빌드 확인용: shared_prefs/debug.xml 의 precip(rain|snow|thunder)로 스킨의 비·눈·천둥을 강제로 띄운다
|
||||
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")
|
||||
if (forced == null) s else s.copy(nowIcon = if (forced == "thunder") "rain" else forced, rain2h = forced != "snow", thunder = forced == "thunder")
|
||||
}
|
||||
|
||||
private fun fetch(context: Context, force: Boolean): Summary? {
|
||||
|
||||
Reference in new issue
Block a user