aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgWaypoint.java
blob: 5703dfa3afc987cf11c87cf70e1cb78d5631a006 (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
package cgeo.geocaching;

import java.util.ArrayList;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

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 Double latitude = null;
	public Double longitude = 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 (prefix == null || prefix.length() == 0) {
			prefix = old.prefix;
		}
		if (lookup == null || lookup.length() == 0) {
			lookup = old.lookup;
		}
		if (name == null || name.length() == 0) {
			name = old.name;
		}
		if (latlon == null || latlon.length() == 0) {
			latlon = old.latlon;
		}
		if (latitudeString == null || latitudeString.length() == 0) {
			latitudeString = old.latitudeString;
		}
		if (longitudeString == null || longitudeString.length() == 0) {
			longitudeString = old.longitudeString;
		}
		if (latitude == null) {
			latitude = old.latitude;
		}
		if (longitude == null) {
			longitude = old.longitude;
		}
		if (note == null || note.length() == 0) {
			note = old.note;
		}
		if (note != null && old.note != null) {
			if (old.note.length() > note.length()) {
				note = old.note;
			}
		}
	}

	public static void mergeWayPoints(ArrayList<cgWaypoint> newPoints,
			ArrayList<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);
				}
			}
		}
	}
}