Skip to content

Commit

Permalink
Fix location request duplication
Browse files Browse the repository at this point in the history
* Fix regression to remove sync'ed locations from database as to not duplicate locations on each push request.
  • Loading branch information
newmanw committed Dec 20, 2023
1 parent a1e8e6b commit dd2b07e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Adheres to [Semantic Versioning](http://semver.org/).
##### Features
##### Bug Fixes

## [7.2.2](https://github.com/ngageoint/mage-android/releases/tag/7.2.2)

##### Bug Fixes
* Fix regression to remove sync'ed locations from database as to not duplicate locations on each push request.

## [7.2.1](https://github.com/ngageoint/mage-android/releases/tag/7.2.1)

##### Features
Expand Down
2 changes: 1 addition & 1 deletion mage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group 'mil.nga.giat.mage'
version '7.2.1'
version '7.2.2'
ext {
sourceRefspec = Grgit.open(currentDir: project.rootDir).head().id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,24 @@ class LocationRepository @Inject constructor(

// Send locations for the current event
val event = locations[0].event
val eventLocations = locations.filter { it.event == event }
val localLocations = locations.filter { it.event == event }

try {
val response = locationService.pushLocations(event.remoteId, eventLocations)
val response = locationService.pushLocations(event.remoteId, localLocations)
if (response.isSuccessful) {
val pushedLocations = response.body() ?: emptyList()
val remoteLocations = response.body() ?: emptyList()
// We've sync-ed locations to the server, lets remove the locations we synced from the database
Log.d(LOG_NAME, "Pushed " + pushedLocations.size + " locations.")
Log.d(LOG_NAME, "Pushed " + remoteLocations.size + " locations.")
try {
eventLocations.forEachIndexed { index, location ->
val remoteId = pushedLocations.getOrNull(index)?.remoteId
if (remoteId == null) {
locationLocalDataSource.delete(listOf(location))
localLocations.forEachIndexed { index, localLocation ->
val remoteLocation = remoteLocations.getOrNull(index)
if (remoteLocation == null) {
locationLocalDataSource.delete(listOf(localLocation))
} else {
location.remoteId = remoteId
locationLocalDataSource.update(location)
remoteLocation.id = localLocation.id
remoteLocation.user = currentUser
remoteLocation.event = event
locationLocalDataSource.update(remoteLocation)
}
}

Expand Down

0 comments on commit dd2b07e

Please sign in to comment.