Skip to content

Commit b5dc365

Browse files
committed
✨ 게시글, 내가 쓴 글 새로고침 기능 추가
1 parent 0365922 commit b5dc365

File tree

2 files changed

+58
-35
lines changed

2 files changed

+58
-35
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ internal class CommunityItemFragment :
118118
viewLifecycleOwner.repeatWhenUiStarted {
119119
postAdapter.loadStateFlow.collectLatest { loadStates ->
120120
binding.shimmerCommunity.isVisible = loadStates.refresh is LoadState.Loading
121+
binding.rvCommunity.isVisible = (loadStates.refresh is LoadState.Loading).not()
121122
}
122123
}
123124

124125
binding.rvCommunity.adapter = postAdapter
125126

127+
binding.swipeRefreshLayout.setOnRefreshListener {
128+
postAdapter.refresh()
129+
binding.rvCommunity.scrollToPosition(0)
130+
binding.swipeRefreshLayout.isRefreshing = false
131+
}
132+
126133
viewLifecycleOwner.repeatWhenUiStarted {
127134
viewModel.myGroupList.collectLatest { myGroupList ->
128135
postAdapter.setMyGroupList(myGroupList)
@@ -138,6 +145,7 @@ internal class CommunityItemFragment :
138145
}
139146

140147
private fun setMyGroupAdapter() {
148+
binding.swipeRefreshLayout.isEnabled = false
141149
val myGroupAdapter = MyGroupAdapter { groupInfo ->
142150
viewModel.onGroupItemClicked(groupInfo)
143151
}
@@ -169,21 +177,29 @@ internal class CommunityItemFragment :
169177
viewLifecycleOwner.repeatWhenUiStarted {
170178
postAdapter.loadStateFlow.collectLatest { loadStates ->
171179
binding.shimmerCommunity.isVisible = loadStates.refresh is LoadState.Loading
180+
binding.rvCommunity.isVisible = (loadStates.refresh is LoadState.Loading).not()
172181
}
173182
}
174183

175184
binding.rvCommunity.adapter = postAdapter
176185

186+
binding.swipeRefreshLayout.setOnRefreshListener {
187+
postAdapter.refresh()
188+
binding.rvCommunity.scrollToPosition(0)
189+
binding.swipeRefreshLayout.isRefreshing = false
190+
}
191+
177192
viewLifecycleOwner.repeatWhenUiStarted {
178193
viewModel.myGroupList.collect { myGroupList ->
179194
postAdapter.setMyGroupList(myGroupList)
180195
}
181196
}
182197

183198
viewLifecycleOwner.repeatWhenUiStarted {
184-
viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope).collectLatest { myPostList ->
185-
postAdapter.submitData(myPostList)
186-
}
199+
viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope)
200+
.collectLatest { myPostList ->
201+
postAdapter.submitData(myPostList)
202+
}
187203
}
188204
}
189205
}

presentation/src/main/res/layout/fragment_community_item.xml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,50 @@
77

88
</data>
99

10-
<androidx.constraintlayout.widget.ConstraintLayout
10+
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
11+
android:id="@+id/swipe_refresh_layout"
1112
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
tools:context=".community.CommunityItemFragment">
14-
15-
<androidx.recyclerview.widget.RecyclerView
16-
android:id="@+id/rv_community"
17-
android:layout_width="0dp"
18-
android:layout_height="0dp"
19-
app:layout_constraintStart_toStartOf="parent"
20-
app:layout_constraintEnd_toEndOf="parent"
21-
app:layout_constraintTop_toTopOf="parent"
22-
app:layout_constraintBottom_toBottomOf="parent"
23-
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
24-
25-
<com.facebook.shimmer.ShimmerFrameLayout
26-
android:id="@+id/shimmer_community"
27-
android:layout_width="match_parent"
28-
android:layout_height="match_parent">
13+
android:layout_height="match_parent">
2914

30-
<LinearLayout
15+
<androidx.constraintlayout.widget.ConstraintLayout
16+
android:layout_width="match_parent"
17+
android:layout_height="match_parent"
18+
tools:context=".community.CommunityItemFragment">
19+
20+
<androidx.recyclerview.widget.RecyclerView
21+
android:id="@+id/rv_community"
22+
android:layout_width="0dp"
23+
android:layout_height="0dp"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintEnd_toEndOf="parent"
26+
app:layout_constraintTop_toTopOf="parent"
27+
app:layout_constraintBottom_toBottomOf="parent"
28+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
29+
30+
<com.facebook.shimmer.ShimmerFrameLayout
31+
android:id="@+id/shimmer_community"
3132
android:layout_width="match_parent"
32-
android:layout_height="match_parent"
33-
android:orientation="vertical">
33+
android:layout_height="match_parent">
34+
35+
<LinearLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent"
38+
android:orientation="vertical">
39+
40+
<include layout="@layout/my_group_item_loading"/>
41+
<include layout="@layout/my_group_item_loading"/>
42+
<include layout="@layout/my_group_item_loading"/>
43+
<include layout="@layout/my_group_item_loading"/>
44+
<include layout="@layout/my_group_item_loading"/>
45+
<include layout="@layout/my_group_item_loading"/>
46+
<include layout="@layout/my_group_item_loading"/>
47+
<include layout="@layout/my_group_item_loading"/>
3448

35-
<include layout="@layout/my_group_item_loading"/>
36-
<include layout="@layout/my_group_item_loading"/>
37-
<include layout="@layout/my_group_item_loading"/>
38-
<include layout="@layout/my_group_item_loading"/>
39-
<include layout="@layout/my_group_item_loading"/>
40-
<include layout="@layout/my_group_item_loading"/>
41-
<include layout="@layout/my_group_item_loading"/>
42-
<include layout="@layout/my_group_item_loading"/>
49+
</LinearLayout>
4350

44-
</LinearLayout>
51+
</com.facebook.shimmer.ShimmerFrameLayout>
4552

46-
</com.facebook.shimmer.ShimmerFrameLayout>
53+
</androidx.constraintlayout.widget.ConstraintLayout>
4754

48-
</androidx.constraintlayout.widget.ConstraintLayout>
55+
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
4956
</layout>

0 commit comments

Comments
 (0)