More dialog fixes

This commit is contained in:
Jobobby04 2020-12-13 23:05:31 -05:00
parent 6659935f3d
commit ba6bcc82b6

View File

@ -3,7 +3,6 @@ package exh.widget.preference
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -40,7 +39,7 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
val scope = CoroutineScope(Job() + Dispatchers.Main) val scope = CoroutineScope(Job() + Dispatchers.Main)
var binding: PrefSiteLoginTwoFactorAuthBinding? = null lateinit var binding: PrefSiteLoginTwoFactorAuthBinding
constructor(source: MangaDex) : this( constructor(source: MangaDex) : this(
bundleOf( bundleOf(
@ -51,31 +50,31 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = PrefSiteLoginTwoFactorAuthBinding.inflate(LayoutInflater.from(activity!!)) binding = PrefSiteLoginTwoFactorAuthBinding.inflate(LayoutInflater.from(activity!!))
val dialog = MaterialDialog(activity!!) val dialog = MaterialDialog(activity!!)
.customView(view = binding!!.root, scrollable = false) .customView(view = binding.root, scrollable = false)
onViewCreated(dialog.view) onViewCreated()
return dialog return dialog
} }
fun onViewCreated(view: View) { fun onViewCreated() {
binding!!.login.setMode(ActionProcessButton.Mode.ENDLESS) binding.login.setMode(ActionProcessButton.Mode.ENDLESS)
binding!!.login.setOnClickListener { checkLogin() } binding.login.setOnClickListener { checkLogin() }
setCredentialsOnView() setCredentialsOnView()
binding!!.twoFactorCheck.setOnCheckedChangeListener { _, isChecked -> binding.twoFactorCheck.setOnCheckedChangeListener { _, isChecked ->
binding!!.twoFactorHolder.isVisible = isChecked binding.twoFactorHolder.isVisible = isChecked
} }
} }
private fun setCredentialsOnView() { private fun setCredentialsOnView() {
binding?.username?.setText(service.getUsername()) binding.username.setText(service.getUsername())
binding?.password?.setText(service.getPassword()) binding.password.setText(service.getPassword())
} }
private fun checkLogin() { private fun checkLogin() {
binding?.apply { with(binding) {
if (username.text.isNullOrBlank() || password.text.isNullOrBlank() || (twoFactorCheck.isChecked && twoFactorEdit.text.isNullOrBlank())) { if (username.text.isNullOrBlank() || password.text.isNullOrBlank() || (twoFactorCheck.isChecked && twoFactorEdit.text.isNullOrBlank())) {
errorResult() errorResult()
root.context.toast(R.string.fields_cannot_be_blank) root.context.toast(R.string.fields_cannot_be_blank)
@ -110,7 +109,7 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
} }
private fun errorResult() { private fun errorResult() {
binding?.apply { with(binding) {
dialog?.setCancelable(true) dialog?.setCancelable(true)
dialog?.setCanceledOnTouchOutside(true) dialog?.setCanceledOnTouchOutside(true)
login.progress = -1 login.progress = -1
@ -127,7 +126,6 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
private fun onDialogClosed() { private fun onDialogClosed() {
scope.cancel() scope.cancel()
binding = null
if (activity != null) { if (activity != null) {
(activity as? Listener)?.siteLoginDialogClosed(source!!) (activity as? Listener)?.siteLoginDialogClosed(source!!)
} else { } else {