Skip to content

Commit

Permalink
Fix: Update logs without marked "Download logs update cache" do not u…
Browse files Browse the repository at this point in the history
…pdate logs

# Conflicts:
#	src/main/java/locus/api/mapper/WaypointMerger.java
  • Loading branch information
arcao committed Mar 9, 2017
1 parent 743e199 commit 6088fd4
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/locus/api/mapper/LocusDataMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public locus.api.objects.extra.Waypoint toLocusPoint(@Nullable Geocache cache) {

d.setDateHidden(toSafeDateLong(cache.getPlaceDate()));
d.setDatePublished(toSafeDateLong(cache.getPublishDate()));
d.setDateUpdated(toSafeDateLong(cache.getLastUpdateDate()));
d.setDateUpdated(toSafeDateLong(cache.getLastUpdateDate()));

d.setContainer(toLocusContainerType(cache.getContainerType()));
d.setFound(cache.isFoundByUser());
Expand All @@ -123,7 +123,7 @@ public locus.api.objects.extra.Waypoint toLocusPoint(@Nullable Geocache cache) {
d.setState(cache.getStateName());

d.setDescriptions(BadBBCodeFixer.fix(cache.getShortDescription()), cache.isShortDescriptionHtml(),
BadBBCodeFixer.fix(cache.getLongDescription()), cache.isLongDescriptionHtml());
BadBBCodeFixer.fix(cache.getLongDescription()), cache.isLongDescriptionHtml());
d.setEncodedHints(cache.getHint());
d.setNotes(cache.getPersonalNote());
d.setFavoritePoints(cache.getFavoritePoints());
Expand Down Expand Up @@ -569,22 +569,34 @@ public void mergePoints(@NonNull Waypoint toPoint, @Nullable Waypoint fromPoint)
return;

fixArchivedCacheLocation(toPoint, fromPoint);
mergeCacheLogs(toPoint, fromPoint);
copyGsakGeocachingLogs(toPoint.gcData.logs, fromPoint.gcData.logs);
fixComputedCoordinates(toPoint, fromPoint);
copyWaypointId(toPoint, fromPoint);
copyGcVote(toPoint, fromPoint);
fixEditedWaypoints(toPoint, fromPoint);
}

// issue #14: Keep cache logs from GSAK when updating cache
public void mergeCacheLogs(@NonNull Waypoint toPoint, @NonNull Waypoint fromPoint) {
if (fromPoint.gcData == null || CollectionUtils.isEmpty(fromPoint.gcData.logs))
public void mergeCacheLogs(@NonNull Waypoint dstWaypoint, @Nullable Waypoint srcWaypoint) {
if (srcWaypoint == null || srcWaypoint.gcData == null)
return;

for(GeocachingLog fromLog : new ReverseListIterator<>(fromPoint.gcData.logs)) {
// store original logs
List<GeocachingLog> originalLogs = new ArrayList<>(dstWaypoint.gcData.logs);

// replace logs with new one
dstWaypoint.gcData.logs.clear();
dstWaypoint.gcData.logs.addAll(srcWaypoint.gcData.logs);

// copy GSAK logs from original logs
copyGsakGeocachingLogs(dstWaypoint.gcData.logs, originalLogs);
}

// issue #14: Keep cache logs from GSAK when updating cache
private void copyGsakGeocachingLogs(@NonNull List<GeocachingLog> dstLogs, @NonNull List<GeocachingLog> srcLogs) {
for(GeocachingLog fromLog : new ReverseListIterator<>(srcLogs)) {
if (GSAK_USERNAME.equalsIgnoreCase(fromLog.getFinder())) {
fromLog.setDate(System.currentTimeMillis());
toPoint.gcData.logs.add(0, fromLog);
dstLogs.add(0, fromLog);
}
}
}
Expand Down

0 comments on commit 6088fd4

Please sign in to comment.