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

feat: Bump Kotlin to 1.5.30 and KotlinX Coroutines to 1.5.1 #162

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ android {
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ buildscript {
'junit' : '1.1.1',
],
'junit' : '4.12',
'kotlin' : '1.4.32',
'kotlinxCoroutines': '1.4.3',
'kotlin' : '1.5.30',
'kotlinxCoroutines': '1.5.1',
'mapsBeta' : '3.1.0-beta',
'mockito' : '3.0.0',
'mockitoKotlin' : '2.2.0',
Expand Down
59 changes: 26 additions & 33 deletions maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ public object IndoorBuildingFocusedEvent : IndoorChangeEvent()
*/
public data class IndoorLevelActivatedEvent(val building: IndoorBuilding) : IndoorChangeEvent()

// Since offer() can throw when the channel is closed (channel can close before the
// block within awaitClose), wrap `offer` calls inside `runCatching`.
// See: https://github.com/Kotlin/kotlinx.coroutines/issues/974
internal fun <E> SendChannel<E>.offerCatching(element: E): Boolean {
return runCatching { offer(element) }.getOrDefault(false)
}

/**
* Returns a [Flow] of [CameraEvent] items so that camera movements can be observed. Using this to
* observe camera events will set listeners and thus override existing listeners to
Expand All @@ -126,16 +119,16 @@ internal fun <E> SendChannel<E>.offerCatching(element: E): Boolean {
public fun GoogleMap.cameraEvents(): Flow<CameraEvent> =
callbackFlow {
setOnCameraIdleListener {
offerCatching(CameraIdleEvent)
trySend(CameraIdleEvent)
}
setOnCameraMoveCanceledListener {
offerCatching(CameraMoveCanceledEvent)
trySend(CameraMoveCanceledEvent)
}
setOnCameraMoveListener {
offerCatching(CameraMoveEvent)
trySend(CameraMoveEvent)
}
setOnCameraMoveStartedListener {
offerCatching(CameraMoveStartedEvent(it))
trySend(CameraMoveStartedEvent(it))
}
awaitClose {
setOnCameraIdleListener(null)
Expand Down Expand Up @@ -186,7 +179,7 @@ public suspend inline fun GoogleMap.awaitMapLoad(): Unit =
public fun GoogleMap.cameraIdleEvents(): Flow<Unit> =
callbackFlow {
setOnCameraIdleListener {
offerCatching(Unit)
trySend(Unit)
}
awaitClose {
setOnCameraIdleListener(null)
Expand All @@ -202,7 +195,7 @@ public fun GoogleMap.cameraIdleEvents(): Flow<Unit> =
public fun GoogleMap.cameraMoveCanceledEvents(): Flow<Unit> =
callbackFlow {
setOnCameraMoveCanceledListener {
offerCatching(Unit)
trySend(Unit)
}
awaitClose {
setOnCameraMoveCanceledListener(null)
Expand All @@ -217,7 +210,7 @@ public fun GoogleMap.cameraMoveCanceledEvents(): Flow<Unit> =
public fun GoogleMap.cameraMoveEvents(): Flow<Unit> =
callbackFlow {
setOnCameraMoveListener {
offerCatching(Unit)
trySend(Unit)
}
awaitClose {
setOnCameraMoveListener(null)
Expand All @@ -244,7 +237,7 @@ public suspend inline fun GoogleMap.awaitSnapshot(bitmap: Bitmap? = null): Bitma
public fun GoogleMap.cameraMoveStartedEvents(): Flow<Unit> =
callbackFlow {
setOnCameraMoveStartedListener {
offerCatching(Unit)
trySend(Unit)
}
awaitClose {
setOnCameraMoveStartedListener(null)
Expand All @@ -259,7 +252,7 @@ public fun GoogleMap.cameraMoveStartedEvents(): Flow<Unit> =
public fun GoogleMap.circleClickEvents(): Flow<Circle> =
callbackFlow {
setOnCircleClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnCircleClickListener(null)
Expand All @@ -275,7 +268,7 @@ public fun GoogleMap.circleClickEvents(): Flow<Circle> =
public fun GoogleMap.groundOverlayClicks(): Flow<GroundOverlay> =
callbackFlow {
setOnGroundOverlayClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnGroundOverlayClickListener(null)
Expand All @@ -292,11 +285,11 @@ public fun GoogleMap.indoorStateChangeEvents(): Flow<IndoorChangeEvent> =
callbackFlow {
setOnIndoorStateChangeListener(object : GoogleMap.OnIndoorStateChangeListener {
override fun onIndoorBuildingFocused() {
offerCatching(IndoorBuildingFocusedEvent)
trySend(IndoorBuildingFocusedEvent)
}

override fun onIndoorLevelActivated(indoorBuilding: IndoorBuilding) {
offerCatching(IndoorLevelActivatedEvent(building = indoorBuilding))
trySend(IndoorLevelActivatedEvent(building = indoorBuilding))
}
})
awaitClose {
Expand All @@ -313,7 +306,7 @@ public fun GoogleMap.indoorStateChangeEvents(): Flow<IndoorChangeEvent> =
public fun GoogleMap.infoWindowClickEvents(): Flow<Marker> =
callbackFlow {
setOnInfoWindowClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnInfoWindowClickListener(null)
Expand All @@ -329,7 +322,7 @@ public fun GoogleMap.infoWindowClickEvents(): Flow<Marker> =
public fun GoogleMap.infoWindowCloseEvents(): Flow<Marker> =
callbackFlow {
setOnInfoWindowCloseListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnInfoWindowCloseListener(null)
Expand All @@ -345,7 +338,7 @@ public fun GoogleMap.infoWindowCloseEvents(): Flow<Marker> =
public fun GoogleMap.infoWindowLongClickEvents(): Flow<Marker> =
callbackFlow {
setOnInfoWindowLongClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnInfoWindowLongClickListener(null)
Expand All @@ -360,7 +353,7 @@ public fun GoogleMap.infoWindowLongClickEvents(): Flow<Marker> =
public fun GoogleMap.mapClickEvents(): Flow<LatLng> =
callbackFlow {
setOnMapClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnMapClickListener(null)
Expand All @@ -375,7 +368,7 @@ public fun GoogleMap.mapClickEvents(): Flow<LatLng> =
public fun GoogleMap.mapLongClickEvents(): Flow<LatLng> =
callbackFlow {
setOnMapLongClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnMapLongClickListener(null)
Expand All @@ -390,7 +383,7 @@ public fun GoogleMap.mapLongClickEvents(): Flow<LatLng> =
public fun GoogleMap.markerClickEvents(): Flow<Marker> =
callbackFlow {
setOnMarkerClickListener {
offerCatching(it)
trySend(it).isSuccess
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious - why do only some of these use .isSuccess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because some callback methods return a boolean (like in this case onMarkerClick). offerCatching returned boolean which was being swallowed in void callback methods. The implementation here of returning isSuccess should be equivalent to calling offerCatching.

Looking at this method a bit more though, I think the return value should be customizable by the caller. As it is currently implemented, if the marker is clicked and the channel is able to send the marker object, the default behavior of moving the camera to center on the marker and displaying an info window will always occur. Will file an issue for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue filed here #163

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok - thanks. That's what I initially thought but I was confusing myself by looking at the wrong methods - in this case, setOnMarkerClickListener, which returns void instead of onMarkerClick, which returns boolean.

I think the return value should be customizable by the caller.

I agree, that makes sense 👍

}
awaitClose {
setOnMarkerClickListener(null)
Expand All @@ -406,15 +399,15 @@ public fun GoogleMap.markerDragEvents(): Flow<OnMarkerDragEvent> =
callbackFlow {
setOnMarkerDragListener(object : GoogleMap.OnMarkerDragListener {
override fun onMarkerDragStart(marker: Marker) {
offerCatching(MarkerDragStartEvent(marker = marker))
trySend(MarkerDragStartEvent(marker = marker))
}

override fun onMarkerDrag(marker: Marker) {
offerCatching(MarkerDragEvent(marker = marker))
trySend(MarkerDragEvent(marker = marker))
}

override fun onMarkerDragEnd(marker: Marker) {
offerCatching(MarkerDragEndEvent(marker = marker))
trySend(MarkerDragEndEvent(marker = marker))
}

})
Expand All @@ -432,7 +425,7 @@ public fun GoogleMap.markerDragEvents(): Flow<OnMarkerDragEvent> =
public fun GoogleMap.myLocationButtonClickEvents(): Flow<Unit> =
callbackFlow {
setOnMyLocationButtonClickListener {
offerCatching(Unit)
trySend(Unit).isSuccess
}
awaitClose {
setOnMyLocationButtonClickListener(null)
Expand All @@ -448,7 +441,7 @@ public fun GoogleMap.myLocationButtonClickEvents(): Flow<Unit> =
public fun GoogleMap.myLocationClickEvents(): Flow<Location> =
callbackFlow {
setOnMyLocationClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnMyLocationClickListener(null)
Expand All @@ -464,7 +457,7 @@ public fun GoogleMap.myLocationClickEvents(): Flow<Location> =
public fun GoogleMap.poiClickEvents(): Flow<PointOfInterest> =
callbackFlow {
setOnPoiClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnPoiClickListener(null)
Expand All @@ -479,7 +472,7 @@ public fun GoogleMap.poiClickEvents(): Flow<PointOfInterest> =
public fun GoogleMap.polygonClickEvents(): Flow<Polygon> =
callbackFlow {
setOnPolygonClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnPolygonClickListener(null)
Expand All @@ -494,7 +487,7 @@ public fun GoogleMap.polygonClickEvents(): Flow<Polygon> =
public fun GoogleMap.polylineClickEvents(): Flow<Polyline> =
callbackFlow {
setOnPolylineClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnPolylineClickListener(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public suspend inline fun StreetViewPanoramaView.awaitStreetViewPanorama(): Stre
public fun StreetViewPanorama.cameraChangeEvents(): Flow<StreetViewPanoramaCamera> =
callbackFlow {
setOnStreetViewPanoramaCameraChangeListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnStreetViewPanoramaCameraChangeListener(null)
Expand All @@ -52,7 +52,7 @@ public fun StreetViewPanorama.cameraChangeEvents(): Flow<StreetViewPanoramaCamer
public fun StreetViewPanorama.changeEvents(): Flow<StreetViewPanoramaLocation> =
callbackFlow {
setOnStreetViewPanoramaChangeListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnStreetViewPanoramaChangeListener(null)
Expand All @@ -68,7 +68,7 @@ public fun StreetViewPanorama.changeEvents(): Flow<StreetViewPanoramaLocation> =
public fun StreetViewPanorama.clickEvents(): Flow<StreetViewPanoramaOrientation> =
callbackFlow {
setOnStreetViewPanoramaClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnStreetViewPanoramaClickListener(null)
Expand All @@ -84,7 +84,7 @@ public fun StreetViewPanorama.clickEvents(): Flow<StreetViewPanoramaOrientation>
public fun StreetViewPanorama.longClickEvents(): Flow<StreetViewPanoramaOrientation> =
callbackFlow {
setOnStreetViewPanoramaLongClickListener {
offerCatching(it)
trySend(it)
}
awaitClose {
setOnStreetViewPanoramaLongClickListener(null)
Expand Down