From 7b0c08126af95c6aaf5a0d78898f4ddb25263823 Mon Sep 17 00:00:00 2001 From: sonora Date: Sat, 3 Jan 2015 11:51:57 +0100 Subject: [PATCH] consolidate code, reference only loc, this should also fix wrong initial arrow direction on non-compass devices --- .../plus/dashboard/DashFavoritesFragment.java | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 0075371e54..388dcb825d 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -65,14 +65,22 @@ public class DashFavoritesFragment extends DashBaseFragment { @Override public void onResume() { super.onResume(); - if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) { - if(!getMyApplication().getSettings().isLastKnownMapLocation()) { - // show first time when application ran - location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation(); - } else { - location = getLocationProvider().getLastKnownLocation(); - } - updateLocation(location); + + //'location' seems actually not needed in this Fragment, as both setupFavorites and updateArrow only reference lastKnownMapLocation + //if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) { + // if(!getMyApplication().getSettings().isLastKnownMapLocation()) { + // // show first time when application ran + // location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation(); + // } else { + // location = getLocationProvider().getLastKnownLocation(); + // } + //} + + //This is used as origin for both Fav-list and direction arrows + if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { + loc = getMyApplication().getSettings().getLastKnownMapLocation(); + } else { + loc = new LatLon(0f, 0f); } setupFavorites(); } @@ -90,14 +98,15 @@ public class DashFavoritesFragment extends DashBaseFragment { } else { (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE); } + Collections.sort(points, new Comparator() { @Override public int compare(FavouritePoint point, FavouritePoint point2) { - LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + //LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), - lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); + loc.getLatitude(), loc.getLongitude())); int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), - lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); + loc.getLatitude(), loc.getLongitude())); return (dist - dist2); } }); @@ -123,9 +132,9 @@ public class DashFavoritesFragment extends DashBaseFragment { arrows.add(direction); name.setText(point.getName()); icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor())); - LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + //LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), - lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); + loc.getLatitude(), loc.getLongitude())); String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override @@ -145,6 +154,7 @@ public class DashFavoritesFragment extends DashBaseFragment { }); favorites.addView(view); } + updateLocation(location); } private void updateArrows() { @@ -175,14 +185,24 @@ public class DashFavoritesFragment extends DashBaseFragment { } public void updateLocation(Location location) { - if (location != null) { + //'location' seems actually not needed in this Fragment, as both setupFavorites and updateArrow only reference lastKnownMapLocation + //if (location != null) { //this.location = location; - loc = new LatLon(location.getLatitude(), location.getLongitude()); - } else if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { + //Next line commented out so that reference is always lastKnownMapLocation, because this is also always used as reference in setupFavorites + // loc = new LatLon(location.getLatitude(), location.getLongitude()); + //} else if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { + // loc = getMyApplication().getSettings().getLastKnownMapLocation(); + //} else { + // return; + //} + + //This is used as origin for both Fav-list and direction arrows + if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { loc = getMyApplication().getSettings().getLastKnownMapLocation(); } else { - return; + loc = new LatLon(0f, 0f); } + this.loc = loc; updateArrows(); }