Skip to content

Commit 6846b5a

Browse files
committed
refactor: MapFragment 리팩토링
1 parent bce6482 commit 6846b5a

File tree

9 files changed

+84
-93
lines changed

9 files changed

+84
-93
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ 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
11+
private val _isBottomSheetVisible = MutableLiveData(false)
12+
val isBottomSheetVisible: LiveData<Boolean> = _isBottomSheetVisible
1313

1414
init {
1515
_fakeAlarmUseCaseItem.value = AlarmUseCaseItem(
@@ -24,7 +24,7 @@ class AlarmViewModel : ViewModel() {
2424
}
2525

2626
fun setVisibility(input: Boolean) {
27-
_bottomSheetVisibility.value = input.not()
27+
_isBottomSheetVisible.value = input.not()
2828
}
2929
}
3030

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

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

33
import android.Manifest.permission
44
import android.os.Bundle
5-
import android.util.Log
65
import android.util.TypedValue
76
import android.view.LayoutInflater
87
import android.view.View
@@ -38,7 +37,6 @@ class MapFragment : Fragment(), MapHandler {
3837
savedInstanceState: Bundle?
3938
): View {
4039
_binding = FragmentMapBinding.inflate(inflater, container, false)
41-
4240
initBinding()
4341

4442
return binding.root
@@ -49,15 +47,23 @@ class MapFragment : Fragment(), MapHandler {
4947

5048
initTMap()
5149
initView()
52-
clickSearchButton()
53-
clickEndLocation()
50+
initNavigateAction()
5451
initBottomSheetBehavior()
5552
}
5653

54+
override fun alertTMapReady() {
55+
requestPermissionsLauncher.launch(PERMISSIONS)
56+
tMap.initListener()
57+
58+
addBookmarkMarker()
59+
observeClickPlace()
60+
observeClickCurrentLocation()
61+
}
62+
5763
private fun initBinding() {
5864
binding.lifecycleOwner = viewLifecycleOwner
59-
binding.placeSearchViewModel = placeSearchViewModel
6065
binding.alarmViewModel = alarmViewModel
66+
binding.placeSearchViewModel = placeSearchViewModel
6167
}
6268

6369
private fun initTMap() {
@@ -79,7 +85,7 @@ class MapFragment : Fragment(), MapHandler {
7985
placeSearchViewModel.currentLocation.longitude,
8086
true
8187
)
82-
tMap.makeMarker(
88+
tMap.addMarker(
8389
PERSON_MARKER,
8490
PERSON_MARKER_IMG,
8591
TMapPoint(
@@ -91,29 +97,37 @@ class MapFragment : Fragment(), MapHandler {
9197
}
9298

9399
binding.layoutBookmark.setOnClickListener {
94-
alarmViewModel.bottomSheetVisibility.value?.let {
100+
alarmViewModel.isBottomSheetVisible.value?.let {
95101
alarmViewModel.setVisibility(it)
96102
}
97103
}
98104
}
99105

100-
private fun clickSearchButton() {
106+
private fun initNavigateAction() {
101107
binding.textViewSearch.setOnClickListener {
102108
binding.root.findNavController().navigate(R.id.action_mapFragment_to_placeSearchFragment)
103109
}
104-
}
105110

106-
private fun clickEndLocation() {
107-
//binding.viewPanelEnd.setOnClickListener {
108-
// binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
109-
//}
111+
/*
112+
binding.layoutBookmark.setOnClickListener {
113+
binding.root.findNavController().navigate(R.id.action_mapFragment_to_bookMarkFragment)
114+
}
115+
*/
116+
117+
binding.layoutPanel.findViewById<View>(R.id.view_panel_start).setOnClickListener {
118+
binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
119+
}
120+
121+
binding.layoutPanel.findViewById<View>(R.id.view_panel_end).setOnClickListener {
122+
binding.root.findNavController().navigate(R.id.action_mapFragment_to_routeFragment)
123+
}
110124
}
111125

112126
private fun initBottomSheetBehavior() {
113127
val behavior = BottomSheetBehavior.from(binding.layoutHomeBottomSheet)
114128

115-
alarmViewModel.bottomSheetVisibility.observe(viewLifecycleOwner) {
116-
if (it) {
129+
alarmViewModel.isBottomSheetVisible.observe(viewLifecycleOwner) { isBottomSheetVisible ->
130+
if (isBottomSheetVisible) {
117131
behavior.state = BottomSheetBehavior.STATE_EXPANDED
118132
behavior.maxHeight = convertDpToPx(200)
119133
} else {
@@ -122,48 +136,24 @@ class MapFragment : Fragment(), MapHandler {
122136
}
123137
}
124138

125-
private fun setViewVisibility() {
126-
with(binding) {
127-
layoutSearch.visibility = mapUIVisibility
128-
layoutCompass.visibility = mapUIVisibility
129-
layoutCurrent.visibility = mapUIVisibility
130-
layoutBookmark.visibility = mapUIVisibility
131-
}
132-
}
133-
134-
private fun setBookmarkMarker() {
139+
private fun addBookmarkMarker() {
135140
placeSearchViewModel.bookmarks.forEachIndexed { index, location ->
136-
tMap.makeMarker(
141+
tMap.addMarker(
137142
index.toString(),
138143
BOOKMARK_MARKER_IMG,
139144
TMapPoint(location.latitude, location.longitude)
140145
)
141146
}
142147
}
143148

144-
private val requestPermissionsLauncher = registerForActivityResult(
145-
ActivityResultContracts.RequestMultiplePermissions()
146-
) { permissions ->
147-
if (permissions.entries.any { it.value }) {
148-
tMap.setTrackingMode()
149-
Log.d("MapFragment","setTrackingMode")
150-
}
151-
}
152-
153149
private fun observeClickPlace() {
154150
placeSearchViewModel.clickPlace.observe(viewLifecycleOwner) { event ->
155151
event.getContentIfNotHandled()?.let { clickPlace ->
156152
val clickTMapPoint = TMapPoint(clickPlace.centerLat, clickPlace.centerLon)
157153

158154
tMap.tMapView.setCenterPoint(clickTMapPoint.latitude, clickTMapPoint.longitude, true)
159-
155+
tMap.addMarker(PLACE_MARKER, PLACE_MARKER_IMG, clickTMapPoint)
160156
setPanel(clickTMapPoint)
161-
162-
tMap.makeMarker(
163-
PLACE_MARKER,
164-
PLACE_MARKER_IMG,
165-
clickTMapPoint
166-
)
167157
}
168158
}
169159
}
@@ -174,21 +164,32 @@ class MapFragment : Fragment(), MapHandler {
174164
.flowWithLifecycle(viewLifecycleOwner.lifecycle)
175165
.collect {
176166
val currentLocation = placeSearchViewModel.currentLocation
177-
val currentTmapPoint = TMapPoint(currentLocation.latitude, currentLocation.longitude)
178-
179-
tMap.tMapView.setCenterPoint(currentTmapPoint.latitude, currentTmapPoint.longitude)
180-
181-
setPanel(currentTmapPoint)
167+
val currentTMapPoint =
168+
TMapPoint(currentLocation.latitude, currentLocation.longitude)
182169

183-
tMap.makeMarker(
184-
PLACE_MARKER,
185-
PLACE_MARKER_IMG,
186-
currentTmapPoint
170+
tMap.tMapView.setCenterPoint(
171+
currentTMapPoint.latitude,
172+
currentTMapPoint.longitude
187173
)
174+
tMap.addMarker(PLACE_MARKER, PLACE_MARKER_IMG, currentTMapPoint)
175+
setPanel(currentTMapPoint)
188176
}
189177
}
190178
}
191179

180+
override fun setPanel(tMapPoint: TMapPoint) {
181+
placeSearchViewModel.getGeoLocationInfo(tMapPoint.latitude, tMapPoint.longitude)
182+
}
183+
184+
private fun setViewVisibility() {
185+
with(binding) {
186+
layoutSearch.visibility = mapUIVisibility
187+
layoutCompass.visibility = mapUIVisibility
188+
layoutCurrent.visibility = mapUIVisibility
189+
layoutBookmark.visibility = mapUIVisibility
190+
}
191+
}
192+
192193
private fun convertDpToPx(dp: Int): Int {
193194
return TypedValue.applyDimension(
194195
TypedValue.COMPLEX_UNIT_DIP,
@@ -197,23 +198,6 @@ class MapFragment : Fragment(), MapHandler {
197198
).toInt()
198199
}
199200

200-
override fun onDestroyView() {
201-
_binding = null
202-
203-
super.onDestroyView()
204-
}
205-
206-
override fun alertTMapReady() {
207-
requestPermissionsLauncher.launch(PERMISSIONS)
208-
209-
tMap.clickLocation()
210-
tMap.clickMap()
211-
setBookmarkMarker()
212-
213-
observeClickPlace()
214-
observeClickCurrentLocation()
215-
}
216-
217201
override fun setOnLocationChangeListener(location: android.location.Location) {
218202
placeSearchViewModel.currentLocation = Location(location.latitude, location.longitude)
219203
}
@@ -228,20 +212,30 @@ class MapFragment : Fragment(), MapHandler {
228212
}
229213
}
230214

231-
override fun setPanel(tMapPoint: TMapPoint) {
232-
placeSearchViewModel.getGeoLocationInfo(tMapPoint.latitude, tMapPoint.longitude)
215+
override fun onDestroyView() {
216+
_binding = null
217+
218+
super.onDestroyView()
219+
}
220+
221+
private val requestPermissionsLauncher = registerForActivityResult(
222+
ActivityResultContracts.RequestMultiplePermissions()
223+
) { permissions ->
224+
if (permissions.entries.any { it.value }) {
225+
tMap.setTrackingMode()
226+
}
233227
}
234228

235229
companion object {
236230
private const val PLACE_MARKER = "place_marker"
237-
private const val PLACE_MARKER_IMG = R.drawable.ic_point_marker
231+
private const val PLACE_MARKER_IMG = R.drawable.ic_place_marker
238232

239-
private const val PERSON_MARKER = "marker_person_pin"
233+
private const val PERSON_MARKER = "person_marker"
240234
private const val PERSON_MARKER_IMG = R.drawable.ic_person_marker
241235

242-
private const val SAME_POINT = 1
243-
val PERMISSIONS = arrayOf(permission.ACCESS_FINE_LOCATION, permission.ACCESS_COARSE_LOCATION)
244-
245236
private const val BOOKMARK_MARKER_IMG = R.drawable.ic_bookmark_marker
237+
238+
private val PERMISSIONS =
239+
arrayOf(permission.ACCESS_FINE_LOCATION, permission.ACCESS_COARSE_LOCATION)
246240
}
247241
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MapTMap(
1010
private val handler: MapHandler,
1111
) : TMap(context, handler) {
1212

13-
fun clickMap() {
13+
fun initListener() {
1414
val enablePoint = mutableSetOf<Location>()
1515
tMapView.setOnEnableScrollWithZoomLevelListener { _, centerPoint ->
1616
enablePoint.add(Location(centerPoint.latitude, centerPoint.longitude))
@@ -23,11 +23,9 @@ class MapTMap(
2323
}
2424
enablePoint.clear()
2525
}
26-
}
2726

28-
fun clickLocation() {
2927
tMapView.setOnLongClickListenerCallback { _, _, tMapPoint ->
30-
makeMarker(
28+
addMarker(
3129
PLACE_MARKER,
3230
PLACE_MARKER_IMG,
3331
tMapPoint
@@ -39,8 +37,8 @@ class MapTMap(
3937
}
4038

4139
companion object {
42-
private const val PLACE_MARKER = "marker"
43-
private const val PLACE_MARKER_IMG = R.drawable.ic_point_marker
40+
private const val PLACE_MARKER = "place_marker"
41+
private const val PLACE_MARKER_IMG = R.drawable.ic_place_marker
4442

4543
private const val SAME_POINT = 1
4644
}

presentation/src/main/java/com/stop/ui/mission/MissionFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.skt.tmap.TMapPoint
1515
import com.stop.R
1616
import com.stop.databinding.FragmentMissionBinding
1717
import com.stop.model.Location
18-
import com.stop.ui.map.MapFragment
1918
import dagger.hilt.android.AndroidEntryPoint
2019

2120
@AndroidEntryPoint
@@ -172,7 +171,7 @@ class MissionFragment : Fragment(), MissionHandler {
172171

173172
viewModel.busCurrentLocation = beforeLocation
174173

175-
tMap.makeMarker(
174+
tMap.addMarker(
176175
BUS_MARKER,
177176
BUS_MARKER_IMG,
178177
TMapPoint(nowLocation.latitude, nowLocation.longitude)

presentation/src/main/java/com/stop/ui/mission/MissionTMap.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MissionTMap(
3232
)
3333
PERSON_LINE_NUM += 1
3434

35-
makeMarker(PERSON_MARKER, PERSON_MARKER_IMG, mockLocation)
35+
addMarker(PERSON_MARKER, PERSON_MARKER_IMG, mockLocation)
3636
tMapView.setLocationPoint(mockLocation.latitude, mockLocation.longitude)
3737
}
3838

presentation/src/main/java/com/stop/ui/util/TMap.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ open class TMap(
6868

6969
tMapView.setLocationPoint(location.latitude, location.longitude)
7070

71-
makeMarker(
71+
addMarker(
7272
PERSON_MARKER,
7373
PERSON_MARKER_IMG,
7474
nowLocation
@@ -85,7 +85,7 @@ open class TMap(
8585
&& location.latitude > KOREA_LATITUDE_MIN && location.latitude < KOREA_LATITUDE_MAX
8686
}
8787

88-
fun makeMarker(id: String, icon: Int, location: TMapPoint) {
88+
fun addMarker(id: String, icon: Int, location: TMapPoint) {
8989
val marker = TMapMarkerItem().apply {
9090
this.id = id
9191
this.icon = ContextCompat.getDrawable(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
android:id="@+id/home_bottom_sheet_no_alarm"
3030
android:layout_width="match_parent"
3131
android:layout_height="wrap_content"
32-
android:visibility="@{alarmViewModel.bottomSheetVisibility ? View.GONE : View.VISIBLE}"
32+
android:visibility="@{alarmViewModel.isBottomSheetVisible ? View.GONE : View.VISIBLE}"
3333
app:layout_constraintTop_toBottomOf="@id/home_bottom_sheet_drag_handle">
3434

3535
<TextView

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
android:background="@drawable/background_panel">
1616

1717
<ImageView
18-
android:id="@+id/image_view_panel_point"
18+
android:id="@+id/image_view_panel_place"
1919
android:layout_width="30dp"
2020
android:layout_height="30dp"
2121
android:layout_marginStart="17dp"
2222
android:layout_marginTop="20dp"
2323
app:layout_constraintStart_toStartOf="parent"
2424
app:layout_constraintTop_toTopOf="parent"
25-
app:srcCompat="@drawable/ic_point_marker" />
25+
app:srcCompat="@drawable/ic_place_marker" />
2626

2727
<TextView
2828
android:id="@+id/text_view_panel_title"
@@ -37,7 +37,7 @@
3737
android:textSize="22sp"
3838
android:textColor="@color/white"
3939
android:gravity="center_vertical"
40-
app:layout_constraintStart_toEndOf="@id/image_view_panel_point"
40+
app:layout_constraintStart_toEndOf="@id/image_view_panel_place"
4141
app:layout_constraintEnd_toStartOf="@id/view_panel_bookmark"
4242
app:layout_constraintTop_toTopOf="parent"
4343
tools:text="성복역" />

0 commit comments

Comments
 (0)