From ebc048523385b3d8be3f675b7bd3c4204562af73 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Tue, 21 Dec 2021 19:58:07 +0100 Subject: [PATCH] fixed stuff --- app/build.gradle | 8 +-- .../cloudstream3/mvvm/ArchComponentExt.kt | 42 ++++++++++--- .../cloudstream3/ui/player/PlayerFragment.kt | 3 +- app/src/main/res/drawable/cs3_cloud.xml | 15 ----- app/src/main/res/layout/subtitle_settings.xml | 60 ++++++++++++++++++- 5 files changed, 95 insertions(+), 33 deletions(-) delete mode 100644 app/src/main/res/drawable/cs3_cloud.xml diff --git a/app/build.gradle b/app/build.gradle index 5d7d2d23..ee771884 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { minSdkVersion 21 targetSdkVersion 30 - versionCode 37 - versionName "2.4.5" + versionCode 38 + versionName "2.4.6" resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" @@ -91,8 +91,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' - implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-beta02' - implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-beta02' + implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-rc01' + implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-rc01' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' testImplementation 'junit:junit:4.13.2' 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 f303a0cf..feac20fc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.net.SocketTimeoutException import java.net.UnknownHostException +import javax.net.ssl.SSLHandshakeException fun LifecycleOwner.observe(liveData: LiveData, action: (t: T) -> Unit) { liveData.observe(this) { it?.let { t -> action(t) } } @@ -50,6 +51,15 @@ fun normalSafeApiCall(apiCall: () -> T): T? { } } +fun safeFail(throwable: Throwable): Resource { + val stackTraceMsg = (throwable.localizedMessage ?: "") + "\n\n" + throwable.stackTrace.joinToString( + separator = "\n" + ) { + "${it.fileName} ${it.lineNumber}" + } + return Resource.Failure(false, null, null, stackTraceMsg) +} + suspend fun safeApiCall( apiCall: suspend () -> T, ): Resource { @@ -59,11 +69,24 @@ suspend fun safeApiCall( } catch (throwable: Throwable) { logError(throwable) when (throwable) { + is NullPointerException -> { + for (line in throwable.stackTrace) { + if (line.fileName.endsWith("provider.kt", ignoreCase = 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 -> { - Resource.Failure(true, null, null, "Please try again later.") + Resource.Failure(true, null, null, "Connection Timeout\nPlease try again later.") } is HttpException -> { - Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage ?: "") + Resource.Failure(false, throwable.statusCode, null, throwable.message ?: "HttpException") } is UnknownHostException -> { Resource.Failure(true, null, null, "Cannot connect to server, try again later.") @@ -74,14 +97,15 @@ suspend fun safeApiCall( is NotImplementedError -> { Resource.Failure(false, null, null, "This operation is not implemented.") } - else -> { - val stackTraceMsg = (throwable.localizedMessage ?: "") + "\n\n" + throwable.stackTrace.joinToString( - separator = "\n" - ) { - "${it.fileName} ${it.lineNumber}" - } - Resource.Failure(false, null, null, stackTraceMsg) // + is SSLHandshakeException -> { + Resource.Failure( + true, + null, + null, + (throwable.message ?: "SSLHandshakeException") + "\nTry again later." + ) } + else -> safeFail(throwable) } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index caffd22b..1e03a1b0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -533,13 +533,12 @@ class PlayerFragment : Fragment() { // https://exoplayer.dev/doc/reference/constant-values.html if (isLocked || exoPlayer.duration == TIME_UNSET || (!swipeEnabled && !swipeVerticalEnabled)) return - val audioManager = activity?.getSystemService(AUDIO_SERVICE) as? AudioManager when (motionEvent.action) { MotionEvent.ACTION_DOWN -> { // SO YOU CAN PULL DOWN STATUSBAR OR NAVBAR - if (motionEvent.rawY > statusBarHeight && motionEvent.rawX < width - navigationBarHeight) { + if (motionEvent.rawY > statusBarHeight && motionEvent.rawX < max(width, height) - navigationBarHeight) { currentX = motionEvent.rawX currentY = motionEvent.rawY isValidTouch = true diff --git a/app/src/main/res/drawable/cs3_cloud.xml b/app/src/main/res/drawable/cs3_cloud.xml deleted file mode 100644 index d8fc1dbd..00000000 --- a/app/src/main/res/drawable/cs3_cloud.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/app/src/main/res/layout/subtitle_settings.xml b/app/src/main/res/layout/subtitle_settings.xml index e87fea68..b17b1541 100644 --- a/app/src/main/res/layout/subtitle_settings.xml +++ b/app/src/main/res/layout/subtitle_settings.xml @@ -43,52 +43,100 @@ - + android:layout_width="wrap_content"> + + +