Skip to content

Commit c4ec36f

Browse files
committed
style : flow 수정
1 parent e6f6a63 commit c4ec36f

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.stop.model.Location
2323
import com.stop.ui.alarmsetting.AlarmSettingViewModel
2424
import com.stop.ui.util.Marker
2525
import dagger.hilt.android.AndroidEntryPoint
26-
import kotlinx.coroutines.flow.collectLatest
26+
import kotlinx.coroutines.flow.collectIndexed
2727
import kotlinx.coroutines.launch
2828

2929
@AndroidEntryPoint
@@ -62,6 +62,7 @@ class MissionFragment : Fragment(), MissionHandler {
6262
_binding = null
6363

6464
super.onDestroyView()
65+
Log.d("MissionWorker","onDestroyView")
6566
}
6667

6768
private fun setDataBinding() {
@@ -135,28 +136,20 @@ class MissionFragment : Fragment(), MissionHandler {
135136
}
136137

137138
private fun drawPersonLine() {
138-
var first = 0
139139
lateinit var beforeLocation: Location
140140
lifecycleScope.launch {
141-
missionViewModel.userLocation.collect { userLocation ->
142-
when (first) {
143-
0 -> {
144-
first += 1
145-
}
146-
1 -> {
147-
initMarker(userLocation)
148-
beforeLocation = userLocation
149-
first += 1
150-
}
151-
else -> {
152-
drawNowLocationLine(TMapPoint(userLocation.latitude, userLocation.longitude), TMapPoint(beforeLocation.latitude, beforeLocation.longitude))
153-
personCurrentLocation = userLocation
154-
if (tMap.isTracking) {
155-
tMap.tMapView.setCenterPoint(userLocation.latitude, userLocation.longitude)
156-
}
157-
beforeLocation = userLocation
158-
arriveDestination(userLocation.latitude, userLocation.longitude)
141+
missionViewModel.userLocation.collectIndexed { index, userLocation ->
142+
if (index == 1) {
143+
initMarker(userLocation)
144+
beforeLocation = userLocation
145+
} else {
146+
drawNowLocationLine(TMapPoint(userLocation.latitude, userLocation.longitude), TMapPoint(beforeLocation.latitude, beforeLocation.longitude))
147+
personCurrentLocation = userLocation
148+
if (tMap.isTracking) {
149+
tMap.tMapView.setCenterPoint(userLocation.latitude, userLocation.longitude)
159150
}
151+
beforeLocation = userLocation
152+
arriveDestination(userLocation.latitude, userLocation.longitude)
160153
}
161154
}
162155
}
@@ -280,7 +273,7 @@ class MissionFragment : Fragment(), MissionHandler {
280273

281274
private fun setMissionOver() {
282275
lifecycleScope.launch {
283-
missionViewModel.isMissionOver.collectLatest { isMissionOver ->
276+
missionViewModel.isMissionOver.collect { isMissionOver ->
284277
if (isMissionOver) {
285278
missionViewModel.cancelMission()
286279
alarmSettingViewModel.deleteAlarm()

0 commit comments

Comments
 (0)