aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgWaypoint.java
blob: a11a2c571e1328f3460fdbdbdfb9c6851c554f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cgeo.geocaching;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.widget.TextView;
import cgeo.geocaching.geopoint.Geopoint;

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");
	}
}