diff --git a/OsmAnd/res/layout/fragment_selected_profile.xml b/OsmAnd/res/layout/fragment_selected_profile.xml index c2a2a24b84..c62a3ca642 100644 --- a/OsmAnd/res/layout/fragment_selected_profile.xml +++ b/OsmAnd/res/layout/fragment_selected_profile.xml @@ -4,13 +4,15 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" + android:background="?attr/ctx_menu_info_view_bg" android:layout_width="match_parent" android:layout_height="match_parent" > + android:layout_gravity="top" + android:layout_marginBottom="@dimen/setting_profile_item_height"> + + android:layout_height="wrap_content" + android:background="?attr/ctx_menu_info_view_bg" + android:orientation="vertical"> + + + + + + + + + android:layout_height="wrap_content" + android:background="?attr/ctx_menu_info_view_bg" + android:orientation="vertical"> + + + + + + - - - + + + + routingProfiles; OsmandApplication app; RoutingProfile selectedRoutingProfile = null; - float defSpeed = 0f; private boolean isNew = false; private boolean isUserProfile = false; @@ -250,8 +250,16 @@ public class EditProfileFragment extends BaseOsmAndFragment { @Override public void onSelectedType(int pos) { isDataChanged = true; + for (int i = 0; i < routingProfiles.size(); i++) { + if (i == pos) { + routingProfiles.get(i).setSelected(true); + } else { + routingProfiles.get(i).setSelected(false); + } + } selectedRoutingProfile = routingProfiles.get(pos); navTypeEt.setText(selectedRoutingProfile.getName()); + LOG.debug(routingProfiles); profile.setRoutingProfile(selectedRoutingProfile); } }; @@ -299,8 +307,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { fragment.setArguments(bundle); if (getActivity() != null) { getActivity().getSupportFragmentManager().beginTransaction() - .add(fragment, "select_nav_type") - .commitAllowingStateLoss(); + .add(fragment, "select_nav_type").commitAllowingStateLoss(); } navTypeEt.setCursorVisible(false); @@ -333,8 +340,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { public void onClick(View v) { if (isDataChanged) { needSaveDialog(); - } else { - + } else if (getSettings() != null) { getSettings().APPLICATION_MODE.set(mode); Intent i = new Intent(getActivity(), MapActivity.class); i.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG); @@ -349,7 +355,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { public void onClick(View v) { if (isDataChanged) { needSaveDialog(); - } else { + } else if (getSettings() != null) { getSettings().APPLICATION_MODE.set(mode); Intent i = new Intent(getActivity(), MapActivity.class); i.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG); @@ -364,7 +370,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { public void onClick(View v) { if (isDataChanged) { needSaveDialog(); - } else { + } else if (getSettings() != null) { getSettings().APPLICATION_MODE.set(mode); Intent i = new Intent(getActivity(), SettingsNavigationActivity.class); i.putExtra(OPEN_CONFIG_ON_MAP, NAV_CONFIG); @@ -425,16 +431,6 @@ public class EditProfileFragment extends BaseOsmAndFragment { } } - private void needSaveDialog() { - if (getActivity() != null) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle("Save Changes"); - bld.setMessage("You need to save changes to Profile before proceed"); - bld.setNegativeButton(R.string.shared_string_ok, null); - bld.show(); - } - } - private boolean saveNewProfile() { if (isUserProfile && !isNew) { @@ -442,27 +438,20 @@ public class EditProfileFragment extends BaseOsmAndFragment { } if (profile.getRoutingProfile() == null && getActivity() != null) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle("Select Routing Type"); - bld.setMessage("You need to select Routing Type to create New Application Profile"); - bld.setNegativeButton(R.string.shared_string_dismiss, null); - bld.show(); + showSaveWarningDialog( + "Select Routing Type", + "You need to select Routing Type to create New Application Profile", + getActivity()); return false; - } else if (profile.getUserProfileTitle().isEmpty() && getActivity() != null) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle("Enter Profile Name"); - bld.setMessage("Profile name shouldn't be empty!"); - bld.setNegativeButton(R.string.shared_string_dismiss, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - navTypeEt.requestFocus(); - } - }); - bld.show(); + } else if (getActivity() != null && profile.getUserProfileTitle().isEmpty() + || profile.getUserProfileTitle().replace(" ", "").length() < 1) { + showSaveWarningDialog( + "Enter Profile Name", + "Profile name shouldn't be empty!", + getActivity() + ); return false; } - for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.getUserProfileName() != null && m.getUserProfileName().equals(profile.getUserProfileTitle()) && getActivity() != null) { @@ -528,6 +517,24 @@ public class EditProfileFragment extends BaseOsmAndFragment { return true; } + private void needSaveDialog() { + if (getActivity() != null) { + AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); + bld.setTitle("Save Changes"); + bld.setMessage("You need to save changes to Profile before proceed"); + bld.setNegativeButton(R.string.shared_string_ok, null); + bld.show(); + } + } + + private void showSaveWarningDialog(String title, String message, Activity activity) { + AlertDialog.Builder bld = new AlertDialog.Builder(activity); + bld.setTitle(title); + bld.setMessage(message); + bld.setNegativeButton(R.string.shared_string_dismiss, null); + bld.show(); + } + void onDeleteProfileClick() { if (getActivity() != null) { AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); @@ -552,8 +559,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { private ArrayList getRoutingProfiles() { ArrayList routingProfiles = new ArrayList<>(); - Map routingProfilesNames = getMyApplication() - .getDefaultRoutingConfig().getAllRoutes(); + Map routingProfilesNames = getMyApplication().getDefaultRoutingConfig().getAllRoutes(); for (Entry e : routingProfilesNames.entrySet()) { String name; String description = getResources().getString(R.string.osmand_default_routing); @@ -579,6 +585,10 @@ public class EditProfileFragment extends BaseOsmAndFragment { iconRes = R.drawable.map_action_sail_boat_dark; name = getString(R.string.app_mode_boat); break; + case "geocoding": + iconRes = R.drawable.ic_action_world_globe; + name = "Geocoding"; + break; default: iconRes = R.drawable.ic_action_world_globe; name = Algorithms @@ -586,10 +596,8 @@ public class EditProfileFragment extends BaseOsmAndFragment { description = "Custom profile"; //todo add filename break; } - routingProfiles.add(new RoutingProfile(e.getKey(), name, description, iconRes, false)); } - return routingProfiles; } diff --git a/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java index 405305c07b..724dc03507 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java @@ -146,11 +146,11 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment final ProfileDataObject item = items.get(position); holder.title.setText(item.getName()); if (item.isSelected()) { - holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode - ? R.color.active_buttons_and_links_dark - : R.color.active_buttons_and_links_light)); - } else { - holder.icon.setImageDrawable(getIcon(item.getIconRes(), R.color.icon_color)); + holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode + ? R.color.active_buttons_and_links_dark + : R.color.active_buttons_and_links_light)); + } else { + holder.icon.setImageDrawable(getIcon(item.getIconRes(), R.color.icon_color)); } holder.itemView.setOnClickListener(new View.OnClickListener() { @@ -167,18 +167,15 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment } } }); - if (item instanceof RoutingProfile) { - holder.descr.setText(Algorithms - .capitalizeFirstLetterAndLowercase(item.getDescription())); - if (item.isSelected()) { - holder.radioButton.setChecked(true); - previousSelection = position; - } else { - holder.radioButton.setChecked(false); - } + + holder.descr.setText(item.getDescription()); + if (item.isSelected()) { + holder.radioButton.setChecked(true); + previousSelection = position; } else { - holder.descr.setText(item.getDescription()); + holder.radioButton.setChecked(false); } + } @Override diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectIconBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SelectIconBottomSheetDialogFragment.java index 78403a206e..f9c22e7afc 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SelectIconBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SelectIconBottomSheetDialogFragment.java @@ -30,6 +30,8 @@ public class SelectIconBottomSheetDialogFragment extends BottomSheetDialogFragme private IconIdListener listListener; private RecyclerView recyclerView; private IconIdAdapter adapter; + private TextView title; + public void setIconIdListener(IconIdListener listener) { this.listener = listener; @@ -75,10 +77,13 @@ public class SelectIconBottomSheetDialogFragment extends BottomSheetDialogFragme } }; recyclerView = view.findViewById(R.id.menu_list_view); + title = view.findViewById(R.id.dialog_title); + title.setText("Select icon"); adapter = new IconIdAdapter(icons, isNightMode(getMyApplication()), listListener); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setAdapter(adapter); + Button cancelBtn = view.findViewById(R.id.cancel_selection); cancelBtn.setOnClickListener(new View.OnClickListener() { @Override @@ -119,15 +124,18 @@ public class SelectIconBottomSheetDialogFragment extends BottomSheetDialogFragme final int pos = position; final IconResWithDescr item = items.get(position); holder.title.setText(item.getTitleId()); - holder.icon.setImageDrawable(getIcon(item.getResId(), isNightMode - ? R.color.active_buttons_and_links_dark - : R.color.active_buttons_and_links_light)); - if(item.isSelected()) { + if (item.isSelected) { + holder.icon.setImageDrawable(getIcon(item.getResId(), isNightMode + ? R.color.active_buttons_and_links_dark + : R.color.active_buttons_and_links_light)); holder.radioButton.setChecked(true); previousSelection = position; } else { holder.radioButton.setChecked(false); + holder.icon.setImageDrawable(getIcon(item.getResId(), R.color.icon_color)); } + + holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java index 1d00eec428..969ce40f17 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SettingsProfileFragment.java @@ -120,7 +120,6 @@ public class SettingsProfileFragment extends BaseOsmAndFragment { Bundle bundle = new Bundle(); bundle.putParcelableArrayList(TYPE_APP_PROFILE, baseProfiles); dialog.setArguments(bundle); - if (getActivity() != null) { getActivity().getSupportFragmentManager().beginTransaction() .add(dialog, "select_base_type").commitAllowingStateLoss(); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 0676250a5d..c75af6e540 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -687,7 +687,6 @@ public class RouteProvider { GeneralRouterProfile p ; if (params.mode.getRoutingProfile() != null ) { - //todo get assigned routing profile from ApplicationMode p = GeneralRouterProfile.CUSTOM; } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { p = GeneralRouterProfile.BICYCLE;