Skip to content

Instantly share code, notes, and snippets.

@polson
Last active August 17, 2020 21:13
Show Gist options
  • Save polson/2a1bf0d6d88ef58d5d2cecdc316ae6fd to your computer and use it in GitHub Desktop.
Save polson/2a1bf0d6d88ef58d5d2cecdc316ae6fd to your computer and use it in GitHub Desktop.
private class DialogBuilderImpl<T>(val context: Context) : DialogBuilder<T> {
data class DialogArgs<T>(
val title: String? = null,
val message: String? = null,
val yesButtonAction: Serializable? = null,
val noButtonAction: Serializable? = null,
val yesButtonText: String? = null,
val noButtonText: String? = null
) : Serializable
var args = DialogArgs<T>()
override fun title(title: String) {
args = args.copy(title = title)
}
override fun title(titleResId: Int) {
args = args.copy(title = context.getString(titleResId))
}
override fun message(message: String) {
args = args.copy(message = message)
}
override fun message(messageResId: Int) {
args = args.copy(message = context.getString(messageResId))
}
override fun positiveButtonAction(action: DialogCallback<T>) {
args = args.copy(yesButtonAction = action as Serializable)
}
override fun negativeButtonAction(action: DialogCallback<T>) {
args = args.copy(noButtonAction = action as Serializable)
}
override fun negativeButtonText(negativeButtonResId: Int) {
args = args.copy(noButtonText = context.getString(negativeButtonResId))
}
override fun negativeButtonText(negativeButtonText: String) {
args = args.copy(noButtonText = negativeButtonText)
}
override fun positiveButtonText(resId: Int) {
args = args.copy(yesButtonText = context.getString(resId))
}
override fun positiveButtonText(positiveButtonText: String) {
args = args.copy(yesButtonText = positiveButtonText)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment