Skip to content

Commit b92d197

Browse files
committed
✨ 내가 쓴 글 탭 구현
1 parent d681ca7 commit b92d197

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class CommunityItemFragment :
4242
setMyGroupAdapter()
4343
}
4444
CommunityCategory.MY_POST -> {
45-
// TODO: Adapter 설정
45+
setMyPostAdapter()
4646
}
4747
}
4848
}
@@ -122,6 +122,28 @@ internal class CommunityItemFragment :
122122
}
123123
}
124124

125+
private fun setMyPostAdapter() {
126+
viewLifecycleOwner.lifecycleScope.launch {
127+
val postAdapter = PostAdapter {
128+
viewModel.onGroupJoinButtonClicked(it)
129+
}
130+
binding.rvCommunity.adapter = postAdapter
131+
132+
viewLifecycleOwner.repeatWhenUiStarted {
133+
viewModel.myGroupList.collect { myGroupList ->
134+
postAdapter.setMyGroupList(myGroupList)
135+
}
136+
}
137+
138+
viewLifecycleOwner.repeatWhenUiStarted {
139+
viewModel.myPostList.collect { myPostList ->
140+
removeShimmer()
141+
postAdapter.submitList(myPostList)
142+
}
143+
}
144+
}
145+
}
146+
125147
private fun removeShimmer() {
126148
binding.shimmerCommunity.apply {
127149
stopShimmer()

presentation/src/main/java/com/whyranoid/presentation/community/CommunityViewModel.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import com.whyranoid.domain.model.Post
66
import com.whyranoid.domain.usecase.GetMyGroupListUseCase
7+
import com.whyranoid.domain.usecase.GetMyPostUseCase
78
import com.whyranoid.domain.usecase.GetPostsUseCase
8-
import com.whyranoid.domain.usecase.GetUidUseCase
99
import com.whyranoid.domain.usecase.JoinGroupUseCase
1010
import com.whyranoid.presentation.model.GroupInfoUiModel
1111
import com.whyranoid.presentation.model.toGroupInfoUiModel
@@ -26,7 +26,7 @@ class CommunityViewModel @Inject constructor(
2626
getMyGroupListUseCase: GetMyGroupListUseCase,
2727
getPostsUseCase: GetPostsUseCase,
2828
private val joinGroupUseCase: JoinGroupUseCase,
29-
val getMyUseCase: GetUidUseCase
29+
private val getMyPostUseCase: GetMyPostUseCase
3030
) : ViewModel() {
3131

3232
private val _postList = MutableStateFlow<List<Post>>(emptyList())
@@ -37,6 +37,10 @@ class CommunityViewModel @Inject constructor(
3737
val myGroupList: StateFlow<List<GroupInfoUiModel>>
3838
get() = _myGroupList.asStateFlow()
3939

40+
private val _myPostList = MutableStateFlow<List<Post>>(emptyList())
41+
val myPostList: StateFlow<List<Post>>
42+
get() = _myPostList.asStateFlow()
43+
4044
private val _eventFlow = MutableSharedFlow<Event>()
4145
val eventFlow: SharedFlow<Event>
4246
get() = _eventFlow.asSharedFlow()
@@ -82,5 +86,11 @@ class CommunityViewModel @Inject constructor(
8286
post.updatedAt
8387
}
8488
}.launchIn(viewModelScope)
89+
90+
viewModelScope.launch {
91+
getMyPostUseCase().onEach { myPostList ->
92+
_myPostList.value = myPostList
93+
}.launchIn(this)
94+
}
8595
}
8696
}

0 commit comments

Comments
 (0)