pull/1303/head
gedoor 3 years ago
parent cc16a8e2d2
commit c93b133b1e
  1. 37
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt

@ -17,6 +17,10 @@ import io.legado.app.ui.widget.text.EditText
import io.legado.app.ui.widget.text.TextInputLayout
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import splitties.views.onClick
class RuleUiLoginDialog : BaseDialogFragment() {
@ -101,21 +105,30 @@ class RuleUiLoginDialog : BaseDialogFragment() {
}
}
}
if (loginData.isEmpty()) {
bookSource.removeLoginInfo()
return@setOnMenuItemClickListener true
}
if (bookSource.putLoginInfo(GSON.toJson(loginData))) {
bookSource.getLoginJs()?.let {
try {
bookSource.evalJS(it)
toastOnUi(R.string.success)
} catch (e: Exception) {
e.printStackTrace()
toastOnUi(e.localizedMessage ?: "ERROR")
launch(IO) {
if (loginData.isEmpty()) {
bookSource.removeLoginInfo()
withContext(Main) {
dismiss()
}
} else if (bookSource.putLoginInfo(GSON.toJson(loginData))) {
bookSource.getLoginJs()?.let {
try {
bookSource.evalJS(it)
toastOnUi(R.string.success)
withContext(Main) {
dismiss()
}
} catch (e: Exception) {
e.printStackTrace()
toastOnUi("error:${e.localizedMessage}")
}
}
}
}
}
}
return@setOnMenuItemClickListener true

Loading…
Cancel
Save