diff --git a/feature/mindrecord/presentation/build.gradle.kts b/feature/mindrecord/presentation/build.gradle.kts index 76d0c5e121..1df4461310 100644 --- a/feature/mindrecord/presentation/build.gradle.kts +++ b/feature/mindrecord/presentation/build.gradle.kts @@ -7,6 +7,8 @@ plugins { android { namespace = "com.afternote.feature.mindrecord.presentation" resourcePrefix = "mindrecord_" + + testOptions.unitTests.isIncludeAndroidResources = true } dependencies { @@ -19,4 +21,9 @@ dependencies { implementation(libs.compose.rich.editor) testImplementation(libs.coroutines.test) + + // 캘린더 날짜 셀 상호작용을 JVM 에서 실제로 눌러 확인한다 (#724). + testImplementation(libs.robolectric) + testImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.test.manifest) } diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DailyCalendar.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DailyCalendar.kt index 5db76bbfa2..b072dafd7f 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DailyCalendar.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DailyCalendar.kt @@ -40,6 +40,10 @@ fun DailyCalendar( modifier: Modifier = Modifier, answeredDays: Set = emptySet(), emotionByDay: Map = emptyMap(), + /** 사용자가 고른 날(같은 달의 일자). 없으면 선택 없음 (#724). */ + selectedDay: Int? = null, + /** 날짜 셀 탭. null 이면 셀이 클릭 대상이 아니다. */ + onDayClick: ((Int) -> Unit)? = null, ) { val days = buildDays(year, month, answeredDays, emotionByDay) @@ -118,7 +122,15 @@ fun DailyCalendar( Row(modifier = Modifier.fillMaxWidth()) { week.forEach { dayModel -> Box(modifier = Modifier.weight(1f)) { - DayCell(model = dayModel, type = type) + DayCell( + model = dayModel, + type = type, + isSelected = dayModel.day != null && dayModel.day == selectedDay, + onClick = + onDayClick?.let { click -> + dayModel.day?.let { day -> { click(day) } } + }, + ) } } // 마지막 주가 7개 미만이면 빈 셀로 채우기 diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DayCell.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DayCell.kt index b66658d839..5235c7ac80 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DayCell.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/component/DayCell.kt @@ -1,6 +1,7 @@ package com.afternote.feature.mindrecord.presentation.component import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -15,6 +16,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp import com.afternote.core.ui.theme.AfternoteDesign import com.afternote.feature.mindrecord.presentation.model.DayState @@ -26,6 +28,9 @@ fun DayCell( model: DayUiModel, type: MindRecordCategoryUi, modifier: Modifier = Modifier, + /** 사용자가 고른 날. 선택 표시는 오늘 표시와 별개다 (#724). */ + isSelected: Boolean = false, + onClick: (() -> Unit)? = null, ) { if (model.day == null) { Box(modifier = Modifier.aspectRatio(1f)) @@ -35,16 +40,19 @@ fun DayCell( // - TODAY: 검은 원 + 흰 글자 // - ANSWERED(작성한 날): 투명 배경 + 진한 글자 + 하단 인디케이터 (diary 는 이모지, 그 외는 점) // - NONE/UNANSWERED: 투명 배경 + 회색 글자, 인디케이터 없음 + // 선택은 오늘보다 우선한다 — 오늘 칸을 골랐을 때도 "고른 칸" 임이 보여야 한다 (#724). val bgColor = - when (model.state) { - DayState.TODAY -> Color(0xFF1A1A1A) + when { + isSelected -> AfternoteDesign.colors.gray9 + model.state == DayState.TODAY -> AfternoteDesign.colors.gray9 else -> Color.Transparent } val textColor = - when (model.state) { - DayState.TODAY -> AfternoteDesign.colors.white - DayState.ANSWERED -> AfternoteDesign.colors.gray9 - DayState.UNANSWERED, DayState.NONE -> AfternoteDesign.colors.gray5 + when { + isSelected -> AfternoteDesign.colors.white + model.state == DayState.TODAY -> AfternoteDesign.colors.white + model.state == DayState.ANSWERED -> AfternoteDesign.colors.gray9 + else -> AfternoteDesign.colors.gray5 } val textStyle = when (model.state) { @@ -56,7 +64,14 @@ fun DayCell( modifier = modifier .aspectRatio(1f) - .padding(4.dp), + .then( + // 날짜 셀에 클릭 콜백이 아예 없어 눌러도 아무 일이 없었다 (#724). + if (onClick == null) { + Modifier + } else { + Modifier.clickable(role = Role.Button, onClick = onClick) + }, + ).padding(4.dp), contentAlignment = Alignment.Center, ) { Box( diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DailyQuestionAnswerListScreen.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DailyQuestionAnswerListScreen.kt index 2806cb3f87..49b52afab4 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DailyQuestionAnswerListScreen.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DailyQuestionAnswerListScreen.kt @@ -78,7 +78,23 @@ private fun DailyQuestionListContent( ) { var yearMonth by remember { mutableStateOf(YearMonth.now()) } val onYearMonthChanged: (YearMonth) -> Unit = { yearMonth = it } + // 월이 바뀌면 그 달의 선택은 무효다. + var selectedDay by remember(yearMonth) { mutableStateOf(null) } + // 캘린더 형에서는 **선택한 월** 기준으로 카드도 함께 좁힌다. 종전에는 캘린더 점만 + // 필터하고 카드는 전체 기간을 그대로 렌더해, 8월 캘린더가 "0개의 답변 완료" 인데 + // 아래에 7월 답변이 남아 있었다 (#724). + val monthAnswers = + if (isListView) { + answers + } else { + answers.filter { it.date.year == yearMonth.year && it.date.monthValue == yearMonth.monthValue } + } + val visibleAnswers = + selectedDay?.let { day -> monthAnswers.filter { it.date.dayOfMonth == day } } ?: monthAnswers + + // 리스트 형에서 전체가 비었을 때만 캘린더 없이 빈 상태를 보여준다. 캘린더 형에서는 + // 빈 상태가 캘린더를 대체하면 월 이동 수단이 사라진다 (#724). if (isListView && answers.isEmpty()) { MindRecordEmptyState(modifier = modifier) return @@ -90,11 +106,7 @@ private fun DailyQuestionListContent( ) { // Figma 2671:16704 — 캘린더 형은 캘린더 아래에 카드 리스트가 바로 이어짐 (gap 24) if (!isListView) { - val answeredDays = - answers - .filter { it.date.year == yearMonth.year && it.date.monthValue == yearMonth.monthValue } - .map { it.date.dayOfMonth } - .toSet() + val answeredDays = monthAnswers.map { it.date.dayOfMonth }.toSet() item { DailyCalendar( year = yearMonth.year, @@ -103,12 +115,19 @@ private fun DailyQuestionListContent( onPrevMonth = { onYearMonthChanged(yearMonth.minusMonths(1)) }, onNextMonth = { onYearMonthChanged(yearMonth.plusMonths(1)) }, answeredDays = answeredDays, + selectedDay = selectedDay, + // 같은 날을 다시 누르면 선택을 푼다 — 그 달 전체로 돌아올 수단이 필요하다. + onDayClick = { day -> selectedDay = if (selectedDay == day) null else day }, ) Spacer(modifier = Modifier.height(16.dp)) } } // Figma 2757:16116 — 리스트 형은 답변 카드만 나열 - items(answers, key = { it.id }) { answer -> + if (visibleAnswers.isEmpty()) { + item { MindRecordEmptyState() } + } + + items(visibleAnswers, key = { it.id }) { answer -> DailyQuestionListCard(answer = answer, onDelete = { onDelete(answer.id) }) } } diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DiaryScreen.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DiaryScreen.kt index 8d255da3a1..b917c23e8c 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DiaryScreen.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/DiaryScreen.kt @@ -18,6 +18,9 @@ import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text 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.stringResource @@ -98,14 +101,9 @@ private fun DiaryListContent( onDelete: (Long) -> Unit = {}, onYearMonthChanged: (YearMonth) -> Unit = {}, ) { - if (isListView && diaries.isEmpty()) { - MindRecordEmptyState( - modifier = modifier, - title = stringResource(R.string.mindrecord_diary_empty_state_title), - description = stringResource(R.string.mindrecord_diary_empty_state_description), - ) - return - } + // 기록이 없다고 조기 반환하지 않는다. 종전에는 빈 상태가 캘린더를 통째로 대체해 + // 월 이동 버튼까지 사라졌고, 기록이 있는 달로 돌아갈 방법이 없었다 (#724). + var selectedDay by remember(yearMonth) { mutableStateOf(null) } val currentMonthDiaries = diaries.filter { it.date.year == yearMonth.year && it.date.monthValue == yearMonth.monthValue } @@ -115,6 +113,11 @@ private fun DiaryListContent( .mapNotNull { diary -> diary.emotion?.let { diary.date.dayOfMonth to it } } .toMap() + // 날짜를 고르면 그 날 기록만, 안 고르면 그 달 전체를 보여준다. + val visibleDiaries = + selectedDay?.let { day -> currentMonthDiaries.filter { it.date.dayOfMonth == day } } + ?: currentMonthDiaries + if (isListView) { LazyColumn(modifier = modifier) { item { @@ -126,6 +129,9 @@ private fun DiaryListContent( onNextMonth = { onYearMonthChanged(yearMonth.plusMonths(1)) }, answeredDays = answeredDays, emotionByDay = emotionByDay, + selectedDay = selectedDay, + // 같은 날을 다시 누르면 선택을 푼다 — 그 달 전체로 돌아올 수단이 필요하다. + onDayClick = { day -> selectedDay = if (selectedDay == day) null else day }, ) Spacer(modifier = Modifier.height(10.dp)) } @@ -145,7 +151,16 @@ private fun DiaryListContent( Spacer(modifier = Modifier.height(10.dp)) } - items(diaries, key = { it.id }) { diary -> + if (visibleDiaries.isEmpty()) { + item { + MindRecordEmptyState( + title = stringResource(R.string.mindrecord_diary_empty_state_title), + description = stringResource(R.string.mindrecord_diary_empty_state_description), + ) + } + } + + items(visibleDiaries, key = { it.id }) { diary -> DiaryComponent( diary = diary, modifier = Modifier.padding(vertical = 8.dp), diff --git a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/HomeScreen.kt b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/HomeScreen.kt index f692733fcc..e5ca6428bc 100644 --- a/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/HomeScreen.kt +++ b/feature/mindrecord/presentation/src/main/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/HomeScreen.kt @@ -17,6 +17,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier @@ -55,10 +56,20 @@ fun HomeScreen( ) } - var isListView by remember { mutableStateOf(true) } var selectedIndex by remember { mutableIntStateOf(0) } val selectedCategory = categories[selectedIndex] + // 탭마다 따로 기억한다. 종전에는 한 값을 두 탭이 공유했는데 의미가 서로 반대였다 — + // 데일리질문은 false 를 캘린더로, 일기는 같은 false 를 2열 그리드로 썼다. 그래서 탭을 + // 오가면 아이콘은 그대로인데 표시가 뒤바뀐 것처럼 보였다 (#724). + var dailyQuestionListView by rememberSaveable { mutableStateOf(true) } + var diaryListView by rememberSaveable { mutableStateOf(true) } + val isListView = + when (selectedCategory) { + MindRecordCategoryUi.DailyQuestion -> dailyQuestionListView + else -> diaryListView + } + val pagerState = rememberPagerState { categories.size } LaunchedEffect(selectedIndex) { pagerState.animateScrollToPage(selectedIndex) @@ -89,7 +100,12 @@ fun HomeScreen( isListView = isListView, image1 = R.drawable.core_ui_list, image2 = R.drawable.core_ui_calendar, - onViewChange = { isListView = it }, + onViewChange = { listView -> + when (selectedCategory) { + MindRecordCategoryUi.DailyQuestion -> dailyQuestionListView = listView + else -> diaryListView = listView + } + }, ) } }, @@ -143,9 +159,17 @@ fun HomeScreen( HorizontalPager(state = pagerState) { _ -> when (selectedCategory) { - MindRecordCategoryUi.DailyQuestion -> DailyQuestionAnswerListScreen(isListView = isListView) - MindRecordCategoryUi.Diary -> DiaryScreen(isListView = isListView) - else -> WeeklyReportScreen() + MindRecordCategoryUi.DailyQuestion -> { + DailyQuestionAnswerListScreen(isListView = dailyQuestionListView) + } + + MindRecordCategoryUi.Diary -> { + DiaryScreen(isListView = diaryListView) + } + + else -> { + WeeklyReportScreen() + } } } } diff --git a/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/CalendarSelectionTest.kt b/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/CalendarSelectionTest.kt new file mode 100644 index 0000000000..4781882d04 --- /dev/null +++ b/feature/mindrecord/presentation/src/test/kotlin/com/afternote/feature/mindrecord/presentation/screen/sender/CalendarSelectionTest.kt @@ -0,0 +1,93 @@ +package com.afternote.feature.mindrecord.presentation.screen.sender + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertHasClickAction +import androidx.compose.ui.test.assertHasNoClickAction +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onAllNodesWithText +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import com.afternote.core.ui.theme.AfternoteTheme +import com.afternote.feature.mindrecord.presentation.component.DailyCalendar +import com.afternote.feature.mindrecord.presentation.model.MindRecordCategoryUi +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +/** + * 캘린더 날짜 셀 상호작용 가드 (#724). + * + * 공용 `DailyCalendar` 에 `selectedDay`·`onDayClick` 이 아예 없어, 날짜를 눌러도 선택 + * 표시도 기록 필터도 일어나지 않았다. 월 이동만 되고 날짜는 죽어 있던 상태다. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [35]) +class CalendarSelectionTest { + @get:Rule + val composeRule = createAndroidComposeRule() + + @Test + fun `날짜 셀을 누르면 그 일자가 콜백으로 온다`() { + var clicked: Int? = null + composeRule.setContent { + AfternoteTheme { + DailyCalendar( + year = 2026, + month = 8, + type = MindRecordCategoryUi.Diary, + onPrevMonth = {}, + onNextMonth = {}, + answeredDays = setOf(12), + onDayClick = { clicked = it }, + ) + } + } + + composeRule.onAllNodesWithText("12")[0].assertHasClickAction() + composeRule.onAllNodesWithText("12")[0].performClick() + + assertEquals(12, clicked) + } + + @Test + fun `콜백을 주지 않으면 셀은 클릭 대상이 아니다`() { + // 수신자 화면 등 선택이 없는 곳에서 헛클릭이 생기지 않게 한다. + composeRule.setContent { + AfternoteTheme { + DailyCalendar( + year = 2026, + month = 8, + type = MindRecordCategoryUi.Diary, + onPrevMonth = {}, + onNextMonth = {}, + ) + } + } + + composeRule.onAllNodesWithText("12")[0].assertHasNoClickAction() + } + + @Test + fun `월 이동 수단은 기록이 없는 달에도 남는다`() { + // 종전에는 빈 상태가 캘린더를 통째로 대체해 이전·다음 월 버튼까지 사라졌다. + composeRule.setContent { + AfternoteTheme { + DailyCalendar( + year = 2026, + month = 8, + type = MindRecordCategoryUi.Diary, + onPrevMonth = {}, + onNextMonth = {}, + answeredDays = emptySet(), + ) + } + } + + composeRule.onNodeWithText("2026년 8월").assertIsDisplayed() + composeRule.onNodeWithText("0개의 답변 완료").assertIsDisplayed() + } +}