Skip to content

Instantly share code, notes, and snippets.

@DjangoLC
Created April 21, 2020 17:07
Show Gist options
  • Save DjangoLC/c91b9dc8dd079061dd351d4e9be6475c to your computer and use it in GitHub Desktop.
Save DjangoLC/c91b9dc8dd079061dd351d4e9be6475c to your computer and use it in GitHub Desktop.
sample
package com.djangomx.airsale.utils.dialogs
import android.content.Context
import androidx.appcompat.app.AlertDialog
typealias onClickAllow = (Boolean) -> Unit
object Dialogs {
var alertDialog: AlertDialog.Builder? = null
fun createDialog(context: Context): AlertDialog.Builder {
alertDialog = AlertDialog.Builder(context)
return alertDialog!!
}
class Builder(val context: Context) {
private var folio = ""
private var onClickAllow: onClickAllow? = null
private var positiveButton = ""
private var cancellable = false
fun setTitle(folio: String): Builder {
this.folio = folio
return this
}
fun setPositiveButton(title: String = "ACEPTAR", listener: (Boolean) -> Unit): Builder {
onClickAllow = listener
positiveButton = title
return this
}
fun setCancellable(boolean: Boolean): Builder {
this.cancellable = boolean
return this
}
fun create() : AlertDialog {
val dialog = createDialog(context)
.setTitle(folio)
.setPositiveButton(positiveButton) { d, w ->
onClickAllow!!.invoke(true)
d.dismiss()
}
.setCancelable(cancellable)
return dialog.create()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment