From f44f7b211f7ced7c845bfb7f97123caf219dae18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Lo=CC=81pez=20Man=CC=83as?= Date: Mon, 27 May 2024 10:55:50 +0200 Subject: [PATCH 1/7] chore: updated Kotlin to 2.0.0 --- app/build.gradle | 12 +-- .../maps/android/ktx/demo/MainActivity.kt | 93 ++++++++++--------- build.gradle | 61 ++---------- gradle.properties | 1 - gradle/libs.versions.toml | 49 ++++++++++ maps-ktx/build.gradle | 24 ++--- maps-utils-ktx/build.gradle | 23 ++--- 7 files changed, 140 insertions(+), 123 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/app/build.gradle b/app/build.gradle index dd31d5e..efcb902 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,8 +25,8 @@ android { defaultConfig { applicationId "com.google.maps.android.ktx.demo" - minSdkVersion 24 - targetSdkVersion versions.android.targetSdk + minSdkVersion libs.versions.androidMinSdk.get().toInteger() + targetSdkVersion libs.versions.androidTargetSdk.get().toInteger() versionCode 1 versionName "1.0" } @@ -51,10 +51,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation deps.kotlin - implementation deps.androidx.appcompat - implementation deps.androidx.coreKtx - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.0' + implementation libs.kotlinStdlib + implementation libs.androidxAppcompat + implementation libs.androidxCoreKtx + implementation libs.lifecycleRuntimeKtx // Instead of the lines below, regular apps would load these libraries from Maven according to // the README installation instructions diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt index ceaabba..a3790e9 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt @@ -23,7 +23,10 @@ import android.widget.Button import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.Lifecycle import androidx.lifecycle.coroutineScope +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.SupportMapFragment @@ -71,27 +74,29 @@ class MainActivity : AppCompatActivity() { } val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment - lifecycle.coroutineScope.launchWhenCreated { - val googleMap = mapFragment.awaitMap() - if (!isRestore) { - googleMap.awaitMapLoad() - googleMap.animateCamera( - CameraUpdateFactory.newLatLngZoom( - london, - 10F + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { + val googleMap = mapFragment.awaitMap() + if (!isRestore) { + googleMap.awaitMapLoad() + googleMap.animateCamera( + CameraUpdateFactory.newLatLngZoom( + london, + 10F + ) ) - ) - } - showMapLayers(googleMap) - addButtonClickListener(googleMap) - launch { - googleMap.cameraMoveStartedEvents().collect { - Log.d(TAG, "Camera moved - reason $it") } - } - launch { - googleMap.cameraIdleEvents().collect { - Log.d(TAG, "Camera is idle.") + showMapLayers(googleMap) + addButtonClickListener(googleMap) + launch { + googleMap.cameraMoveStartedEvents().collect { + Log.d(TAG, "Camera moved - reason $it") + } + } + launch { + googleMap.cameraIdleEvents().collect { + Log.d(TAG, "Camera is idle.") + } } } } @@ -100,34 +105,38 @@ class MainActivity : AppCompatActivity() { private suspend fun addButtonClickListener(googleMap: GoogleMap) { findViewById