Browse Source

fix crunchroll parser login crash if login failed

develop
Jannik 3 months ago
parent
commit
5b5a74a1de
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 28
      app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt
  2. 17
      app/src/main/java/org/mosad/teapod/ui/activity/main/MainActivity.kt
  3. 2
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AboutFragment.kt

28
app/src/main/java/org/mosad/teapod/parser/crunchyroll/Crunchyroll.kt

@ -25,6 +25,7 @@ package org.mosad.teapod.parser.crunchyroll
import android.util.Log
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.client.request.*
@ -102,14 +103,27 @@ object Crunchyroll {
var success = false// is false
withContext(Dispatchers.IO) {
// TODO handle exceptions
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
header("Authorization", "Basic $basicApiToken")
}
token = response.receive()
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
Log.i(TAG, "getting token ...")
Log.i(TAG, "login complete with code ${response.status}")
success = (response.status == HttpStatusCode.OK)
val status = try {
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
header("Authorization", "Basic $basicApiToken")
}
token = response.receive()
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
response.status
} catch (ex: ClientRequestException) {
val status = ex.response.status
if (status == HttpStatusCode.Unauthorized) {
Log.e(TAG, "Could not complete login: " +
"${status.value} ${status.description}. " +
"Propably wrong username or password")
}
status
}
Log.i(TAG, "Login complete with code $status")
success = (status == HttpStatusCode.OK)
}
return@runBlocking success

17
app/src/main/java/org/mosad/teapod/ui/activity/main/MainActivity.kt

@ -43,7 +43,6 @@ import org.mosad.teapod.ui.activity.main.fragments.LibraryFragment
import org.mosad.teapod.ui.activity.main.fragments.SearchFragment
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
import org.mosad.teapod.ui.activity.player.PlayerActivity
import org.mosad.teapod.ui.components.LoginModalBottomSheet
import org.mosad.teapod.util.DataTypes
import org.mosad.teapod.util.metadb.MetaDBController
import java.util.*
@ -184,22 +183,6 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
return scope.launch { MetaDBController.list() }
}
private fun showLoginDialog() {
val loginModal = LoginModalBottomSheet().apply {
positiveAction = {
EncryptedPreferences.saveCredentials(login, password, requireContext())
// TODO only dismiss if login was successful
this.dismiss()
}
negativeAction = {
Log.i(classTag, "Login canceled, exiting.")
finish()
}
}
loginModal.show(this.supportFragmentManager, LoginModalBottomSheet.TAG)
}
/**
* start the onboarding activity and finish the main activity
*/

2
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AboutFragment.kt

@ -113,6 +113,8 @@ class AboutFragment : Fragment() {
"https://ktor.io/", License.APACHE2),
ThirdPartyComponent("kotlinx.coroutines", "2016-2021", "JetBrains s.r.o",
"https://github.com/Kotlin/kotlinx.coroutines", License.APACHE2),
ThirdPartyComponent(" kotlinx.serialization", "2017-2021", "JetBrains s.r.o",
"https://github.com/Kotlin/kotlinx.serialization", License.APACHE2),
ThirdPartyComponent("Glide", "2014", "Google Inc.",
"https://github.com/bumptech/glide", License.BSD2),
ThirdPartyComponent("Glide Transformations", "2020", "Wasabeef",

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close