From 266458344f039e022d8638591486a8f1c2dcd767 Mon Sep 17 00:00:00 2001 From: Patrick Pamponet Steiger Date: Mon, 18 Apr 2022 14:15:29 -0300 Subject: [PATCH] Release 8.2.1 - Update `AGP` to 7.1.3, `Gradle` to 7.4.2 - Only collect location from API if user is collecting `LocationFetcher.location`. The previous restriction (only collect if `Lifecycle.State` >= `STARTED`) still holds, so the new logic for collecting from API is: 1. `Lifecycle.State` >= `STARTED` 2. User is collecting `LocationFetcher.location` --- README.md | 2 +- .../com/freelapp/app/ui/main/MainFragment.kt | 10 ++++------ build.gradle.kts | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- locationfetcher/build.gradle.kts | 4 ++-- .../impl/LocationFetcherImpl.kt | 18 +++++++++++++++--- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f37f477..418ec4f 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ On app-level `build.gradle`, add dependency: ```kotlin dependencies { - implementation("app.freel:locationfetcher:8.2.0") + implementation("app.freel:locationfetcher:8.2.1") } ``` diff --git a/app/src/main/java/com/freelapp/app/ui/main/MainFragment.kt b/app/src/main/java/com/freelapp/app/ui/main/MainFragment.kt index db7009b..473df23 100644 --- a/app/src/main/java/com/freelapp/app/ui/main/MainFragment.kt +++ b/app/src/main/java/com/freelapp/app/ui/main/MainFragment.kt @@ -21,12 +21,10 @@ class MainFragment : Fragment() { fun newInstance() = MainFragment() } - private val locationFetcher by lazy { - requireContext().applicationContext.locationFetcher(this, "Rationale") { - debug = true - interval = 5.seconds - priority = LocationRequest.PRIORITY_HIGH_ACCURACY - } + private val locationFetcher = locationFetcher("Rationale") { + debug = true + interval = 5.seconds + priority = LocationRequest.PRIORITY_HIGH_ACCURACY } private lateinit var viewModel: MainViewModel diff --git a/build.gradle.kts b/build.gradle.kts index 1959551..996192a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - id("com.android.library") version "7.1.2" apply false + id("com.android.application") version "7.1.3" apply false + id("com.android.library") version "7.1.3" apply false kotlin("android") version "1.6.20" apply false id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.8.0" - id("com.android.application") version "7.1.2" apply false } tasks.register("clean") { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dc9aa95..175ce19 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Feb 01 23:58:48 BRT 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/locationfetcher/build.gradle.kts b/locationfetcher/build.gradle.kts index 54a54be..6326c05 100644 --- a/locationfetcher/build.gradle.kts +++ b/locationfetcher/build.gradle.kts @@ -8,7 +8,7 @@ plugins { apply(from = "$rootDir/scripts/publish-root.gradle.kts") group = "app.freel" -version = "8.2.0" +version = "8.2.1" android { compileSdk = 31 @@ -42,7 +42,7 @@ afterEvaluate { register("release") { from(components["release"]) groupId = "app.freel" - version = "8.2.0" + version = "8.2.1" artifactId = project.name artifact(sourcesJar).apply { classifier = "sources" diff --git a/locationfetcher/src/main/java/com/freelapp/libs/locationfetcher/impl/LocationFetcherImpl.kt b/locationfetcher/src/main/java/com/freelapp/libs/locationfetcher/impl/LocationFetcherImpl.kt index 27cf27b..e1cbcfd 100644 --- a/locationfetcher/src/main/java/com/freelapp/libs/locationfetcher/impl/LocationFetcherImpl.kt +++ b/locationfetcher/src/main/java/com/freelapp/libs/locationfetcher/impl/LocationFetcherImpl.kt @@ -142,7 +142,21 @@ internal class LocationFetcherImpl private constructor( } } - private suspend fun CoroutineScope.launchLocationFlow() { + private fun CoroutineScope.launchLocationFlow() { + LOCATION.subscriptionCount + .map { count -> count > 0 } // map count into active/inactive flag + .distinctUntilChanged() // only react to true<->false changes + .flatMapLatest { isActive -> + when { + isActive -> internalLocationFlow + else -> emptyFlow() + } + } + .onEach { LOCATION.tryEmit(it.toEither()) } + .launchIn(this) + } + + private val internalLocationFlow = run { val perms = PERMISSION_STATUS .onSubscription { if (!checkLocationPermissionsAllowed()) { @@ -163,8 +177,6 @@ internal class LocationFetcherImpl private constructor( .onEach { logd("API holder=$it") } .flatMapLatestRight { config.value.providers.asLocationFlow(it, locationRequest) } .onEach { logd("Location=$it") } - .onEach { LOCATION.tryEmit(it.toEither()) } - .launchIn(this) } override suspend fun requestLocationPermissions() {