fix crunchroll parser login crash if login failed
This commit is contained in:
parent
7a860a7270
commit
5b5a74a1de
|
@ -25,6 +25,7 @@ package org.mosad.teapod.parser.crunchyroll
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.*
|
||||||
|
import io.ktor.client.features.*
|
||||||
import io.ktor.client.features.json.*
|
import io.ktor.client.features.json.*
|
||||||
import io.ktor.client.features.json.serializer.*
|
import io.ktor.client.features.json.serializer.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
|
@ -102,14 +103,27 @@ object Crunchyroll {
|
||||||
var success = false// is false
|
var success = false// is false
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
// TODO handle exceptions
|
// TODO handle exceptions
|
||||||
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
Log.i(TAG, "getting token ...")
|
||||||
header("Authorization", "Basic $basicApiToken")
|
|
||||||
}
|
|
||||||
token = response.receive()
|
|
||||||
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
|
||||||
|
|
||||||
Log.i(TAG, "login complete with code ${response.status}")
|
val status = try {
|
||||||
success = (response.status == HttpStatusCode.OK)
|
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
|
return@runBlocking success
|
||||||
|
|
|
@ -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.main.fragments.SearchFragment
|
||||||
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
|
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
|
||||||
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
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.DataTypes
|
||||||
import org.mosad.teapod.util.metadb.MetaDBController
|
import org.mosad.teapod.util.metadb.MetaDBController
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -184,22 +183,6 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
|
||||||
return scope.launch { MetaDBController.list() }
|
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
|
* start the onboarding activity and finish the main activity
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -113,6 +113,8 @@ class AboutFragment : Fragment() {
|
||||||
"https://ktor.io/", License.APACHE2),
|
"https://ktor.io/", License.APACHE2),
|
||||||
ThirdPartyComponent("kotlinx.coroutines", "2016-2021", "JetBrains s.r.o",
|
ThirdPartyComponent("kotlinx.coroutines", "2016-2021", "JetBrains s.r.o",
|
||||||
"https://github.com/Kotlin/kotlinx.coroutines", License.APACHE2),
|
"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.",
|
ThirdPartyComponent("Glide", "2014", "Google Inc.",
|
||||||
"https://github.com/bumptech/glide", License.BSD2),
|
"https://github.com/bumptech/glide", License.BSD2),
|
||||||
ThirdPartyComponent("Glide Transformations", "2020", "Wasabeef",
|
ThirdPartyComponent("Glide Transformations", "2020", "Wasabeef",
|
||||||
|
|
Loading…
Reference in New Issue