fixed stuff

This commit is contained in:
LagradOst 2021-12-21 19:58:07 +01:00
parent 67ade4d0b4
commit ebc0485233
5 changed files with 95 additions and 33 deletions

View file

@ -35,8 +35,8 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 37 versionCode 38
versionName "2.4.5" versionName "2.4.6"
resValue "string", "app_version", resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}" "${defaultConfig.versionName}${versionNameSuffix ?: ""}"
@ -91,8 +91,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-beta02' implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-rc01'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-beta02' implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-rc01'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'

View file

@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.net.SocketTimeoutException import java.net.SocketTimeoutException
import java.net.UnknownHostException import java.net.UnknownHostException
import javax.net.ssl.SSLHandshakeException
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) { it?.let { t -> action(t) } } liveData.observe(this) { it?.let { t -> action(t) } }
@ -50,6 +51,15 @@ fun <T> normalSafeApiCall(apiCall: () -> T): T? {
} }
} }
fun <T> safeFail(throwable: Throwable): Resource<T> {
val stackTraceMsg = (throwable.localizedMessage ?: "") + "\n\n" + throwable.stackTrace.joinToString(
separator = "\n"
) {
"${it.fileName} ${it.lineNumber}"
}
return Resource.Failure(false, null, null, stackTraceMsg)
}
suspend fun <T> safeApiCall( suspend fun <T> safeApiCall(
apiCall: suspend () -> T, apiCall: suspend () -> T,
): Resource<T> { ): Resource<T> {
@ -59,11 +69,24 @@ suspend fun <T> safeApiCall(
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
logError(throwable) logError(throwable)
when (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 -> { is SocketTimeoutException -> {
Resource.Failure(true, null, null, "Please try again later.") Resource.Failure(true, null, null, "Connection Timeout\nPlease try again later.")
} }
is HttpException -> { is HttpException -> {
Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage ?: "") Resource.Failure(false, throwable.statusCode, null, throwable.message ?: "HttpException")
} }
is UnknownHostException -> { is UnknownHostException -> {
Resource.Failure(true, null, null, "Cannot connect to server, try again later.") Resource.Failure(true, null, null, "Cannot connect to server, try again later.")
@ -74,14 +97,15 @@ suspend fun <T> safeApiCall(
is NotImplementedError -> { is NotImplementedError -> {
Resource.Failure(false, null, null, "This operation is not implemented.") Resource.Failure(false, null, null, "This operation is not implemented.")
} }
else -> { is SSLHandshakeException -> {
val stackTraceMsg = (throwable.localizedMessage ?: "") + "\n\n" + throwable.stackTrace.joinToString( Resource.Failure(
separator = "\n" true,
) { null,
"${it.fileName} ${it.lineNumber}" null,
} (throwable.message ?: "SSLHandshakeException") + "\nTry again later."
Resource.Failure(false, null, null, stackTraceMsg) // )
} }
else -> safeFail(throwable)
} }
} }
} }

View file

@ -533,13 +533,12 @@ class PlayerFragment : Fragment() {
// https://exoplayer.dev/doc/reference/constant-values.html // https://exoplayer.dev/doc/reference/constant-values.html
if (isLocked || exoPlayer.duration == TIME_UNSET || (!swipeEnabled && !swipeVerticalEnabled)) return if (isLocked || exoPlayer.duration == TIME_UNSET || (!swipeEnabled && !swipeVerticalEnabled)) return
val audioManager = activity?.getSystemService(AUDIO_SERVICE) as? AudioManager val audioManager = activity?.getSystemService(AUDIO_SERVICE) as? AudioManager
when (motionEvent.action) { when (motionEvent.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
// SO YOU CAN PULL DOWN STATUSBAR OR NAVBAR // 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 currentX = motionEvent.rawX
currentY = motionEvent.rawY currentY = motionEvent.rawY
isValidTouch = true isValidTouch = true

View file

@ -1,15 +0,0 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="850dp"
android:height="850dp"
android:viewportWidth="850"
android:viewportHeight="850">
<group android:name="group_6">
<path
android:name="path_2"
android:pathData="M 698.92 450.33 C 697.92 440.99 690.27 432.74 679.92 430.25 L 653.67 430.75 C 655.17 407.75 636.67 386.63 618.79 384 C 611.804 381.871 604.367 381.698 597.29 383.5 C 597.91 379.77 602.74 347.16 578.79 322 C 558.72 300.92 532.54 299.13 517.67 299.31 L 500.37 298.92 C 494.76 293.4 460.65 262.47 412.62 266.67 C 382.23 269.32 354.96 277.67 334.79 302.67 C 333.11 304.74 327.6 311.81 321.17 320.81 C 318.82 323.81 316.91 327.43 314.79 330.5 C 314.63 330.74 288.79 326.44 272.79 331 C 247.52 338.2 224.79 358.54 217.29 385.5 C 215.44 392.18 209.08 415.09 219.79 435 C 222.101 439.202 223.081 444.009 222.6 448.78 C 219.48 450.41 205.02 450.94 182.29 450 C 164.43 449.27 149.83 463.6 149.79 480 C 149.74 497.17 165.23 510.58 184.29 510 C 205.93 510.23 605.96 510.67 637.04 510.56 C 650.12 510.56 656.79 499.17 656.79 499.17 C 661.24 493.35 661.09 486.09 661.04 481.5 L 661.04 477 L 664.79 477 L 675.96 476.33 C 690.35 474.78 700.21 462.36 698.92 450.33 Z M 407.54 456 L 407.54 349.25 L 483.75 402.63 Z"
android:fillColor="#ffffff"
android:strokeWidth="1"/>
</group>
</vector>

View file

@ -43,52 +43,100 @@
</FrameLayout> </FrameLayout>
<TextView <TextView
android:nextFocusDown="@id/subs_font_size"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_font" android:id="@+id/subs_font"
android:text="@string/subs_font" android:text="@string/subs_font"
style="@style/SettingsItem"> style="@style/SettingsItem">
<requestFocus/>
</TextView> </TextView>
<TextView <TextView
android:nextFocusUp="@id/subs_font"
android:nextFocusDown="@id/subs_text_color"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_font_size" android:id="@+id/subs_font_size"
android:text="@string/subs_font_size" android:text="@string/subs_font_size"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_font_size"
android:nextFocusDown="@id/subs_outline_color"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_text_color" android:id="@+id/subs_text_color"
android:text="@string/subs_text_color" android:text="@string/subs_text_color"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_text_color"
android:nextFocusDown="@id/subs_background_color"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_outline_color" android:id="@+id/subs_outline_color"
android:text="@string/subs_outline_color" android:text="@string/subs_outline_color"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_outline_color"
android:nextFocusDown="@id/subs_window_color"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_background_color" android:id="@+id/subs_background_color"
android:text="@string/subs_background_color" android:text="@string/subs_background_color"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_background_color"
android:nextFocusDown="@id/subs_edge_type"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_window_color" android:id="@+id/subs_window_color"
android:text="@string/subs_window_color" android:text="@string/subs_window_color"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_window_color"
android:nextFocusDown="@id/subs_subtitle_elevation"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_edge_type" android:id="@+id/subs_edge_type"
android:text="@string/subs_edge_type" android:text="@string/subs_edge_type"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_edge_type"
android:nextFocusDown="@id/subs_auto_select_language"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_subtitle_elevation" android:id="@+id/subs_subtitle_elevation"
android:text="@string/subs_subtitle_elevation" android:text="@string/subs_subtitle_elevation"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_subtitle_elevation"
android:nextFocusDown="@id/subs_download_languages"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_auto_select_language" android:id="@+id/subs_auto_select_language"
android:text="@string/subs_auto_select_language" android:text="@string/subs_auto_select_language"
style="@style/SettingsItem" style="@style/SettingsItem"
/> />
<TextView <TextView
android:nextFocusUp="@id/subs_auto_select_language"
android:nextFocusDown="@id/apply_btt"
android:nextFocusLeft="@id/apply_btt"
android:nextFocusRight="@id/cancel_btt"
android:id="@+id/subs_download_languages" android:id="@+id/subs_download_languages"
android:text="@string/subs_download_languages" android:text="@string/subs_download_languages"
style="@style/SettingsItem" style="@style/SettingsItem"
@ -112,14 +160,20 @@
android:layout_height="60dp"> android:layout_height="60dp">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:nextFocusUp="@id/subs_download_languages"
android:nextFocusRight="@id/cancel_btt"
style="@style/WhiteButton" style="@style/WhiteButton"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:visibility="visible" android:visibility="visible"
android:text="@string/sort_apply" android:text="@string/sort_apply"
android:id="@+id/apply_btt" android:id="@+id/apply_btt"
android:layout_width="wrap_content" android:layout_width="wrap_content">
/> <requestFocus/>
</com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:nextFocusUp="@id/subs_download_languages"
android:nextFocusLeft="@id/apply_btt"
style="@style/BlackButton" style="@style/BlackButton"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:text="@string/sort_cancel" android:text="@string/sort_cancel"