From c5ae8a73734c57fb30450d209375b68bc001f341 Mon Sep 17 00:00:00 2001 From: Nazar Date: Wed, 10 Jul 2019 14:01:41 +0300 Subject: [PATCH] fix settings navigation no profiles crash --- OsmAnd/res/values/strings.xml | 1 + OsmAnd/src/net/osmand/plus/OsmandSettings.java | 8 ++++++++ .../plus/activities/SettingsNavigationActivity.java | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6e98272927..16dd773404 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Please turn on at least one application profile, to use this setting. Winter road Ice road Winter and ice roads diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index e070268d07..a3c93cdbda 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -339,6 +339,14 @@ public class OsmandSettings { public ApplicationMode getApplicationMode() { return APPLICATION_MODE.get(); } + + public boolean hasAvailableApplicationMode() { + int currentModeCount = ApplicationMode.values(ctx).size(); + if (currentModeCount == 0 || currentModeCount == 1 && getApplicationMode() == ApplicationMode.DEFAULT) { + return false; + } + return true; + } protected ApplicationMode readApplicationMode() { String s = settingsAPI.getString(globalPreferences, APPLICATION_MODE.getId(), ApplicationMode.DEFAULT.getStringKey()); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 8649c08af5..a3d790470e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -25,6 +25,7 @@ import android.widget.ArrayAdapter; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; +import android.widget.Toast; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; @@ -81,6 +82,11 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { public void onCreate(Bundle savedInstanceState) { ((OsmandApplication) getApplication()).applyTheme(this); super.onCreate(savedInstanceState); + settings = getMyApplication().getSettings(); + if (!settings.hasAvailableApplicationMode()) { + Toast.makeText(this, R.string.turn_on_profile_desc, Toast.LENGTH_SHORT).show(); + onBackPressed(); + } getToolbar().setTitle(R.string.routing_settings); createUI(); } @@ -98,7 +104,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { private void createUI() { addPreferencesFromResource(R.xml.navigation_settings); PreferenceScreen screen = getPreferenceScreen(); - settings = getMyApplication().getSettings(); RouteService[] vls = RouteService.getAvailableRouters(getMyApplication()); String[] entries = new String[vls.length]; for (int i = 0; i < entries.length; i++) {