Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix location request duplication #61

Merged
merged 2 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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