@@ -2,7 +2,6 @@ package com.stop.ui.map
2
2
3
3
import android.Manifest.permission
4
4
import android.os.Bundle
5
- import android.util.Log
6
5
import android.util.TypedValue
7
6
import android.view.LayoutInflater
8
7
import android.view.View
@@ -38,7 +37,6 @@ class MapFragment : Fragment(), MapHandler {
38
37
savedInstanceState : Bundle ?
39
38
): View {
40
39
_binding = FragmentMapBinding .inflate(inflater, container, false )
41
-
42
40
initBinding()
43
41
44
42
return binding.root
@@ -49,15 +47,23 @@ class MapFragment : Fragment(), MapHandler {
49
47
50
48
initTMap()
51
49
initView()
52
- clickSearchButton()
53
- clickEndLocation()
50
+ initNavigateAction()
54
51
initBottomSheetBehavior()
55
52
}
56
53
54
+ override fun alertTMapReady () {
55
+ requestPermissionsLauncher.launch(PERMISSIONS )
56
+ tMap.initListener()
57
+
58
+ addBookmarkMarker()
59
+ observeClickPlace()
60
+ observeClickCurrentLocation()
61
+ }
62
+
57
63
private fun initBinding () {
58
64
binding.lifecycleOwner = viewLifecycleOwner
59
- binding.placeSearchViewModel = placeSearchViewModel
60
65
binding.alarmViewModel = alarmViewModel
66
+ binding.placeSearchViewModel = placeSearchViewModel
61
67
}
62
68
63
69
private fun initTMap () {
@@ -79,7 +85,7 @@ class MapFragment : Fragment(), MapHandler {
79
85
placeSearchViewModel.currentLocation.longitude,
80
86
true
81
87
)
82
- tMap.makeMarker (
88
+ tMap.addMarker (
83
89
PERSON_MARKER ,
84
90
PERSON_MARKER_IMG ,
85
91
TMapPoint (
@@ -91,29 +97,37 @@ class MapFragment : Fragment(), MapHandler {
91
97
}
92
98
93
99
binding.layoutBookmark.setOnClickListener {
94
- alarmViewModel.bottomSheetVisibility .value?.let {
100
+ alarmViewModel.isBottomSheetVisible .value?.let {
95
101
alarmViewModel.setVisibility(it)
96
102
}
97
103
}
98
104
}
99
105
100
- private fun clickSearchButton () {
106
+ private fun initNavigateAction () {
101
107
binding.textViewSearch.setOnClickListener {
102
108
binding.root.findNavController().navigate(R .id.action_mapFragment_to_placeSearchFragment)
103
109
}
104
- }
105
110
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
+ }
110
124
}
111
125
112
126
private fun initBottomSheetBehavior () {
113
127
val behavior = BottomSheetBehavior .from(binding.layoutHomeBottomSheet)
114
128
115
- alarmViewModel.bottomSheetVisibility .observe(viewLifecycleOwner) {
116
- if (it ) {
129
+ alarmViewModel.isBottomSheetVisible .observe(viewLifecycleOwner) { isBottomSheetVisible ->
130
+ if (isBottomSheetVisible ) {
117
131
behavior.state = BottomSheetBehavior .STATE_EXPANDED
118
132
behavior.maxHeight = convertDpToPx(200 )
119
133
} else {
@@ -122,48 +136,24 @@ class MapFragment : Fragment(), MapHandler {
122
136
}
123
137
}
124
138
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 () {
135
140
placeSearchViewModel.bookmarks.forEachIndexed { index, location ->
136
- tMap.makeMarker (
141
+ tMap.addMarker (
137
142
index.toString(),
138
143
BOOKMARK_MARKER_IMG ,
139
144
TMapPoint (location.latitude, location.longitude)
140
145
)
141
146
}
142
147
}
143
148
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
-
153
149
private fun observeClickPlace () {
154
150
placeSearchViewModel.clickPlace.observe(viewLifecycleOwner) { event ->
155
151
event.getContentIfNotHandled()?.let { clickPlace ->
156
152
val clickTMapPoint = TMapPoint (clickPlace.centerLat, clickPlace.centerLon)
157
153
158
154
tMap.tMapView.setCenterPoint(clickTMapPoint.latitude, clickTMapPoint.longitude, true )
159
-
155
+ tMap.addMarker( PLACE_MARKER , PLACE_MARKER_IMG , clickTMapPoint)
160
156
setPanel(clickTMapPoint)
161
-
162
- tMap.makeMarker(
163
- PLACE_MARKER ,
164
- PLACE_MARKER_IMG ,
165
- clickTMapPoint
166
- )
167
157
}
168
158
}
169
159
}
@@ -174,21 +164,32 @@ class MapFragment : Fragment(), MapHandler {
174
164
.flowWithLifecycle(viewLifecycleOwner.lifecycle)
175
165
.collect {
176
166
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)
182
169
183
- tMap.makeMarker(
184
- PLACE_MARKER ,
185
- PLACE_MARKER_IMG ,
186
- currentTmapPoint
170
+ tMap.tMapView.setCenterPoint(
171
+ currentTMapPoint.latitude,
172
+ currentTMapPoint.longitude
187
173
)
174
+ tMap.addMarker(PLACE_MARKER , PLACE_MARKER_IMG , currentTMapPoint)
175
+ setPanel(currentTMapPoint)
188
176
}
189
177
}
190
178
}
191
179
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
+
192
193
private fun convertDpToPx (dp : Int ): Int {
193
194
return TypedValue .applyDimension(
194
195
TypedValue .COMPLEX_UNIT_DIP ,
@@ -197,23 +198,6 @@ class MapFragment : Fragment(), MapHandler {
197
198
).toInt()
198
199
}
199
200
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
-
217
201
override fun setOnLocationChangeListener (location : android.location.Location ) {
218
202
placeSearchViewModel.currentLocation = Location (location.latitude, location.longitude)
219
203
}
@@ -228,20 +212,30 @@ class MapFragment : Fragment(), MapHandler {
228
212
}
229
213
}
230
214
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
+ }
233
227
}
234
228
235
229
companion object {
236
230
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
238
232
239
- private const val PERSON_MARKER = " marker_person_pin "
233
+ private const val PERSON_MARKER = " person_marker "
240
234
private const val PERSON_MARKER_IMG = R .drawable.ic_person_marker
241
235
242
- private const val SAME_POINT = 1
243
- val PERMISSIONS = arrayOf(permission.ACCESS_FINE_LOCATION , permission.ACCESS_COARSE_LOCATION )
244
-
245
236
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 )
246
240
}
247
241
}
0 commit comments