diff --git a/app/build.gradle b/app/build.gradle index d721cb07..00d912b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { defaultConfig { applicationId "com.google.maps.android.ktx.demo" - minSdkVersion versions.android.minSdk + minSdkVersion 24 targetSdkVersion versions.android.targetSdk versionCode 1 versionName "1.0" @@ -41,6 +41,7 @@ android { kotlinOptions { freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"] + jvmTarget = "1.8" } } diff --git a/build.gradle b/build.gradle index 5f1292b9..5959fcff 100644 --- a/build.gradle +++ b/build.gradle @@ -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', @@ -132,7 +132,7 @@ subprojects { project -> // Code coverage jacoco { - toolVersion = "0.8.4" + toolVersion = "0.8.7" } tasks.withType(Test) { diff --git a/maps-ktx/build.gradle b/maps-ktx/build.gradle index 7cb4430b..cb7bde3a 100644 --- a/maps-ktx/build.gradle +++ b/maps-ktx/build.gradle @@ -32,6 +32,7 @@ android { kotlinOptions { freeCompilerArgs += '-Xexplicit-api=strict' + jvmTarget = "1.8" } } diff --git a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt index f32ed461..d8643b84 100644 --- a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt +++ b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt @@ -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 SendChannel.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 @@ -126,16 +119,16 @@ internal fun SendChannel.offerCatching(element: E): Boolean { public fun GoogleMap.cameraEvents(): Flow = 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) @@ -186,7 +179,7 @@ public suspend inline fun GoogleMap.awaitMapLoad(): Unit = public fun GoogleMap.cameraIdleEvents(): Flow = callbackFlow { setOnCameraIdleListener { - offerCatching(Unit) + trySend(Unit) } awaitClose { setOnCameraIdleListener(null) @@ -202,7 +195,7 @@ public fun GoogleMap.cameraIdleEvents(): Flow = public fun GoogleMap.cameraMoveCanceledEvents(): Flow = callbackFlow { setOnCameraMoveCanceledListener { - offerCatching(Unit) + trySend(Unit) } awaitClose { setOnCameraMoveCanceledListener(null) @@ -217,7 +210,7 @@ public fun GoogleMap.cameraMoveCanceledEvents(): Flow = public fun GoogleMap.cameraMoveEvents(): Flow = callbackFlow { setOnCameraMoveListener { - offerCatching(Unit) + trySend(Unit) } awaitClose { setOnCameraMoveListener(null) @@ -244,7 +237,7 @@ public suspend inline fun GoogleMap.awaitSnapshot(bitmap: Bitmap? = null): Bitma public fun GoogleMap.cameraMoveStartedEvents(): Flow = callbackFlow { setOnCameraMoveStartedListener { - offerCatching(Unit) + trySend(Unit) } awaitClose { setOnCameraMoveStartedListener(null) @@ -259,7 +252,7 @@ public fun GoogleMap.cameraMoveStartedEvents(): Flow = public fun GoogleMap.circleClickEvents(): Flow = callbackFlow { setOnCircleClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnCircleClickListener(null) @@ -275,7 +268,7 @@ public fun GoogleMap.circleClickEvents(): Flow = public fun GoogleMap.groundOverlayClicks(): Flow = callbackFlow { setOnGroundOverlayClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnGroundOverlayClickListener(null) @@ -292,11 +285,11 @@ public fun GoogleMap.indoorStateChangeEvents(): Flow = 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 { @@ -313,7 +306,7 @@ public fun GoogleMap.indoorStateChangeEvents(): Flow = public fun GoogleMap.infoWindowClickEvents(): Flow = callbackFlow { setOnInfoWindowClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnInfoWindowClickListener(null) @@ -329,7 +322,7 @@ public fun GoogleMap.infoWindowClickEvents(): Flow = public fun GoogleMap.infoWindowCloseEvents(): Flow = callbackFlow { setOnInfoWindowCloseListener { - offerCatching(it) + trySend(it) } awaitClose { setOnInfoWindowCloseListener(null) @@ -345,7 +338,7 @@ public fun GoogleMap.infoWindowCloseEvents(): Flow = public fun GoogleMap.infoWindowLongClickEvents(): Flow = callbackFlow { setOnInfoWindowLongClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnInfoWindowLongClickListener(null) @@ -360,7 +353,7 @@ public fun GoogleMap.infoWindowLongClickEvents(): Flow = public fun GoogleMap.mapClickEvents(): Flow = callbackFlow { setOnMapClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnMapClickListener(null) @@ -375,7 +368,7 @@ public fun GoogleMap.mapClickEvents(): Flow = public fun GoogleMap.mapLongClickEvents(): Flow = callbackFlow { setOnMapLongClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnMapLongClickListener(null) @@ -390,7 +383,7 @@ public fun GoogleMap.mapLongClickEvents(): Flow = public fun GoogleMap.markerClickEvents(): Flow = callbackFlow { setOnMarkerClickListener { - offerCatching(it) + trySend(it).isSuccess } awaitClose { setOnMarkerClickListener(null) @@ -406,15 +399,15 @@ public fun GoogleMap.markerDragEvents(): Flow = 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)) } }) @@ -432,7 +425,7 @@ public fun GoogleMap.markerDragEvents(): Flow = public fun GoogleMap.myLocationButtonClickEvents(): Flow = callbackFlow { setOnMyLocationButtonClickListener { - offerCatching(Unit) + trySend(Unit).isSuccess } awaitClose { setOnMyLocationButtonClickListener(null) @@ -448,7 +441,7 @@ public fun GoogleMap.myLocationButtonClickEvents(): Flow = public fun GoogleMap.myLocationClickEvents(): Flow = callbackFlow { setOnMyLocationClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnMyLocationClickListener(null) @@ -464,7 +457,7 @@ public fun GoogleMap.myLocationClickEvents(): Flow = public fun GoogleMap.poiClickEvents(): Flow = callbackFlow { setOnPoiClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnPoiClickListener(null) @@ -479,7 +472,7 @@ public fun GoogleMap.poiClickEvents(): Flow = public fun GoogleMap.polygonClickEvents(): Flow = callbackFlow { setOnPolygonClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnPolygonClickListener(null) @@ -494,7 +487,7 @@ public fun GoogleMap.polygonClickEvents(): Flow = public fun GoogleMap.polylineClickEvents(): Flow = callbackFlow { setOnPolylineClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnPolylineClickListener(null) diff --git a/maps-ktx/src/main/java/com/google/maps/android/ktx/StreetViewPanoramaView.kt b/maps-ktx/src/main/java/com/google/maps/android/ktx/StreetViewPanoramaView.kt index 8ca2c331..0b63a619 100644 --- a/maps-ktx/src/main/java/com/google/maps/android/ktx/StreetViewPanoramaView.kt +++ b/maps-ktx/src/main/java/com/google/maps/android/ktx/StreetViewPanoramaView.kt @@ -36,7 +36,7 @@ public suspend inline fun StreetViewPanoramaView.awaitStreetViewPanorama(): Stre public fun StreetViewPanorama.cameraChangeEvents(): Flow = callbackFlow { setOnStreetViewPanoramaCameraChangeListener { - offerCatching(it) + trySend(it) } awaitClose { setOnStreetViewPanoramaCameraChangeListener(null) @@ -52,7 +52,7 @@ public fun StreetViewPanorama.cameraChangeEvents(): Flow = callbackFlow { setOnStreetViewPanoramaChangeListener { - offerCatching(it) + trySend(it) } awaitClose { setOnStreetViewPanoramaChangeListener(null) @@ -68,7 +68,7 @@ public fun StreetViewPanorama.changeEvents(): Flow = public fun StreetViewPanorama.clickEvents(): Flow = callbackFlow { setOnStreetViewPanoramaClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnStreetViewPanoramaClickListener(null) @@ -84,7 +84,7 @@ public fun StreetViewPanorama.clickEvents(): Flow public fun StreetViewPanorama.longClickEvents(): Flow = callbackFlow { setOnStreetViewPanoramaLongClickListener { - offerCatching(it) + trySend(it) } awaitClose { setOnStreetViewPanoramaLongClickListener(null) diff --git a/maps-utils-ktx/build.gradle b/maps-utils-ktx/build.gradle index caa89d50..35beb080 100644 --- a/maps-utils-ktx/build.gradle +++ b/maps-utils-ktx/build.gradle @@ -35,6 +35,7 @@ android { kotlinOptions { freeCompilerArgs += '-Xexplicit-api=strict' + jvmTarget = "1.8" } } diff --git a/maps-utils-v3-ktx/build.gradle b/maps-utils-v3-ktx/build.gradle index 38ede923..a6e05d31 100644 --- a/maps-utils-v3-ktx/build.gradle +++ b/maps-utils-v3-ktx/build.gradle @@ -35,6 +35,7 @@ android { kotlinOptions { freeCompilerArgs += '-Xexplicit-api=strict' + jvmTarget = "1.8" } } diff --git a/maps-v3-ktx/build.gradle b/maps-v3-ktx/build.gradle index 838e4cb4..c9a6089d 100644 --- a/maps-v3-ktx/build.gradle +++ b/maps-v3-ktx/build.gradle @@ -32,6 +32,7 @@ android { kotlinOptions { freeCompilerArgs += '-Xexplicit-api=strict' + jvmTarget = "1.8" } }