Created
April 20, 2017 05:55
-
-
Save PrashamTrivedi/45f608790113af7eb8e59ace78e77b1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Part of Functions.kt, this and below 3 functions helps to create dialog. | |
public fun Context.showDialog(cancelable: Boolean = false, cancelableTouchOutside: Boolean = false, builderFunction: AlertDialog.Builder.() -> Any) { | |
val builder = AlertDialog.Builder(this) | |
builder.builderFunction() | |
val dialog = builder.create(); | |
dialog.setCancelable(cancelable) | |
dialog.setCanceledOnTouchOutside(cancelableTouchOutside) | |
dialog.show() | |
} | |
public fun AlertDialog.Builder.positiveButton(text: String = "OK", handleClick: (i: Int) -> Unit = {}) { | |
this.setPositiveButton(text, { dialogInterface, i -> handleClick(i) }) | |
} | |
public fun AlertDialog.Builder.negativeButton(text: String = "CANCEL", handleClick: (i: Int) -> Unit = {}) { | |
this.setNegativeButton(text, { dialogInterface, i -> handleClick(i) }) | |
} | |
public fun AlertDialog.Builder.neutralButton(text: String, handleClick: (i: Int) -> Unit = {}) { | |
this.setNeutralButton(text, { dialogInterface, i -> handleClick(i) }) | |
} | |
//Sample of this code in MainActivityViewModel | |
activity.showDialog { | |
setTitle("Pick Path") | |
positiveButton("Pick Files", { pickPathToRead() }) | |
negativeButton() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment