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.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) //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) }
|
||||||
|
|
|
@ -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 -> {
|
||||||
|
|
|
@ -17,48 +17,62 @@
|
||||||
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>
|
||||||
<com.google.android.material.button.MaterialButton
|
<LinearLayout
|
||||||
android:layout_columnWeight="1"
|
android:id="@+id/result_loading_error"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_height="50dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_marginBottom="50dp"
|
android:layout_height="wrap_content">
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_height="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"
|
||||||
android:text="@string/reload_error"
|
android:text="@string/reload_error"
|
||||||
android:id="@+id/result_reload_connectionerror"
|
android:id="@+id/result_reload_connectionerror"
|
||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
android:textSize="15sp"
|
android:textSize="15sp"
|
||||||
app:cornerRadius="5dp"
|
app:cornerRadius="5dp"
|
||||||
app:strokeWidth="2dp"
|
app:strokeWidth="2dp"
|
||||||
app:strokeColor="@color/colorAccent"
|
app:strokeColor="@color/colorAccent"
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
app:rippleColor="@color/colorPrimary"
|
app:rippleColor="@color/colorPrimary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:minWidth="200dp"
|
android:minWidth="200dp"
|
||||||
>
|
>
|
||||||
</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_margin="5dp"
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
|
|
||||||
app:icon="@drawable/ic_baseline_public_24"
|
app:icon="@drawable/ic_baseline_public_24"
|
||||||
app:iconSize="20dp"
|
app:iconSize="20dp"
|
||||||
android:text="@string/result_open_in_browser"
|
android:text="@string/result_open_in_browser"
|
||||||
android:id="@+id/result_reload_connection_open_in_browser"
|
android:id="@+id/result_reload_connection_open_in_browser"
|
||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
android:textSize="15sp"
|
android:textSize="15sp"
|
||||||
app:cornerRadius="5dp"
|
app:cornerRadius="5dp"
|
||||||
app:strokeWidth="2dp"
|
app:strokeWidth="2dp"
|
||||||
app:strokeColor="@color/colorAccent"
|
app:strokeColor="@color/colorAccent"
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
app:rippleColor="@color/colorPrimary"
|
app:rippleColor="@color/colorPrimary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
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"
|
||||||
|
|
Loading…
Reference in a new issue