Skip to content

Kotlin DSL Component #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2021
Merged

Kotlin DSL Component #95

merged 3 commits into from
May 13, 2021

Conversation

julianfalcionelli
Copy link
Contributor

@julianfalcionelli julianfalcionelli commented May 10, 2021

One Line Summary

Creating a component through the use of Kotlin DSL.

Issue(s) Addressed

Closes #90

Steps to Reproduce/Test

From the Home Screen Click on the "Dsl Dialog" menu, and a very generic Dialog should appear.

Checklist

  • Functionally tested
  • Unit tests created / updated
  • Backend dependencies deployed (if needed)

Copy link
Contributor

@brimanning brimanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good, just had a couple questions. I'm wondering if there's a way to abstract out blocks like this:

title?.let {
    setTitle(it)
} ?: run {
    titleRes?.let {
        setTitle(it)
    }
}

I'm guessing there is, just wondering how to do it and make it understandable.

}

content?.let {
setTitle(it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be setMessage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch 👍

setTitle(it)
} ?: run {
contentRes?.let {
setTitle(it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same here?

@julianfalcionelli
Copy link
Contributor Author

julianfalcionelli commented May 11, 2021

Looking pretty good, just had a couple questions. I'm wondering if there's a way to abstract out blocks like this:

title?.let {
    setTitle(it)
} ?: run {
    titleRes?.let {
        setTitle(it)
    }
}

I'm guessing there is, just wondering how to do it and make it understandable.

I couldn't figure out a better native way with scope functions, so I created a "quartus" extension function to simplify this, let me know your thoughts about it.

private fun <T, U> Any.quartus(
    primaryValue: T?,
    primaryAction: ((T) -> Unit)? = null,
    secondaryValue: U?,
    secondaryAction: ((U) -> Unit)? = null
) {
    primaryValue?.let {
        primaryAction?.invoke(it)
    } ?: run {
        secondaryValue?.let {
            secondaryAction?.invoke(it)
        }
    }
}

fun Fragment.dialog(setup: DialogBuilder.() -> Unit) {
val builder = DialogBuilder(requireContext(), setup = setup)
builder.build().show()
private fun <T, U> Any.ternary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesss! Clever (in a good way)!

@julianfalcionelli julianfalcionelli merged commit 75e649f into master May 13, 2021
@julianfalcionelli julianfalcionelli deleted the julian/kotlin-dsl branch May 13, 2021 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DSL Usage
2 participants