diff --git a/OsmAnd/res/layout/profile_list_item.xml b/OsmAnd/res/layout/profile_list_item.xml index 1056d60f6d..bd3ff6cb96 100644 --- a/OsmAnd/res/layout/profile_list_item.xml +++ b/OsmAnd/res/layout/profile_list_item.xml @@ -91,6 +91,7 @@ (ApplicationMode.values(getMyApplication()))); + setupHeightAndBackground(getView()); + + } + + private void getData() { + allModes.addAll(ApplicationMode.allPossibleValues()); + allModes.remove(ApplicationMode.DEFAULT); + selectedModes.addAll(ApplicationMode.values(getMyApplication())); + selectedModes.remove(ApplicationMode.DEFAULT); } @Override diff --git a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java index 2d7083b374..16694509f2 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java @@ -385,25 +385,30 @@ public class EditProfileFragment extends BaseOsmAndFragment { } }); - saveButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (saveNewProfile()) { - activateMode(mode); - getActivity().onBackPressed(); + if (!isNew && !isUserProfile) { + saveButtonSV.setEnabled(false); + saveButton.setEnabled(false); + } else { + saveButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (saveNewProfile()) { + activateMode(mode); + getActivity().onBackPressed(); + } } - } - }); + }); - saveButtonSV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (saveNewProfile()) { - activateMode(mode); - getActivity().onBackPressed(); + saveButtonSV.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (saveNewProfile()) { + activateMode(mode); + getActivity().onBackPressed(); + } } - } - }); + }); + } view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java index 81bda62d76..4db5def5cb 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java @@ -26,9 +26,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter private Set selectedItems; private ProfileListener listener; private final OsmandApplication app; - @ColorRes private int selectedIconColorRes; + @ColorRes + private int selectedIconColorRes; + private boolean isBottomSheet = false; - public ProfileMenuAdapter(List items, Set selectedItems, OsmandApplication app, ProfileListener listener) { + public ProfileMenuAdapter(List items, Set selectedItems, + OsmandApplication app, ProfileListener listener) { this.items = items; this.listener = listener; this.app = app; @@ -47,6 +50,10 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter notifyDataSetChanged(); } + public void setBottomSheetMode(boolean isBottomSheet) { + this.isBottomSheet = isBottomSheet; + } + public void setListener(ProfileListener listener) { this.listener = listener; } @@ -70,10 +77,18 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter @Override public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) { final ApplicationMode item = items.get(position); + + if (isBottomSheet) { + holder.divider.setBackgroundColor(isNightMode(app) + ? app.getResources().getColor(R.color.divider_dark) + : app.getResources().getColor(R.color.divider_light)); + } + if (item.getParent() != null) { holder.title.setText(item.getUserProfileName()); holder.descr.setText(String.format(app.getString(R.string.profile_type_descr_string), - Algorithms.capitalizeFirstLetterAndLowercase(item.getParent().getStringKey().replace("_", " ")))); + Algorithms.capitalizeFirstLetterAndLowercase( + item.getParent().getStringKey().replace("_", " ")))); } else { holder.title.setText(app.getResources().getString(item.getStringResource())); holder.descr.setText(R.string.profile_type_base_string); @@ -97,7 +112,8 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter if (selectedItems.contains(item)) { holder.aSwitch.setChecked(true); - holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes)); + holder.icon + .setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes)); } else { holder.aSwitch.setChecked(false); holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color)); @@ -108,18 +124,20 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter public void onClick(View v) { listener.changeProfileStatus(item, holder.aSwitch.isChecked()); if (selectedItems.contains(item)) { - holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), selectedIconColorRes)); + holder.icon.setImageDrawable(app.getUIUtilities() + .getIcon(item.getSmallIconDark(), selectedIconColorRes)); } else { - holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), R.color.icon_color)); + holder.icon.setImageDrawable( + app.getUIUtilities().getIcon(item.getSmallIconDark(), R.color.icon_color)); } } }); holder.profileOptions.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - listener.editProfile(item); - } - }); + @Override + public void onClick(View v) { + listener.editProfile(item); + } + }); } @Override @@ -132,10 +150,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter } class ProfileViewHolder extends RecyclerView.ViewHolder { + TextView title, descr; SwitchCompat aSwitch; ImageView icon; LinearLayout profileOptions; + View divider; ProfileViewHolder(View itemView) { super(itemView); @@ -144,11 +164,14 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter aSwitch = itemView.findViewById(R.id.compound_button); icon = itemView.findViewById(R.id.icon); profileOptions = itemView.findViewById(R.id.profile_settings); + divider = itemView.findViewById(R.id.divider_bottom); } } public interface ProfileListener { + void changeProfileStatus(ApplicationMode item, boolean isSelected); + void editProfile(ApplicationMode item); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 2098deb2ba..01d32eb8a8 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -733,7 +733,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener @Override public void onClick(View v) { - showProfileBottomSheetDialog(mapActivity); + showProfileBottomSheetDialog(); //todo clear (+ method's body) before final commit //availableProfileDialog(); } @@ -750,7 +750,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener updateApplicationModesOptions(); } - private void showProfileBottomSheetDialog(Activity activity) { + private void showProfileBottomSheetDialog() { final AppModesBottomSheetDialogFragment fragment = new AppModesBottomSheetDialogFragment(); fragment.setUpdateMapRouteMenuListener(new UpdateMapRouteMenuListener() { @Override @@ -760,45 +760,42 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener }); getMapActivity().getSupportFragmentManager().beginTransaction() .add(fragment, "app_profile_settings").commitAllowingStateLoss(); - - - } - private void availableProfileDialog() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - AlertDialog.Builder b = new AlertDialog.Builder(mapActivity); - final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); - final List modes = ApplicationMode.allPossibleValues(); - modes.remove(ApplicationMode.DEFAULT); - final Set selected = new LinkedHashSet<>(ApplicationMode.values(mapActivity.getMyApplication())); - selected.remove(ApplicationMode.DEFAULT); - View v = AppModeDialog.prepareAppModeView(mapActivity, modes, selected, null, false, true, false, - new OnClickListener() { - - @Override - public void onClick(View v) { - StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey() + ","); - for (ApplicationMode mode : modes) { - if (selected.contains(mode)) { - vls.append(mode.getStringKey()).append(","); - } - } - settings.AVAILABLE_APP_MODES.set(vls.toString()); - } - }); - b.setTitle(R.string.profile_settings); - b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - updateApplicationModes(); - } - }); - b.setView(v); - b.show(); - } - } +// private void availableProfileDialog() { +// MapActivity mapActivity = getMapActivity(); +// if (mapActivity != null) { +// AlertDialog.Builder b = new AlertDialog.Builder(mapActivity); +// final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); +// final List modes = ApplicationMode.allPossibleValues(); +// modes.remove(ApplicationMode.DEFAULT); +// final Set selected = new LinkedHashSet<>(ApplicationMode.values(mapActivity.getMyApplication())); +// selected.remove(ApplicationMode.DEFAULT); +// View v = AppModeDialog.prepareAppModeView(mapActivity, modes, selected, null, false, true, false, +// new OnClickListener() { +// +// @Override +// public void onClick(View v) { +// StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey() + ","); +// for (ApplicationMode mode : modes) { +// if (selected.contains(mode)) { +// vls.append(mode.getStringKey()).append(","); +// } +// } +// settings.AVAILABLE_APP_MODES.set(vls.toString()); +// } +// }); +// b.setTitle(R.string.profile_settings); +// b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// updateApplicationModes(); +// } +// }); +// b.setView(v); +// b.show(); +// } +// } private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) { MapActivity mapActivity = getMapActivity();