From 0365922025f866a60e3ca1058283aaf8586177e4 Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 8 Dec 2022 14:08:03 +0900 Subject: [PATCH 1/4] =?UTF-8?q?:wrench:=20swiperefreshlayout=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + presentation/build.gradle | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 7180cfe6..da341988 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 d160bfe3..c11dc74e 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 From b5dc365ba7fe817c74c13c7b412aa2162846f6fc Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 8 Dec 2022 14:08:21 +0900 Subject: [PATCH 2/4] =?UTF-8?q?:sparkles:=20=EA=B2=8C=EC=8B=9C=EA=B8=80,?= =?UTF-8?q?=20=EB=82=B4=EA=B0=80=20=EC=93=B4=20=EA=B8=80=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=EA=B3=A0=EC=B9=A8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/CommunityItemFragment.kt | 22 +++++- .../res/layout/fragment_community_item.xml | 71 ++++++++++--------- 2 files changed, 58 insertions(+), 35 deletions(-) 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 e91645d5..44474bc7 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,18 @@ 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.setOnRefreshListener { + postAdapter.refresh() + binding.rvCommunity.scrollToPosition(0) + binding.swipeRefreshLayout.isRefreshing = false + } + viewLifecycleOwner.repeatWhenUiStarted { viewModel.myGroupList.collectLatest { myGroupList -> postAdapter.setMyGroupList(myGroupList) @@ -138,6 +145,7 @@ internal class CommunityItemFragment : } private fun setMyGroupAdapter() { + binding.swipeRefreshLayout.isEnabled = false val myGroupAdapter = MyGroupAdapter { groupInfo -> viewModel.onGroupItemClicked(groupInfo) } @@ -169,11 +177,18 @@ 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.setOnRefreshListener { + postAdapter.refresh() + binding.rvCommunity.scrollToPosition(0) + binding.swipeRefreshLayout.isRefreshing = false + } + viewLifecycleOwner.repeatWhenUiStarted { viewModel.myGroupList.collect { myGroupList -> postAdapter.setMyGroupList(myGroupList) @@ -181,9 +196,10 @@ internal class CommunityItemFragment : } viewLifecycleOwner.repeatWhenUiStarted { - viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope).collectLatest { myPostList -> - postAdapter.submitData(myPostList) - } + viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope) + .collectLatest { myPostList -> + postAdapter.submitData(myPostList) + } } } } diff --git a/presentation/src/main/res/layout/fragment_community_item.xml b/presentation/src/main/res/layout/fragment_community_item.xml index 22ebebdb..f8a7bdc6 100644 --- a/presentation/src/main/res/layout/fragment_community_item.xml +++ b/presentation/src/main/res/layout/fragment_community_item.xml @@ -7,43 +7,50 @@ - - - - - + android:layout_height="match_parent"> - + + + + + android:layout_height="match_parent"> + + + + + + + + + + + - - - - - - - - + - + - + - + \ No newline at end of file From 4afe25bf70309b0c1cb09f0de1b79d07f3f4a982 Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 8 Dec 2022 14:12:44 +0900 Subject: [PATCH 3/4] =?UTF-8?q?:lipstick:=20=EB=AA=A8=EA=B0=81=EB=9F=B0=20?= =?UTF-8?q?=ED=85=8C=EB=A7=88=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EB=A0=88=EC=8A=A4=20=EC=83=89=EC=83=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/CommunityItemFragment.kt | 24 ++++++++++++------- .../res/layout/fragment_community_item.xml | 3 ++- 2 files changed, 18 insertions(+), 9 deletions(-) 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 44474bc7..0496052f 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt @@ -124,10 +124,14 @@ internal class CommunityItemFragment : binding.rvCommunity.adapter = postAdapter - binding.swipeRefreshLayout.setOnRefreshListener { - postAdapter.refresh() - binding.rvCommunity.scrollToPosition(0) - binding.swipeRefreshLayout.isRefreshing = false + binding.swipeRefreshLayout.apply { + setOnRefreshListener { + postAdapter.refresh() + binding.rvCommunity.scrollToPosition(0) + binding.swipeRefreshLayout.isRefreshing = false + } + + setColorSchemeColors(context.getColor(R.color.mogakrun_on_primary)) } viewLifecycleOwner.repeatWhenUiStarted { @@ -183,10 +187,14 @@ internal class CommunityItemFragment : binding.rvCommunity.adapter = postAdapter - binding.swipeRefreshLayout.setOnRefreshListener { - postAdapter.refresh() - binding.rvCommunity.scrollToPosition(0) - binding.swipeRefreshLayout.isRefreshing = false + binding.swipeRefreshLayout.apply { + setOnRefreshListener { + postAdapter.refresh() + binding.rvCommunity.scrollToPosition(0) + binding.swipeRefreshLayout.isRefreshing = false + } + + setColorSchemeColors(context.getColor(R.color.mogakrun_on_primary)) } viewLifecycleOwner.repeatWhenUiStarted { diff --git a/presentation/src/main/res/layout/fragment_community_item.xml b/presentation/src/main/res/layout/fragment_community_item.xml index f8a7bdc6..0af2cac8 100644 --- a/presentation/src/main/res/layout/fragment_community_item.xml +++ b/presentation/src/main/res/layout/fragment_community_item.xml @@ -10,7 +10,8 @@ + android:layout_height="match_parent" + app:swipeRefreshLayoutProgressSpinnerBackgroundColor="@color/mogakrun_background"> Date: Thu, 8 Dec 2022 16:05:13 +0900 Subject: [PATCH 4/4] =?UTF-8?q?:recycle:=200=EC=9D=84=20=EC=83=81=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/community/CommunityItemFragment.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 0496052f..7129fa05 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt @@ -127,7 +127,7 @@ internal class CommunityItemFragment : binding.swipeRefreshLayout.apply { setOnRefreshListener { postAdapter.refresh() - binding.rvCommunity.scrollToPosition(0) + binding.rvCommunity.scrollToPosition(POSITION_TOP) binding.swipeRefreshLayout.isRefreshing = false } @@ -190,7 +190,7 @@ internal class CommunityItemFragment : binding.swipeRefreshLayout.apply { setOnRefreshListener { postAdapter.refresh() - binding.rvCommunity.scrollToPosition(0) + binding.rvCommunity.scrollToPosition(POSITION_TOP) binding.swipeRefreshLayout.isRefreshing = false } @@ -221,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()