Skip to content

Commit

Permalink
Keep AdvancedDialog button always enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jun 11, 2024
1 parent 3ddba7a commit 9d2d497
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions app/src/main/kotlin/com/github/gotify/login/AdvancedDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.github.gotify.login

import android.content.Context
import android.view.LayoutInflater
import android.widget.Button
import android.widget.CompoundButton
import androidx.appcompat.app.AlertDialog
import androidx.core.widget.doOnTextChanged
import com.github.gotify.R
import com.github.gotify.databinding.AdvancedSettingsDialogBinding
Expand All @@ -14,7 +12,6 @@ internal class AdvancedDialog(
private val context: Context,
private val layoutInflater: LayoutInflater
) {
private lateinit var dialogDoneButton: Button
private lateinit var binding: AdvancedSettingsDialogBinding
private var onCheckedChangeListener: CompoundButton.OnCheckedChangeListener? = null
private lateinit var onClickSelectCaCertificate: Runnable
Expand Down Expand Up @@ -50,7 +47,7 @@ internal class AdvancedDialog(
return this
}

fun onClose(onClose: (passworrd: String) -> Unit): AdvancedDialog {
fun onClose(onClose: (password: String) -> Unit): AdvancedDialog {
this.onClose = onClose
return this
}
Expand All @@ -75,16 +72,6 @@ internal class AdvancedDialog(
showPasswordMissing(binding.clientCertPasswordEdittext.text.toString().isEmpty())
}
}
val dialog = MaterialAlertDialogBuilder(context)
.setView(binding.root)
.setTitle(R.string.advanced_settings)
.setPositiveButton(context.getString(R.string.done), null)
.setOnDismissListener {
onClose(binding.clientCertPasswordEdittext.text.toString())
}
.create()
dialog.show()
dialogDoneButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
if (caCertPath == null) {
showSelectCaCertificate()
} else {
Expand All @@ -95,6 +82,14 @@ internal class AdvancedDialog(
} else {
showRemoveClientCertificate()
}
MaterialAlertDialogBuilder(context)
.setView(binding.root)
.setTitle(R.string.advanced_settings)
.setPositiveButton(context.getString(R.string.done), null)
.setOnDismissListener {
onClose(binding.clientCertPasswordEdittext.text.toString())
}
.show()
return this
}

Expand Down Expand Up @@ -132,7 +127,6 @@ internal class AdvancedDialog(
}

private fun showPasswordMissing(toggled: Boolean) {
dialogDoneButton.isEnabled = !toggled
val error = if (toggled) {
context.getString(R.string.client_cert_password_missing)
} else {
Expand Down

0 comments on commit 9d2d497

Please sign in to comment.