From e75469cf92971dda4acce8aa6c9efb44638eb3aa Mon Sep 17 00:00:00 2001 From: swit-jim Date: Fri, 15 Mar 2024 00:56:40 +0900 Subject: [PATCH] =?UTF-8?q?[feat/group=5Fselect]:=20=EB=B7=B0=20Visible=20?= =?UTF-8?q?=EC=A0=9C=EC=95=BD=20=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/view/home/HomeFragment.kt | 124 ++++++++---------- .../src/main/res/layout/fragment_home.xml | 83 ++++++------ 2 files changed, 100 insertions(+), 107 deletions(-) diff --git a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt index c3c9a7f7..051282dd 100644 --- a/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/view/home/HomeFragment.kt @@ -147,19 +147,6 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } - - private fun setRestaurantListBottomSheet() { - standardBottomSheetBehavior.addBottomSheetCallback( - object : BottomSheetBehavior.BottomSheetCallback() { - fun setBottomSheetRelatedView(isVisible: Boolean) { - binding.bottomSheetHandle.isVisible = isVisible - binding.bottomSheetHandleSpace.isVisible = isVisible - binding.mapOptionContainer.isVisible = isVisible - } - - setRestaurantListBottomSheet() - } - private fun setGroup() { binding.groupArrow.setOnClickListener { repeatWhenUiStarted { @@ -305,37 +292,38 @@ class HomeFragment : Fragment(), ViewHolderBindListener { standardBottomSheetBehavior.addBottomSheetCallback( object : BottomSheetBehavior.BottomSheetCallback() { - fun setBottomSheetRelatedView(isVisible: Boolean) { - binding.bottomSheetHandle.isVisible = isVisible - binding.bottomSheetHandleSpace.isVisible = isVisible - binding.mapOptionContainer.isVisible = isVisible + fun setBottomSheetRelatedView(isExpanded: Boolean) { + viewModel.currentGroup.value.let { + val isNotFullExpanded = isExpanded.not() || it == null || it.restaurantCnt == 0 + + with(binding) { + binding.bottomSheetActionButtons.isVisible = isExpanded && it != null && it.restaurantCnt != 0 + bottomSheetHandle.isVisible = isNotFullExpanded + bottomSheetHandleSpace.isVisible = isNotFullExpanded + mapOptionContainer.isVisible = isNotFullExpanded + groupHeader.elevation = if (isNotFullExpanded) 0F else 10F + bottomSheet.background = + ResourcesCompat.getDrawable( + resources, + if (isNotFullExpanded) + R.drawable.bg_bottom_sheet_top_round + else + R.color.white, + null + ) + + } + } } override fun onStateChanged(bottomSheet: View, newState: Int) { when (newState) { BottomSheetBehavior.STATE_EXPANDED -> { - binding.groupHeader.elevation = 10F - binding.bottomSheetActionButtons.isVisible = true - - setBottomSheetRelatedView(false) - binding.bottomSheet.background = ResourcesCompat.getDrawable( - resources, - R.color.white, - null - ) - } - BottomSheetBehavior.STATE_HALF_EXPANDED -> { - binding.mapOptionContainer.isVisible = true + setBottomSheetRelatedView(true) } BottomSheetBehavior.STATE_DRAGGING -> { - binding.groupHeader.elevation = 0F - setBottomSheetRelatedView(true) - binding.bottomSheet.background = ResourcesCompat.getDrawable( - resources, - R.drawable.bg_bottom_sheet_top_round, - null - ) + setBottomSheetRelatedView(false) } } } @@ -380,29 +368,9 @@ class HomeFragment : Fragment(), ViewHolderBindListener { is ResultState.OnSuccess -> { val groupList = state.response - if (groupList.isEmpty()) { + if (groupList.isNullOrEmpty()) { viewModel.setCurrentGroup(null) - } else { - groupList.forEach { - if (it.isSelected) { - viewModel.setCurrentGroup(it) - return@forEach - } - } - } - } - else -> {} - } - } - } - - repeatWhenUiStarted { - viewModel.currentGroup.collect { state -> - when(state) { - is ResultState.OnSuccess -> { - val group = state.response - if (group == null) { BottomSheetDialog(requireContext()) .bindBuilder( ContentSheetEmptyGroupBinding.inflate(LayoutInflater.from(requireContext())) @@ -420,25 +388,43 @@ class HomeFragment : Fragment(), ViewHolderBindListener { } } } else { - binding.groupHeader.isVisible = true - binding.groupName.text = group.groupName - binding.groupImage.apply { - Glide.with(this.context).load(group.groupProfileImageUrl) - .into(this) - invalidate() - } - - if (group.restaurantCnt == 0) { - - binding.recyclerView.isVisible = false - binding.registGroup.isVisible = true + groupList.forEach { + if (it.isSelected) { + viewModel.setCurrentGroup(it) + return@forEach + } } } } + else -> {} } } } + + repeatWhenUiStarted { + viewModel.currentGroup.collect { + if (it != null) { + binding.groupHeader.isVisible = true + binding.groupName.text = it.groupName + binding.groupImage.apply { + Glide.with(this.context).load(it.groupProfileImageUrl) + .into(this) + } + + if (it.restaurantCnt == 0) { + binding.bottomSheet.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT + binding.recyclerView.isVisible = false + binding.registLayout.isVisible = true + } else { + binding.bottomSheet.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT + binding.recyclerView.isVisible = true + binding.registLayout.isVisible = false + } + } + } + + } } override fun onDestroyView() { diff --git a/presentation/src/main/res/layout/fragment_home.xml b/presentation/src/main/res/layout/fragment_home.xml index 869f4f87..959a44f5 100644 --- a/presentation/src/main/res/layout/fragment_home.xml +++ b/presentation/src/main/res/layout/fragment_home.xml @@ -178,47 +178,54 @@ app:layout_constraintTop_toBottomOf="@+id/bottom_sheet_handle_space" app:layout_constraintBottom_toBottomOf="parent"/> - - - + android:gravity="center" + app:layout_constraintVertical_bias="0" + android:paddingBottom="@dimen/bottom_navigation_height_with_item" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + android:orientation="vertical"> - + - + + + +