fix crunchroll parser login crash if login failed

This commit is contained in:
Jannik 2022-04-02 20:08:29 +02:00
parent 7a860a7270
commit 5b5a74a1de
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 23 additions and 24 deletions

View File

@ -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
Log.i(TAG, "getting token ...")
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")
}
Log.i(TAG, "login complete with code ${response.status}")
success = (response.status == HttpStatusCode.OK)
status
}
Log.i(TAG, "Login complete with code $status")
success = (status == HttpStatusCode.OK)
}
return@runBlocking success

View File

@ -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
*/

View File

@ -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",