Add possibility to change navigation type for all profiles
This commit is contained in:
parent
cc7959dc32
commit
349212bbc7
9 changed files with 93 additions and 33 deletions
|
@ -37,14 +37,6 @@
|
|||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="@string/routing_settings_2" />
|
||||
|
||||
<include
|
||||
layout="@layout/profile_button_small"
|
||||
android:layout_width="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_height="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
|
@ -9,7 +9,6 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:summary="@string/rendering_value_car_name"
|
||||
android:title="@string/nav_type_hint"
|
||||
app:fragment="net.osmand.plus.settings.SelectProfileBottomSheetDialogFragment"
|
||||
tools:icon="@drawable/ic_action_car_dark" />
|
||||
|
||||
<Preference
|
||||
|
|
|
@ -720,7 +720,7 @@ public class ApplicationMode {
|
|||
mb.userProfileName = mode.userProfileName;
|
||||
mb.iconColor = mode.iconColor;
|
||||
mb.iconName = mode.iconResName;
|
||||
mb.parent = mode.parentAppMode.getStringKey();
|
||||
mb.parent = mode.parentAppMode != null ? mode.parentAppMode.getStringKey() : null;
|
||||
mb.stringKey = mode.stringKey;
|
||||
mb.routeService = mode.routeService;
|
||||
mb.routingProfile = mode.routingProfile;
|
||||
|
|
|
@ -2113,7 +2113,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
String fragmentName = pref.getFragment();
|
||||
Fragment fragment = Fragment.instantiate(this, fragmentName);
|
||||
if (caller instanceof BaseSettingsFragment) {
|
||||
fragment.setArguments(((BaseSettingsFragment) caller).buildArguments(pref.getKey()));
|
||||
fragment.setArguments(((BaseSettingsFragment) caller).buildArguments());
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
|
||||
|
|
|
@ -775,7 +775,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
|
||||
public static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
|
||||
List<RoutingProfileDataObject> profilesObjects = new ArrayList<>();
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
|||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.settings.NavigationFragment;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -223,6 +224,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
|
||||
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
|
||||
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
|
||||
|
||||
if (editProfileFragment != null) {
|
||||
switch (type) {
|
||||
|
@ -231,6 +233,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
break;
|
||||
case TYPE_NAV_PROFILE:
|
||||
listener = editProfileFragment.getNavProfileListener();
|
||||
|
||||
break;
|
||||
case TYPE_ICON:
|
||||
listener = editProfileFragment.getIconListener();
|
||||
|
@ -238,6 +241,8 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
}
|
||||
} else if (settingsProfileFragment != null) {
|
||||
listener = settingsProfileFragment.getBaseProfileListener();
|
||||
} else if (navigationFragment != null) {
|
||||
listener = navigationFragment.getNavProfileListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,7 +277,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
return icons;
|
||||
}
|
||||
|
||||
interface SelectProfileListener {
|
||||
public interface SelectProfileListener {
|
||||
void onSelectedType(int pos, String stringRes);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch),
|
||||
PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
|
||||
GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, R.xml.general_profile_settings, R.layout.profile_preference_toolbar_big),
|
||||
NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar_big),
|
||||
NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar),
|
||||
COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, R.xml.coordinates_format, R.layout.profile_preference_toolbar),
|
||||
ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, R.xml.route_parameters, R.layout.profile_preference_toolbar),
|
||||
SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
|
||||
|
|
|
@ -90,6 +90,16 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
return super.onPreferenceChange(preference, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String prefId = preference.getKey();
|
||||
if (APP_PROFILES.equals(preference.getParent().getKey())) {
|
||||
BaseSettingsFragment.showInstance(getActivity(), SettingsScreenType.CONFIGURE_PROFILE, ApplicationMode.valueOfStringKey(prefId, null));
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
private void setupConfigureProfilePref() {
|
||||
ApplicationMode selectedMode = app.getSettings().APPLICATION_MODE.get();
|
||||
String title = selectedMode.toHumanString(getContext());
|
||||
|
|
|
@ -4,13 +4,19 @@ import android.os.Bundle;
|
|||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.SwitchPreferenceCompat;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.profiles.EditProfileFragment;
|
||||
import net.osmand.plus.profiles.EditProfileFragment.RoutingProfilesResources;
|
||||
import net.osmand.plus.profiles.RoutingProfileDataObject;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.routing.RouteProvider;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
|
||||
|
@ -18,20 +24,30 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
|
|||
public class NavigationFragment extends BaseSettingsFragment {
|
||||
|
||||
public static final String TAG = NavigationFragment.class.getSimpleName();
|
||||
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
|
||||
List<RoutingProfileDataObject> routingProfileDataObjects;
|
||||
private Preference navigationType;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
Preference navigationType = findPreference("navigation_type");
|
||||
navigationType = findPreference("navigation_type");
|
||||
Preference routeParameters = findPreference("route_parameters");
|
||||
SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId());
|
||||
SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId());
|
||||
SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId());
|
||||
SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId());
|
||||
|
||||
GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
|
||||
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase());
|
||||
navigationType.setSummary(routingProfilesResources.getStringRes());
|
||||
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
|
||||
if (getSelectedAppMode().getRoutingProfile() != null) {
|
||||
GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
|
||||
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase());
|
||||
navigationType.setSummary(routingProfilesResources.getStringRes());
|
||||
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
|
||||
}
|
||||
routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
|
||||
showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert));
|
||||
speakRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_volume_up));
|
||||
|
@ -56,21 +72,59 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference.getKey().equals("navigation_type")) {
|
||||
if (getSelectedAppMode().isCustomProfile()) {
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (getSelectedAppMode() != null) {
|
||||
bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(dialog, "select_nav_type").commitAllowingStateLoss();
|
||||
}
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (getSelectedAppMode() != null) {
|
||||
bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(dialog, "select_nav_type").commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public SelectProfileBottomSheetDialogFragment.SelectProfileListener getNavProfileListener() {
|
||||
if (navTypeListener == null) {
|
||||
navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
updateRoutingProfile(pos);
|
||||
}
|
||||
};
|
||||
}
|
||||
return navTypeListener;
|
||||
}
|
||||
|
||||
void updateRoutingProfile(int pos) {
|
||||
for (int i = 0; i < routingProfileDataObjects.size(); i++) {
|
||||
if (i == pos) {
|
||||
routingProfileDataObjects.get(i).setSelected(true);
|
||||
} else {
|
||||
routingProfileDataObjects.get(i).setSelected(false);
|
||||
}
|
||||
}
|
||||
RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(pos);
|
||||
navigationType.setSummary(selectedRoutingProfileDataObject.getName());
|
||||
navigationType.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes()));
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode());
|
||||
if (selectedRoutingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
|
||||
} else if (selectedRoutingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.BROUTER);
|
||||
} else {
|
||||
builder.setRoutingProfile(selectedRoutingProfileDataObject.getStringKey());
|
||||
}
|
||||
|
||||
ApplicationMode mode = ApplicationMode.saveProfile(builder, app);
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, app);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupVehicleParametersPref() {
|
||||
|
|
Loading…
Reference in a new issue