워치앱의 MainActivity.kt에서 Unresolved reference 'dayKey' 빌드 에러 발생
타일/메인 화면 일부 텍스트가 길어 줄임표(...)로 보이는 문제
스크롤바가 배경과 유사해 가시성이 떨어짐
하드코딩된 한글 문자열의 국제화(strings.xml) 필요
// 컴파일 에러 예시 (요약) // e: MainActivity.kt: Unresolved reference 'dayKey' // 자정 체크 로직에서 dayKey 상태가 정의되어 있지 않음
해결 과정 (How I Solved It)
dayKey 상태 추가: 자정 변경 감지를 위해 remember { mutableStateOf(...) }로 dayKey를 선언
스크롤바 색 개선: 배경색의 보색(Complementary color)로 스크롤바 트랙/썸을 그려 가시성 상승
텍스트 레이아웃 개선: 여백 조정 및 항목 분리로 줄임표 빈도 감소, 향후 Chip/버튼 폭/높이 조정 계획 반영
국제화: 화면에 보이는 주요 한글 문자열은 stringResource(...)로 대체하고 리소스로 이동(추가 정리 예정)
// 핵심 수정 예시: dayKey 상태 추가 및 자정 리셋 로직 유지 @Composable fun WearApp() { // ... 기존 상태들 ... // 일자 키(자정 교체 감지용) var dayKey by remember { mutableStateOf( java.time.ZonedDateTime.now() .format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd")) ) }
// 자정 변경 감지: 1분마다 체크하여 dayKey 달라지면 스텝/PDR 리셋 LaunchedEffect(Unit) { while (true) { val current = java.time.ZonedDateTime.now() .format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd")) if (current != dayKey) { dayKey = current // 스텝 리셋 및 PDR 리셋 passiveStepsManager.stop(); passiveStepsManager.start() pdr.reset() } kotlinx.coroutines.delay(60_000L) } } }
// 스크롤바 가시성 개선: 배경색 보색 사용 val animatedBg by animateColorAsState(targetValue = bgColor, animationSpec = tween(150)) val scrollbarColor = Color(1f - animatedBg.red, 1f - animatedBg.green, 1f - animatedBg.blue)
Canvas(modifier = Modifier .align(Alignment.CenterEnd) .padding(end = 2.dp) .height(100.dp) .width(3.dp)) { val contentHeight = scrollState.maxValue.toFloat() + size.height if (contentHeight > size.height + 1f) { val ratio = size.height / contentHeight val thumbHeight = (size.height * ratio).coerceAtLeast(12f) val scrollY = (scrollState.value / scrollState.maxValue.toFloat()).coerceIn(0f, 1f) val thumbTop = (size.height - thumbHeight) * scrollY drawRect(color = scrollbarColor.copy(alpha = 0.2f), size = size) // 트랙 drawRect(color = scrollbarColor, topLeft = Offset(0f, thumbTop), size = Size(size.width, thumbHeight)) // 썸 } }
댓글 없음:
댓글 쓰기