diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleWithButtonItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleWithButtonItem.java index a674279d60..4965076072 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleWithButtonItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleWithButtonItem.java @@ -19,22 +19,61 @@ public class TitleWithButtonItem extends SimpleBottomSheetItem { private View.OnClickListener onClickListener; private String iconPosition; - private Drawable textIcon; - private String textButton; + private Drawable icon; + private String textOnButton; + private TextView textButtonTV; public TitleWithButtonItem(View.OnClickListener onClickListener, - Drawable textIcon, + Drawable icon, String title, - String textButton, + String textOnButton, String iconPosition) { this.title = title; this.layoutId = R.layout.bottom_sheet_item_title_with_button; - this.textIcon = textIcon; - this.textButton = textButton; + this.icon = icon; + this.textOnButton = textOnButton; this.iconPosition = iconPosition; this.onClickListener = onClickListener; } + public void setButtonIcon(Drawable icon, String iconPosition) { + this.icon = icon; + if (this.icon != null) { + switch (iconPosition) { + case textOnLeft: + textButtonTV.setCompoundDrawablesWithIntrinsicBounds(this.icon, null, null, null); + break; + case textOnTop: + textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, this.icon, null, null); + break; + case textOnRight: + textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, null, this.icon, null); + break; + case textOnBottom: + textButtonTV.setCompoundDrawablesWithIntrinsicBounds(null, null, null, this.icon); + break; + } + } + } + + public void setButtonText(String text) { + textOnButton = text; + textButtonTV.setText(textOnButton); + + } + + @Override + public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { + super.inflate(app, container, nightMode); + + if (textOnButton != null) { + textButtonTV = (TextView) view.findViewById(R.id.text_button); + textButtonTV.setOnClickListener(onClickListener); + setButtonIcon(icon, iconPosition); + setButtonText(textOnButton); + } + } + public static class Builder extends BaseBottomSheetItem.Builder { private Drawable textIcon; @@ -77,31 +116,4 @@ public class TitleWithButtonItem extends SimpleBottomSheetItem { iconPosition); } } - - @Override - public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { - super.inflate(app, container, nightMode); - - if (textButton != null) { - TextView descriptionTv = (TextView) view.findViewById(R.id.text_button); - descriptionTv.setText(textButton); - descriptionTv.setOnClickListener(onClickListener); - if (textIcon != null) { - switch (iconPosition) { - case textOnLeft: - descriptionTv.setCompoundDrawablesWithIntrinsicBounds(textIcon, null, null, null); - break; - case textOnTop: - descriptionTv.setCompoundDrawablesWithIntrinsicBounds(null, textIcon, null, null); - break; - case textOnRight: - descriptionTv.setCompoundDrawablesWithIntrinsicBounds(null, null, textIcon, null); - break; - case textOnBottom: - descriptionTv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, textIcon); - break; - } - } - } - } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java index 93d8012e27..cd1bced383 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java @@ -40,7 +40,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag boolean target; boolean intermediate; - private MapActivity mapActivity; private Location location; private Float heading; private List favouritePoints; @@ -49,28 +48,23 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag private boolean sortByDist = false; private boolean locationUpdateStarted; private boolean compassUpdateAllowed = true; + private TitleWithButtonItem title; + private MapRouteInfoMenu routeMenu; @Override public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); target = args.getBoolean(TARGET); intermediate = args.getBoolean(INTERMEDIATE); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; +// final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; FavouritesDbHelper favouritesDbHelper = getMyApplication().getFavorites(); - mapActivity = (MapActivity) getActivity(); favouritePoints = favouritesDbHelper.getVisibleFavouritePoints(); - - View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.bottom_sheet_item_title_with_button, null); - ((TextView) titleView.findViewById(R.id.title)).setText(R.string.favourites); - final TextView textButton = (TextView) titleView.findViewById(R.id.text_button); + routeMenu = ((MapActivity) getActivity()).getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); recyclerView = new RecyclerView(getContext()); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - textButton.setText(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name); - final TitleWithButtonItem title = new TitleWithButtonItem.Builder() + title = new TitleWithButtonItem.Builder() .setIcon(getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name, nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light)) .setIconPosition(TitleWithButtonItem.textOnRight) @@ -83,13 +77,16 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag return; } sortFavourites(); + title.setButtonIcon(getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name, + nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light), TitleWithButtonItem.textOnRight); + title.setButtonText(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name)); adapter.notifyDataSetChanged(); } }) .create(); items.add(title); - adapter = new FavouritesAdapter(mapActivity, favouritePoints); + adapter = new FavouritesAdapter(getContext(), favouritePoints); adapter.setItemClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -133,7 +130,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag } void selectFavorite(FavouritePoint point) { - final MapRouteInfoMenu routeMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); LatLon ll = new LatLon(point.getLatitude(), point.getLongitude()); @@ -147,13 +143,16 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag if (!intermediate && getActivity() instanceof MapActivity) { routeMenu.updateFromIcon(); } + if (routeMenu.mainView != null) { + routeMenu.setupSpinners(routeMenu.mainView, target, intermediate); + } dismiss(); } @Override public void onResume() { super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(mapActivity)); + adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); startLocationUpdate(); } @@ -198,7 +197,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag @Override public void run() { if (location == null) { - location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + location = getMyApplication().getLocationProvider().getLastKnownLocation(); } if (location == null) { return; @@ -247,4 +246,12 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag super.onSaveInstanceState(outState); outState.putParcelable(BUNDLE_RECYCLER_LAYOUT, recyclerView.getLayoutManager().onSaveInstanceState()); } + + @Override + protected void onCloseRowClickAction() { + super.onCloseRowClickAction(); + if (routeMenu.mainView != null) { + routeMenu.setupSpinners(routeMenu.mainView, target, intermediate); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java index f6974b17ec..d6ea2762ba 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java @@ -81,7 +81,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { private OnDismissListener onDismissListener; private OnMarkerSelectListener onMarkerSelectListener; - View.OnClickListener dismissListener; + View mainView; private static final long SPINNER_MY_LOCATION_ID = 1; public static final long SPINNER_FAV_ID = 2; @@ -198,6 +198,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { } public void updateInfo(final View main) { + mainView = main; nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); updateViaView(main); updateFromSpinner(main); @@ -479,14 +480,19 @@ public class MapRouteInfoMenu implements IRouteInformationListener { args.putBoolean(FavouritesBottomSheetMenuFragment.INTERMEDIATE, intermediate); fragment.setArguments(args); fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG); + } - if (target) { - setupToSpinner(parentView); - } else { - setupFromSpinner(parentView); + public void setupSpinners(@Nullable final View parentView, final boolean target, final boolean intermediate) { + if (!intermediate && parentView != null) { + if (target) { + setupToSpinner(parentView); + } else { + setupFromSpinner(parentView); + } } } + public void selectMapMarker(final int index, final boolean target, final boolean intermediate) { if (index != -1) { MapMarker m = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().get(index);