One Dialog for All — QuickDialog

Bill Inkoom
4 min readJun 5, 2018

Dialogs are part of android development, they are like really part of it. You just can’t do without them or maybe you could. But what if there was just this one dialog you could use for everything from confirmation, verification, information or progression (I really needed to finish the rhyming, but this means to show progress as in a ProgreesDialog).

Well I came up with one such dialog that , I call the QuickDialog.

Quick Dialog

Quick dialog simply gives you multiple consistent variants of dialogs you need in your Android App.

  • Message Dialog
  • Progress Dialog
  • Alert Dialog
  • Input Dialog

Quick Start

Add it in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Add the dependency

dependencies {
implementation ‘com.github.billkainkoom:quickdialog:v0.70’
}

Message Dialog

A message dialog simply displays an image with one button.

QuickDialog(
context = this,
style = QuickDialogType.Message,
title = "Hello World",
message = "The quick dialog jumped over the old dialog",
image = R.drawable.ic_info_outline_black_24dp)
.overrideButtonNames("OK" ).overrideClicks({ ->
Toast.makeText(context, "Clicked on OK", Toast.LENGTH_SHORT).show()
}).show()

A progress dialog shows a circular progress in an indeterminate state with or without a button

QuickDialog(
context = context,
style = QuickDialogType.Progress,
title = "Please wait",
message = "Walking round the world")
.show()

This variant however shows a button so that a user can dismiss the dialog

QuickDialog(
context = context,
style = QuickDialogType.Progress,
title = "Please wait",
message = "Walking round the world")
.overrideButtonNames("Hide Progress")
.overrideClicks({ ->
Toast.makeText(context, "Clicked on Hide Progress", Toast.LENGTH_SHORT).show()
}).showPositiveButton()
.show()

Alert Dialog

An alert dialog is used in situations when a user has to make a decision

QuickDialog(
context = context,
style = QuickDialogType.Alert,
title = "Proceed",
message = "Do you want to take this action")
.overrideButtonNames("Yes", "No")
.overrideClicks(positiveClick = { ->
Toast.makeText(context, "Yes", Toast.LENGTH_SHORT).show()
}, negativeClick = { ->
Toast.makeText(context, "No", Toast.LENGTH_SHORT).show()
})
.show()

The overrideClicks appears in three forms

OverrideClicks #1

fun overrideClicks(
positiveClick: () -> Unit = {},
negativeClick: () -> Unit = {},
neutralClick: () -> Unit = {}
)

OverrideClicks #2

fun overrideClicks(
positiveClick: (dismiss: () -> Unit) -> Unit = { d -> },
negativeClick: (dismiss: () -> Unit) -> Unit = { d -> },
neutralClick: (dismiss: () -> Unit) -> Unit = { d -> }
)

The variable d is an anonymos function that is passed from the implemetation of the overideClicks function. It is the dismiss function in QuickDialog and it helps you dismiss the dialog in the click closure. All overloaded methods with dsupplied do not dismiss automatically.

Lets see an example

QuickDialog(
context = context,
style = QuickDialogType.Alert,
title = "Proceed",
message = "Do you want to take this action")
.overrideButtonNames("Yes", "No")
.overrideClicks(positiveClick = { dismiss ->
if (true) {
Toast.makeText(context, "Yes", Toast.LENGTH_SHORT).show()
dismiss()
}
}, negativeClick = { dismiss ->
if (true) {
Toast.makeText(context, "No", Toast.LENGTH_SHORT).show()
dismiss()
}
})
.show()

If we dont invoke dismiss the Quick dialog wont disappear.

OverrideClicks #3

fun overrideClicks(
positiveClick: (dismiss: () -> Unit, inputText: String) -> Unit = { d, s -> },
negativeClick: (dismiss: () -> Unit, inputText: String) -> Unit = { d, s -> },
neutralClick: (dismiss: () -> Unit, inputText: String) -> Unit = { d, s -> }
)

The d is same as the one described above. However the s is text that a user entered in the WithInput variation of the QuickDialog

WithInput Dialog

I agree its a weird name, but this is meant for verification, the type where you usually have to enter some code.

lets see an example

QuickDialog(
context = context,
style = QuickDialogType.WithInput,
title = "Verify Code",
message = "Please verify the SMS code that was sent to you")
.overrideButtonNames("Verify", "Cancel", "Re-send")
.overrideClicks(positiveClick = { dismiss, inputText ->
if (inputText.length < 3) {
Toast.makeText(context, "Please enter a 4 digit code", Toast.LENGTH_SHORT).show()
} else if (inputText == "4000") {
Toast.makeText(context, "Verified", Toast.LENGTH_SHORT).show()
dismiss()
} else {
Toast.makeText(context, "You entered the wrong code", Toast.LENGTH_SHORT).show()
}
}, negativeClick = { dismiss, inputText ->
dismiss()
}, neutralClick = { dismiss, inputText ->
//Your action
dismiss()
})
.withInputHint("Code")
.withInputLength(4)
.withInputType(InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL)
.showNeutralButton()
.show()

You can find QuickDialog on GitHub by following this link

https://github.com/billkainkoom/quickdialog/

--

--

Bill Inkoom

Software Engineer with great love for Mathematics especially Abstract Mathematics.