Skip to content

Commit

Permalink
Merge branch 'fix-download-logs'
Browse files Browse the repository at this point in the history
  • Loading branch information
arcao committed Mar 9, 2017
2 parents 743e199 + 3342613 commit dc77609
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arcao.geocaching4locus"
android:versionName="2.1.5"
android:versionName="2.1.5.1"
android:installLocation="auto">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Expand Down
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 dc77609

Please sign in to comment.