diff --git a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt index 239aa8066..44f4f580c 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt @@ -72,8 +72,9 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { // JavaScript rowUi.action?.let { kotlin.runCatching { - saveLoginData(source, loginUi) - source.evalJS(it) + source.evalJS(it) { + put("result", getLoginData(loginUi)) + } }.onFailure { AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", it) } @@ -104,9 +105,9 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { } } - private fun getLoginData(loginUi: List): HashMap { + private fun getLoginData(loginUi: List?): HashMap { val loginData = hashMapOf() - loginUi.forEachIndexed { index, rowUi -> + loginUi?.forEachIndexed { index, rowUi -> when (rowUi.type) { "text", "password" -> { val rowView = binding.root.findViewById(index) @@ -119,15 +120,6 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) { return loginData } - private fun saveLoginData(source: BaseSource, loginUi: List) { - val loginData = getLoginData(loginUi) - if (loginData.isEmpty()) { - source.removeLoginInfo() - } else { - source.putLoginInfo(GSON.toJson(loginData)) - } - } - private fun login(source: BaseSource, loginData: HashMap) { launch(IO) { if (loginData.isEmpty()) {