diff --git a/core/ui/src/main/res/drawable/core_ui_bell.xml b/core/ui/src/main/res/drawable/core_ui_bell.xml index f42399699a..935cc6c747 100644 --- a/core/ui/src/main/res/drawable/core_ui_bell.xml +++ b/core/ui/src/main/res/drawable/core_ui_bell.xml @@ -1,24 +1,22 @@ - + + android:viewportWidth="18" + android:viewportHeight="18"> - + + android:strokeLineCap="round" + android:strokeLineJoin="round" + android:fillColor="#00000000"/> diff --git a/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxContent.kt b/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxContent.kt new file mode 100644 index 0000000000..7dc2b3f116 --- /dev/null +++ b/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxContent.kt @@ -0,0 +1,164 @@ +package com.afternote.feature.home.presentation.notification + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.unit.dp +import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.compose.LifecycleEventEffect +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.afternote.core.domain.repository.notification.NotificationInboxItem +import com.afternote.core.ui.modifierextention.bottomBorder +import com.afternote.core.ui.theme.AfternoteDesign +import com.afternote.core.ui.topbar.DetailTopBar +import com.afternote.feature.home.presentation.R + +/** 알림함 화면의 상태 없는 본문 — Figma 「알람창」 (#2321). ViewModel 은 [NotificationInboxScreen] 이 든다. */ +@Composable +internal fun NotificationInboxContent( + uiState: NotificationInboxUiState, + onBack: () -> Unit, + onRetry: () -> Unit, + onItemClick: (NotificationInboxItem) -> Unit, +) { + Scaffold( + topBar = { DetailTopBar(title = stringResource(R.string.home_notification_inbox_title), onBackClick = onBack) }, + containerColor = Color.Transparent, + ) { padding -> + Box(modifier = Modifier.fillMaxSize().padding(padding)) { + when { + uiState.isLoading -> { + CircularProgressIndicator( + color = AfternoteDesign.colors.gray9, + modifier = Modifier.align(Alignment.Center), + ) + } + + uiState.loadFailed -> { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource(R.string.home_notification_inbox_load_failed), + style = AfternoteDesign.typography.bodySmallR, + color = AfternoteDesign.colors.gray7, + ) + Spacer(Modifier.height(16.dp)) + TextButton(onClick = onRetry) { + Text( + text = stringResource(R.string.home_tab_retry), + style = AfternoteDesign.typography.captionLargeB, + color = AfternoteDesign.colors.gray9, + ) + } + } + } + + uiState.items.isEmpty() -> { + Text( + text = stringResource(R.string.home_notification_inbox_empty), + style = AfternoteDesign.typography.bodyBase, + color = AfternoteDesign.colors.gray5, + modifier = Modifier.align(Alignment.Center), + ) + } + + else -> { + LazyColumn(modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp)) { + items(uiState.items, key = NotificationInboxItem::id) { item -> + NotificationInboxRow(item = item, onClick = { onItemClick(item) }) + } + } + } + } + } + } +} + +/** + * 알림함 한 줄 — Figma 「알람창」 의 alarm_1~4·alarm_check (#2321). + * + * 읽은 알림은 아이콘·제목·본문을 모두 gray5 로 낮춘다(alarm_check). 날짜 줄은 서버 알림함 응답에 시각이 + * 없어 아직 그리지 않는다. + */ +@Composable +private fun NotificationInboxRow( + item: NotificationInboxItem, + onClick: () -> Unit, +) { + val readColor = AfternoteDesign.colors.gray5 + Row( + modifier = + Modifier + .fillMaxWidth() + .clickable(role = Role.Button, onClick = onClick) + .bottomBorder(color = AfternoteDesign.colors.gray3, width = 1.dp) + .padding(horizontal = 20.dp, vertical = 12.dp), + horizontalArrangement = Arrangement.spacedBy(20.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Image( + painter = painterResource(item.iconRes()), + contentDescription = null, + colorFilter = if (item.isRead) ColorFilter.tint(readColor) else null, + modifier = Modifier.size(24.dp), + ) + Column(modifier = Modifier.weight(1f)) { + Text( + text = item.title, + style = AfternoteDesign.typography.captionLargeR, + color = if (item.isRead) readColor else AfternoteDesign.colors.gray9, + ) + Text( + text = item.body, + style = AfternoteDesign.typography.captionLargeR, + color = if (item.isRead) readColor else AfternoteDesign.colors.gray6, + ) + } + } +} + +/** 알림이 가리키는 곳으로 아이콘을 고른다. 기록·질문은 책, 편지·수신인은 편지, 설정을 권하면 연필, 확인이 필요하면 느낌표. */ +@DrawableRes +private fun NotificationInboxItem.iconRes(): Int = + when (data["destination"]) { + "TIME_LETTER_LIST", "TIME_LETTER_DETAIL", "TIME_LETTER_COMPOSE", + "RECEIVER_LIST", "RECEIVER_DETAIL", "INVITATION_DETAIL", "INVITATION", "RECEIVER_HOME", + -> R.drawable.home_ic_notification_letter + + "AGENT_SETTINGS" -> R.drawable.home_ic_notification_setting + + "RETENTION_CONFIRMATION", "AGENT_CONFIRMATION" -> R.drawable.home_ic_notification_alert + + else -> R.drawable.home_ic_notification_record + } diff --git a/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxScreen.kt b/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxScreen.kt index 1ad6951590..3eab608660 100644 --- a/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxScreen.kt +++ b/feature/home/presentation/src/main/kotlin/com/afternote/feature/home/presentation/notification/NotificationInboxScreen.kt @@ -1,6 +1,7 @@ package com.afternote.feature.home.presentation.notification -import androidx.compose.foundation.background +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -14,7 +15,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Scaffold import androidx.compose.material3.Text @@ -27,9 +27,10 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.Lifecycle @@ -69,108 +70,6 @@ fun NotificationInboxScreen( ) } -@Composable -internal fun NotificationInboxContent( - uiState: NotificationInboxUiState, - onBack: () -> Unit, - onRetry: () -> Unit, - onItemClick: (NotificationInboxItem) -> Unit, -) { - Scaffold( - topBar = { DetailTopBar(title = stringResource(R.string.home_notification_inbox_title), onBackClick = onBack) }, - containerColor = Color.Transparent, - ) { padding -> - Box(modifier = Modifier.fillMaxSize().padding(padding)) { - when { - uiState.isLoading -> { - CircularProgressIndicator( - color = AfternoteDesign.colors.gray9, - modifier = Modifier.align(Alignment.Center), - ) - } - - uiState.loadFailed -> { - Column( - modifier = Modifier.align(Alignment.Center), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - Text( - text = stringResource(R.string.home_notification_inbox_load_failed), - style = AfternoteDesign.typography.bodySmallR, - color = AfternoteDesign.colors.gray7, - ) - Spacer(Modifier.height(16.dp)) - TextButton(onClick = onRetry) { - Text( - text = stringResource(R.string.home_tab_retry), - style = AfternoteDesign.typography.captionLargeB, - color = AfternoteDesign.colors.gray9, - ) - } - } - } - - uiState.items.isEmpty() -> { - Text( - text = stringResource(R.string.home_notification_inbox_empty), - style = AfternoteDesign.typography.bodyBase, - color = AfternoteDesign.colors.gray5, - modifier = Modifier.align(Alignment.Center), - ) - } - - else -> { - LazyColumn(modifier = Modifier.fillMaxSize()) { - items(uiState.items, key = NotificationInboxItem::id) { item -> - NotificationInboxRow(item = item, onClick = { onItemClick(item) }) - } - } - } - } - } - } -} - -@Composable -private fun NotificationInboxRow( - item: NotificationInboxItem, - onClick: () -> Unit, -) { - Row( - modifier = - Modifier - .fillMaxWidth() - .clickable(role = Role.Button, onClick = onClick) - .bottomBorder(color = AfternoteDesign.colors.gray3, width = 1.dp) - .padding(horizontal = 20.dp, vertical = 16.dp), - horizontalArrangement = Arrangement.spacedBy(10.dp), - ) { - // 읽지 않은 알림 표시. 읽은 줄도 자리를 비워 두어 글 줄이 흔들리지 않게 한다. - Box( - modifier = - Modifier - .padding(top = 7.dp) - .size(6.dp) - .background(if (item.isRead) Color.Transparent else AfternoteDesign.colors.error, CircleShape), - ) - Column(modifier = Modifier.weight(1f)) { - Text( - text = item.title, - style = if (item.isRead) AfternoteDesign.typography.bodyBase else AfternoteDesign.typography.bodyLargeB, - color = if (item.isRead) AfternoteDesign.colors.gray6 else AfternoteDesign.colors.gray9, - ) - Spacer(Modifier.height(4.dp)) - Text( - text = item.body, - style = AfternoteDesign.typography.captionLargeR, - color = AfternoteDesign.colors.gray6, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - } - } -} - /** * 홈 탑바 알림 점. 화면이 보일 때마다(처음 포함) 다시 센다 — 알림함에서 읽고 돌아오거나 푸시를 받은 뒤 * 홈으로 돌아오면 점이 맞춰진다. diff --git a/feature/home/presentation/src/main/res/drawable/home_ic_notification_alert.xml b/feature/home/presentation/src/main/res/drawable/home_ic_notification_alert.xml new file mode 100644 index 0000000000..bdb31a8db4 --- /dev/null +++ b/feature/home/presentation/src/main/res/drawable/home_ic_notification_alert.xml @@ -0,0 +1,29 @@ + + + + + + + diff --git a/feature/home/presentation/src/main/res/drawable/home_ic_notification_letter.xml b/feature/home/presentation/src/main/res/drawable/home_ic_notification_letter.xml new file mode 100644 index 0000000000..d34e52179e --- /dev/null +++ b/feature/home/presentation/src/main/res/drawable/home_ic_notification_letter.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/feature/home/presentation/src/main/res/drawable/home_ic_notification_record.xml b/feature/home/presentation/src/main/res/drawable/home_ic_notification_record.xml new file mode 100644 index 0000000000..e47f9cabbc --- /dev/null +++ b/feature/home/presentation/src/main/res/drawable/home_ic_notification_record.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/feature/home/presentation/src/main/res/drawable/home_ic_notification_setting.xml b/feature/home/presentation/src/main/res/drawable/home_ic_notification_setting.xml new file mode 100644 index 0000000000..3423e34382 --- /dev/null +++ b/feature/home/presentation/src/main/res/drawable/home_ic_notification_setting.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/feature/home/presentation/src/main/res/values/strings.xml b/feature/home/presentation/src/main/res/values/strings.xml index 3d6c74a2bc..72eb4cd381 100644 --- a/feature/home/presentation/src/main/res/values/strings.xml +++ b/feature/home/presentation/src/main/res/values/strings.xml @@ -50,7 +50,7 @@ %1$s개 의 애프터노트가 있습니다. - 알림 + 알람 아직 받은 알림이 없어요 알림을 불러오지 못했어요. 알림이 꺼져 있어 기록 알림과 전달 소식을 받을 수 없어요 diff --git a/feature/home/presentation/src/screenshotTest/kotlin/com/afternote/feature/home/presentation/NotificationInboxScreenshotTest.kt b/feature/home/presentation/src/screenshotTest/kotlin/com/afternote/feature/home/presentation/NotificationInboxScreenshotTest.kt new file mode 100644 index 0000000000..af184d8851 --- /dev/null +++ b/feature/home/presentation/src/screenshotTest/kotlin/com/afternote/feature/home/presentation/NotificationInboxScreenshotTest.kt @@ -0,0 +1,57 @@ +package com.afternote.feature.home.presentation + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview +import com.afternote.core.domain.repository.notification.NotificationInboxItem +import com.afternote.core.ui.theme.AfternoteTheme +import com.afternote.feature.home.presentation.notification.NotificationInboxContent +import com.afternote.feature.home.presentation.notification.NotificationInboxUiState +import com.android.tools.screenshot.PreviewTest + +/** Figma 「알람창」 — 알림 종류별 아이콘과 읽은 알림(alarm_check) (#2321). */ +@PreviewTest +@Preview(showBackground = true) +@Composable +internal fun notificationInboxScreenshot() { + AfternoteTheme { + NotificationInboxContent( + uiState = + NotificationInboxUiState( + isLoading = false, + items = + listOf( + item(1, "오늘의 질문이 도착했어요", "오늘의 질문에 답하고 마음을 기록해 볼까요?", "DAILY_QUESTION"), + item(2, "편지 전달까지 7일 남았어요", "김민지님께 예약하신 편지가 곧 전달돼요.", "TIME_LETTER_DETAIL"), + item(3, "대리인을 아직 지정하지 않으셨어요", "소중한 기록을 안전하게 관리할 수 있도록 대리인을 지정해 주세요.", "AGENT_SETTINGS"), + item(4, "보관 확인 절차가 진행 중이에요", "대리인의 확인 요청이 접수됐어요.\n앱에서 진행 상태를 확인하고 절차를 취소할 수 있어요.", "RETENTION_CONFIRMATION"), + item(5, "오늘의 질문이 도착했어요", "오늘의 질문에 답하고 마음을 기록해 볼까요?", "DAILY_QUESTION", isRead = true), + ), + ), + onBack = {}, + onRetry = {}, + onItemClick = {}, + ) + } +} + +@PreviewTest +@Preview(showBackground = true) +@Composable +internal fun notificationInboxEmptyScreenshot() { + AfternoteTheme { + NotificationInboxContent( + uiState = NotificationInboxUiState(isLoading = false), + onBack = {}, + onRetry = {}, + onItemClick = {}, + ) + } +} + +private fun item( + id: Long, + title: String, + body: String, + destination: String, + isRead: Boolean = false, +) = NotificationInboxItem(id, title, body, mapOf("destination" to destination), isRead) diff --git a/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxEmptyScreenshot_748aa731_0.png b/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxEmptyScreenshot_748aa731_0.png new file mode 100644 index 0000000000..e3238780f4 Binary files /dev/null and b/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxEmptyScreenshot_748aa731_0.png differ diff --git a/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxScreenshot_748aa731_0.png b/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxScreenshot_748aa731_0.png new file mode 100644 index 0000000000..405766c7b7 Binary files /dev/null and b/feature/home/presentation/src/screenshotTestDebug/reference/com/afternote/feature/home/presentation/NotificationInboxScreenshotTestKt/notificationInboxScreenshot_748aa731_0.png differ diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingLocalNavActions.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingLocalNavActions.kt index 3d6f168b6b..7438b3c229 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingLocalNavActions.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingLocalNavActions.kt @@ -49,10 +49,6 @@ internal class SettingLocalNavActions( backStack.add(SettingRoute.PushNotificationRoute) } - override fun onNotificationPreferenceClick() { - backStack.add(SettingRoute.NotificationPreferenceRoute) - } - override fun onDelegateClick() { backStack.add(SettingRoute.DelegateRoute) } diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavActions.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavActions.kt index c82dd779a1..814cf63948 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavActions.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavActions.kt @@ -28,8 +28,6 @@ internal interface SettingNavActions { fun onPushNotificationClick() - fun onNotificationPreferenceClick() - fun onDelegateClick() fun onAnniversaryClick() diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavHost.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavHost.kt index e498866f0d..9a5bd75286 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavHost.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingNavHost.kt @@ -30,7 +30,6 @@ import com.afternote.feature.setting.presentation.notification.NotificationSetti import com.afternote.feature.setting.presentation.notification.PushNotificationScreen import com.afternote.feature.setting.presentation.notification.anniversary.AnniversaryScreen import com.afternote.feature.setting.presentation.notification.delegate.DelegateScreen -import com.afternote.feature.setting.presentation.notification.preference.NotificationPreferenceScreen import com.afternote.feature.setting.presentation.passkey.PassKeyListIntent import com.afternote.feature.setting.presentation.passkey.PassKeyListScreen import com.afternote.feature.setting.presentation.passkey.PassKeyListViewModel @@ -162,16 +161,11 @@ public fun SettingNavHost( NotificationSettingScreen( onBack = actions::popBack, onPushNotificationClick = actions::onPushNotificationClick, - onNotificationPreferenceClick = actions::onNotificationPreferenceClick, onDelegateClick = actions::onDelegateClick, onAnniversaryClick = actions::onAnniversaryClick, ) } - entry { - NotificationPreferenceScreen(onBack = actions::popBack) - } - entry { DelegateScreen(onBack = actions::popBack) } diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingRoute.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingRoute.kt index 06accc10d0..6879190741 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingRoute.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/navigation/SettingRoute.kt @@ -43,10 +43,6 @@ internal sealed interface SettingRoute : NavKey { @Serializable data object PushNotificationRoute : SettingRoute - /** 기록 알림 시각·요일·주간 목표 (#2321). */ - @Serializable - data object NotificationPreferenceRoute : SettingRoute - /** 오래 접속하지 않을 때 연락받을 대리인 (#2321). */ @Serializable data object DelegateRoute : SettingRoute diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingScreen.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingScreen.kt index 8c049d5ae5..f231f22d9b 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingScreen.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingScreen.kt @@ -52,7 +52,6 @@ import kotlinx.coroutines.launch internal fun NotificationSettingScreen( onBack: () -> Unit, onPushNotificationClick: () -> Unit, - onNotificationPreferenceClick: () -> Unit, onDelegateClick: () -> Unit, onAnniversaryClick: () -> Unit, viewModel: PushNotificationViewModel = hiltViewModel(), @@ -114,7 +113,6 @@ internal fun NotificationSettingScreen( snackbarHostState = snackbarHostState, onBack = onBack, onPushNotificationClick = onPushNotificationClick, - onNotificationPreferenceClick = onNotificationPreferenceClick, onDelegateClick = onDelegateClick, onAnniversaryClick = onAnniversaryClick, onDeviceAlarmClick = { @@ -145,7 +143,6 @@ private fun NotificationSettingContent( snackbarHostState: SnackbarHostState, onBack: () -> Unit, onPushNotificationClick: () -> Unit, - onNotificationPreferenceClick: () -> Unit, onDelegateClick: () -> Unit, onAnniversaryClick: () -> Unit, onDeviceAlarmClick: () -> Unit, @@ -206,12 +203,7 @@ private fun NotificationSettingContent( onPushCheck = { onMarketingConsentChange(MarketingConsent.PUSH, it) }, ) } - // 서버 알림 설정(#2321)은 기기 알림이 꺼져 있어도 고칠 수 있다 — 대리인·기념일은 푸시가 아니어도 - // 알림함과 알림톡으로 쓰인다. - SettingMenuItem( - label = stringResource(R.string.setting_notification_preference_menu), - onClick = onNotificationPreferenceClick, - ) + // 대리인·기념일(#2321)은 기기 알림이 꺼져 있어도 고칠 수 있다 — 푸시가 아니어도 알림함과 알림톡으로 쓰인다. SettingMenuItem( label = stringResource(R.string.setting_delegate_menu), onClick = onDelegateClick, diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationContent.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationContent.kt index d2fdd7c93e..8cb00064fa 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationContent.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationContent.kt @@ -37,6 +37,8 @@ internal fun PushNotificationContent( onMindRecordToggle: (Boolean) -> Unit, onAfternoteToggle: (Boolean) -> Unit, onRetry: () -> Unit, + // 알림 시간 설정(#2321). null 이면 그 구역을 그리지 않는다. + timeSection: (@Composable () -> Unit)? = null, ) { Scaffold( topBar = { @@ -83,6 +85,10 @@ internal fun PushNotificationContent( style = AfternoteDesign.typography.captionLargeR, color = AfternoteDesign.colors.gray5, ) + if (timeSection != null) { + Spacer(Modifier.height(32.dp)) + timeSection() + } } } } diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreen.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreen.kt index 87333a6a64..3ef0cd3e80 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreen.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreen.kt @@ -1,20 +1,37 @@ package com.afternote.feature.setting.presentation.notification +import android.widget.Toast import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.ui.platform.LocalContext import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.LifecycleEventEffect import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.afternote.core.ui.asString +import com.afternote.core.ui.mvi.ObserveSignal import com.afternote.core.ui.popup.NetworkErrorPopup import com.afternote.core.ui.popup.ServerErrorPopup +import com.afternote.feature.setting.presentation.notification.preference.NotificationPreferenceIntent +import com.afternote.feature.setting.presentation.notification.preference.NotificationPreferenceViewModel +import com.afternote.feature.setting.presentation.notification.preference.NotificationTimeSection @Composable internal fun PushNotificationScreen( onBack: () -> Unit, viewModel: PushNotificationViewModel = hiltViewModel(), + timeViewModel: NotificationPreferenceViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() + val timeState by timeViewModel.uiState.collectAsStateWithLifecycle() + val context = LocalContext.current + // 시각 저장 실패는 고른 값을 되돌리고 짧게 알린다. 이 화면에는 스낵바 자리가 없다. + val timeError = timeState.errorMessage?.asString() + ObserveSignal( + signal = timeError, + consumed = NotificationPreferenceIntent.ConsumeError, + onIntent = timeViewModel::onIntent, + ) { message -> Toast.makeText(context, message, Toast.LENGTH_SHORT).show() } LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { viewModel.onIntent(PushNotificationIntent.RefreshOnReturn) } PushNotificationContent( @@ -24,6 +41,7 @@ internal fun PushNotificationScreen( onNewsletterToggle = { viewModel.onIntent(PushNotificationIntent.TogglePushSetting(PushSetting.NEWSLETTER, it)) }, onMindRecordToggle = { viewModel.onIntent(PushNotificationIntent.TogglePushSetting(PushSetting.MIND_RECORD, it)) }, onAfternoteToggle = { viewModel.onIntent(PushNotificationIntent.TogglePushSetting(PushSetting.AFTERNOTE, it)) }, + timeSection = { NotificationTimeSection(uiState = timeState, onIntent = timeViewModel::onIntent) }, ) when (uiState.saveFailure) { diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceContract.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceContract.kt index 9c4946f40b..6707e09c96 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceContract.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceContract.kt @@ -5,46 +5,27 @@ import com.afternote.core.ui.mvi.MviIntent import com.afternote.core.ui.mvi.ReducerEvent import com.afternote.core.ui.mvi.UiState import com.afternote.feature.setting.domain.NotificationPreferences -import java.time.DayOfWeek import java.time.LocalTime internal sealed interface NotificationPreferenceIntent : MviIntent { data object Retry : NotificationPreferenceIntent - data class ChangeEnabled( - val enabled: Boolean, - ) : NotificationPreferenceIntent - data class ChangeTime( val time: LocalTime, ) : NotificationPreferenceIntent - data class ToggleWeekday( - val day: DayOfWeek, - ) : NotificationPreferenceIntent - - data class ChangeWeeklyGoal( - val goal: Int, - ) : NotificationPreferenceIntent - - data object Save : NotificationPreferenceIntent - - data object ConsumeSaved : NotificationPreferenceIntent - data object ConsumeError : NotificationPreferenceIntent } /** - * @property form 편집 중인 값. 불러오기 전에는 null 이다 — 기본값을 채워 두면 서버 값을 받기 전에 - * 「18:00」 이 사용자의 설정처럼 보인다. - * @property isSaved 저장 성공 신호. 화면이 한 번 안내하고 소비한다. + * @property preferences 서버 설정. 불러오기 전에는 null 이다 — 기본값을 채워 두면 서버 값을 받기 전에 + * 그 시각이 사용자의 설정처럼 보인다. */ internal data class NotificationPreferenceUiState( val isLoading: Boolean = true, val loadFailed: Boolean = false, - val form: NotificationPreferences? = null, + val preferences: NotificationPreferences? = null, val isSaving: Boolean = false, - val isSaved: Boolean = false, val errorMessage: UiText? = null, ) : UiState @@ -57,21 +38,19 @@ internal sealed interface NotificationPreferenceReducerEvent : ReducerEvent { data object LoadFailed : NotificationPreferenceReducerEvent - data class Edited( - val form: NotificationPreferences, + /** 고른 시각을 먼저 그린다. 저장이 실패하면 [Failed] 가 [previous] 로 되돌린다. */ + data class Saving( + val preferences: NotificationPreferences, ) : NotificationPreferenceReducerEvent - data object Saving : NotificationPreferenceReducerEvent - data class Saved( val preferences: NotificationPreferences, ) : NotificationPreferenceReducerEvent data class Failed( + val previous: NotificationPreferences, val message: UiText, ) : NotificationPreferenceReducerEvent - data object SavedConsumed : NotificationPreferenceReducerEvent - data object ErrorConsumed : NotificationPreferenceReducerEvent } diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceScreen.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceScreen.kt deleted file mode 100644 index ef1c244c69..0000000000 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceScreen.kt +++ /dev/null @@ -1,342 +0,0 @@ -package com.afternote.feature.setting.presentation.notification.preference - -import androidx.compose.foundation.border -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.TimePicker -import androidx.compose.material3.rememberTimePickerState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.Role -import androidx.compose.ui.semantics.selected -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.unit.dp -import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.afternote.core.ui.asString -import com.afternote.core.ui.button.AfternoteButton -import com.afternote.core.ui.mvi.ObserveFlag -import com.afternote.core.ui.mvi.ObserveSignal -import com.afternote.core.ui.theme.AfternoteDesign -import com.afternote.core.ui.topbar.DetailTopBar -import com.afternote.feature.setting.domain.NotificationPreferences -import com.afternote.feature.setting.presentation.R -import com.afternote.feature.setting.presentation.notification.component.LabeledSwitchRow -import com.afternote.feature.setting.presentation.shared.component.SettingLoadErrorContent -import kotlinx.coroutines.launch -import java.time.DayOfWeek -import java.time.LocalTime -import java.time.format.DateTimeFormatter -import java.time.format.TextStyle -import java.util.Locale - -@Composable -internal fun NotificationPreferenceScreen( - onBack: () -> Unit, - viewModel: NotificationPreferenceViewModel = hiltViewModel(), -) { - val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val snackbarHostState = remember { SnackbarHostState() } - val snackbarScope = rememberCoroutineScope() - val savedMessage = stringResource(R.string.setting_notification_preference_saved) - - ObserveFlag( - raised = uiState.isSaved, - consumed = NotificationPreferenceIntent.ConsumeSaved, - onIntent = viewModel::onIntent, - ) { - snackbarScope.launch { snackbarHostState.showSnackbar(savedMessage) } - } - val errorMessage = uiState.errorMessage?.asString() - ObserveSignal( - signal = errorMessage, - consumed = NotificationPreferenceIntent.ConsumeError, - onIntent = viewModel::onIntent, - ) { message -> - snackbarScope.launch { snackbarHostState.showSnackbar(message) } - } - - NotificationPreferenceContent( - uiState = uiState, - snackbarHostState = snackbarHostState, - onBack = onBack, - onIntent = viewModel::onIntent, - ) -} - -@Composable -internal fun NotificationPreferenceContent( - uiState: NotificationPreferenceUiState, - snackbarHostState: SnackbarHostState, - onBack: () -> Unit, - onIntent: (NotificationPreferenceIntent) -> Unit, -) { - Scaffold( - topBar = { - DetailTopBar( - title = stringResource(R.string.setting_notification_preference_title), - onBackClick = onBack, - ) - }, - snackbarHost = { SnackbarHost(snackbarHostState) }, - containerColor = Color.Transparent, - ) { padding -> - val form = uiState.form - when { - form != null -> { - PreferenceForm( - form = form, - isSaving = uiState.isSaving, - onIntent = onIntent, - modifier = Modifier.padding(padding), - ) - } - - uiState.loadFailed -> { - SettingLoadErrorContent( - message = stringResource(R.string.setting_notification_preference_load_failed), - onRetry = { onIntent(NotificationPreferenceIntent.Retry) }, - modifier = Modifier.padding(padding), - ) - } - - else -> { - Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) { - CircularProgressIndicator(color = AfternoteDesign.colors.gray9) - } - } - } - } -} - -@Composable -private fun PreferenceForm( - form: NotificationPreferences, - isSaving: Boolean, - onIntent: (NotificationPreferenceIntent) -> Unit, - modifier: Modifier = Modifier, -) { - var isPickingTime by rememberSaveable { mutableStateOf(false) } - Column( - modifier = - modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()) - .padding(horizontal = 20.dp, vertical = 16.dp), - ) { - LabeledSwitchRow( - label = stringResource(R.string.setting_notification_preference_enabled), - checked = form.enabled, - onCheckedChange = { onIntent(NotificationPreferenceIntent.ChangeEnabled(it)) }, - enabled = !isSaving, - ) - Text( - text = stringResource(R.string.setting_notification_preference_description), - style = AfternoteDesign.typography.captionLargeR, - color = AfternoteDesign.colors.gray6, - ) - - SectionLabel(stringResource(R.string.setting_notification_preference_time)) - Row( - modifier = - Modifier - .fillMaxWidth() - .clickable(enabled = form.enabled && !isSaving, role = Role.Button) { isPickingTime = true } - .padding(vertical = 12.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = form.time.toDisplayText(), - style = AfternoteDesign.typography.bodyLargeB, - color = if (form.enabled) AfternoteDesign.colors.gray9 else AfternoteDesign.colors.gray5, - modifier = Modifier.weight(1f), - ) - Text( - text = stringResource(R.string.setting_notification_preference_change), - style = AfternoteDesign.typography.captionLargeR, - color = AfternoteDesign.colors.gray6, - ) - } - - SectionLabel(stringResource(R.string.setting_notification_preference_weekdays)) - Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) { - DayOfWeek.entries.forEach { day -> - WeekdayChip( - day = day, - selected = day in form.weekdays, - enabled = form.enabled && !isSaving, - onClick = { onIntent(NotificationPreferenceIntent.ToggleWeekday(day)) }, - ) - } - } - - SectionLabel(stringResource(R.string.setting_notification_preference_goal)) - Row(verticalAlignment = Alignment.CenterVertically) { - StepButton( - text = "−", - enabled = !isSaving && form.weeklyGoal > 1, - onClick = { onIntent(NotificationPreferenceIntent.ChangeWeeklyGoal(form.weeklyGoal - 1)) }, - ) - Text( - text = stringResource(R.string.setting_notification_preference_goal_value, form.weeklyGoal), - style = AfternoteDesign.typography.bodyLargeB, - color = AfternoteDesign.colors.gray9, - modifier = Modifier.padding(horizontal = 16.dp), - ) - StepButton( - text = "+", - enabled = !isSaving && form.weeklyGoal < 7, - onClick = { onIntent(NotificationPreferenceIntent.ChangeWeeklyGoal(form.weeklyGoal + 1)) }, - ) - } - Text( - text = stringResource(R.string.setting_notification_preference_goal_description), - style = AfternoteDesign.typography.captionLargeR, - color = AfternoteDesign.colors.gray6, - modifier = Modifier.padding(top = 8.dp), - ) - - Spacer(Modifier.height(32.dp)) - AfternoteButton( - text = stringResource(R.string.setting_notification_preference_save), - onClick = { onIntent(NotificationPreferenceIntent.Save) }, - isLoading = isSaving, - modifier = Modifier.fillMaxWidth(), - ) - } - - if (isPickingTime) { - TimePickerDialog( - initial = form.time, - onConfirm = { time -> - isPickingTime = false - onIntent(NotificationPreferenceIntent.ChangeTime(time)) - }, - onDismiss = { isPickingTime = false }, - ) - } -} - -@Composable -private fun SectionLabel(text: String) { - Text( - text = text, - style = AfternoteDesign.typography.captionLargeR, - color = AfternoteDesign.colors.gray6, - modifier = Modifier.padding(top = 24.dp, bottom = 8.dp), - ) -} - -@Composable -private fun WeekdayChip( - day: DayOfWeek, - selected: Boolean, - enabled: Boolean, - onClick: () -> Unit, -) { - val label = day.getDisplayName(TextStyle.NARROW, Locale.KOREAN) - Box( - modifier = - Modifier - .size(40.dp) - .border( - width = 1.dp, - color = if (selected) AfternoteDesign.colors.gray9 else AfternoteDesign.colors.gray3, - shape = CircleShape, - ).clickable(enabled = enabled, role = Role.Checkbox, onClick = onClick) - .semantics { this.selected = selected }, - contentAlignment = Alignment.Center, - ) { - Text( - text = label, - style = AfternoteDesign.typography.bodyBase, - color = - when { - !enabled -> AfternoteDesign.colors.gray5 - selected -> AfternoteDesign.colors.gray9 - else -> AfternoteDesign.colors.gray6 - }, - ) - } -} - -@Composable -private fun StepButton( - text: String, - enabled: Boolean, - onClick: () -> Unit, -) { - Box( - modifier = - Modifier - .size(36.dp) - .border(1.dp, AfternoteDesign.colors.gray3, CircleShape) - .clickable(enabled = enabled, role = Role.Button, onClick = onClick), - contentAlignment = Alignment.Center, - ) { - Text( - text = text, - style = AfternoteDesign.typography.bodyLargeB, - color = if (enabled) AfternoteDesign.colors.gray9 else AfternoteDesign.colors.gray5, - ) - } -} - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -private fun TimePickerDialog( - initial: LocalTime, - onConfirm: (LocalTime) -> Unit, - onDismiss: () -> Unit, -) { - val state = rememberTimePickerState(initialHour = initial.hour, initialMinute = initial.minute, is24Hour = false) - AlertDialog( - onDismissRequest = onDismiss, - confirmButton = { - TextButton(onClick = { onConfirm(LocalTime.of(state.hour, state.minute)) }) { - Text(stringResource(R.string.setting_notification_preference_confirm), color = AfternoteDesign.colors.gray9) - } - }, - dismissButton = { - TextButton(onClick = onDismiss) { - Text(stringResource(R.string.setting_notification_preference_cancel), color = AfternoteDesign.colors.gray6) - } - }, - text = { TimePicker(state = state) }, - containerColor = AfternoteDesign.colors.white, - ) -} - -/** 「오후 6:00」 처럼 보여 준다. 서버 계약은 24시간 `HH:mm` 이고 표시만 바꾼다. */ -private fun LocalTime.toDisplayText(): String = format(DISPLAY_TIME) - -private val DISPLAY_TIME: DateTimeFormatter = DateTimeFormatter.ofPattern("a h:mm", Locale.KOREAN) diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceViewModel.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceViewModel.kt index dc55886dd5..6918d609d4 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceViewModel.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationPreferenceViewModel.kt @@ -1,21 +1,19 @@ package com.afternote.feature.setting.presentation.notification.preference -import androidx.annotation.StringRes import androidx.lifecycle.viewModelScope import com.afternote.core.ui.UiText import com.afternote.core.ui.mvi.MviViewModel import com.afternote.feature.setting.domain.NotificationPreferenceRepository -import com.afternote.feature.setting.domain.NotificationPreferences import com.afternote.feature.setting.presentation.R import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject /** - * 기록 알림 시각·요일·주간 목표를 고친다 (#2321). + * 푸시 알림 화면의 「알림 시간 설정」 (#2321, Figma 설정 - 푸시알림 설정). * - * 값을 바꿀 때마다 저장하지 않고 «저장» 으로 한 번에 보낸다. 서버는 설정이 바뀔 때마다 대기 중인 - * 기록 알림을 취소하고 다시 잡으므로, 시각을 고르는 도중의 값마다 그 일을 시키지 않는다. + * 시·분을 고르는 즉시 저장한다 — 시안에 저장 버튼이 없다. 서버 계약은 요일·주간 목표·켜짐도 함께 받으므로 + * 불러온 값을 그대로 실어 시각만 바꾼다. 저장이 실패하면 고르기 전 시각으로 되돌리고 알린다. */ @HiltViewModel internal class NotificationPreferenceViewModel @@ -32,12 +30,7 @@ internal class NotificationPreferenceViewModel override fun onIntent(intent: NotificationPreferenceIntent) { when (intent) { NotificationPreferenceIntent.Retry -> load() - is NotificationPreferenceIntent.ChangeEnabled -> edit { it.copy(enabled = intent.enabled) } - is NotificationPreferenceIntent.ChangeTime -> edit { it.copy(time = intent.time.withSecond(0).withNano(0)) } - is NotificationPreferenceIntent.ToggleWeekday -> edit { it.copy(weekdays = it.weekdays.toggle(intent.day)) } - is NotificationPreferenceIntent.ChangeWeeklyGoal -> edit { it.copy(weeklyGoal = intent.goal.coerceIn(MIN_GOAL, MAX_GOAL)) } - NotificationPreferenceIntent.Save -> save() - NotificationPreferenceIntent.ConsumeSaved -> dispatch(NotificationPreferenceReducerEvent.SavedConsumed) + is NotificationPreferenceIntent.ChangeTime -> changeTime(intent) NotificationPreferenceIntent.ConsumeError -> dispatch(NotificationPreferenceReducerEvent.ErrorConsumed) } } @@ -47,15 +40,33 @@ internal class NotificationPreferenceViewModel event: NotificationPreferenceReducerEvent, ): NotificationPreferenceUiState = when (event) { - NotificationPreferenceReducerEvent.Loading -> state.copy(isLoading = true, loadFailed = false) - is NotificationPreferenceReducerEvent.Loaded -> state.copy(isLoading = false, form = event.preferences) - NotificationPreferenceReducerEvent.LoadFailed -> state.copy(isLoading = false, loadFailed = true) - is NotificationPreferenceReducerEvent.Edited -> state.copy(form = event.form) - NotificationPreferenceReducerEvent.Saving -> state.copy(isSaving = true, errorMessage = null) - is NotificationPreferenceReducerEvent.Saved -> state.copy(isSaving = false, isSaved = true, form = event.preferences) - is NotificationPreferenceReducerEvent.Failed -> state.copy(isSaving = false, errorMessage = event.message) - NotificationPreferenceReducerEvent.SavedConsumed -> state.copy(isSaved = false) - NotificationPreferenceReducerEvent.ErrorConsumed -> state.copy(errorMessage = null) + NotificationPreferenceReducerEvent.Loading -> { + state.copy(isLoading = true, loadFailed = false) + } + + is NotificationPreferenceReducerEvent.Loaded -> { + state.copy(isLoading = false, preferences = event.preferences) + } + + NotificationPreferenceReducerEvent.LoadFailed -> { + state.copy(isLoading = false, loadFailed = true) + } + + is NotificationPreferenceReducerEvent.Saving -> { + state.copy(isSaving = true, preferences = event.preferences, errorMessage = null) + } + + is NotificationPreferenceReducerEvent.Saved -> { + state.copy(isSaving = false, preferences = event.preferences) + } + + is NotificationPreferenceReducerEvent.Failed -> { + state.copy(isSaving = false, preferences = event.previous, errorMessage = event.message) + } + + NotificationPreferenceReducerEvent.ErrorConsumed -> { + state.copy(errorMessage = null) + } } private fun load() { @@ -68,41 +79,21 @@ internal class NotificationPreferenceViewModel } } - private fun edit(transform: (NotificationPreferences) -> NotificationPreferences) { - val form = currentState.form ?: return + private fun changeTime(intent: NotificationPreferenceIntent.ChangeTime) { + val previous = currentState.preferences ?: return if (currentState.isSaving) return - dispatch(NotificationPreferenceReducerEvent.Edited(transform(form))) - } - - private fun save() { - val form = currentState.form ?: return - if (currentState.isSaving) return - // 알림을 받는 동안 요일이 하나도 없으면 서버가 거부한다. 요청 전에 막아 이유를 알려 준다. - if (form.enabled && form.weekdays.isEmpty()) { - dispatch( - NotificationPreferenceReducerEvent.Failed(UiText.Resource(R.string.setting_notification_preference_weekday_required)), - ) - return - } - dispatch(NotificationPreferenceReducerEvent.Saving) + val time = intent.time.withSecond(0).withNano(0) + if (time == previous.time) return + val requested = previous.copy(time = time) + dispatch(NotificationPreferenceReducerEvent.Saving(requested)) viewModelScope.launch { repository - .updatePreferences(form) + .updatePreferences(requested) .onSuccess { dispatch(NotificationPreferenceReducerEvent.Saved(it)) } .onFailure { - dispatch( - NotificationPreferenceReducerEvent.Failed( - UiText.Resource(R.string.setting_notification_preference_save_failed), - ), - ) + val message = UiText.Resource(R.string.setting_notification_preference_save_failed) + dispatch(NotificationPreferenceReducerEvent.Failed(previous, message)) } } } - - private companion object { - const val MIN_GOAL = 1 - const val MAX_GOAL = 7 - } } - -private fun Set.toggle(value: T): Set = if (value in this) this - value else this + value diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationTimeSection.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationTimeSection.kt new file mode 100644 index 0000000000..65902cecf7 --- /dev/null +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/notification/preference/NotificationTimeSection.kt @@ -0,0 +1,184 @@ +package com.afternote.feature.setting.presentation.notification.preference + +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import com.afternote.core.ui.modifierextention.bottomBorder +import com.afternote.core.ui.theme.AfternoteDesign +import com.afternote.feature.setting.presentation.R +import java.time.LocalTime + +/** + * 푸시 알림 화면 아래의 「알림 시간 설정」 — Figma 「설정 - 푸시알림 설정」 (#2321). + * + * 구분선, 제목, 시·분 드롭다운 두 칸, 안내 한 줄이다. 시는 0~23 을 그대로, 분은 10분 단위로 고른다. + * 서버 설정을 불러오지 못했으면 드롭다운 대신 다시 시도를 둔다 — 기본값을 그리면 사용자의 설정처럼 보인다. + */ +@Composable +internal fun NotificationTimeSection( + uiState: NotificationPreferenceUiState, + onIntent: (NotificationPreferenceIntent) -> Unit, + modifier: Modifier = Modifier, +) { + Column(modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(16.dp)) { + HorizontalDivider(color = AfternoteDesign.colors.gray2) + Text( + text = stringResource(R.string.setting_notification_time_title), + style = AfternoteDesign.typography.bodyBase, + color = AfternoteDesign.colors.gray9, + ) + val preferences = uiState.preferences + when { + preferences != null -> { + TimePickers( + time = preferences.time, + enabled = !uiState.isSaving, + onTimeChange = { onIntent(NotificationPreferenceIntent.ChangeTime(it)) }, + ) + } + + uiState.loadFailed -> { + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + text = stringResource(R.string.setting_notification_preference_load_failed), + style = AfternoteDesign.typography.captionLargeR, + color = AfternoteDesign.colors.gray6, + modifier = Modifier.weight(1f), + ) + TextButton(onClick = { onIntent(NotificationPreferenceIntent.Retry) }) { + Text( + text = stringResource(R.string.setting_notification_time_retry), + style = AfternoteDesign.typography.captionLargeR, + color = AfternoteDesign.colors.gray9, + ) + } + } + } + } + Row { + Image( + painter = painterResource(R.drawable.setting_ic_bullet), + contentDescription = null, + modifier = Modifier.padding(top = 6.dp), + ) + Spacer(Modifier.width(8.dp)) + Text( + text = stringResource(R.string.setting_notification_time_guide), + style = AfternoteDesign.typography.captionLargeR, + color = AfternoteDesign.colors.gray9, + ) + } + } +} + +@Composable +private fun TimePickers( + time: LocalTime, + enabled: Boolean, + onTimeChange: (LocalTime) -> Unit, +) { + Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { + TimeDropdown( + selected = time.hour, + options = HOURS, + label = { it.toString() }, + enabled = enabled, + onSelect = { onTimeChange(time.withHour(it)) }, + contentDescription = stringResource(R.string.setting_notification_time_hour), + ) + TimeDropdown( + selected = time.minute, + // 서버는 분 단위로 받지만 시안은 칸 하나라 10분 단위로 줄인다. 다른 분에 저장돼 있으면 그 값도 보인다. + options = (MINUTES + time.minute).distinct().sorted(), + label = { "%02d".format(it) }, + enabled = enabled, + onSelect = { onTimeChange(time.withMinute(it)) }, + contentDescription = stringResource(R.string.setting_notification_time_minute), + ) + } +} + +@Composable +private fun TimeDropdown( + selected: Int, + options: List, + label: (Int) -> String, + enabled: Boolean, + onSelect: (Int) -> Unit, + contentDescription: String, +) { + var expanded by remember { mutableStateOf(false) } + Box { + Row( + modifier = + Modifier + .width(160.dp) + .clickable(enabled = enabled, role = Role.DropdownList, onClickLabel = contentDescription) { expanded = true } + .bottomBorder(color = AfternoteDesign.colors.gray3, width = 0.5.dp) + .padding(top = 4.dp, bottom = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = label(selected), + style = AfternoteDesign.typography.captionLargeR, + color = AfternoteDesign.colors.gray9, + modifier = Modifier.weight(1f), + ) + Image(painter = painterResource(R.drawable.setting_ic_time_dropdown), contentDescription = null) + } + DropdownMenu( + expanded = expanded, + onDismissRequest = { expanded = false }, + shape = RoundedCornerShape(8.dp), + containerColor = AfternoteDesign.colors.white, + modifier = Modifier.width(164.dp).height(DROPDOWN_HEIGHT), + ) { + options.forEach { option -> + Text( + text = label(option), + style = AfternoteDesign.typography.textField, + color = AfternoteDesign.colors.gray9, + textAlign = TextAlign.Center, + modifier = + Modifier + .fillMaxWidth() + .clickable(role = Role.Button) { + expanded = false + onSelect(option) + }.padding(16.dp), + ) + } + } + } +} + +private val HOURS = (0..23).toList() +private val MINUTES = (0..50 step 10).toList() + +/** 시안의 펼친 목록은 세 줄이 보인다. 나머지는 스크롤한다. */ +private val DROPDOWN_HEIGHT = 162.dp diff --git a/feature/setting/presentation/src/main/res/drawable/setting_ic_bullet.xml b/feature/setting/presentation/src/main/res/drawable/setting_ic_bullet.xml new file mode 100644 index 0000000000..ff0953be20 --- /dev/null +++ b/feature/setting/presentation/src/main/res/drawable/setting_ic_bullet.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/feature/setting/presentation/src/main/res/drawable/setting_ic_time_dropdown.xml b/feature/setting/presentation/src/main/res/drawable/setting_ic_time_dropdown.xml new file mode 100644 index 0000000000..4703a24906 --- /dev/null +++ b/feature/setting/presentation/src/main/res/drawable/setting_ic_time_dropdown.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/feature/setting/presentation/src/main/res/values/strings.xml b/feature/setting/presentation/src/main/res/values/strings.xml index 8f3682e7c8..5f107fd32a 100644 --- a/feature/setting/presentation/src/main/res/values/strings.xml +++ b/feature/setting/presentation/src/main/res/values/strings.xml @@ -219,23 +219,15 @@ 패스키 등록에 실패했습니다. 다시 시도해 주세요. 패스키 생성이 완료되었습니다 - 기록 알림 시간 대리인 수신인 기념일 - 기록 알림 - 기록 알림 받기 - 고른 요일·시각에 기록을 권하는 알림을 보내요. 다른 알림과 합쳐 하루에 한 번만 보내고, 밤 10시부터 아침 8시 사이에는 보내지 않아요. - 알림 시각 - 변경 - 알림 요일 - 주간 목표 - 주 %1$d회 - 이번 주 기록 횟수를 이 목표와 견주어 금요일에 알려 드려요. - 저장 - 알림 설정을 저장했어요 + 알림 시간 설정 + 알림 시 선택 + 알림 분 선택 + 다시 시도 + 알림 시간을 설정하지 않으면 기본 시간인 매일 오후 6시에 알림이 발송됩니다. 알림 설정을 저장하지 못했어요. 잠시 후 다시 시도해 주세요. 알림 설정을 불러오지 못했어요. - 알림 요일을 하나 이상 골라 주세요. 확인 취소 대리인 diff --git a/feature/setting/presentation/src/screenshotTest/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTest.kt b/feature/setting/presentation/src/screenshotTest/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTest.kt index 07e49c4ead..a521c05b15 100644 --- a/feature/setting/presentation/src/screenshotTest/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTest.kt +++ b/feature/setting/presentation/src/screenshotTest/kotlin/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTest.kt @@ -4,9 +4,14 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.afternote.core.ui.UiText import com.afternote.core.ui.theme.AfternoteTheme +import com.afternote.feature.setting.domain.NotificationPreferences import com.afternote.feature.setting.presentation.COMPACT_DEVICE_SPEC import com.afternote.feature.setting.presentation.R +import com.afternote.feature.setting.presentation.notification.preference.NotificationPreferenceUiState +import com.afternote.feature.setting.presentation.notification.preference.NotificationTimeSection import com.android.tools.screenshot.PreviewTest +import java.time.DayOfWeek +import java.time.LocalTime @PreviewTest @Preview(showBackground = true) @@ -51,3 +56,30 @@ internal fun pushNotificationLoadingScreenshot() { internal fun pushNotificationLoadErrorScreenshot() { PushNotificationScreenshotContent(PushNotificationUiState(errorMessage = UiText.Resource(R.string.setting_push_load_error))) } + +/** Figma 「설정 - 푸시알림 설정」 — 토글 아래 알림 시간 설정 구역 (#2321). */ +@PreviewTest +@Preview(showBackground = true) +@Composable +internal fun pushNotificationWithTimeScreenshot() { + AfternoteTheme { + PushNotificationContent( + onRetry = {}, + uiState = PushNotificationUiState(isAfternoteOn = true), + onBack = {}, + onNewsletterToggle = {}, + onMindRecordToggle = {}, + onAfternoteToggle = {}, + timeSection = { + NotificationTimeSection( + uiState = + NotificationPreferenceUiState( + isLoading = false, + preferences = NotificationPreferences(true, LocalTime.of(9, 0), DayOfWeek.entries.toSet(), 3), + ), + onIntent = {}, + ) + }, + ) + } +} diff --git a/feature/setting/presentation/src/screenshotTestDebug/reference/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTestKt/pushNotificationWithTimeScreenshot_748aa731_0.png b/feature/setting/presentation/src/screenshotTestDebug/reference/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTestKt/pushNotificationWithTimeScreenshot_748aa731_0.png new file mode 100644 index 0000000000..3b854638d1 Binary files /dev/null and b/feature/setting/presentation/src/screenshotTestDebug/reference/com/afternote/feature/setting/presentation/notification/PushNotificationScreenScreenshotTestKt/pushNotificationWithTimeScreenshot_748aa731_0.png differ diff --git a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationPreferenceSettingsTest.kt b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationPreferenceSettingsTest.kt index 04c856b0cd..3c3bee250e 100644 --- a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationPreferenceSettingsTest.kt +++ b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationPreferenceSettingsTest.kt @@ -45,50 +45,51 @@ class NotificationPreferenceSettingsTest { } @Test - fun `기록 알림 - 고친 값을 저장 한 번에 보낸다`() = + fun `알림 시간 - 고른 시각만 바꿔 바로 저장하고 나머지 설정은 그대로 보낸다`() = runTest(dispatcher) { val repository = FakeNotificationPreferenceRepository() val viewModel = NotificationPreferenceViewModel(repository) advanceUntilIdle() viewModel.onIntent(NotificationPreferenceIntent.ChangeTime(LocalTime.of(21, 30, 15))) - viewModel.onIntent(NotificationPreferenceIntent.ToggleWeekday(DayOfWeek.MONDAY)) - viewModel.onIntent(NotificationPreferenceIntent.ChangeWeeklyGoal(9)) - assertTrue(repository.savedPreferences.isEmpty()) - - viewModel.onIntent(NotificationPreferenceIntent.Save) advanceUntilIdle() - val saved = repository.savedPreferences.single() - assertEquals(LocalTime.of(21, 30), saved.time) - assertEquals(DayOfWeek.entries.toSet() - DayOfWeek.MONDAY, saved.weekdays) - assertEquals(7, saved.weeklyGoal) - assertTrue(viewModel.uiState.value.isSaved) + assertEquals( + listOf(NotificationPreferences(true, LocalTime.of(21, 30), DayOfWeek.entries.toSet(), 3)), + repository.savedPreferences, + ) + assertEquals( + LocalTime.of(21, 30), + viewModel.uiState.value.preferences + ?.time, + ) } @Test - fun `기록 알림 - 요일을 모두 끄면 보내지 않고 이유를 알린다`() = + fun `알림 시간 - 저장이 실패하면 고르기 전 시각으로 되돌리고 알린다`() = runTest(dispatcher) { - val repository = FakeNotificationPreferenceRepository() + val repository = FakeNotificationPreferenceRepository(saveFails = true) val viewModel = NotificationPreferenceViewModel(repository) advanceUntilIdle() - DayOfWeek.entries.forEach { viewModel.onIntent(NotificationPreferenceIntent.ToggleWeekday(it)) } - viewModel.onIntent(NotificationPreferenceIntent.Save) + viewModel.onIntent(NotificationPreferenceIntent.ChangeTime(LocalTime.of(9, 0))) advanceUntilIdle() - assertTrue(repository.savedPreferences.isEmpty()) + assertEquals( + LocalTime.of(18, 0), + viewModel.uiState.value.preferences + ?.time, + ) assertNotNull(viewModel.uiState.value.errorMessage) } @Test - fun `기록 알림 - 불러오기 전에는 기본값을 그리지 않는다`() = + fun `알림 시간 - 불러오기 전에는 시각을 그리지 않는다`() = runTest(dispatcher) { - val repository = FakeNotificationPreferenceRepository(loadFails = true) - val viewModel = NotificationPreferenceViewModel(repository) + val viewModel = NotificationPreferenceViewModel(FakeNotificationPreferenceRepository(loadFails = true)) advanceUntilIdle() - assertNull(viewModel.uiState.value.form) + assertNull(viewModel.uiState.value.preferences) assertTrue(viewModel.uiState.value.loadFailed) } @@ -162,6 +163,7 @@ class NotificationPreferenceSettingsTest { private class FakeNotificationPreferenceRepository( private val loadFails: Boolean = false, + private val saveFails: Boolean = false, val anniversaries: MutableList = mutableListOf(), ) : NotificationPreferenceRepository { val savedPreferences = mutableListOf() @@ -175,6 +177,7 @@ class NotificationPreferenceSettingsTest { } override suspend fun updatePreferences(preferences: NotificationPreferences): Result { + if (saveFails) return Result.failure(IllegalStateException("offline")) savedPreferences += preferences return Result.success(preferences) } diff --git a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingSignalTest.kt b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingSignalTest.kt index 4a40a52020..8844005fe9 100644 --- a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingSignalTest.kt +++ b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/notification/NotificationSettingSignalTest.kt @@ -142,7 +142,6 @@ class NotificationSettingSignalTest { NotificationSettingScreen( onBack = {}, onPushNotificationClick = {}, - onNotificationPreferenceClick = {}, onDelegateClick = {}, onAnniversaryClick = {}, viewModel = viewModel,