class Pizza private constructor(
val size: String,
val cheese: Int,
val olives: Int,
val bacon: Int
) {
class Builder(private val size: String) {
private var cheese: Int = 0
private var olives: Int = 0
private var bacon: Int = 0
fun setCheese(value: Int): Builder = apply {
cheese = value
}
fun setOlives(value: Int): Builder = apply {
olives = value
}
fun setBacon(value: Int): Builder = apply {
bacon = value
}
fun build() = Pizza(size, cheese, olives, bacon)
}
}
val myFavorite = Pizza.Builder("L").setOlives(3).build()
val villagePizza = Pizza.Builder("L")
.setCheese(1)
.setOlives(2)
.setBacon(3)
.build()
val dialog = context.alert(R.string.fire_missiles) {
positiveButton(R.string.fire) {
// FIRE ZE MISSILES!
}
negativeButton {
// User cancelled the dialog
}
}
val route = router {
"/home" directsTo ::showHome
"/users" directsTo ::showUsers
}
fun Context.makeDefaultDialogBuilder() =
AlertDialog.Builder(this)
.setIcon(R.drawable.ic_dialog)
.setTitle(R.string.dialog_title)
.setOnCancelListener { it.cancel() }
data class DialogConfig(
val icon: Int = -1,
val title: Int = -1,
val onCancelListener: (() -> Unit)? = null
//...
)
fun makeDefaultDialogConfig() = DialogConfig(
icon = R.drawable.ic_dialog,
title = R.string.dialog_title,
onCancelListener = { it.cancel() }
)