diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-08 00:00:58 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-08 11:32:14 +0200 |
| commit | 39ec7accd759fd60706523b366977ba371efd168 (patch) | |
| tree | 401ba08d9ec58e49d02ce614e12db5cf7b2b57bd /src/cgeo/geocaching/cgCacheListAdapter.java | |
| parent | 668472ec735f827a4741a971614596df02618689 (diff) | |
| download | cgeo-39ec7accd759fd60706523b366977ba371efd168.zip cgeo-39ec7accd759fd60706523b366977ba371efd168.tar.gz cgeo-39ec7accd759fd60706523b366977ba371efd168.tar.bz2 | |
Refactoring to use Geopoint for coordinates
This uses the new Geopoint immutable class discussed in #58. No more
independent longitude or latitude fields -- they are now treated
and defined as a consistent pair.
Diffstat (limited to 'src/cgeo/geocaching/cgCacheListAdapter.java')
| -rw-r--r-- | src/cgeo/geocaching/cgCacheListAdapter.java | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index 968f809..66ca5a3 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -35,6 +35,7 @@ import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import cgeo.geocaching.filter.cgFilter; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.sorting.CacheComparator; import cgeo.geocaching.sorting.DistanceComparator; import cgeo.geocaching.sorting.VisitComparator; @@ -52,8 +53,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { private DistanceComparator dstComparator = null; private CacheComparator statComparator = null; private boolean historic = false; - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; private Double azimuth = Double.valueOf(0); private long lastSort = 0L; private boolean sort = true; @@ -105,7 +105,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { public void setComparator(CacheComparator comparator) { statComparator = comparator; - forceSort(latitude, longitude); + forceSort(coords); } /** @@ -241,7 +241,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { notifyDataSetChanged(); } - public void forceSort(Double latitudeIn, Double longitudeIn) { + public void forceSort(final Geopoint coordsIn) { if (list == null || list.isEmpty()) { return; } @@ -253,11 +253,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (statComparator != null) { Collections.sort((List<cgCache>) list, statComparator); } else { - if (latitudeIn == null || longitudeIn == null) { + if (coordsIn == null) { return; } - dstComparator.setCoords(latitudeIn, longitudeIn); + dstComparator.setCoords(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); @@ -266,20 +266,19 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } } - public void setActualCoordinates(Double latitudeIn, Double longitudeIn) { - if (latitudeIn == null || longitudeIn == null) { + public void setActualCoordinates(final Geopoint coordsIn) { + if (coordsIn == null) { return; } - latitude = latitudeIn; - longitude = longitudeIn; + coords = coordsIn; if (list != null && list.isEmpty() == false && (System.currentTimeMillis() - lastSort) > 1000 && sort) { try { if (statComparator != null) { Collections.sort((List<cgCache>) list, statComparator); } else { - dstComparator.setCoords(latitudeIn, longitudeIn); + dstComparator.setCoords(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); @@ -292,13 +291,13 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (CollectionUtils.isNotEmpty(distances)) { for (cgDistanceView distance : distances) { - distance.update(latitudeIn, longitudeIn); + distance.update(coordsIn); } } if (CollectionUtils.isNotEmpty(compasses)) { for (cgCompassMini compass : compasses) { - compass.updateCoords(latitudeIn, longitudeIn); + compass.updateCoords(coordsIn); } } } @@ -438,11 +437,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (distances.contains(holder.distance) == false) { distances.add(holder.distance); } - holder.distance.setContent(base, cache.latitude, cache.longitude); + holder.distance.setContent(base, cache.coords); if (compasses.contains(holder.direction) == false) { compasses.add(holder.direction); } - holder.direction.setContent(cache.latitude, cache.longitude); + holder.direction.setContent(cache.coords); if (cache.found && cache.logOffline) { holder.logStatusMark.setImageResource(R.drawable.mark_green_red); @@ -484,12 +483,12 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } boolean setDiDi = false; - if (cache.latitude != null && cache.longitude != null) { + if (cache.coords != null) { holder.direction.setVisibility(View.VISIBLE); holder.direction.updateAzimuth(azimuth); - if (latitude != null && longitude != null) { - holder.distance.update(latitude, longitude); - holder.direction.updateCoords(latitude, longitude); + if (coords != null) { + holder.distance.update(coords); + holder.direction.updateCoords(coords); } setDiDi = true; } else { @@ -806,7 +805,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } if (sort) { - forceSort(latitude, longitude); + forceSort(coords); } } |
