From 8ab797c51db3486f1d02347e1667c714a3c7ef6a Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 8 Feb 2024 22:55:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=EA=B3=B5=EC=A7=80=20=ED=81=B4?= =?UTF-8?q?=EB=A6=AD=20=EC=8B=9C=20=EA=B3=B5=EC=A7=80=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20viewYn=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/notice/NoticeScreen.kt | 10 ++++-- .../presentation/ui/notice/NoticeViewModel.kt | 33 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt index 152aef15..6b4e1841 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt @@ -95,13 +95,19 @@ fun NoticeScreen( onClickUnreadNoticeFilter = { viewModel.updateVisibleOnlyUnreadNotice(it) }, - onNoticeClick = onNoticeClick + onNoticeClick = { + onNoticeClick(it) + viewModel.updateNoticeAsViewedInList(it.noticeId) + } ) } NoticeTab.CURRICULUM-> { CurriculumListScreen( curriculumList = curriculumList, - onNoticeClick = onNoticeClick + onNoticeClick = { + onNoticeClick(it) + viewModel.updateNoticeAsViewedInList(it.noticeId) + } ) } } diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt index 94d1a606..8c6fa746 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt @@ -2,6 +2,7 @@ package com.kusitms.presentation.ui.notice import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.kusitms.domain.model.notice.NoticeModel import com.kusitms.domain.usecase.notice.GetCurriculumListUseCase import com.kusitms.domain.usecase.notice.GetNoticeListUseCase import dagger.hilt.android.lifecycle.HiltViewModel @@ -10,23 +11,30 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class NoticeViewModel @Inject constructor( - getNoticeListUseCase: GetNoticeListUseCase, + private val getNoticeListUseCase: GetNoticeListUseCase, getCurriculumListUseCase: GetCurriculumListUseCase ) : ViewModel() { - val noticeList = getNoticeListUseCase().catch { + private val _noticeList = MutableStateFlow>(emptyList()) + val noticeList : StateFlow> = _noticeList.asStateFlow() - }.stateIn( - viewModelScope, - started = SharingStarted.Eagerly, - initialValue = emptyList() - ) + init { + viewModelScope.launch { + getNoticeListUseCase().catch { + + }.collect { + _noticeList.emit(it) + } + } + + } val curriculumList = getCurriculumListUseCase().catch { @@ -44,4 +52,15 @@ class NoticeViewModel @Inject constructor( _visibleOnlyUnreadNotice.emit(isVisible) } } + + fun updateNoticeAsViewedInList(noticeId : Int){ + viewModelScope.launch { + _noticeList.emit( + noticeList.value.map { + if(it.noticeId == noticeId && !it.viewYn) it.copy(viewYn = true) + else it + } + ) + } + } } \ No newline at end of file From ff310260c487e8abf082e0553218d97ca95f40d0 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Fri, 9 Feb 2024 17:26:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20=EB=8C=80=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20-=20=EA=B8=B0=EC=A1=B4=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C/=EC=8B=A0=EA=B3=A0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=88=84=EB=9D=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/detail/NoticeDetailBottomSheet.kt | 18 ++++++++++++++++-- .../ui/notice/detail/NoticeDetailScreen.kt | 3 +++ .../ui/notice/detail/NoticeDetailViewModel.kt | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt index f2e73d72..158f4b10 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt @@ -68,7 +68,8 @@ fun NoticeCommentBottom( noticeDetailViewModel: NoticeDetailViewModel = hiltViewModel(), targetComment : CommentModel, onClickChildReport : (NoticeDetailModalState.Report) -> Unit, - onClickChildDelete : (NoticeDetailDialogState.CommentDelete) -> Unit + onClickChildDelete : (NoticeDetailDialogState.CommentDelete) -> Unit, + onDismiss: () -> Unit = {} ){ val childCommentList by noticeDetailViewModel.childCommentList.collectAsStateWithLifecycle() @@ -95,7 +96,20 @@ fun NoticeCommentBottom( NoticeComment( comment = targetComment, commentCount = childCommentList.size, - isParentCommentAsReply = true + isParentCommentAsReply = true, + onClickReport = { + onClickChildReport( + NoticeDetailModalState.Report(targetComment, targetComment.writerId) + ) + }, + onClickDelete = { + onClickChildDelete( + NoticeDetailDialogState.CommentDelete( + comment = targetComment + ) + ) + onDismiss() + } ) KusitmsMarginVerticalSpacer(size = 20) diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt index cdc8f66f..2e923999 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt @@ -282,6 +282,9 @@ fun NoticeDetailScreen( }, onClickChildDelete = { openDialogState = it + }, + onDismiss = { + openBottomSheet = null } ) } diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt index 39906c0a..12f01acf 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt @@ -155,6 +155,7 @@ class NoticeDetailViewModel @Inject constructor( ).catch { _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { + fetchCommentList() fetchChildCommentList(commentId) } }