@@ -55,6 +55,10 @@ class MissionViewModel @Inject constructor(
55
55
val errorMessage: LiveData <Event <ErrorType >>
56
56
get() = _errorMessage
57
57
58
+ private val _transportIsArrived = MutableLiveData <Event <Boolean >>()
59
+ val transportIsArrived: LiveData <Event <Boolean >>
60
+ get() = _transportIsArrived
61
+
58
62
val leftMinute: LiveData <String > = Transformations .switchMap(estimatedTimeRemaining) {
59
63
MutableLiveData <String >().apply {
60
64
value = (it / TIME_UNIT ).toString().padStart(TIME_DIGIT , ' 0' )
@@ -80,8 +84,15 @@ class MissionViewModel @Inject constructor(
80
84
lateinit var startSubwayStation: String
81
85
82
86
init {
83
- getBusNowLocation()
84
- getSubwayRoute()
87
+ startMission()
88
+ }
89
+
90
+ fun startMission () {
91
+ val transportLastTime = _transportLastTime .value ? : return
92
+ when (transportLastTime.transportMoveType) {
93
+ TransportMoveType .BUS -> getBusNowLocation(transportLastTime)
94
+ TransportMoveType .SUBWAY -> getSubwayRoute()
95
+ }
85
96
}
86
97
87
98
fun setDestination (inputDestination : String ) {
@@ -121,20 +132,14 @@ class MissionViewModel @Inject constructor(
121
132
}
122
133
}
123
134
124
- private fun getBusNowLocation () {
125
- val lastTimeValue = _transportLastTime .value
126
- if (lastTimeValue == null ) {
127
- _errorMessage .value = Event (ErrorType .TRANSPORT_LAST_TIME_IS_NOT_RECEIVED_YET )
128
- throw AlreadyHandledException ()
129
- }
130
-
135
+ private fun getBusNowLocation (transportLastTime : TransportLastTime ) {
131
136
viewModelScope.launch {
132
137
/* *
133
138
* 이 작업은 알람 화면에서 진행되고,
134
139
* 탑승해야 하는 버스 아이디 1개만 전해줍니다.
135
140
* 여기서는 임의로 중간에 있는 버스를 선택했습니다.
136
141
*/
137
- var busVehicleIds = getBusesOnRouteUseCase(lastTimeValue )
142
+ var busVehicleIds = getBusesOnRouteUseCase(transportLastTime )
138
143
if (busVehicleIds.isEmpty()) {
139
144
_errorMessage .value = Event (ErrorType .AVAILABLE_BUS_NO_EXIST_YET )
140
145
throw AlreadyHandledException ()
@@ -162,12 +167,17 @@ class MissionViewModel @Inject constructor(
162
167
}
163
168
delay(5000 )
164
169
}
165
- _errorMessage .value = Event (ErrorType .MISSION_SOMETHING_WRONG )
170
+ val transportIsArrived = _transportIsArrived .value?.peekContent()
171
+ if (transportIsArrived != true ) {
172
+ _errorMessage .value = Event (ErrorType .MISSION_SOMETHING_WRONG )
173
+ return @launch
174
+ }
166
175
}
167
176
}
168
177
169
178
// TODO: 버스가 도착했을 때 처리하기
170
179
private fun busArrivedAtDestination () {
180
+ _transportIsArrived .value = Event (true )
171
181
}
172
182
173
183
private suspend fun getSubwayTrainNowLocation (): TrainLocationInfoDomain {
@@ -226,9 +236,6 @@ class MissionViewModel @Inject constructor(
226
236
private const val RANDOM_LIMIT = 5
227
237
private const val ZERO = 0
228
238
229
- private const val TEST_BUS_540_ROUTE_ID = " 100100083"
230
- private var TIME_TEST = 0
231
-
232
239
private const val TEST_SUBWAY_LINE_NUMBER = 4
233
240
private const val LINE = " 호선" // 임시로.. 종성님이 어떻게 넘겨주시느냐에 따라 달림
234
241
0 commit comments