From e09508f6514911e7cc3b0f8da0ec8fd339188a85 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 18 Mar 2016 19:49:44 +0300 Subject: [PATCH] Fix route preferences (set profile for nav settings, refresh params, UI). Fix geocoding result crash. --- .../src/net/osmand/plus/OsmandSettings.java | 22 +++++++++----- .../net/osmand/plus/TargetPointsHelper.java | 30 +++++++++++-------- .../osmand/plus/activities/MapActivity.java | 2 ++ .../plus/activities/SettingsBaseActivity.java | 13 ++++++-- .../osmand/plus/dashboard/DashboardOnMap.java | 14 +++++---- .../other/RoutePreferencesMenu.java | 1 + 6 files changed, 55 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 3e243160c5..5a70a0ff31 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2004,19 +2004,27 @@ public class OsmandSettings { List ps = getPoints(); List ds = getPointDescriptions(ps.size()); int i = ps.indexOf(new LatLon(latitude, longitude)); - ds.set(i, PointDescription.serializeToString(historyDescription)); - if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { - SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); + if (i != -1) { + ds.set(i, PointDescription.serializeToString(historyDescription)); + if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { + SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); + } + return savePoints(ps, ds); + } else { + return false; } - return savePoints(ps, ds); } public boolean deletePoint(int index) { List ps = getPoints(); List ds = getPointDescriptions(ps.size()); - ps.remove(index); - ds.remove(index); - return savePoints(ps, ds); + if (index < ps.size()) { + ps.remove(index); + ds.remove(index); + return savePoints(ps, ds); + } else { + return false; + } } public boolean savePoints(List ps, List ds) { diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index 8ce63691fd..2e784fa62d 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -138,10 +138,12 @@ public class TargetPointsHelper { AddressLookupRequest lookupRequest = new AddressLookupRequest(targetPoint.point, new GeocodingLookupService.OnAddressLookupResult() { @Override public void geocodingDone(String address) { - targetPoint.pointDescription.setName(address); - settings.updateIntermediatePoint(targetPoint.point.getLatitude(), targetPoint.point.getLongitude(), - targetPoint.pointDescription); - updateRouteAndRefresh(false); + if (intermediatePoints.contains(targetPoint)) { + targetPoint.pointDescription.setName(address); + settings.updateIntermediatePoint(targetPoint.point.getLatitude(), targetPoint.point.getLongitude(), + targetPoint.pointDescription); + updateRouteAndRefresh(false); + } } }, null); ctx.getGeocodingLookupService().lookupAddress(lookupRequest); @@ -156,10 +158,12 @@ public class TargetPointsHelper { @Override public void geocodingDone(String address) { startPointRequest = null; - pointToStart.pointDescription.setName(address); - settings.setPointToStart(pointToStart.point.getLatitude(), pointToStart.point.getLongitude(), - pointToStart.pointDescription); - updateRouteAndRefresh(false); + if (pointToStart != null) { + pointToStart.pointDescription.setName(address); + settings.setPointToStart(pointToStart.point.getLatitude(), pointToStart.point.getLongitude(), + pointToStart.pointDescription); + updateRouteAndRefresh(false); + } } }, null); ctx.getGeocodingLookupService().lookupAddress(startPointRequest); @@ -174,10 +178,12 @@ public class TargetPointsHelper { @Override public void geocodingDone(String address) { targetPointRequest = null; - pointToNavigate.pointDescription.setName(address); - settings.setPointToNavigate(pointToNavigate.point.getLatitude(), pointToNavigate.point.getLongitude(), - pointToNavigate.pointDescription); - updateRouteAndRefresh(false); + if (pointToNavigate != null) { + pointToNavigate.pointDescription.setName(address); + settings.setPointToNavigate(pointToNavigate.point.getLatitude(), pointToNavigate.point.getLongitude(), + pointToNavigate.pointDescription); + updateRouteAndRefresh(false); + } } }, null); ctx.getGeocodingLookupService().lookupAddress(targetPointRequest); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index c4740dfda7..1b4e6216f5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -486,6 +486,8 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents, new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog"); } } + } else { + dashboardOnMap.updateDashboard(); } } dashboardOnMap.updateLocation(true, true, false); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index 95d2ce3bdd..e01487194c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -44,10 +44,10 @@ import java.util.Set; public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener { + public static final String INTENT_APP_MODE = "INTENT_APP_MODE"; - protected OsmandSettings settings; - protected final boolean profileSettings ; + protected final boolean profileSettings; protected List modes = new ArrayList(); private ApplicationMode previousAppMode; @@ -388,7 +388,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity super.onResume(); if (profileSettings) { previousAppMode = settings.getApplicationMode(); - boolean found = setSelectedAppMode(previousAppMode); + boolean found; + if (getIntent() != null && getIntent().hasExtra(INTENT_APP_MODE)) { + String modeStr = getIntent().getStringExtra(INTENT_APP_MODE); + ApplicationMode mode = ApplicationMode.valueOfStringKey(modeStr, previousAppMode); + found = setSelectedAppMode(mode); + } else { + found = setSelectedAppMode(previousAppMode); + } if (!found) { getSpinner().setSelection(0); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 4762871e70..0f8e10e4e9 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -784,14 +784,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } else { scrollView.setVisibility(View.GONE); listViewLayout.setVisibility(View.VISIBLE); - listView.scrollTo(0, 0); - listView.clearParams(); - if (listView instanceof ObservableListView) { - onScrollChanged(listView.getScrollY(), false, false); - } if (refresh) { refreshContent(false); } else { + listView.scrollTo(0, 0); + listView.clearParams(); + onScrollChanged(listView.getScrollY(), false, false); updateListAdapter(); } updateListBackgroundHeight(); @@ -836,6 +834,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } } + public void updateDashboard() { + if (visibleType == DashboardType.ROUTE_PREFERENCES) { + refreshContent(false); + } + } + private void applyDayNightMode() { if (nightMode) { if (listBackgroundView != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index 318350421b..8a364a96c9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -292,6 +292,7 @@ public class RoutePreferencesMenu { if (obj instanceof OtherSettingsRoutingParameter) { final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class); settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true); + settings.putExtra(SettingsBaseActivity.INTENT_APP_MODE, routingHelper.getAppMode().getStringKey()); mapActivity.startActivity(settings); } else if (obj instanceof MuteSoundRoutingParameter) { final CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);