Skip to content

Commit

Permalink
fix: moves the key function call to inside of the GoogleMap composable
Browse files Browse the repository at this point in the history
feat: update to Places SDK 4.0.0.  remove places-ktx dependency
chore: clean up log statements and unused code
  • Loading branch information
dkhawk committed Oct 2, 2024
1 parent c209ceb commit 7e86ac9
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 351 deletions.
30 changes: 14 additions & 16 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ accompanistPermissions = "0.34.0"
activityCompose = "1.9.2"
agp = "8.6.1"
appcompat = "1.7.0"
composeBom = "2024.09.01"
composeBom = "2024.09.02"
coreKtx = "1.13.1"
dokka = "1.9.20"
espressoCore = "3.6.1"
Expand All @@ -16,23 +16,23 @@ kotlin = "2.0.0"
kotlinReflect = "2.0.0"
kotlinxCoroutinesPlayServices = "1.8.1"
ksp = "2.0.0-1.0.21"
lifecycleRuntimeKtx = "2.8.5"
lifecycleViewmodelCompose = "2.8.5"
lifecycleRuntimeKtx = "2.8.6"
lifecycleViewmodelCompose = "2.8.6"
mapsCompose = "6.1.0"
mapsUtilsKtx = "5.1.1"
materialVersion = "1.13.0-alpha05"
navigationCompose = "2.8.0"
materialVersion = "1.13.0-alpha06"
navigationCompose = "2.8.1"
org-jacoco-core = "0.8.11"
places = "3.5.0"
placesKtx = "3.2.0"
places = "4.0.0"
robolectric = "4.12.2"
secretsGradlePlugin = "2.0.1"
truth = "1.4.2"
uiToolingVersion = "1.7.1"
uiTestAndroid = "1.7.1"
uiTestAndroid = "1.7.2"
uiToolingVersion = "1.7.2"

[libraries]
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" }
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
Expand All @@ -46,34 +46,32 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-test-android = { group = "androidx.compose.ui", name = "ui-test-android", version.ref = "uiTestAndroid" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
dagger = { group = "com.google.dagger", name = "dagger", version.ref = "hiltVersion" }
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
google-truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hiltVersion" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hiltVersion" }
jacoco-android-plugin = { module = "com.mxalbert.gradle:jacoco-android", version.ref = "jacoco-plugin", version.require = "0.2.1" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlinReflect" }
kotlinx-coroutines-play-services = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-play-services", version.ref = "kotlinxCoroutinesPlayServices" }
maps-compose = { group = "com.google.maps.android", name = "maps-compose", version.ref = "mapsCompose" }
maps-compose-utils = { module = "com.google.maps.android:maps-compose-utils", version.ref = "mapsCompose" }
maps-compose-widgets = { module = "com.google.maps.android:maps-compose-widgets", version.ref = "mapsCompose" }
maps-utils-ktx = { module = "com.google.maps.android:maps-utils-ktx", version.ref = "mapsUtilsKtx" }
material = { group = "com.google.android.material", name = "material", version.ref = "materialVersion" }
org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" }
places = { group = "com.google.android.libraries.places", name = "places", version.ref = "places" }
places-ktx = { group = "com.google.maps.android", name = "places-ktx", version.ref = "placesKtx" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
androidx-ui-test-android = { group = "androidx.compose.ui", name = "ui-test-android", version.ref = "uiTestAndroid" }
ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "uiToolingVersion" }
ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "uiToolingVersion" }
jacoco-android-plugin = { module = "com.mxalbert.gradle:jacoco-android", version.ref = "jacoco-plugin", version.require = "0.2.1" }
org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
13 changes: 0 additions & 13 deletions places-compose-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,7 @@ dependencies {
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

////////////////////////////////////////

// probably not needed...
// implementation(libs.androidx.material3.android)

// probably needed...
// implementation(libs.kotlinx.coroutines.play.services)


// implementation(project(":maps-compose-widgets"))
// implementation(libs.androidx.foundation)

implementation(libs.places)
implementation(libs.places.ktx)

implementation(libs.kotlin.reflect)
implementation(libs.androidx.navigation.compose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
// limitations under the License.
package com.google.android.libraries.places.compose.demo.data.models

/**
* Holds a county with its name, country code, and flag in unicode.
*/
data class Country(val name: String, val flag: String, val code: String)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import com.google.android.libraries.places.compose.demo.data.models.Country

class CountriesRepository {
companion object {

/**
* Returns a flag emoji for the given country code.
*/
private fun getFlagEmoji(countryCode: String): String {
val firstLetter = Character.codePointAt(countryCode, 0) - 0x41 + 0x1F1E6
val secondLetter = Character.codePointAt(countryCode, 1) - 0x41 + 0x1F1E6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.WhileSubscribed
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
Expand Down Expand Up @@ -115,7 +116,7 @@ class LocationRepository(context: Context, private val scope: CoroutineScope) {

return _locationUpdates.stateIn(
scope = scope,
SharingStarted.WhileSubscribed(5000),
SharingStarted.WhileSubscribed(5.seconds),
initialValue = Location("MockLocation")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.google.android.libraries.places.compose.demo.data.repositories

import android.Manifest
import android.annotation.SuppressLint
import android.util.Log
import androidx.annotation.RequiresPermission
import com.google.android.gms.maps.model.LatLng
import kotlinx.coroutines.CoroutineScope
Expand All @@ -13,7 +12,6 @@ import kotlinx.coroutines.flow.WhileSubscribed
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.shareIn
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
Expand All @@ -24,6 +22,9 @@ data class CompositeLocation(
val isMockLocation: Boolean = true,
)

/**
* A repository class that allows switching between the actual device location and a mock location.
*/
class MergedLocationRepository
@Inject
constructor(
Expand All @@ -33,31 +34,11 @@ constructor(
) {
private val _useMockLocation = MutableStateFlow(true)

val mergedLocation = merge(
locationRepository.latestLocation.mapNotNull { latLng ->
latLng?.let {
CompositeLocation(
latLng = it,
label = "Current Location",
isMockLocation = false,
)
}
},
mockLocationRepository.location.map {
CompositeLocation(
latLng = it.latLng,
label = it.label,
isMockLocation = true,
)
},
)

@SuppressLint("MissingPermission")
@ExperimentalCoroutinesApi
@RequiresPermission(allOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
val location = _useMockLocation.flatMapLatest { useMockLocation ->
if (useMockLocation) {
Log.d("MergedLocationRepository", "Emitting mock location")
mockLocationRepository.location.map {
CompositeLocation(
latLng = it.latLng,
Expand All @@ -66,7 +47,6 @@ constructor(
)
}
} else {
Log.d("MergedLocationRepository", "Emitting system location")
locationRepository.latestLocation.mapNotNull { latLng ->
latLng?.let {
CompositeLocation(
Expand Down
Loading

0 comments on commit 7e86ac9

Please sign in to comment.