Skip to content

Commit c84f510

Browse files
authored
Merge pull request #87 from boostcampwm-2022/86-fix-map-fragment
[PR] Map Fragment ๋ฒ„๊ทธ ๋ฐ UI ์ˆ˜์ •
2 parents b1d27f5 + fbf414f commit c84f510

File tree

18 files changed

+162
-101
lines changed

18 files changed

+162
-101
lines changed

โ€Ž.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ render.experimental.xml
3131
*.keystore
3232

3333
# Google Services (e.g. APIs or Firebase)
34-
google-services.json
34+
presentation/google-services.json
3535

3636
# Android Profiling
3737
*.hprof

โ€Ždomain/src/main/java/com/stop/domain/model/geoLocation/GeoLocationInfo.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ data class GeoLocationInfo(
66
val lotAddress: String,
77
val distance: String
88
)
9+
10+
fun GeoLocationInfo.toClickedGeoLocationInfo(clickedPlaceName: String): GeoLocationInfo {
11+
return this.copy(
12+
title = clickedPlaceName
13+
)
14+
}

โ€Ždomain/src/main/java/com/stop/domain/usecase/geoLocation/GeoLocationUseCaseImpl.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@ package com.stop.domain.usecase.geoLocation
33
import com.stop.domain.model.geoLocation.AddressType
44
import com.stop.domain.model.geoLocation.GeoLocationInfo
55
import com.stop.domain.model.route.tmap.custom.Coordinate
6+
import com.stop.domain.model.route.tmap.origin.AddressInfo
67
import com.stop.domain.repository.RouteRepository
78
import javax.inject.Inject
89

910
class GeoLocationUseCaseImpl @Inject constructor(
1011
private val routeRepository: RouteRepository
1112
) : GeoLocationUseCase {
12-
1313
override suspend fun getGeoLocationInfo(lat: Double, lon: Double): GeoLocationInfo {
1414
val result = routeRepository.reverseGeocoding(
1515
Coordinate(lat.toString(), lon.toString()),
1616
AddressType.FULL_ADDRESS
1717
).addressInfo
18-
1918
val address = result.fullAddress.split(",").drop(1)
19+
2020
return GeoLocationInfo(
21-
title = result.buildingName,
21+
title = getTitle(result),
2222
roadAddress = address.first(),
2323
lotAddress = address.last().replace(result.buildingName, ""),
2424
distance = result.mappingDistance
2525
)
2626
}
27+
28+
private fun getTitle(result: AddressInfo): String {
29+
return if (result.buildingName != "") {
30+
result.buildingName
31+
} else {
32+
result.fullAddress.split(",").drop(1).first()
33+
}
34+
}
2735
}

โ€Žpresentation/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
android:launchMode="singleTask"
5151
android:screenOrientation="portrait"
5252
android:showOnLockScreen="true"
53+
android:configChanges="orientation|screenSize|keyboardHidden"
5354
android:theme="@style/Theme.Splash">
5455

5556
<intent-filter>

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

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import androidx.fragment.app.activityViewModels
1212
import androidx.lifecycle.asLiveData
1313
import androidx.lifecycle.flowWithLifecycle
1414
import androidx.lifecycle.lifecycleScope
15-
import androidx.navigation.findNavController
1615
import androidx.navigation.fragment.findNavController
1716
import com.google.android.material.bottomsheet.BottomSheetBehavior
1817
import com.skt.tmap.TMapPoint
@@ -44,7 +43,6 @@ class MapFragment : Fragment(), MapHandler {
4443
savedInstanceState: Bundle?
4544
): View {
4645
_binding = FragmentMapBinding.inflate(inflater, container, false)
47-
4846
initBinding()
4947

5048
return binding.root
@@ -54,34 +52,45 @@ class MapFragment : Fragment(), MapHandler {
5452
super.onViewCreated(view, savedInstanceState)
5553

5654
initTMap()
57-
initNavigateAction()
5855
initBottomSheetBehavior()
59-
listenButtonClick()
56+
initBottomSheetView()
6057
}
6158

6259
override fun alertTMapReady() {
6360
requestPermissionsLauncher.launch(PERMISSIONS)
6461

6562
tMap.initListener()
63+
initAfterTMapReady()
64+
}
65+
66+
private fun initAfterTMapReady() {
67+
initView()
68+
initNavigateAction()
6669
observeClickPlace()
6770
observeClickCurrentLocation()
6871
}
6972

7073
private fun initBinding() {
7174
alarmViewModel.getAlarm()
75+
7276
binding.lifecycleOwner = viewLifecycleOwner
7377
binding.alarmViewModel = alarmViewModel
7478
binding.placeSearchViewModel = placeSearchViewModel
7579
binding.fragment = this@MapFragment
7680
}
7781

7882
private fun initTMap() {
79-
tMap = MapTMap(requireActivity(), this)
80-
tMap.init()
81-
82-
binding.frameLayoutContainer.addView(tMap.tMapView)
83+
placeSearchViewModel.tMap?.let {
84+
tMap = it
85+
tMap.setHandler(this)
86+
initAfterTMapReady()
87+
} ?: run {
88+
tMap = MapTMap(requireActivity(), this)
89+
tMap.init()
90+
placeSearchViewModel.tMap = tMap
91+
}
8392

84-
initView()
93+
binding.layoutContainer.addView(tMap.tMapView)
8594
}
8695

8796
private fun initView() {
@@ -112,22 +121,27 @@ class MapFragment : Fragment(), MapHandler {
112121

113122
private fun initNavigateAction() {
114123
binding.textViewSearch.setOnClickListener {
115-
binding.root.findNavController()
116-
.navigate(R.id.action_mapFragment_to_placeSearchFragment)
124+
findNavController().navigate(R.id.action_mapFragment_to_placeSearchFragment)
117125
}
118126

119-
binding.layoutPanel.findViewById<View>(R.id.view_panel_start).setOnClickListener {
120-
val navController = findNavController()
121-
navController.setGraph(R.navigation.route_nav_graph)
122-
val action = RouteNavGraphDirections.actionGlobalRouteFragment().setStart(placeSearchViewModel.panelInfo)
123-
navController.navigate(action)
127+
binding.homePanel.viewPanelStart.setOnClickListener {
128+
findNavController().apply {
129+
setGraph(R.navigation.route_nav_graph)
130+
navigate(
131+
RouteNavGraphDirections.actionGlobalRouteFragment()
132+
.setStart(placeSearchViewModel.panelInfo)
133+
)
134+
}
124135
}
125136

126-
binding.layoutPanel.findViewById<View>(R.id.view_panel_end).setOnClickListener {
127-
val navController = findNavController()
128-
navController.setGraph(R.navigation.route_nav_graph)
129-
val action = RouteNavGraphDirections.actionGlobalRouteFragment().setEnd(placeSearchViewModel.panelInfo)
130-
navController.navigate(action)
137+
binding.homePanel.viewPanelEnd.setOnClickListener {
138+
findNavController().apply {
139+
setGraph(R.navigation.route_nav_graph)
140+
navigate(
141+
RouteNavGraphDirections.actionGlobalRouteFragment()
142+
.setEnd(placeSearchViewModel.panelInfo)
143+
)
144+
}
131145
}
132146
}
133147

@@ -164,22 +178,31 @@ class MapFragment : Fragment(), MapHandler {
164178
}
165179

166180
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
167-
168181
})
169182
}
170183

184+
private fun initBottomSheetView() {
185+
binding.homeBottomSheet.layoutStateExpanded.buttonAlarmTurnOff.setOnClickListener {
186+
val behavior = BottomSheetBehavior.from(binding.layoutHomeBottomSheet)
187+
188+
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
189+
alarmViewModel.deleteAlarm()
190+
}
191+
}
192+
171193
private fun observeClickPlace() {
172194
placeSearchViewModel.clickPlaceUseCaseItem.observe(viewLifecycleOwner) { event ->
173195
event.getContentIfNotHandled()?.let { clickPlace ->
174196
val clickTMapPoint = TMapPoint(clickPlace.centerLat, clickPlace.centerLon)
175197

198+
tMap.isTracking = false
176199
tMap.tMapView.setCenterPoint(
177200
clickTMapPoint.latitude,
178201
clickTMapPoint.longitude,
179202
true
180203
)
181204
tMap.addMarker(Marker.PLACE_MARKER, Marker.PLACE_MARKER_IMG, clickTMapPoint)
182-
setPanel(clickTMapPoint)
205+
setPanel(clickTMapPoint, true)
183206
}
184207
}
185208
}
@@ -193,27 +216,32 @@ class MapFragment : Fragment(), MapHandler {
193216
val currentTMapPoint =
194217
TMapPoint(currentLocation.latitude, currentLocation.longitude)
195218

219+
tMap.isTracking = false
196220
tMap.tMapView.setCenterPoint(
197221
currentTMapPoint.latitude,
198222
currentTMapPoint.longitude
199223
)
200224
tMap.addMarker(Marker.PLACE_MARKER, Marker.PLACE_MARKER_IMG, currentTMapPoint)
201-
setPanel(currentTMapPoint)
225+
setPanel(currentTMapPoint, false)
202226
}
203227
}
204228
}
205229

206-
override fun setPanel(tMapPoint: TMapPoint) {
207-
placeSearchViewModel.getGeoLocationInfo(tMapPoint.latitude, tMapPoint.longitude)
230+
override fun setPanel(tMapPoint: TMapPoint, isClickedFromPlaceSearch: Boolean) {
231+
placeSearchViewModel.getGeoLocationInfo(
232+
tMapPoint.latitude,
233+
tMapPoint.longitude,
234+
isClickedFromPlaceSearch
235+
)
208236
}
209237

210238
override fun setOnLocationChangeListener(location: android.location.Location) {
211239
placeSearchViewModel.currentLocation = Location(location.latitude, location.longitude)
212240
}
213241

214242
override fun setOnDisableScrollWIthZoomLevelListener() {
215-
if (binding.layoutPanel.visibility == View.VISIBLE) {
216-
binding.layoutPanel.visibility = View.GONE
243+
if (binding.homePanel.layoutPanel.visibility == View.VISIBLE) {
244+
binding.homePanel.layoutPanel.visibility = View.GONE
217245
tMap.tMapView.removeTMapMarkerItem(Marker.PLACE_MARKER)
218246
} else {
219247
setViewVisibility()
@@ -259,6 +287,8 @@ class MapFragment : Fragment(), MapHandler {
259287
}
260288

261289
override fun onDestroyView() {
290+
placeSearchViewModel.setPanelVisibility(binding.homePanel.layoutPanel.visibility)
291+
binding.layoutContainer.removeView(tMap.tMapView)
262292
_binding = null
263293

264294
super.onDestroyView()

โ€Žpresentation/src/main/java/com/stop/ui/map/MapHandler.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import com.skt.tmap.TMapPoint
44
import com.stop.ui.util.Handler
55

66
interface MapHandler : Handler {
7-
87
fun alertTMapReady()
98

109
fun setOnLocationChangeListener(location: android.location.Location)
1110

1211
fun setOnDisableScrollWIthZoomLevelListener()
1312

14-
fun setPanel(tMapPoint: TMapPoint)
15-
13+
fun setPanel(tMapPoint: TMapPoint, isClickedFromPlaceSearch: Boolean)
1614
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import com.stop.ui.util.TMap
1313

1414
class MapTMap(
1515
context: Context,
16-
private val handler: MapHandler,
16+
private var handler: MapHandler,
1717
) : TMap(context, handler) {
1818

1919
private val enablePoints = mutableSetOf<Location>()
2020
private var isLongClick = false
2121

22+
fun setHandler(handler: MapHandler) {
23+
this.handler = handler
24+
}
25+
2226
fun initListener() {
2327
tMapView.setOnClickListenerCallback(onClickListenerCallback)
2428
tMapView.setOnLongClickListenerCallback(onLongClickListenerCallback)
@@ -54,7 +58,7 @@ class MapTMap(
5458
isLongClick = true
5559
tMapView.setCenterPoint(tMapPoint.latitude, tMapPoint.longitude, true)
5660
addMarker(Marker.PLACE_MARKER, Marker.PLACE_MARKER_IMG, tMapPoint)
57-
handler.setPanel(tMapPoint)
61+
handler.setPanel(tMapPoint, false)
5862
}
5963

6064
private val onEnableScrollWithZoomLevelCallback =

โ€Žpresentation/src/main/java/com/stop/ui/placesearch/PlaceSearchViewModel.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
66
import androidx.lifecycle.ViewModel
77
import androidx.lifecycle.viewModelScope
88
import com.stop.domain.model.geoLocation.GeoLocationInfo
9+
import com.stop.domain.model.geoLocation.toClickedGeoLocationInfo
910
import com.stop.domain.model.nearplace.PlaceUseCaseItem
1011
import com.stop.domain.usecase.geoLocation.GeoLocationUseCase
1112
import com.stop.domain.usecase.nearplace.DeleteRecentPlaceSearchUseCase
@@ -15,6 +16,7 @@ import com.stop.domain.usecase.nearplace.InsertRecentPlaceSearchUseCase
1516
import com.stop.model.Event
1617
import com.stop.model.Location
1718
import com.stop.model.route.Coordinate
19+
import com.stop.ui.map.MapTMap
1820
import dagger.hilt.android.lifecycle.HiltViewModel
1921
import kotlinx.coroutines.Dispatchers
2022
import kotlinx.coroutines.channels.Channel
@@ -33,8 +35,9 @@ class PlaceSearchViewModel @Inject constructor(
3335
) : ViewModel() {
3436

3537
// ๊ธฐ๋ณธ ์ฃผ์†Œ๋กœ ์„œ์šธ์—ญ ์ฃผ์†Œ ์ง€์ •
38+
var tMap: MapTMap? = null
3639
var currentLocation = Location(37.553836, 126.969652)
37-
40+
var clickedPlaceName = ""
3841
var panelInfo: com.stop.model.route.Place? = null
3942

4043
private val _nearPlaces = MutableStateFlow<List<PlaceUseCaseItem>>(emptyList())
@@ -91,6 +94,7 @@ class PlaceSearchViewModel @Inject constructor(
9194

9295
fun setClickPlace(placeUseCaseItem: PlaceUseCaseItem) {
9396
_clickPlaceUseCaseItem.value = Event(placeUseCaseItem)
97+
clickedPlaceName = placeUseCaseItem.name
9498
}
9599

96100
fun setClickCurrentLocation() {
@@ -99,13 +103,19 @@ class PlaceSearchViewModel @Inject constructor(
99103
}
100104
}
101105

102-
fun getGeoLocationInfo(latitude: Double, longitude: Double) {
106+
fun getGeoLocationInfo(latitude: Double, longitude: Double, isClickedFromPlaceSearch: Boolean) {
103107
viewModelScope.launch {
104108
try {
105-
_geoLocation.value = geoLocationUseCase.getGeoLocationInfo(latitude, longitude)
109+
val geoLocationInfo = geoLocationUseCase.getGeoLocationInfo(latitude, longitude)
106110

107-
readySendValue(latitude, longitude)
111+
_geoLocation.value = if (isClickedFromPlaceSearch) {
112+
geoLocationInfo.toClickedGeoLocationInfo(clickedPlaceName)
113+
} else {
114+
geoLocationInfo
115+
}
108116
_panelVisibility.value = View.VISIBLE
117+
118+
readySendValue(latitude, longitude)
109119
getDistance(latitude, longitude)
110120
} catch (e: IllegalArgumentException) {
111121
errorMessageChannel.send(e.message ?: "something is wrong")
@@ -146,4 +156,7 @@ class PlaceSearchViewModel @Inject constructor(
146156
}
147157
}
148158

159+
fun setPanelVisibility(panelVisibility: Int) {
160+
_panelVisibility.value = panelVisibility
161+
}
149162
}

โ€Žpresentation/src/main/java/com/stop/ui/routedetail/RouteDetailAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class RouteDetailAdapter(
2020
) : RecyclerView.ViewHolder(binding.root) {
2121
fun bind(routeItem: RouteItem) {
2222
binding.routeItem = routeItem
23+
binding.executePendingBindings()
2324
}
2425
}
2526

@@ -28,6 +29,7 @@ class RouteDetailAdapter(
2829
) : RecyclerView.ViewHolder(binding.root) {
2930
fun bind(routeItem: RouteItem) {
3031
binding.routeItem = routeItem
32+
binding.executePendingBindings()
3133
}
3234
}
3335

@@ -36,6 +38,7 @@ class RouteDetailAdapter(
3638
) : RecyclerView.ViewHolder(binding.root) {
3739
fun bind(routeItem: RouteItem) {
3840
binding.routeItem = routeItem
41+
binding.executePendingBindings()
3942
}
4043
}
4144

โ€Žpresentation/src/main/java/com/stop/ui/routedetail/RouteDetailFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RouteDetailFragment : Fragment(), RouteDetailHandler {
6969
}
7070

7171
binding.routeDetailDrawer.viewAlarm.setOnClickListener {
72-
binding.root.findNavController().navigate(R.id.action_routeDetailFragment_to_alarmSetting)
72+
findNavController().navigate(R.id.action_routeDetailFragment_to_alarmSetting)
7373
}
7474

7575
binding.imageViewClose.setOnClickListener {

0 commit comments

Comments
ย (0)