-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect click listener on speed info view
- Loading branch information
1 parent
fac840d
commit 93428c5
Showing
27 changed files
with
197 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/ClickBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mapbox.navigation.dropin | ||
|
||
import kotlinx.coroutines.channels.BufferOverflow | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
|
||
internal class ClickBehavior<T> { | ||
|
||
private val _onViewClicked = MutableSharedFlow<T>( | ||
extraBufferCapacity = 1, | ||
onBufferOverflow = BufferOverflow.DROP_OLDEST, | ||
) | ||
val onViewClicked = _onViewClicked.asSharedFlow() | ||
|
||
fun onClicked(value: T) { | ||
_onViewClicked.tryEmit(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/map/MapClickBehavior.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ropin/src/main/java/com/mapbox/navigation/dropin/navigationview/NavigationViewBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mapbox.navigation.dropin.navigationview | ||
|
||
import com.mapbox.geojson.Point | ||
import com.mapbox.navigation.dropin.ClickBehavior | ||
import com.mapbox.navigation.dropin.infopanel.InfoPanelBehavior | ||
import com.mapbox.navigation.dropin.maneuver.ManeuverBehavior | ||
import com.mapbox.navigation.ui.speedlimit.model.SpeedInfoValue | ||
|
||
internal class NavigationViewBehavior { | ||
val maneuverBehavior = ManeuverBehavior() | ||
val infoPanelBehavior = InfoPanelBehavior() | ||
val mapClickBehavior = ClickBehavior<Point>() | ||
val speedInfoBehavior = ClickBehavior<SpeedInfoValue?>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...n/src/main/java/com/mapbox/navigation/dropin/speedlimit/SpeedInfoComponentContractImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mapbox.navigation.dropin.speedlimit | ||
|
||
import com.mapbox.navigation.dropin.ClickBehavior | ||
import com.mapbox.navigation.ui.speedlimit.internal.SpeedInfoComponentContract | ||
import com.mapbox.navigation.ui.speedlimit.model.SpeedInfoValue | ||
|
||
internal class SpeedInfoComponentContractImpl( | ||
private val speedInfoBehavior: ClickBehavior<SpeedInfoValue?> | ||
) : SpeedInfoComponentContract { | ||
|
||
override fun onSpeedInfoClicked(speedInfo: SpeedInfoValue?) { | ||
speedInfoBehavior.onClicked(speedInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/ClickBehaviorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.mapbox.navigation.dropin | ||
|
||
import com.mapbox.geojson.Point | ||
import com.mapbox.navigation.ui.speedlimit.model.SpeedInfoValue | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.cancelAndJoin | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
@ExperimentalCoroutinesApi | ||
class ClickBehaviorTest { | ||
|
||
@Test | ||
fun `when speed info is clicked, event is received`() = runBlockingTest { | ||
val sut = ClickBehavior<SpeedInfoValue?>() | ||
val events = arrayListOf<SpeedInfoValue?>() | ||
val job = sut.onViewClicked.onEach { events.add(it) }.launchIn(scope = this) | ||
|
||
val speedInfo = mockk<SpeedInfoValue>() | ||
sut.onClicked(speedInfo) | ||
job.cancelAndJoin() | ||
|
||
assertEquals(listOf(speedInfo), events) | ||
} | ||
|
||
@Test | ||
fun `when map is clicked, event is received`() = runBlockingTest { | ||
val sut = ClickBehavior<Point>() | ||
val events = arrayListOf<Point>() | ||
val job = sut.onViewClicked.onEach { events.add(it) }.launchIn(scope = this) | ||
|
||
val point = mockk<Point>() | ||
sut.onClicked(point) | ||
job.cancelAndJoin() | ||
|
||
assertEquals(listOf(point), events) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.