From 8d0d37093f020518d24893141e67bb040224cecc Mon Sep 17 00:00:00 2001 From: LagradOst Date: Thu, 8 Jul 2021 20:03:17 +0200 Subject: [PATCH] fixed --- .../cloudstream3/mvvm/ArchComponentExt.kt | 24 +++-- .../services/VideoDownloadKeepAliveService.kt | 3 + .../cloudstream3/ui/result/ResultFragment.kt | 9 +- app/src/main/res/layout/fragment_result.xml | 92 +++++++++++-------- 4 files changed, 76 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt b/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt index fb8f6ffc..73c0b296 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt @@ -4,8 +4,11 @@ import android.util.Log import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import com.bumptech.glide.load.HttpException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import java.net.SocketTimeoutException +import java.net.UnknownHostException fun LifecycleOwner.observe(liveData: LiveData, action: (t: T) -> Unit) { liveData.observe(this, Observer { it?.let { t -> action(t) } }) @@ -55,17 +58,22 @@ suspend fun safeApiCall( } catch (throwable: Throwable) { logError(throwable) when (throwable) { - /*is HttpException -> { - Resource.Failure(false, throwable.code(), throwable.response()?.errorBody(), throwable.localizedMessage) - } is SocketTimeoutException -> { - Resource.Failure(true,null,null,"Please try again later.") + Resource.Failure(true, null, null, "Please try again later.") + } + is HttpException -> { + Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage) + } + is UnknownHostException -> { + Resource.Failure(true, null, null, "Cannot connect to server, try again later.") } - is UnknownHostException ->{ - Resource.Failure(true,null,null,"Cannot connect to server, try again later.") - }*/ else -> { - Resource.Failure(true, null, null, throwable.localizedMessage) + val stackTraceMsg = throwable.localizedMessage + "\n\n" + throwable.stackTrace.joinToString( + separator = "\n" + ) { + "${it.fileName} ${it.lineNumber}" + } + Resource.Failure(false, null, null, stackTraceMsg) // } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/services/VideoDownloadKeepAliveService.kt b/app/src/main/java/com/lagradost/cloudstream3/services/VideoDownloadKeepAliveService.kt index f43f02e2..05a0e280 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/services/VideoDownloadKeepAliveService.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/services/VideoDownloadKeepAliveService.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.services import android.app.Service import android.content.Intent import android.os.IBinder +import android.util.Log import com.lagradost.cloudstream3.recivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKeys @@ -19,6 +20,8 @@ class VideoDownloadKeepAliveService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val startValue = intent?.getIntExtra(START_VALUE_KEY, RESTART_NONE) ?: RESTART_NONE + Log.i("Service", "Restarted with start value of $startValue") + if (startValue == RESTART_ALL_DOWNLOADS_AND_QUEUE) { val keys = this.getKeys(VideoDownloadManager.KEY_RESUME_PACKAGES) val resumePkg = keys.mapNotNull { k -> this.getKey(k) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 72e0eee1..e2902dc7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -171,20 +171,18 @@ class ResultFragment : Fragment() { 0 -> { result_loading.visibility = VISIBLE result_finish_loading.visibility = GONE - result_reload_connectionerror.visibility = GONE - result_reload_connection_open_in_browser.visibility = GONE + result_loading_error.visibility = GONE } 1 -> { result_loading.visibility = GONE result_finish_loading.visibility = GONE - result_reload_connectionerror.visibility = VISIBLE + result_loading_error.visibility = VISIBLE result_reload_connection_open_in_browser.visibility = if (url == null) GONE else VISIBLE } 2 -> { result_loading.visibility = GONE result_finish_loading.visibility = VISIBLE - result_reload_connectionerror.visibility = GONE - result_reload_connection_open_in_browser.visibility = GONE + result_loading_error.visibility = GONE } } } @@ -660,6 +658,7 @@ activity?.startActivityForResult(vlcIntent, REQUEST_CODE) } } is Resource.Failure -> { + result_error_text.text = data.errorString updateVisStatus(1) } is Resource.Loading -> { diff --git a/app/src/main/res/layout/fragment_result.xml b/app/src/main/res/layout/fragment_result.xml index ef4b8039..8b36c0ca 100644 --- a/app/src/main/res/layout/fragment_result.xml +++ b/app/src/main/res/layout/fragment_result.xml @@ -17,48 +17,62 @@ android:layout_gravity="center" android:layout_width="50dp" android:layout_height="50dp"> - + - - + + - + app:icon="@drawable/ic_baseline_public_24" + app:iconSize="20dp" + android:text="@string/result_open_in_browser" + android:id="@+id/result_reload_connection_open_in_browser" + android:textAllCaps="false" + android:textSize="15sp" + app:cornerRadius="5dp" + app:strokeWidth="2dp" + app:strokeColor="@color/colorAccent" + style="@style/Widget.MaterialComponents.Button.OutlinedButton" + app:rippleColor="@color/colorPrimary" + android:layout_width="wrap_content" + android:minWidth="200dp" + > + + + +