From da6577e5875696eacb725f9a900485fdebca9b36 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:47:22 +0200 Subject: [PATCH] actions java 11 -> 17 & fixed parent job is cancelling message --- .github/workflows/build_to_archive.yml | 4 +- .github/workflows/generate_dokka.yml | 4 +- .github/workflows/prerelease.yml | 4 +- .github/workflows/pull_request.yml | 4 +- .../cloudstream3/mvvm/ArchComponentExt.kt | 119 ++++++++++-------- .../cloudstream3/ui/home/HomeViewModel.kt | 1 + 6 files changed, 74 insertions(+), 62 deletions(-) diff --git a/.github/workflows/build_to_archive.yml b/.github/workflows/build_to_archive.yml index 83430766..9cd2c523 100644 --- a/.github/workflows/build_to_archive.yml +++ b/.github/workflows/build_to_archive.yml @@ -32,10 +32,10 @@ jobs: private_key: ${{ secrets.GH_APP_KEY }} repository: "recloudstream/cloudstream-archive" - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/generate_dokka.yml b/.github/workflows/generate_dokka.yml index 3c5caad7..abeee0b2 100644 --- a/.github/workflows/generate_dokka.yml +++ b/.github/workflows/generate_dokka.yml @@ -42,10 +42,10 @@ jobs: cd $GITHUB_WORKSPACE/dokka/ rm -rf "./-cloudstream" - - name: Setup JDK 11 + - name: Setup JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Setup Android SDK uses: android-actions/setup-android@v2 diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 4ce7dba1..856d267c 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -24,10 +24,10 @@ jobs: private_key: ${{ secrets.GH_APP_KEY }} repository: "recloudstream/secrets" - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 36199cd6..b6177710 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - name: Grant execute permission for gradlew run: chmod +x gradlew 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 28b552d1..eb575775 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt @@ -129,6 +129,70 @@ fun CoroutineScope.launchSafe( return this.launch(context, start, obj) } +fun throwAbleToResource( + throwable: Throwable +): Resource { + return when (throwable) { + is NullPointerException -> { + for (line in throwable.stackTrace) { + if (line?.fileName?.endsWith("provider.kt", ignoreCase = true) == true) { + return Resource.Failure( + false, + null, + null, + "NullPointerException at ${line.fileName} ${line.lineNumber}\nSite might have updated or added Cloudflare/DDOS protection" + ) + } + } + safeFail(throwable) + } + is SocketTimeoutException, is InterruptedIOException -> { + Resource.Failure( + true, + null, + null, + "Connection Timeout\nPlease try again later." + ) + } + is HttpException -> { + Resource.Failure( + false, + throwable.statusCode, + null, + throwable.message ?: "HttpException" + ) + } + is UnknownHostException -> { + Resource.Failure(true, null, null, "Cannot connect to server, try again later.\n${throwable.message}") + } + is ErrorLoadingException -> { + Resource.Failure( + true, + null, + null, + throwable.message ?: "Error loading, try again later." + ) + } + is NotImplementedError -> { + Resource.Failure(false, null, null, "This operation is not implemented.") + } + is SSLHandshakeException -> { + Resource.Failure( + true, + null, + null, + (throwable.message ?: "SSLHandshakeException") + "\nTry a VPN or DNS." + ) + } + is CancellationException -> { + throwable.cause?.let { + throwAbleToResource(it) + } ?: safeFail(throwable) + } + else -> safeFail(throwable) + } +} + suspend fun safeApiCall( apiCall: suspend () -> T, ): Resource { @@ -137,60 +201,7 @@ suspend fun safeApiCall( Resource.Success(apiCall.invoke()) } catch (throwable: Throwable) { logError(throwable) - when (throwable) { - is NullPointerException -> { - for (line in throwable.stackTrace) { - if (line?.fileName?.endsWith("provider.kt", ignoreCase = true) == true) { - return@withContext Resource.Failure( - false, - null, - null, - "NullPointerException at ${line.fileName} ${line.lineNumber}\nSite might have updated or added Cloudflare/DDOS protection" - ) - } - } - safeFail(throwable) - } - is SocketTimeoutException, is InterruptedIOException -> { - Resource.Failure( - true, - null, - null, - "Connection Timeout\nPlease try again later." - ) - } - is HttpException -> { - Resource.Failure( - false, - throwable.statusCode, - null, - throwable.message ?: "HttpException" - ) - } - is UnknownHostException -> { - Resource.Failure(true, null, null, "Cannot connect to server, try again later.") - } - is ErrorLoadingException -> { - Resource.Failure( - true, - null, - null, - throwable.message ?: "Error loading, try again later." - ) - } - is NotImplementedError -> { - Resource.Failure(false, null, null, "This operation is not implemented.") - } - is SSLHandshakeException -> { - Resource.Failure( - true, - null, - null, - (throwable.message ?: "SSLHandshakeException") + "\nTry a VPN or DNS." - ) - } - else -> safeFail(throwable) - } + throwAbleToResource(throwable) } } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index 16f21738..563a326e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -370,6 +370,7 @@ class HomeViewModel : ViewModel() { else -> Unit } + onGoingLoad = null } fun click(callback: SearchClickCallback) {