Browse Source

Resolve #1573, fixes dialog callbacks (show/cancel/dismiss) not working due to a simple logical error.

Aidan Follestad 6 years ago
parent
commit
c5e7dc4a33

+ 2 - 12
core/src/main/java/com/afollestad/materialdialogs/callbacks/DialogCallbackExt.kt

@@ -15,6 +15,8 @@ fun MaterialDialog.onPreShow(callback: DialogCallback): MaterialDialog {
 /**
  * Adds a listener that's invoked when the dialog is [show]'n. If this is called
  * multiple times, it appends additional callbacks, rather than overwriting.
+ *
+ * If the dialog is already showing, the callback be will be invoked immediately.
  */
 fun MaterialDialog.onShow(callback: DialogCallback): MaterialDialog {
   this.showListeners.add(callback)
@@ -22,10 +24,6 @@ fun MaterialDialog.onShow(callback: DialogCallback): MaterialDialog {
     // Already showing, invoke now
     this.showListeners.invokeAll(this)
   }
-  if (this.showListeners.isNotEmpty()) {
-    // Already set the base show listener
-    return this
-  }
   setOnShowListener { this.showListeners.invokeAll(this) }
   return this
 }
@@ -36,10 +34,6 @@ fun MaterialDialog.onShow(callback: DialogCallback): MaterialDialog {
  */
 fun MaterialDialog.onDismiss(callback: DialogCallback): MaterialDialog {
   this.dismissListeners.add(callback)
-  if (this.dismissListeners.isNotEmpty()) {
-    // Already set the base dismiss listener
-    return this
-  }
   setOnDismissListener { dismissListeners.invokeAll(this) }
   return this
 }
@@ -50,10 +44,6 @@ fun MaterialDialog.onDismiss(callback: DialogCallback): MaterialDialog {
  */
 fun MaterialDialog.onCancel(callback: DialogCallback): MaterialDialog {
   this.cancelListeners.add(callback)
-  if (this.cancelListeners.isNotEmpty()) {
-    // Already set the base cancel listener
-    return this
-  }
   setOnCancelListener { cancelListeners.invokeAll(this) }
   return this
 }