added ability to change text and icon in titleItem

This commit is contained in:
Chumva 2018-03-14 18:16:01 +02:00
parent 4458c514a5
commit fa988e3c2a
3 changed files with 78 additions and 53 deletions

View file

@ -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;
}
}
}
}
}

View file

@ -40,7 +40,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
boolean target;
boolean intermediate;
private MapActivity mapActivity;
private Location location;
private Float heading;
private List<FavouritePoint> 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);
}
}
}

View file

@ -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);