feat: Wear OS 워치앱 — 웹 시안 B 디자인의 앱 다섯 장, 타일, 컴플리케이션
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6ee2893745
commit
3f806f9955
64 files changed
+1460
No files matched your search
@@ -0,0 +1,88 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.wear.compose.foundation.pager.VerticalPager
|
||||
import androidx.wear.compose.foundation.pager.rememberPagerState
|
||||
import androidx.wear.compose.material3.MaterialTheme
|
||||
import androidx.wear.compose.material3.VerticalPageIndicator
|
||||
import kotlinx.coroutines.delay
|
||||
import java.time.Instant
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private var summary by mutableStateOf<Summary?>(null)
|
||||
private var loading by mutableStateOf(true)
|
||||
|
||||
private val askLocation = registerForActivityResult(ActivityResultContracts.RequestPermission()) { load() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent { MaterialTheme { App(summary, loading) { load(force = true) } } }
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) load()
|
||||
else askLocation.launch(Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
}
|
||||
|
||||
private fun load(force: Boolean = false) {
|
||||
loading = true
|
||||
thread {
|
||||
val s = SummaryRepo.load(this, force)
|
||||
runOnUiThread { summary = s; loading = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum class Page { HERO, TOP, PICKS, SUNSET, HOURS }
|
||||
|
||||
@Composable
|
||||
private fun App(s: Summary?, loading: Boolean, onRetry: () -> Unit) {
|
||||
var now by remember { mutableStateOf(Instant.now()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
delay(20_000)
|
||||
now = Instant.now()
|
||||
}
|
||||
}
|
||||
if (s == null) {
|
||||
StatePage(loading, onRetry)
|
||||
return
|
||||
}
|
||||
// 받은 재료가 있는 장만
|
||||
val pages = buildList {
|
||||
add(Page.HERO)
|
||||
if (s.top.isNotEmpty()) add(Page.TOP)
|
||||
if (s.picks.isNotEmpty()) add(Page.PICKS)
|
||||
if (s.sunset != null) add(Page.SUNSET)
|
||||
if (s.slots.isNotEmpty()) add(Page.HOURS)
|
||||
}
|
||||
val state = rememberPagerState { pages.size }
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
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.PICKS -> GakListPage("내 각", s.picks, bgMint, medals = false, now)
|
||||
Page.SUNSET -> SunsetPage(s.sunset!!, now)
|
||||
Page.HOURS -> HoursPage(s, now)
|
||||
}
|
||||
}
|
||||
val page = pages[state.currentPage]
|
||||
val light = page == Page.SUNSET || (page == Page.HERO && isDark(s.mode))
|
||||
val dot = if (light) Color.White else Tok.ink
|
||||
VerticalPageIndicator(pagerState = state, selectedColor = dot, unselectedColor = dot.copy(alpha = 0.35f), backgroundColor = Color.Transparent)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user