Skip to content

Commit

Permalink
[feat/group_select]: 뷰 Visible 제약 조건 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-swit committed Mar 14, 2024
1 parent 980445e commit e75469c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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()))
Expand All @@ -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() {
Expand Down
83 changes: 45 additions & 38 deletions presentation/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,47 +178,54 @@
app:layout_constraintTop_toBottomOf="@+id/bottom_sheet_handle_space"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/regist_title"
style="@style/title_small_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="그룹에 맛집을 등록해 볼까요?"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/regist_sub_title"
style="@style/text_large_medium"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/regist_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="아직 등록된 맛집이 없어요"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regist_title"/>
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">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/regist_button"
style="@style/JmtButtonMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="맛집 등록하기"
android:paddingHorizontal="30dp"
android:paddingVertical="16dp"
app:layout_constraintTop_toBottomOf="@+id/regist_sub_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/regist_title"
style="@style/title_small_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="그룹에 맛집을 등록해 볼까요?"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<androidx.constraintlayout.widget.Group
android:id="@+id/regist_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="regist_title,regist_sub_title,regist_button"
android:visibility="gone"/>
<TextView
android:id="@+id/regist_sub_title"
style="@style/text_large_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="아직 등록된 맛집이 없어요"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regist_title"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/regist_button"
style="@style/JmtButtonMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="맛집 등록하기"
android:paddingHorizontal="30dp"
android:paddingVertical="16dp"
android:layout_marginBottom="@dimen/bottom_sheet_bottom_padding"
app:layout_constraintTop_toBottomOf="@+id/regist_sub_title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/scroll_up_button"
Expand Down

0 comments on commit e75469c

Please sign in to comment.