This commit is contained in:
LagradOst 2021-07-08 20:03:17 +02:00
parent 576377e4bb
commit 8d0d37093f
4 changed files with 76 additions and 52 deletions

View file

@ -4,8 +4,11 @@ import android.util.Log
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.bumptech.glide.load.HttpException
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.net.SocketTimeoutException
import java.net.UnknownHostException
fun <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) { fun <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) {
liveData.observe(this, Observer { it?.let { t -> action(t) } }) liveData.observe(this, Observer { it?.let { t -> action(t) } })
@ -55,17 +58,22 @@ suspend fun <T> safeApiCall(
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
logError(throwable) logError(throwable)
when (throwable) { when (throwable) {
/*is HttpException -> {
Resource.Failure(false, throwable.code(), throwable.response()?.errorBody(), throwable.localizedMessage)
}
is SocketTimeoutException -> { 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 -> { 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) //
} }
} }
} }

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.services
import android.app.Service import android.app.Service
import android.content.Intent import android.content.Intent
import android.os.IBinder import android.os.IBinder
import android.util.Log
import com.lagradost.cloudstream3.recivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.recivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.getKeys import com.lagradost.cloudstream3.utils.DataStore.getKeys
@ -19,6 +20,8 @@ class VideoDownloadKeepAliveService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val startValue = intent?.getIntExtra(START_VALUE_KEY, RESTART_NONE) ?: RESTART_NONE 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) { if (startValue == RESTART_ALL_DOWNLOADS_AND_QUEUE) {
val keys = this.getKeys(VideoDownloadManager.KEY_RESUME_PACKAGES) val keys = this.getKeys(VideoDownloadManager.KEY_RESUME_PACKAGES)
val resumePkg = keys.mapNotNull { k -> this.getKey<VideoDownloadManager.DownloadResumePackage>(k) } val resumePkg = keys.mapNotNull { k -> this.getKey<VideoDownloadManager.DownloadResumePackage>(k) }

View file

@ -171,20 +171,18 @@ class ResultFragment : Fragment() {
0 -> { 0 -> {
result_loading.visibility = VISIBLE result_loading.visibility = VISIBLE
result_finish_loading.visibility = GONE result_finish_loading.visibility = GONE
result_reload_connectionerror.visibility = GONE result_loading_error.visibility = GONE
result_reload_connection_open_in_browser.visibility = GONE
} }
1 -> { 1 -> {
result_loading.visibility = GONE result_loading.visibility = GONE
result_finish_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 result_reload_connection_open_in_browser.visibility = if (url == null) GONE else VISIBLE
} }
2 -> { 2 -> {
result_loading.visibility = GONE result_loading.visibility = GONE
result_finish_loading.visibility = VISIBLE result_finish_loading.visibility = VISIBLE
result_reload_connectionerror.visibility = GONE result_loading_error.visibility = GONE
result_reload_connection_open_in_browser.visibility = GONE
} }
} }
} }
@ -660,6 +658,7 @@ activity?.startActivityForResult(vlcIntent, REQUEST_CODE)
} }
} }
is Resource.Failure -> { is Resource.Failure -> {
result_error_text.text = data.errorString
updateVisStatus(1) updateVisStatus(1)
} }
is Resource.Loading -> { is Resource.Loading -> {

View file

@ -17,11 +17,16 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="50dp" android:layout_height="50dp"> android:layout_width="50dp" android:layout_height="50dp">
</ProgressBar> </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 <com.google.android.material.button.MaterialButton
android:layout_columnWeight="1"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_marginBottom="50dp" android:layout_margin="5dp"
app:icon="@drawable/ic_baseline_autorenew_24" app:icon="@drawable/ic_baseline_autorenew_24"
app:iconSize="20dp" app:iconSize="20dp"
@ -39,10 +44,9 @@
> >
</com.google.android.material.button.MaterialButton> </com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:layout_columnWeight="1"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_marginTop="50dp" android:layout_margin="5dp"
app:icon="@drawable/ic_baseline_public_24" app:icon="@drawable/ic_baseline_public_24"
app:iconSize="20dp" app:iconSize="20dp"
@ -59,6 +63,16 @@
android:minWidth="200dp" android:minWidth="200dp"
> >
</com.google.android.material.button.MaterialButton> </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 <FrameLayout
android:visibility="gone" android:visibility="gone"