Skip to content

Commit

Permalink
Release 8.2.1
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
psteiger committed Apr 18, 2022
1 parent 657ff77 commit 2664583
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
```

Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/com/freelapp/app/ui/main/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<Delete>("clean") {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions locationfetcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +42,7 @@ afterEvaluate {
register<MavenPublication>("release") {
from(components["release"])
groupId = "app.freel"
version = "8.2.0"
version = "8.2.1"
artifactId = project.name
artifact(sourcesJar).apply {
classifier = "sources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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() {
Expand Down

0 comments on commit 2664583

Please sign in to comment.