Skip to content

Commit 8fd31c4

Browse files
committed
feat: home_bottom_sheet 기본 behavior 설정
1 parent a0325ed commit 8fd31c4

File tree

7 files changed

+100
-37
lines changed

7 files changed

+100
-37
lines changed

presentation/src/main/java/com/stop/ui/alarmsetting/AlarmViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class AlarmViewModel : ViewModel() {
88
private val _fakeAlarmUseCaseItem = MutableLiveData<AlarmUseCaseItem>()
99
val fakeAlarmUseCaseItem: LiveData<AlarmUseCaseItem> = _fakeAlarmUseCaseItem
1010

11+
private val _bottomSheetVisibility = MutableLiveData(false)
12+
val bottomSheetVisibility: LiveData<Boolean> = _bottomSheetVisibility
13+
1114
init {
1215
_fakeAlarmUseCaseItem.value = AlarmUseCaseItem(
1316
startPosition = "성복역 신분당선",
@@ -19,6 +22,10 @@ class AlarmViewModel : ViewModel() {
1922
isMission = true
2023
)
2124
}
25+
26+
fun setVisibility(input: Boolean) {
27+
_bottomSheetVisibility.value = input.not()
28+
}
2229
}
2330

2431
data class AlarmUseCaseItem(

presentation/src/main/java/com/stop/ui/map/MapFragment.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.stop.ui.map
22

33
import android.Manifest.permission
44
import android.os.Bundle
5+
import android.util.TypedValue
56
import android.view.LayoutInflater
67
import android.view.View
78
import android.view.ViewGroup
@@ -13,6 +14,7 @@ import androidx.fragment.app.activityViewModels
1314
import androidx.lifecycle.flowWithLifecycle
1415
import androidx.lifecycle.lifecycleScope
1516
import androidx.navigation.findNavController
17+
import com.google.android.material.bottomsheet.BottomSheetBehavior
1618
import com.skt.tmap.TMapGpsManager
1719
import com.skt.tmap.TMapPoint
1820
import com.skt.tmap.TMapView
@@ -54,6 +56,7 @@ class MapFragment : Fragment() {
5456
initView()
5557
initNavigateAction()
5658
initTMap()
59+
initBottomSheetBehavior()
5760
}
5861

5962
private fun initBinding() {
@@ -76,6 +79,12 @@ class MapFragment : Fragment() {
7679
true
7780
)
7881
}
82+
83+
binding.layoutBookmark.setOnClickListener {
84+
alarmViewModel.bottomSheetVisibility.value?.let {
85+
alarmViewModel.setVisibility(it)
86+
}
87+
}
7988
}
8089

8190
private fun initNavigateAction() {
@@ -84,9 +93,11 @@ class MapFragment : Fragment() {
8493
.navigate(R.id.action_mapFragment_to_placeSearchFragment)
8594
}
8695

96+
/*
8797
binding.layoutBookmark.setOnClickListener {
8898
binding.root.findNavController().navigate(R.id.action_mapFragment_to_bookMarkFragment)
8999
}
100+
*/
90101

91102
/*
92103
binding.textViewStartLocation.setOnClickListener {
@@ -117,6 +128,19 @@ class MapFragment : Fragment() {
117128
binding.frameLayoutContainer.addView(tMapView)
118129
}
119130

131+
private fun initBottomSheetBehavior() {
132+
val behavior = BottomSheetBehavior.from(binding.layoutHomeBottomSheet)
133+
134+
alarmViewModel.bottomSheetVisibility.observe(viewLifecycleOwner) {
135+
if (it) {
136+
behavior.state = BottomSheetBehavior.STATE_EXPANDED
137+
behavior.maxHeight = convertDpToPx(200)
138+
} else {
139+
behavior.maxHeight = convertDpToPx(100)
140+
}
141+
}
142+
}
143+
120144
private fun setTrackingMode() {
121145
val manager = TMapGpsManager(requireContext()).apply {
122146
minDistance = TMAP_MIN_DISTANCE
@@ -199,14 +223,22 @@ class MapFragment : Fragment() {
199223
View.GONE
200224
}
201225

202-
with (binding) {
226+
with(binding) {
203227
layoutSearch.visibility = viewVisibility
204228
layoutCompass.visibility = viewVisibility
205229
layoutCurrent.visibility = viewVisibility
206230
layoutBookmark.visibility = viewVisibility
207231
}
208232
}
209233

234+
private fun convertDpToPx(dp: Int): Int {
235+
return TypedValue.applyDimension(
236+
TypedValue.COMPLEX_UNIT_DIP,
237+
dp.toFloat(),
238+
resources.displayMetrics
239+
).toInt()
240+
}
241+
210242
private val requestPermissionsLauncher = registerForActivityResult(
211243
ActivityResultContracts.RequestMultiplePermissions()
212244
) { permissions ->

presentation/src/main/res/layout/fragment_map.xml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<layout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools">
4+
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:bind="http://schemas.android.com/apk/res-auto">
56

67
<data>
78
<variable
@@ -45,13 +46,6 @@
4546
android:orientation="horizontal"
4647
app:layout_constraintGuide_end="115dp" />
4748

48-
<androidx.constraintlayout.widget.Guideline
49-
android:id="@+id/guideline_panel"
50-
android:layout_width="wrap_content"
51-
android:layout_height="wrap_content"
52-
android:orientation="horizontal"
53-
app:layout_constraintGuide_percent="0.25" />
54-
5549
<FrameLayout
5650
android:id="@+id/frame_layout_container"
5751
android:layout_width="match_parent"
@@ -158,11 +152,12 @@
158152
android:id="@+id/text_view_panel_distance_km"
159153
android:layout_width="wrap_content"
160154
android:layout_height="wrap_content"
161-
android:layout_marginStart="7dp"
155+
android:layout_marginStart="10dp"
162156
android:layout_marginBottom="22dp"
163157
android:text="@string/km"
164158
android:textSize="20sp"
165159
android:textColor="@color/white"
160+
android:textStyle="bold"
166161
app:layout_constraintStart_toEndOf="@id/text_view_panel_distance"
167162
app:layout_constraintBottom_toBottomOf="parent"
168163
tools:text="km" />
@@ -308,12 +303,23 @@
308303
<androidx.coordinatorlayout.widget.CoordinatorLayout
309304
android:layout_width="match_parent"
310305
android:layout_height="match_parent"
311-
android:elevation="20dp" >
306+
android:elevation="20dp">
312307

313-
<include
314-
android:id="@+id/home_bottom_sheet"
315-
layout="@layout/home_bottom_sheet" />
308+
<androidx.constraintlayout.widget.ConstraintLayout
309+
android:id="@+id/layout_home_bottom_sheet"
310+
android:layout_width="match_parent"
311+
android:layout_height="match_parent"
312+
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
313+
app:behavior_peekHeight="100dp"
314+
app:behavior_hideable="false">
315+
316+
<include
317+
android:id="@+id/home_bottom_sheet"
318+
layout="@layout/home_bottom_sheet"
319+
bind:alarmViewModel="@{alarmViewModel}"
320+
tools:layout_editor_absoluteX="0dp"
321+
tools:layout_editor_absoluteY="16dp" />
322+
</androidx.constraintlayout.widget.ConstraintLayout>
316323
</androidx.coordinatorlayout.widget.CoordinatorLayout>
317324
</androidx.constraintlayout.widget.ConstraintLayout>
318-
</layout>
319-
325+
</layout>
Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout
2+
<layout xmlns:tools="http://schemas.android.com/tools"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto">
55

6+
<data>
7+
<import type="android.view.View"/>
8+
9+
<variable
10+
name="alarmViewModel"
11+
type="com.stop.ui.alarmsetting.AlarmViewModel" />
12+
</data>
13+
614
<androidx.constraintlayout.widget.ConstraintLayout
715
android:layout_width="match_parent"
816
android:layout_height="match_parent"
9-
android:background="@drawable/background_bottom_sheet"
10-
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
11-
app:behavior_peekHeight="100dp"
12-
app:behavior_hideable="false">
17+
android:background="@drawable/background_bottom_sheet">
1318

14-
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
15-
android:id="@+id/drag_handle"
16-
android:layout_width="wrap_content"
17-
android:layout_height="wrap_content"
19+
<View
20+
android:id="@+id/home_bottom_sheet_drag_handle"
21+
android:layout_width="35dp"
22+
android:layout_height="5dp"
23+
android:layout_marginTop="17dp"
24+
android:background="@drawable/background_panel"
1825
app:layout_constraintStart_toStartOf="parent"
1926
app:layout_constraintEnd_toEndOf="parent"
2027
app:layout_constraintTop_toTopOf="parent" />
2128

22-
<TextView
23-
android:id="@+id/textView"
24-
android:layout_width="wrap_content"
29+
<androidx.constraintlayout.widget.ConstraintLayout
30+
android:id="@+id/home_bottom_sheet_no_alarm"
31+
android:layout_width="match_parent"
2532
android:layout_height="wrap_content"
26-
android:layout_marginTop="25dp"
27-
android:text="현재 등록된 막차 알림이 없습니다."
28-
android:textSize="15sp"
29-
android:textColor="#808590"
30-
app:layout_constraintStart_toStartOf="parent"
31-
app:layout_constraintEnd_toEndOf="parent"
32-
app:layout_constraintTop_toTopOf="parent" />
33+
android:visibility="@{alarmViewModel.bottomSheetVisibility ? View.GONE : View.VISIBLE}"
34+
app:layout_constraintTop_toBottomOf="@id/home_bottom_sheet_drag_handle">
35+
36+
<TextView
37+
android:id="@+id/textView"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_marginTop="25dp"
41+
android:layout_marginBottom="25dp"
42+
android:text="@string/no_alarm"
43+
android:textColor="#808590"
44+
android:textSize="15sp"
45+
app:layout_constraintEnd_toEndOf="parent"
46+
app:layout_constraintStart_toStartOf="parent"
47+
app:layout_constraintTop_toTopOf="parent"
48+
app:layout_constraintBottom_toBottomOf="parent"/>
49+
</androidx.constraintlayout.widget.ConstraintLayout>
3350
</androidx.constraintlayout.widget.ConstraintLayout>
3451
</layout>

presentation/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
<color name="light_grey">#D3CCCC</color>
1212
<color name="gray_d9">#D9D9D9</color>
13+
<color name="main_dark_grey">#404550</color>
14+
<color name="main_light_grey">#808590</color>
1315
</resources>

presentation/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
<string name="plus">+</string>
2222
<string name="search_hint">장소, 주소 검색</string>
2323
<string name="km">km</string>
24+
<string name="no_alarm">현재 등록된 막차 알림이 없습니다.</string>
2425
</resources>

presentation/src/main/res/values/themes.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<item name="colorSecondaryVariant">@color/teal_700</item>
1111
<item name="colorOnSecondary">@color/black</item>
1212
<!-- Status bar color. -->
13-
<item name="android:windowTranslucentStatus">true</item>
14-
<item name="android:windowTranslucentNavigation">true</item>
1513
<item name="android:windowLightStatusBar">true</item>
1614
<!-- Customize your theme here. -->
1715
</style>

0 commit comments

Comments
 (0)