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