Zatrzymaj aktywny kurs po wygaśnięciu sesji
This commit is contained in:
@@ -67,9 +67,11 @@ class RoutePointWorker(
|
||||
"retryable" to error.retryable,
|
||||
),
|
||||
)
|
||||
if (shouldStopRouteTrackingAfterPointError(error.kind, error.code)) {
|
||||
ActiveRouteTrackingService.stop(applicationContext, routeId)
|
||||
}
|
||||
if (isInactiveRoutePointError(error.code)) {
|
||||
dao.delete(pointIds)
|
||||
ActiveRouteTrackingService.stop(applicationContext, routeId)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -105,3 +107,6 @@ class RoutePointWorker(
|
||||
}
|
||||
|
||||
internal fun isInactiveRoutePointError(code: String?): Boolean = code == "ROUTE_POINTS_INVALID_STATUS"
|
||||
|
||||
internal fun shouldStopRouteTrackingAfterPointError(kind: ApiErrorKind, code: String?): Boolean =
|
||||
kind == ApiErrorKind.Auth || isInactiveRoutePointError(code)
|
||||
|
||||
@@ -136,6 +136,13 @@ class ActiveRouteTrackingService : Service(), LocationListener {
|
||||
|
||||
override fun onDestroy() {
|
||||
runCatching { locationManager.removeUpdates(this) }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
stopForeground(true)
|
||||
}
|
||||
getSystemService(NotificationManager::class.java).cancel(NOTIFICATION_ID)
|
||||
getSharedPreferences(TRACKING_PREFERENCES, Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.remove(ACTIVE_ROUTE_ID)
|
||||
|
||||
@@ -463,15 +463,14 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}.onFailure { throwable ->
|
||||
if (generation != routesRequestGeneration) return@onFailure
|
||||
reportHandledException("load_routes", throwable, mapOf("date" to date))
|
||||
_state.update {
|
||||
val apiError = ApiErrorMapper.map(throwable)
|
||||
it.withApiError(throwable).copy(
|
||||
screen = when {
|
||||
apiError.kind == ApiErrorKind.Auth -> DriverScreen.Phone
|
||||
it.screen == DriverScreen.Initializing -> DriverScreen.Routes
|
||||
else -> it.screen
|
||||
},
|
||||
)
|
||||
if (ApiErrorMapper.map(throwable).kind == ApiErrorKind.Auth) {
|
||||
handleExpiredSession()
|
||||
} else {
|
||||
_state.update {
|
||||
it.withApiError(throwable).copy(
|
||||
screen = if (it.screen == DriverScreen.Initializing) DriverScreen.Routes else it.screen,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +547,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
.onFailure { throwable ->
|
||||
if (generation == routeDetailRequestGeneration) _state.update { it.withApiError(throwable) }
|
||||
if (generation != routeDetailRequestGeneration) return@onFailure
|
||||
if (ApiErrorMapper.map(throwable).kind == ApiErrorKind.Auth) {
|
||||
handleExpiredSession()
|
||||
} else {
|
||||
_state.update { it.withApiError(throwable) }
|
||||
}
|
||||
}
|
||||
|
||||
if (generation == routeDetailRequestGeneration) _state.update { it.copy(refreshing = false) }
|
||||
@@ -1455,6 +1459,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
dispatchSheetUploadsJob?.cancel()
|
||||
realtimeBannerJob?.cancel()
|
||||
liveSyncClient.stop()
|
||||
ActiveRouteTrackingService.stop(getApplication())
|
||||
offlineOutboxManager.clearAll()
|
||||
repository.logout(notifyServer = _state.value.isOnline)
|
||||
syncRepository.clearCache()
|
||||
@@ -1665,6 +1670,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
private suspend fun handleExpiredSession() {
|
||||
liveSyncClient.stop()
|
||||
ActiveRouteTrackingService.stop(getApplication())
|
||||
offlineOutboxManager.clearAll()
|
||||
repository.logout(notifyServer = false)
|
||||
syncRepository.clearCache()
|
||||
|
||||
Reference in New Issue
Block a user