Skip to content

Commit

Permalink
🔀 #87 from boostcampwm-2022/feat/swipeRefresh
Browse files Browse the repository at this point in the history
Shimmer관련 이슈 수정, 새로고침 기능 구현
  • Loading branch information
soopeach authored Dec 8, 2022
2 parents fd2a23a + a967d9e commit 63a825a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 34 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ buildscript {
hiltWorkerVersion = "1.0.0"
hiltCompilerVersion = "1.0.0"
crashlyticsVersion = "2.9.2"
swipeRefreshLayoutVersion = "1.1.0"
}
dependencies {
classpath "com.google.gms:google-services:$googleServiceVersion"
Expand Down
4 changes: 4 additions & 0 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@ dependencies {
// HiltWorker
implementation "androidx.hilt:hilt-work:$hiltWorkerVersion"
kapt "androidx.hilt:hilt-compiler:$hiltCompilerVersion"

// SwipeRefresh
implementation "androidx.swiperefreshlayout:swiperefreshlayout:$swipeRefreshLayoutVersion"

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,22 @@ internal class CommunityItemFragment :
viewLifecycleOwner.repeatWhenUiStarted {
postAdapter.loadStateFlow.collectLatest { loadStates ->
binding.shimmerCommunity.isVisible = loadStates.refresh is LoadState.Loading
binding.rvCommunity.isVisible = (loadStates.refresh is LoadState.Loading).not()
}
}

binding.rvCommunity.adapter = postAdapter

binding.swipeRefreshLayout.apply {
setOnRefreshListener {
postAdapter.refresh()
binding.rvCommunity.scrollToPosition(POSITION_TOP)
binding.swipeRefreshLayout.isRefreshing = false
}

setColorSchemeColors(context.getColor(R.color.mogakrun_on_primary))
}

viewLifecycleOwner.repeatWhenUiStarted {
viewModel.myGroupList.collectLatest { myGroupList ->
postAdapter.setMyGroupList(myGroupList)
Expand All @@ -138,6 +149,7 @@ internal class CommunityItemFragment :
}

private fun setMyGroupAdapter() {
binding.swipeRefreshLayout.isEnabled = false
val myGroupAdapter = MyGroupAdapter { groupInfo ->
viewModel.onGroupItemClicked(groupInfo)
}
Expand Down Expand Up @@ -169,21 +181,33 @@ internal class CommunityItemFragment :
viewLifecycleOwner.repeatWhenUiStarted {
postAdapter.loadStateFlow.collectLatest { loadStates ->
binding.shimmerCommunity.isVisible = loadStates.refresh is LoadState.Loading
binding.rvCommunity.isVisible = (loadStates.refresh is LoadState.Loading).not()
}
}

binding.rvCommunity.adapter = postAdapter

binding.swipeRefreshLayout.apply {
setOnRefreshListener {
postAdapter.refresh()
binding.rvCommunity.scrollToPosition(POSITION_TOP)
binding.swipeRefreshLayout.isRefreshing = false
}

setColorSchemeColors(context.getColor(R.color.mogakrun_on_primary))
}

viewLifecycleOwner.repeatWhenUiStarted {
viewModel.myGroupList.collect { myGroupList ->
postAdapter.setMyGroupList(myGroupList)
}
}

viewLifecycleOwner.repeatWhenUiStarted {
viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope).collectLatest { myPostList ->
postAdapter.submitData(myPostList)
}
viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope)
.collectLatest { myPostList ->
postAdapter.submitData(myPostList)
}
}
}
}
Expand All @@ -197,6 +221,7 @@ internal class CommunityItemFragment :

companion object {
private const val COMMUNITY_CATEGORY_KEY = "communityCategoryKey"
private const val POSITION_TOP = 0

fun newInstance(communityCategory: CommunityCategory): CommunityItemFragment {
val fragment = CommunityItemFragment()
Expand Down
70 changes: 39 additions & 31 deletions presentation/src/main/res/layout/fragment_community_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,51 @@

</data>

<androidx.constraintlayout.widget.ConstraintLayout
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".community.CommunityItemFragment">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_community"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer_community"
android:layout_width="match_parent"
android:layout_height="match_parent">
app:swipeRefreshLayoutProgressSpinnerBackgroundColor="@color/mogakrun_background">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".community.CommunityItemFragment">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_community"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer_community"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>

<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
<include layout="@layout/my_group_item_loading"/>
</LinearLayout>

</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>

</com.facebook.shimmer.ShimmerFrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</layout>

0 comments on commit 63a825a

Please sign in to comment.