aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-06-07 09:39:33 -0400
committerAllan Wang <me@allanwang.ca>2019-06-07 09:39:33 -0400
commitd6a61d5b2601b3849bf402e48fcf1c50a32cfcab (patch)
tree745ed921423e572c8bff8da6dc08db5ec115115b /core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
parentb9feba20d45505a22162c386e18dfc1a4f117d3f (diff)
downloadkau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.tar.gz
kau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.tar.bz2
kau-d6a61d5b2601b3849bf402e48fcf1c50a32cfcab.zip
Begin initial md port
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt21
1 files changed, 13 insertions, 8 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 94750e3..82d5608 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -45,7 +45,9 @@ import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import ca.allanwang.kau.R
import ca.allanwang.kau.logging.KL
+import com.afollestad.materialdialogs.DialogBehavior
import com.afollestad.materialdialogs.MaterialDialog
+import com.afollestad.materialdialogs.ModalDialog
/**
* Created by Allan Wang on 2017-06-03.
@@ -193,17 +195,20 @@ fun Context.resolveString(@AttrRes attr: Int, fallback: String = ""): String {
}
/**
- * Wrapper function for the MaterialDialog adapterBuilder
- * There is no need to call build() or show() as those are done by default
+ * Wrapper function for MaterialDialog
+ *
+ * Mainly handles invalid creations, such as showing a dialog when an activity is finishing
+ * See https://github.com/afollestad/material-dialogs/issues/1778
*/
-inline fun Context.materialDialog(action: MaterialDialog.Builder.() -> Unit): MaterialDialog {
- val builder = MaterialDialog.Builder(this)
- builder.action()
+inline fun Context.materialDialog(
+ dialogBehavior: DialogBehavior = ModalDialog,
+ action: MaterialDialog.() -> Unit
+) {
+ val dialog = MaterialDialog(this, dialogBehavior)
if (isFinishing) {
- KL.d { "Material Dialog triggered from finishing context; did not show" }
- return builder.build()
+ return KL.d { "Material Dialog triggered from finishing context; did not show" }
}
- return builder.show()
+ dialog.show(action)
}
fun Context.getDip(value: Float): Float =