Repository: cgeo/cgeo (Java)

Issue:
Store waypoint visited flag with personal cache note
### Tell us your idea!

At the moment you can backup (copy + upload) any custom waypoints or additions to existing waypoints via our feature to copy those into the personal cache note.

The only helpful information, which is not covered is whether the specific waypoint has been marked as visited.

### What solution would you suggest?

Extend the feature to also copy the waypoint visited flag into the personal note, to allow backup + restore of this information

### Is there an alternative?

None

### Additional Information

_No response_



Fix (patch):
diff --git a/main/src/main/java/cgeo/geocaching/models/CacheArtefactParser.java b/main/src/main/java/cgeo/geocaching/models/CacheArtefactParser.java
index 0788ab877d4..be65efe711c 100644
--- a/main/src/main/java/cgeo/geocaching/models/CacheArtefactParser.java
+++ b/main/src/main/java/cgeo/geocaching/models/CacheArtefactParser.java
@@ -42,6 +42,8 @@ public class CacheArtefactParser {
 
     //Constants for waypoint parsing
     public static final String PARSING_CALCULATED_COORD = "{" + CalculatedCoordinate.CONFIG_KEY + "|";
+
+    public static final String PARSING_VISITED_FLAG = "{v}";
     private static final String PARSING_NAME_PRAEFIX = "@";
     private static final char PARSING_USERNOTE_DELIM = '"';
     private static final char PARSING_USERNOTE_ESCAPE = '\\';
@@ -170,7 +172,8 @@ private Waypoint parseSingleWaypoint(final GeopointWrapper match, final int coun
         final String text = match.getText();
         final String matchedText = text.substring(start, end);
 
-        final String[] wordsBefore = TextUtils.getWords(TextUtils.getTextBeforeIndexUntil(text, start, "\n"));
+        final String textBeforeIndex = TextUtils.getTextBeforeIndexUntil(text, start, "\n");
+        final String[] wordsBefore = TextUtils.getWords(textBeforeIndex);
         final String lastWordBefore = wordsBefore.length == 0 ? "" : wordsBefore[wordsBefore.length - 1];
 
         //try to get a waypointType
@@ -184,10 +187,14 @@ private Waypoint parseSingleWaypoint(final GeopointWrapper match, final int coun
             name = namePrefix + " " + counter;
         }
 
+        //try to get visited-flag
+        final boolean isVisited = textBeforeIndex.contains(PARSING_VISITED_FLAG);
+
         //create the waypoint
         final Waypoint waypoint = new Waypoint(name, wpType, true);
         waypoint.setCoords(point);
         waypoint.setPrefix(prefix);
+        waypoint.setVisited(isVisited);
 
         String afterCoords = TextUtils.getTextAfterIndexUntil(text, end - 1, null);
 
@@ -300,6 +307,7 @@ private boolean useWordForParsedName(final String word, final boolean isLast, fi
                 (!StringUtils.isBlank(word)) &&
                         //remove words which are in parenthesis (is usually the waypoint type)
                         !(word.startsWith(PARSING_TYPE_OPEN) && word.endsWith(PARSING_TYPE_CLOSE)) &&
+                        !word.equals(PARSING_VISITED_FLAG) &&
                         //remove last word if it is just the waypoint type id
                         !(isLast && word.toLowerCase(Locale.getDefault()).equals(wpType.getShortId().toLowerCase(Locale.getDefault())));
     }
@@ -435,6 +443,11 @@ public static String getParseableText(final Waypoint wp) {
         sb.append(PARSING_TYPE_OPEN).append(wp.getWaypointType().getShortId().toUpperCase(Locale.US))
                 .append(PARSING_TYPE_CLOSE).append(" ");
 
+        //visited-flag
+        if (wp.isVisited()) {
+            sb.append(PARSING_VISITED_FLAG).append(" ");
+        }
+
         // formula
         final String formulaString = getParseableFormula(wp);
         if (StringUtils.isNotEmpty(formulaString)) {
diff --git a/main/src/main/java/cgeo/geocaching/models/Waypoint.java b/main/src/main/java/cgeo/geocaching/models/Waypoint.java
index 644477cfc97..ce8a5ec083c 100644
--- a/main/src/main/java/cgeo/geocaching/models/Waypoint.java
+++ b/main/src/main/java/cgeo/geocaching/models/Waypoint.java
@@ -173,7 +173,7 @@ public boolean isUserDefined() {
      */
     public boolean isUserModified() {
         return
-                isUserDefined() ||
+                isUserDefined() || isVisited() ||
                         (isOriginalCoordsEmpty() && (getCoords() != null || getCalcStateConfig() != null)) ||
                         StringUtils.isNotBlank(getUserNote());
     }
@@ -393,6 +393,11 @@ public boolean mergeFromParsedText(final Waypoint parsedWaypoint, final String p
             this.setUserNote(parsedWaypoint.getUserNote());
             changed = true;
         }
+
+        if (parsedWaypoint.isVisited()) {
+            setVisited(true);
+        }
+
         return changed;
     }