diff --git a/anko/library/robolectricTests/src/test/java/DialogsTest.kt b/anko/library/robolectricTests/src/test/java/DialogsTest.kt index c98e22ec..eb86ff0e 100644 --- a/anko/library/robolectricTests/src/test/java/DialogsTest.kt +++ b/anko/library/robolectricTests/src/test/java/DialogsTest.kt @@ -7,8 +7,7 @@ import android.view.View import android.widget.Button import org.jetbrains.anko.* import org.jetbrains.anko.sdk15.listeners.onClick -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric @@ -41,6 +40,15 @@ open class DialogsTestActivity : Activity() { }.show() } } + button { + id = 4 + onClick { + alert("Message", "NonCancelable") { + isCancelable = false + positiveButton("Ok") { dialog -> dialog.dismiss() } + }.show() + } + } } } } @@ -53,6 +61,7 @@ open class DialogsTestActivity : Activity() { val button1 = activity.findViewById(1) as Button val button2 = activity.findViewById(2) as Button val button3 = activity.findViewById(3) as Button + val button4 = activity.findViewById(4) as Button button1.performClick() ShadowLooper.idleMainLooper() @@ -77,7 +86,15 @@ open class DialogsTestActivity : Activity() { assertEquals(View.GONE, alert.getButton(DialogInterface.BUTTON_NEUTRAL).visibility) alert.dismiss() + ShadowLooper.idleMainLooper() + + button4.performClick() + val nonCancelableAlert = ShadowAlertDialog.getLatestAlertDialog() + assertNotNull(nonCancelableAlert) + val nonCancelableAlertShadow = ShadowExtractor.extract(nonCancelableAlert) as ShadowAlertDialog + assertEquals("NonCancelable", nonCancelableAlertShadow.title.toString()) + assertFalse(nonCancelableAlertShadow.isCancelable) + println("[COMPLETE]") } - } \ No newline at end of file diff --git a/anko/library/static/appcompatV7/src/SupportAlertBuilder.kt b/anko/library/static/appcompatV7/src/SupportAlertBuilder.kt index 1634ba7a..0e9a11f9 100644 --- a/anko/library/static/appcompatV7/src/SupportAlertBuilder.kt +++ b/anko/library/static/appcompatV7/src/SupportAlertBuilder.kt @@ -16,13 +16,14 @@ package org.jetbrains.anko.appcompat.v7 -import org.jetbrains.anko.* import android.content.Context import android.content.DialogInterface import android.graphics.drawable.Drawable import android.support.v7.app.AlertDialog import android.view.KeyEvent import android.view.View +import org.jetbrains.anko.AlertBuilder +import org.jetbrains.anko.AlertBuilderFactory import org.jetbrains.anko.internals.AnkoInternals import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER import kotlin.DeprecationLevel.ERROR @@ -64,6 +65,10 @@ internal class AppcompatAlertBuilder(override val ctx: Context) : AlertBuilder Unit) { builder.setOnCancelListener(handler) } diff --git a/anko/library/static/commons/src/dialogs/AlertBuilder.kt b/anko/library/static/commons/src/dialogs/AlertBuilder.kt index 0a9b3d76..35d979ba 100644 --- a/anko/library/static/commons/src/dialogs/AlertBuilder.kt +++ b/anko/library/static/commons/src/dialogs/AlertBuilder.kt @@ -58,6 +58,9 @@ interface AlertBuilder { var customView: View @Deprecated(NO_GETTER, level = ERROR) get + var isCancelable: Boolean + @Deprecated(NO_GETTER, level = ERROR) get + fun onCancelled(handler: (dialog: DialogInterface) -> Unit) fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) diff --git a/anko/library/static/commons/src/dialogs/AndroidAlertBuilder.kt b/anko/library/static/commons/src/dialogs/AndroidAlertBuilder.kt index 92dc054d..cc7b991e 100644 --- a/anko/library/static/commons/src/dialogs/AndroidAlertBuilder.kt +++ b/anko/library/static/commons/src/dialogs/AndroidAlertBuilder.kt @@ -63,6 +63,10 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder Unit) { builder.setOnCancelListener(handler) }