Skip to content
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

New Alert builder system #53

Merged
merged 15 commits into from
Nov 12, 2019
21 changes: 21 additions & 0 deletions alerts/src/androidLibAndroidTest/kotlin/MockAlertsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ class MockAlertsTest {
}
}

@Test
fun testConcurrentBuilders() = runBlockingTest {
val builder = AlertBuilder(activityRule.activity)
val alerts: MutableList<AlertInterface> = mutableListOf()

CoroutineScope(Dispatchers.Main).launch {
for (i in 0 until 10) {
alerts.add(builder.alert {
setTitle("Alert$i")
setPositiveButton("OK$i")
})
}
for (i in 0 until 10) {
alerts[i].show()
device.wait(Until.findObject(By.text("Alert$i")), DEFAULT_TIMEOUT)
device.findObject(By.text("OK$i")).click()
assertTrue(device.wait(Until.gone(By.text("Alert$i")), DEFAULT_TIMEOUT))
}
}
}
Comment on lines +86 to +105
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


@Test
fun testAlertShow() = runBlockingTest {
CoroutineScope(Dispatchers.Main).launch(Dispatchers.Main) {
Expand Down
8 changes: 4 additions & 4 deletions alerts/src/androidLibMain/kotlin/Alerts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ Copyright 2019 Splendo Consulting B.V. The Netherlands

*/

inline fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit): T = apply {
if (condition) block(this)
}

actual class AlertBuilder(private val context: Context) : BaseAlertBuilder() {
override fun create() = AlertInterface(createAlert(), context)
}
Expand All @@ -33,6 +29,10 @@ actual class AlertInterface(
private val context: Context
) : BaseAlertPresenter(alert) {

private inline fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit): T = apply {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We would also only have this ones if we put it in a good spot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I put it in Components, then Alerts has to bring all dependencies which we have in Components. So it's better to make for example Utils component in dependency free stuff?

Copy link
Collaborator

@thoutbeckers thoutbeckers Nov 8, 2019

Choose a reason for hiding this comment

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

Yes, Components is from before the split into modules. It contains a bunch of utils stuff but needs to be split, see #16 You can pick it up if you want, till then I'd say it's ok for your module to depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to fulfil all dependencies but end up with circular one. I'd like to leave it here for now, so Alerts will be released and puck up #16 as next one

if (condition) block(this)
}

private var alertDialog: AlertDialog? = null

private companion object {
Expand Down