mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
feat(LoginUI): bind loginData to result
This commit is contained in:
parent
853c94e37e
commit
61538ddbc6
@ -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<RowUi>): HashMap<String, String> {
|
||||
private fun getLoginData(loginUi: List<RowUi>?): HashMap<String, String> {
|
||||
val loginData = hashMapOf<String, String>()
|
||||
loginUi.forEachIndexed { index, rowUi ->
|
||||
loginUi?.forEachIndexed { index, rowUi ->
|
||||
when (rowUi.type) {
|
||||
"text", "password" -> {
|
||||
val rowView = binding.root.findViewById<View>(index)
|
||||
@ -119,15 +120,6 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
return loginData
|
||||
}
|
||||
|
||||
private fun saveLoginData(source: BaseSource, loginUi: List<RowUi>) {
|
||||
val loginData = getLoginData(loginUi)
|
||||
if (loginData.isEmpty()) {
|
||||
source.removeLoginInfo()
|
||||
} else {
|
||||
source.putLoginInfo(GSON.toJson(loginData))
|
||||
}
|
||||
}
|
||||
|
||||
private fun login(source: BaseSource, loginData: HashMap<String, String>) {
|
||||
launch(IO) {
|
||||
if (loginData.isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user