Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.12 KB | None | 0 0
  1. fun Bone.presentStreaming(scheduleEvent: ScheduleEvent, isTablet: Boolean) {
  2.     if (showPaywallIfNeeded(scheduleEvent) { isSuccess ->
  3.             if (!isSuccess) return@showPaywallIfNeeded
  4.             GlobalScope.launch {
  5.                 ProgressBone.lock()
  6.                 val bone = StreamingScreenBone(scheduleEvent, networkGuard { LifeRequest().list() })
  7.                 withContext(Main) {
  8.                     ProgressBone.unlock()
  9.                     if (isTablet) show(bone)
  10.                     else present(bone)
  11.                 }
  12.             }
  13.         }) return
  14.     GlobalScope.launch {
  15.         ProgressBone.lock()
  16.         val bone = StreamingScreenBone(scheduleEvent, networkGuard { LifeRequest().list() })
  17.         withContext(Main) {
  18.             ProgressBone.unlock()
  19.             if (isTablet) show(bone)
  20.             else present(bone)
  21.         }
  22.     }
  23. }
  24.  
  25.  
  26. suspend fun <T> networkGuard(nested: suspend () -> T): T {
  27.     try {
  28.         Log.d("Попытка")
  29.         return nested()
  30.     }catch (e : NetworkNotAvailable){
  31.         val context: Context = service(App)
  32.         Log.d("ошибка")
  33.  
  34.         PopupData(
  35.             VectorDrawableCompat.create(context.resources, drawable.ic_no_connection, null),
  36.             "Кажется, пропала связь",
  37.             e.localizedMessage ?: "Ошибка",
  38.             { isReplay ->
  39.                 if(isReplay) {
  40.                     Log.d("повтор")
  41.                     GlobalScope.launch {
  42.                         networkGuard(nested)
  43.                     }
  44.                 } else {
  45.                     ProgressBone.unlock()
  46.  
  47.                 }
  48.             },
  49.             PopupDataButton("Закрыть", type = NEGATIVE, actionCallback = { })
  50.         ).show((context.activity() as RootActivity).bone)
  51.     }
  52.     return nested()
  53. }
  54.  
  55.  
  56.  
  57.  
  58. /*
  59. suspend fun <T> networkGuard(nested: suspend () -> T): T = coroutineScope {
  60.     try {
  61.         Log.d("Попытка")
  62.         nested()
  63.     } catch (e: NetworkNotAvailable) {
  64.         Log.d("ошибка")
  65.         suspendCoroutine<T> {
  66.             launch(Main) {
  67.                 val context: Context = service(App)
  68.  
  69.                 PopupData(
  70.                     VectorDrawableCompat.create(context.resources, drawable.ic_no_connection, null),
  71.                     "Кажется, пропала связь",
  72.                     e.localizedMessage ?: "Ошибка",
  73.                     { isReplay ->
  74.                         if(isReplay) {
  75.                             Log.d("повтор")
  76.                             launch {
  77.                                 it.resume(networkGuard(nested))
  78.                             }
  79.                         } else {
  80.                             ProgressBone.unlock()
  81.                         }
  82.                     },
  83.                     PopupDataButton("Закрыть", type = NEGATIVE, actionCallback = { })
  84.                 ).show((context.activity() as RootActivity).bone)
  85.               */
  86. /*  launch {
  87.                     it.resume(networkGuard(nested))
  88.                 }*//*
  89.  
  90.               //it.resumeWithException(e)
  91.             }
  92.         }
  93.     }
  94. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement