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

@ -11,6 +11,7 @@ import androidx.core.view.setPadding
import androidx.fragment.app.activityViewModels
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.DialogLoginBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.text.EditText
@ -105,33 +106,34 @@ class RuleUiLoginDialog : BaseDialogFragment() {
}
}
}
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}")
}
}
}
login(bookSource, loginData)
}
}
return@setOnMenuItemClickListener true
}
}
private fun login(bookSource: BookSource, loginData: HashMap<String, String>) {
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