Skip to content

Commit dd2b07e

Browse files
committed
Fix location request duplication
* Fix regression to remove sync'ed locations from database as to not duplicate locations on each push request.
1 parent a1e8e6b commit dd2b07e

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Adheres to [Semantic Versioning](http://semver.org/).
77
##### Features
88
##### Bug Fixes
99

10+
## [7.2.2](https://github.com/ngageoint/mage-android/releases/tag/7.2.2)
11+
12+
##### Bug Fixes
13+
* Fix regression to remove sync'ed locations from database as to not duplicate locations on each push request.
14+
1015
## [7.2.1](https://github.com/ngageoint/mage-android/releases/tag/7.2.1)
1116

1217
##### Features

mage/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'mil.nga.giat.mage'
13-
version '7.2.1'
13+
version '7.2.2'
1414
ext {
1515
sourceRefspec = Grgit.open(currentDir: project.rootDir).head().id
1616

mage/src/main/java/mil/nga/giat/mage/data/repository/location/LocationRepository.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,24 @@ class LocationRepository @Inject constructor(
147147

148148
// Send locations for the current event
149149
val event = locations[0].event
150-
val eventLocations = locations.filter { it.event == event }
150+
val localLocations = locations.filter { it.event == event }
151151

152152
try {
153-
val response = locationService.pushLocations(event.remoteId, eventLocations)
153+
val response = locationService.pushLocations(event.remoteId, localLocations)
154154
if (response.isSuccessful) {
155-
val pushedLocations = response.body() ?: emptyList()
155+
val remoteLocations = response.body() ?: emptyList()
156156
// We've sync-ed locations to the server, lets remove the locations we synced from the database
157-
Log.d(LOG_NAME, "Pushed " + pushedLocations.size + " locations.")
157+
Log.d(LOG_NAME, "Pushed " + remoteLocations.size + " locations.")
158158
try {
159-
eventLocations.forEachIndexed { index, location ->
160-
val remoteId = pushedLocations.getOrNull(index)?.remoteId
161-
if (remoteId == null) {
162-
locationLocalDataSource.delete(listOf(location))
159+
localLocations.forEachIndexed { index, localLocation ->
160+
val remoteLocation = remoteLocations.getOrNull(index)
161+
if (remoteLocation == null) {
162+
locationLocalDataSource.delete(listOf(localLocation))
163163
} else {
164-
location.remoteId = remoteId
165-
locationLocalDataSource.update(location)
164+
remoteLocation.id = localLocation.id
165+
remoteLocation.user = currentUser
166+
remoteLocation.event = event
167+
locationLocalDataSource.update(remoteLocation)
166168
}
167169
}
168170

0 commit comments

Comments
 (0)