diff options
Diffstat (limited to 'main/src/cgeo/geocaching/cgWaypoint.java')
| -rw-r--r-- | main/src/cgeo/geocaching/cgWaypoint.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/cgWaypoint.java b/main/src/cgeo/geocaching/cgWaypoint.java new file mode 100644 index 0000000..c0dd719 --- /dev/null +++ b/main/src/cgeo/geocaching/cgWaypoint.java @@ -0,0 +1,97 @@ +package cgeo.geocaching; + +import cgeo.geocaching.geopoint.Geopoint; + +import org.apache.commons.lang3.StringUtils; + +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.widget.TextView; + +import java.util.List; + +public class cgWaypoint { + public Integer id = 0; + public String geocode = "geocode"; + public String type = "waypoint"; + public String prefix = ""; + public String lookup = ""; + public String name = ""; + public String latlon = ""; + public String latitudeString = ""; + public String longitudeString = ""; + public Geopoint coords = null; + public String note = ""; + + public void setIcon(Resources res, cgBase base, TextView nameView) { + int iconId = R.drawable.waypoint_waypoint; + if (type != null) { + int specialId = res.getIdentifier("waypoint_" + type, "drawable", base.context.getPackageName()); + if (specialId > 0) { + iconId = specialId; + } + } + nameView.setCompoundDrawablesWithIntrinsicBounds((Drawable) res.getDrawable(iconId), null, null, null); + } + + public void merge(final cgWaypoint old) { + if (StringUtils.isBlank(prefix)) { + prefix = old.prefix; + } + if (StringUtils.isBlank(lookup)) { + lookup = old.lookup; + } + if (StringUtils.isBlank(name)) { + name = old.name; + } + if (StringUtils.isBlank(latlon)) { + latlon = old.latlon; + } + if (StringUtils.isBlank(latitudeString)) { + latitudeString = old.latitudeString; + } + if (StringUtils.isBlank(longitudeString)) { + longitudeString = old.longitudeString; + } + if (coords == null) { + coords = old.coords; + } + if (StringUtils.isBlank(note)) { + note = old.note; + } + if (note != null && old.note != null) { + if (old.note.length() > note.length()) { + note = old.note; + } + } + } + + public static void mergeWayPoints(List<cgWaypoint> newPoints, + List<cgWaypoint> oldPoints) { + // copy user modified details of the waypoints + if (newPoints != null && oldPoints != null) { + for (cgWaypoint old : oldPoints) { + boolean merged = false; + if (old != null && old.name != null && old.name.length() > 0) { + for (cgWaypoint waypoint : newPoints) { + if (waypoint != null && waypoint.name != null) { + if (old.name.equalsIgnoreCase(waypoint.name)) { + waypoint.merge(old); + merged = true; + break; + } + } + } + } + // user added waypoints should also be in the new list + if (!merged) { + newPoints.add(old); + } + } + } + } + + public boolean isUserDefined() { + return type != null && type.equalsIgnoreCase("own"); + } +}
\ No newline at end of file |
