Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun Bone.presentStreaming(scheduleEvent: ScheduleEvent, isTablet: Boolean) {
- fun showStreaming() {
- GlobalScope.launch {
- var bone: Bone? = null
- ProgressBone.lock()
- try {
- bone = StreamingScreenBone(scheduleEvent, networkGuard { LifeRequest().list() })
- } catch (e: Exception) {
- }
- bone?.let {
- withContext(Main) {
- ProgressBone.unlock()
- if (isTablet) show(bone)
- else present(bone)
- }
- }
- }
- }
- if (showPaywallIfNeeded(scheduleEvent) { isSuccess -> if (isSuccess) showStreaming() }) return
- showStreaming()
- }
- suspend fun <T> networkGuard(nested: suspend () -> T): T = coroutineScope {
- try {
- Log.d("Попытка")
- nested()
- } catch (e: NetworkNotAvailable) {
- Log.d("ошибка")
- suspendCoroutine<T> {
- launch(Main) {
- val context: Context = service(App)
- PopupData(
- VectorDrawableCompat.create(context.resources, drawable.ic_no_connection, null),
- "Кажется, пропала связь",
- e.localizedMessage ?: "Ошибка",
- { isReplay ->
- if (isReplay) {
- Log.d("повтор")
- launch {
- it.resume(networkGuard(nested))
- ProgressBone.unlock()
- }
- } else {
- ProgressBone.unlock()
- it.resumeWithException(e)
- }
- },
- PopupDataButton("Закрыть", type = NEGATIVE, actionCallback = { })
- ).show((context.activity() as RootActivity).bone)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement