fix settings navigation no profiles crash
This commit is contained in:
parent
386041950c
commit
c5ae8a7373
3 changed files with 15 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="turn_on_profile_desc">Please turn on at least one application profile, to use this setting.</string>
|
||||
<string name="rendering_attr_winter_road_name">Winter road</string>
|
||||
<string name="rendering_attr_ice_road_name">Ice road</string>
|
||||
<string name="routeInfo_winter_ice_road_name">Winter and ice roads</string>
|
||||
|
|
|
@ -340,6 +340,14 @@ public class OsmandSettings {
|
|||
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());
|
||||
return ApplicationMode.valueOfStringKey(s, ApplicationMode.DEFAULT);
|
||||
|
|
|
@ -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++) {
|
||||
|
|
Loading…
Reference in a new issue