forked from recloudstream/cloudstream
fixed
This commit is contained in:
parent
576377e4bb
commit
8d0d37093f
4 changed files with 76 additions and 52 deletions
|
@ -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 <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) {
|
||||
liveData.observe(this, Observer { it?.let { t -> action(t) } })
|
||||
|
@ -55,17 +58,22 @@ suspend fun <T> 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.")
|
||||
}
|
||||
is HttpException -> {
|
||||
Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage)
|
||||
}
|
||||
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) //
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<VideoDownloadManager.DownloadResumePackage>(k) }
|
||||
|
|
|
@ -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 -> {
|
||||
|
|
|
@ -17,11 +17,16 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_width="50dp" android:layout_height="50dp">
|
||||
</ProgressBar>
|
||||
<LinearLayout
|
||||
android:id="@+id/result_loading_error"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:layout_columnWeight="1"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:layout_margin="5dp"
|
||||
|
||||
app:icon="@drawable/ic_baseline_autorenew_24"
|
||||
app:iconSize="20dp"
|
||||
|
@ -39,10 +44,9 @@
|
|||
>
|
||||
</com.google.android.material.button.MaterialButton>
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:layout_columnWeight="1"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:layout_margin="5dp"
|
||||
|
||||
app:icon="@drawable/ic_baseline_public_24"
|
||||
app:iconSize="20dp"
|
||||
|
@ -59,6 +63,16 @@
|
|||
android:minWidth="200dp"
|
||||
>
|
||||
</com.google.android.material.button.MaterialButton>
|
||||
<TextView
|
||||
android:layout_margin="5dp"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/result_error_text"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:visibility="gone"
|
||||
|
|
Loading…
Reference in a new issue