Fix weird MangaDex login dialog fill-in

This commit is contained in:
Jobobby04 2020-12-25 20:07:06 -05:00
parent d68341aaba
commit bbc70801db

View File

@ -74,14 +74,16 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
} }
private fun checkLogin() { private fun checkLogin() {
with(binding) { val username = binding.username.text?.toString()
if (username.text.isNullOrBlank() || password.text.isNullOrBlank() || (twoFactorCheck.isChecked && twoFactorEdit.text.isNullOrBlank())) { val password = binding.password.text?.toString()
val twoFactor = binding.twoFactorEdit.text?.toString()
if (username.isNullOrBlank() || password.isNullOrBlank() || (binding.twoFactorCheck.isChecked && twoFactor.isNullOrBlank())) {
errorResult() errorResult()
root.context.toast(R.string.fields_cannot_be_blank) binding.root.context.toast(R.string.fields_cannot_be_blank)
return return
} }
login.progress = 1 binding.login.progress = 1
dialog?.setCancelable(false) dialog?.setCancelable(false)
dialog?.setCanceledOnTouchOutside(false) dialog?.setCanceledOnTouchOutside(false)
@ -89,21 +91,20 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
scope.launch { scope.launch {
try { try {
val result = source?.login( val result = source?.login(
username.text.toString(), username,
password.text.toString(), password,
twoFactorEdit.text.toString() twoFactor.toString()
) ?: false ) ?: false
if (result) { if (result) {
dialog?.dismiss() dialog?.dismiss()
preferences.setTrackCredentials(Injekt.get<TrackManager>().mdList, username.toString(), password.toString()) preferences.setTrackCredentials(service, username, password)
root.context.toast(R.string.login_success) binding.root.context.toast(R.string.login_success)
} else { } else {
errorResult() errorResult()
} }
} catch (error: Exception) { } catch (error: Exception) {
errorResult() errorResult()
error.message?.let { root.context.toast(it) } error.message?.let { binding.root.context.toast(it) }
}
} }
} }
} }