Skip to content

Commit 2b6297e

Browse files
committed
refactor: MapTMap 객체를 재생성하지 않도록 변경
1 parent 4ec0ace commit 2b6297e

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class MapFragment : Fragment(), MapHandler {
5252
initNavigateAction()
5353
initBottomSheetBehavior()
5454
initBottomSheetView()
55+
56+
observeClickPlace()
57+
observeClickCurrentLocation()
5558
}
5659

5760
override fun alertTMapReady() {
5861
requestPermissionsLauncher.launch(PERMISSIONS)
59-
6062
tMap.initListener()
61-
observeClickPlace()
62-
observeClickCurrentLocation()
6363
}
6464

6565
private fun initBinding() {
@@ -69,8 +69,14 @@ class MapFragment : Fragment(), MapHandler {
6969
}
7070

7171
private fun initTMap() {
72-
tMap = MapTMap(requireActivity(), this)
73-
tMap.init()
72+
placeSearchViewModel.tMap?.let {
73+
tMap = it
74+
tMap.setHandler(this)
75+
} ?: run {
76+
tMap = MapTMap(requireActivity(), this)
77+
tMap.init()
78+
placeSearchViewModel.tMap = tMap
79+
}
7480

7581
binding.layoutContainer.addView(tMap.tMapView)
7682
}
@@ -232,6 +238,7 @@ class MapFragment : Fragment(), MapHandler {
232238
}
233239

234240
override fun onDestroyView() {
241+
binding.layoutContainer.removeView(tMap.tMapView)
235242
_binding = null
236243

237244
super.onDestroyView()

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

Lines changed: 5 additions & 1 deletion
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)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.stop.domain.usecase.nearplace.InsertRecentPlaceSearchUseCase
1515
import com.stop.model.Event
1616
import com.stop.model.Location
1717
import com.stop.model.route.Coordinate
18+
import com.stop.ui.map.MapTMap
1819
import dagger.hilt.android.lifecycle.HiltViewModel
1920
import kotlinx.coroutines.Dispatchers
2021
import kotlinx.coroutines.channels.Channel
@@ -37,6 +38,8 @@ class PlaceSearchViewModel @Inject constructor(
3738

3839
var panelInfo: com.stop.model.route.Place? = null
3940

41+
var tMap: MapTMap? = null
42+
4043
private val _nearPlaces = MutableStateFlow<List<PlaceUseCaseItem>>(emptyList())
4144
val nearPlaces: StateFlow<List<PlaceUseCaseItem>> = _nearPlaces
4245

0 commit comments

Comments
 (0)