Skip to content

Commit db72f11

Browse files
committed
Merge branch 'develop' into demo
# Conflicts: # presentation/src/main/java/com/stop/ui/route/RouteFragment.kt
2 parents 4fddf49 + dc25100 commit db72f11

File tree

9 files changed

+61
-20
lines changed

9 files changed

+61
-20
lines changed

โ€Ždata/src/main/java/com/stop/data/remote/model/route/gyeonggi/GyeonggiBusLastTimeResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import com.tickaroo.tikxml.annotation.Xml
88
internal data class GyeonggiBusLastTimeResponse(
99
@Path("msgBody")
1010
@Element(name = "busRouteInfoItem")
11-
val lastTimes: List<GyeonggiBusLastTime>
11+
val lastTimes: List<GyeonggiBusLastTime>?
1212
)

โ€Ždata/src/main/java/com/stop/data/remote/source/route/RouteRemoteDataSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ internal interface RouteRemoteDataSource {
2929

3030
suspend fun getSeoulBusStationArsId(stationName: String): List<BusStationInfo>
3131
suspend fun getSeoulBusRoute(stationId: String): List<BusRouteInfo>
32-
suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>
32+
suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>?
3333

3434
suspend fun getGyeonggiBusStationId(stationName: String): List<GyeonggiBusStation>
3535
suspend fun getGyeonggiBusRoute(stationId: String): List<GyeonggiBusRoute>
36-
suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>
36+
suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>?
3737
suspend fun getGyeonggiBusRouteStations(lineId: String): List<GyeonggiBusStation>
3838
}

โ€Ždata/src/main/java/com/stop/data/remote/source/route/RouteRemoteDataSourceImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal class RouteRemoteDataSourceImpl @Inject constructor(
140140
override suspend fun getSeoulBusLastTime(
141141
stationId: String,
142142
lineId: String
143-
): List<LastTimeInfo> {
143+
): List<LastTimeInfo>? {
144144
with(wsBusApiService.getBusLastTime(stationId, lineId)) {
145145
return when (this) {
146146
is NetworkResult.Success -> this.data.lastTimeMsgBody.lastTimes
@@ -173,10 +173,10 @@ internal class RouteRemoteDataSourceImpl @Inject constructor(
173173
}
174174
}
175175

176-
override suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime> {
176+
override suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>? {
177177
with(apisDataService.getBusLastTime(lineId)) {
178178
return when (this) {
179-
is NetworkResult.Success -> this.data.lastTimes.map { it.toDomain() }
179+
is NetworkResult.Success -> this.data.lastTimes?.map { it.toDomain() }
180180
is NetworkResult.Failure -> throw IllegalArgumentException(this.message)
181181
is NetworkResult.NetworkError -> throw this.exception
182182
is NetworkResult.Unexpected -> throw this.exception

โ€Ždata/src/main/java/com/stop/data/repository/RouteRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal class RouteRepositoryImpl @Inject constructor(
7676
return remoteDataSource.getSeoulBusRoute(stationId)
7777
}
7878

79-
override suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo> {
79+
override suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>? {
8080
return remoteDataSource.getSeoulBusLastTime(stationId, lineId)
8181
}
8282

@@ -88,7 +88,7 @@ internal class RouteRepositoryImpl @Inject constructor(
8888
return remoteDataSource.getGyeonggiBusRoute(stationId)
8989
}
9090

91-
override suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime> {
91+
override suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>? {
9292
return remoteDataSource.getGyeonggiBusLastTime(lineId)
9393
}
9494

โ€Ždomain/src/main/java/com/stop/domain/model/route/seoul/bus/LastTimeMsgBody.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import com.squareup.moshi.JsonClass
66
@JsonClass(generateAdapter = true)
77
data class LastTimeMsgBody(
88
@Json(name = "itemList")
9-
val lastTimes: List<LastTimeInfo>
9+
val lastTimes: List<LastTimeInfo>?
1010
)

โ€Ždomain/src/main/java/com/stop/domain/repository/RouteRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface RouteRepository {
3030

3131
suspend fun getSeoulBusStationArsId(stationName: String): List<BusStationInfo>
3232
suspend fun getSeoulBusRoute(stationId: String): List<BusRouteInfo>
33-
suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>
33+
suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>?
3434
suspend fun getSubwayRoute(
3535
routeRequest: RouteRequest,
3636
subwayLine: String,
@@ -40,6 +40,6 @@ interface RouteRepository {
4040

4141
suspend fun getGyeonggiBusStationId(stationName: String): List<GyeonggiBusStation>
4242
suspend fun getGyeonggiBusRoute(stationId: String): List<GyeonggiBusRoute>
43-
suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>
43+
suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>?
4444
suspend fun getGyeonggiBusRouteStations(lineId: String): List<GyeonggiBusStation>
4545
}

โ€Ždomain/src/main/java/com/stop/domain/usecase/route/GetLastTransportTimeUseCaseImpl.kt

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,44 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
299299
private suspend fun getSeoulBusLastTransportTime(
300300
transportIdRequest: TransportIdRequest
301301
): String {
302-
var lastTime = routeRepository.getSeoulBusLastTime(
302+
val lastTimes = routeRepository.getSeoulBusLastTime(
303303
transportIdRequest.stationId,
304304
transportIdRequest.routeId
305-
).first().lastTime?.toInt() ?: throw ApiServerDataException()
305+
) ?: return getRectifiedGyeonggiBusLastTransportTime(transportIdRequest)
306+
307+
var lastTime = lastTimes.first().lastTime?.toInt() ?: throw ApiServerDataException()
306308

307309
if (lastTime < MID_NIGHT) {
308310
lastTime += TIME_CORRECTION_VALUE
309311
}
310312
return lastTime.toString().chunked(2).joinToString(":")
311313
}
312314

315+
private suspend fun getRectifiedGyeonggiBusLastTransportTime(
316+
transportIdRequest: TransportIdRequest
317+
): String {
318+
var newTransportIdRequest = convertGyeonggiBusStationId(transportIdRequest)
319+
newTransportIdRequest = convertGyeonggiBusRouteId(newTransportIdRequest)
320+
321+
val lastTime = routeRepository.getGyeonggiBusLastTime(
322+
newTransportIdRequest.routeId
323+
)?.first() ?: throw ApiServerDataException()
324+
325+
val destinationIsLastStation = checkGyeonggiBusDestinationIsLastStation(newTransportIdRequest)
326+
327+
return if (destinationIsLastStation) {
328+
addSecondsFormat(lastTime.upLastTime)
329+
} else {
330+
addSecondsFormat(lastTime.downLastTime)
331+
}
332+
}
333+
313334
private suspend fun getGyeonggiBusLastTransportTime(
314335
transportIdRequest: TransportIdRequest
315336
): String {
316337
val lastTime = routeRepository.getGyeonggiBusLastTime(
317338
transportIdRequest.routeId
318-
).first()
339+
)?.first() ?: return getRectifiedSeoulBusLastTransportTime(transportIdRequest)
319340

320341
val destinationIsLastStation = checkGyeonggiBusDestinationIsLastStation(transportIdRequest)
321342

@@ -326,6 +347,25 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
326347
}
327348
}
328349

350+
private suspend fun getRectifiedSeoulBusLastTransportTime(
351+
transportIdRequest: TransportIdRequest
352+
) : String {
353+
var newTransportIdRequest = convertSeoulBusStationId(transportIdRequest)
354+
newTransportIdRequest = convertSeoulBusRouteId(newTransportIdRequest)
355+
356+
val lastTimes = routeRepository.getSeoulBusLastTime(
357+
newTransportIdRequest.stationId,
358+
newTransportIdRequest.routeId
359+
) ?: throw ApiServerDataException()
360+
361+
var lastTime = lastTimes.first().lastTime?.toInt() ?: throw ApiServerDataException()
362+
363+
if (lastTime < MID_NIGHT) {
364+
lastTime += TIME_CORRECTION_VALUE
365+
}
366+
return lastTime.toString().chunked(2).joinToString(":")
367+
}
368+
329369
private fun addSecondsFormat(time: String): String {
330370
return "$time:00"
331371
}

โ€Žpresentation/src/main/java/com/stop/ui/route/RouteFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ class RouteFragment : Fragment() {
9595
}
9696

9797
viewModel.lastTimeResponse.observe(viewLifecycleOwner) {
98-
binding.root.findNavController()
99-
.navigate(R.id.action_routeFragment_to_routeDetailFragment)
98+
it.getContentIfNotHandled()?.let {
99+
binding.root.findNavController().navigate(R.id.action_routeFragment_to_routeDetailFragment)
100+
}
100101
}
101102
}
102103

โ€Žpresentation/src/main/java/com/stop/ui/route/RouteViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class RouteViewModel @Inject constructor(
3535
val routeResponse: LiveData<List<Itinerary>>
3636
get() = _routeResponse
3737

38-
private val _lastTimeResponse = MutableLiveData<List<String?>>()
39-
val lastTimeResponse: LiveData<List<String?>>
38+
private val _lastTimeResponse = MutableLiveData<Event<List<String?>>>()
39+
val lastTimeResponse: LiveData<Event<List<String?>>>
4040
get() = _lastTimeResponse
4141

4242
private val _errorMessage = MutableLiveData<Event<ErrorType>>()
@@ -69,7 +69,7 @@ class RouteViewModel @Inject constructor(
6969
fun calculateLastTransportTime(itinerary: Itinerary) {
7070
checkClickedItinerary(itinerary)
7171
viewModelScope.launch {
72-
this@RouteViewModel._lastTimeResponse.value = getLastTransportTimeUseCase(itinerary)
72+
this@RouteViewModel._lastTimeResponse.value = Event(getLastTransportTimeUseCase(itinerary))
7373
}
7474
}
7575

@@ -90,7 +90,7 @@ class RouteViewModel @Inject constructor(
9090
val lastTimes = _lastTimeResponse.value ?: return "์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ ์‹œ์ ์— ๋ง‰์ฐจ ๋ฐ์ดํ„ฐ๊ฐ€ null์ธ ๋…ผ๋ฆฌ์  ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."
9191

9292
return clickedItinerary.routes.mapIndexed { index, route ->
93-
"${route.start.name}(${lastTimes[index]})"
93+
"${route.start.name}(${lastTimes.peekContent()[index]})"
9494
}.joinToString(" -> ")
9595
}
9696
}

0 commit comments

Comments
ย (0)