diff --git a/build.gradle b/build.gradle index 7180cfe..da34198 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/presentation/build.gradle b/presentation/build.gradle index d160bfe..c11dc74 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -117,4 +117,8 @@ dependencies { // HiltWorker implementation "androidx.hilt:hilt-work:$hiltWorkerVersion" kapt "androidx.hilt:hilt-compiler:$hiltCompilerVersion" + + // SwipeRefresh + implementation "androidx.swiperefreshlayout:swiperefreshlayout:$swipeRefreshLayoutVersion" + } \ No newline at end of file diff --git a/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt b/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt index e91645d..7129fa0 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt @@ -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) @@ -138,6 +149,7 @@ internal class CommunityItemFragment : } private fun setMyGroupAdapter() { + binding.swipeRefreshLayout.isEnabled = false val myGroupAdapter = MyGroupAdapter { groupInfo -> viewModel.onGroupItemClicked(groupInfo) } @@ -169,11 +181,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.collect { myGroupList -> postAdapter.setMyGroupList(myGroupList) @@ -181,9 +204,10 @@ internal class CommunityItemFragment : } viewLifecycleOwner.repeatWhenUiStarted { - viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope).collectLatest { myPostList -> - postAdapter.submitData(myPostList) - } + viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope) + .collectLatest { myPostList -> + postAdapter.submitData(myPostList) + } } } } @@ -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() diff --git a/presentation/src/main/res/layout/fragment_community_item.xml b/presentation/src/main/res/layout/fragment_community_item.xml index 22ebebd..0af2cac 100644 --- a/presentation/src/main/res/layout/fragment_community_item.xml +++ b/presentation/src/main/res/layout/fragment_community_item.xml @@ -7,43 +7,51 @@ - - - - - + app:swipeRefreshLayoutProgressSpinnerBackgroundColor="@color/mogakrun_background"> - + + + + + android:layout_height="match_parent"> + + + + + + + + + + + - - - - - - - - + - + - + - + \ No newline at end of file