added title with button and refactored some code

This commit is contained in:
Chumva 2018-03-14 17:37:02 +02:00
parent 583b3659ee
commit 4458c514a5
7 changed files with 267 additions and 167 deletions

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:minHeight="@dimen/bottom_sheet_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="Some Title"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:drawablePadding="2dp"
android:drawableRight="@drawable/ic_action_sort_by_name"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_title_height"
android:paddingRight="@dimen/content_padding"
android:text="@string/sort_by_name"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"
osmand:typeface="@string/font_roboto_medium" />
</RelativeLayout>

View file

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:minHeight="@dimen/bottom_sheet_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="Some Title"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium" />
<LinearLayout
android:id="@+id/sort_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/content_padding">
<TextView
android:id="@+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_title_height"
android:text="@string/sort_by_name"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold" />
<ImageView
android:id="@+id/sort_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_title_height"
android:minWidth="@dimen/bottom_sheet_title_height"
android:paddingLeft="@dimen/content_padding"
android:src="@drawable/ic_action_sort_by_name" />
</LinearLayout>
</RelativeLayout>

View file

@ -0,0 +1,107 @@
package net.osmand.plus.base.bottomsheetmenu.simpleitems;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
public class TitleWithButtonItem extends SimpleBottomSheetItem {
public static final String textOnLeft = "LEFT";
public static final String textOnTop = "TOP";
public static final String textOnRight = "RIGHT";
public static final String textOnBottom = "BOTTOM";
private View.OnClickListener onClickListener;
private String iconPosition;
private Drawable textIcon;
private String textButton;
public TitleWithButtonItem(View.OnClickListener onClickListener,
Drawable textIcon,
String title,
String textButton,
String iconPosition) {
this.title = title;
this.layoutId = R.layout.bottom_sheet_item_title_with_button;
this.textIcon = textIcon;
this.textButton = textButton;
this.iconPosition = iconPosition;
this.onClickListener = onClickListener;
}
public static class Builder extends BaseBottomSheetItem.Builder {
private Drawable textIcon;
protected String title;
private String textOnRight;
protected View.OnClickListener onClickListener;
private String iconPosition;
public TitleWithButtonItem.Builder setIcon(Drawable textIcon) {
this.textIcon = textIcon;
return this;
}
public TitleWithButtonItem.Builder setIconPosition(String iconPosition) {
this.iconPosition = iconPosition;
return this;
}
public TitleWithButtonItem.Builder setOnClickListener(View.OnClickListener onClickListener) {
this.onClickListener = onClickListener;
return this;
}
public TitleWithButtonItem.Builder setTextOnRight(String textOnRight) {
this.textOnRight = textOnRight;
return this;
}
public TitleWithButtonItem.Builder setTitle(String title) {
this.title = title;
return this;
}
public TitleWithButtonItem create() {
return new TitleWithButtonItem(onClickListener,
textIcon,
title,
textOnRight,
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

@ -1086,7 +1086,7 @@ public class WaypointDialogHelper {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (id == MapRouteInfoMenu.SPINNER_FAV_ID) { if (id == MapRouteInfoMenu.SPINNER_FAV_ID) {
routeMenu.selectFavorite(false, true); routeMenu.selectFavorite(null,false, true);
} else if (id == MapRouteInfoMenu.SPINNER_MAP_ID) { } else if (id == MapRouteInfoMenu.SPINNER_MAP_ID) {
routeMenu.selectOnScreen(false, true); routeMenu.selectOnScreen(false, true);
} else if (id == MapRouteInfoMenu.SPINNER_ADDRESS_ID) { } else if (id == MapRouteInfoMenu.SPINNER_ADDRESS_ID) {

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapcontextmenu.other; package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -15,7 +16,6 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -24,32 +24,15 @@ import java.util.List;
public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private View.OnClickListener listener;
private final Context context; private final Context context;
private final List<FavouritePoint> favouritePoints; private final List<FavouritePoint> favouritePoints;
private View.OnClickListener listener;
private LatLon location; private LatLon location;
private Float heading; private Float heading;
private boolean useCenter; private boolean useCenter;
private int screenOrientation; private int screenOrientation;
static class FavouritesViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final TextView description;
final TextView distance;
final ImageView arrowImage;
final ImageView favouriteImage;
public FavouritesViewHolder(View itemView) {
super(itemView);
favouriteImage = (ImageView) itemView.findViewById(R.id.favourite_icon);
title = (TextView) itemView.findViewById(R.id.favourite_title);
description = (TextView) itemView.findViewById(R.id.favourite_description);
distance = (TextView) itemView.findViewById(R.id.favourite_distance);
arrowImage = (ImageView) itemView.findViewById(R.id.favourite_direction_icon);
}
}
public FavouritesAdapter(Context context, List<FavouritePoint> FavouritePoints) { public FavouritesAdapter(Context context, List<FavouritePoint> FavouritePoints) {
this.favouritePoints = FavouritePoints; this.favouritePoints = FavouritePoints;
@ -59,26 +42,18 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.favourite_list_item, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.favourite_list_item, viewGroup, false);
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(listener);
@Override
public void onClick(View view) {
if (listener != null) {
listener.onClick(view);
}
}
});
return new FavouritesViewHolder(view); return new FavouritesViewHolder(view);
} }
@Override @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof FavouritesViewHolder) { if (holder instanceof FavouritesViewHolder) {
OsmandApplication app = ((MapActivity) context).getMyApplication(); OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
IconsCache iconsCache = app.getIconsCache(); IconsCache iconsCache = app.getIconsCache();
FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder; FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
FavouritePoint favouritePoint = getItem(position); FavouritePoint favouritePoint = getItem(position);
favouritesViewHolder.title.setText(favouritePoint.getName()); favouritesViewHolder.title.setText(favouritePoint.getName());
if (favouritePoint.getCategory().equals("")) { if (favouritePoint.getCategory().equals("")) {
favouritesViewHolder.description.setText(R.string.shared_string_favorites); favouritesViewHolder.description.setText(R.string.shared_string_favorites);
} else { } else {
@ -109,7 +84,7 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
return favouritePoints.get(position); return favouritePoints.get(position);
} }
public void setAdapterListener(View.OnClickListener listener) { public void setItemClickListener(View.OnClickListener listener) {
this.listener = listener; this.listener = listener;
} }
@ -128,5 +103,23 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
public void setUseCenter(boolean useCenter) { public void setUseCenter(boolean useCenter) {
this.useCenter = useCenter; this.useCenter = useCenter;
} }
class FavouritesViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final TextView description;
final TextView distance;
final ImageView arrowImage;
final ImageView favouriteImage;
public FavouritesViewHolder(View itemView) {
super(itemView);
favouriteImage = (ImageView) itemView.findViewById(R.id.favourite_icon);
title = (TextView) itemView.findViewById(R.id.favourite_title);
description = (TextView) itemView.findViewById(R.id.favourite_description);
distance = (TextView) itemView.findViewById(R.id.favourite_distance);
arrowImage = (ImageView) itemView.findViewById(R.id.favourite_direction_icon);
}
}
} }

View file

@ -1,12 +1,12 @@
package net.osmand.plus.mapcontextmenu.other; package net.osmand.plus.mapcontextmenu.other;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.Location; import net.osmand.Location;
@ -16,13 +16,15 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleWithButtonItem;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.text.Collator;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -33,70 +35,71 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
public static final String TARGET = "target"; public static final String TARGET = "target";
public static final String INTERMEDIATE = "intermediate"; public static final String INTERMEDIATE = "intermediate";
public static final String TAG = "FavouritesBottomSheetMenuFragment"; public static final String TAG = "FavouritesBottomSheetMenuFragment";
private static final String BUNDLE_RECYCLER_LAYOUT = "FavouritesBottomSheetMenuFragment.recycler";
boolean target;
boolean intermediate;
private MapActivity mapActivity; private MapActivity mapActivity;
private Location location; private Location location;
private Float heading; private Float heading;
private List<FavouritePoint> favouritePoints;
private FavouritesAdapter adapter;
private RecyclerView recyclerView;
private boolean sortByDist = false; private boolean sortByDist = false;
private boolean locationUpdateStarted; private boolean locationUpdateStarted;
private boolean compassUpdateAllowed = true; private boolean compassUpdateAllowed = true;
private List<FavouritePoint> list;
private FavouritesAdapter adapter;
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { 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(); FavouritesDbHelper favouritesDbHelper = getMyApplication().getFavorites();
mapActivity = (MapActivity) getActivity(); mapActivity = (MapActivity) getActivity();
list = favouritesDbHelper.getVisibleFavouritePoints(); favouritePoints = favouritesDbHelper.getVisibleFavouritePoints();
View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.favourite_title_list_item, null); R.layout.bottom_sheet_item_title_with_button, null);
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), ((TextView) titleView.findViewById(R.id.title)).setText(R.string.favourites);
R.layout.fragment_marker_add_group_bottom_sheet_dialog, null); final TextView textButton = (TextView) titleView.findViewById(R.id.text_button);
recyclerView = new RecyclerView(getContext());
TextView title = (TextView) titleView.findViewById(R.id.title);
final ImageView sortIconView = (ImageView) titleView.findViewById(R.id.sort_icon);
final TextView sortText = (TextView) titleView.findViewById(R.id.sort_text);
LinearLayout sort = (LinearLayout) titleView.findViewById(R.id.sort_by);
final RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
title.setText(R.string.favourites);
sortIconView.setImageDrawable(getIcon(R.drawable.ic_action_sort_by_name, nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light));
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
sortText.setText(R.string.sort_by_name); textButton.setText(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name);
sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (location == null) {
return;
}
sortFavourites(sortByDist, list);
sortText.setText(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name);
sortIconView.setImageDrawable(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));
adapter.notifyDataSetChanged();
}
});
items.add(new TitleItem.Builder()
.setCustomView(titleView)
.create());
adapter = new FavouritesAdapter(mapActivity, list); final TitleWithButtonItem title = new TitleWithButtonItem.Builder()
adapter.setAdapterListener(new View.OnClickListener() { .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)
.setTitle(getString(R.string.favourites))
.setTextOnRight(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (location == null) {
return;
}
sortFavourites();
adapter.notifyDataSetChanged();
}
})
.create();
items.add(title);
adapter = new FavouritesAdapter(mapActivity, favouritePoints);
adapter.setItemClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int position = recyclerView.getChildAdapterPosition(v); int position = recyclerView.getChildAdapterPosition(v);
if (position == RecyclerView.NO_POSITION) { if (position == RecyclerView.NO_POSITION) {
return; return;
} }
selectFavorite(list.get(position)); selectFavorite(favouritePoints.get(position));
} }
}); });
recyclerView.setLayoutManager(new LinearLayoutManager(mapActivity, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -106,53 +109,42 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
} }
}); });
items.add(new BaseBottomSheetItem.Builder(). items.add(new BaseBottomSheetItem.Builder().
setCustomView(mainView). setCustomView(recyclerView).
create()); create());
} }
private void sortFavourites(boolean sortByDist, List<FavouritePoint> favourites) { private void sortFavourites() {
if (sortByDist) { final Collator inst = Collator.getInstance();
Collections.sort(favourites, new Comparator<FavouritePoint>() { Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
@Override @Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) { public int compare(FavouritePoint lhs, FavouritePoint rhs) {
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude()); LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
double d1 = MapUtils.getDistance(latLon, lhs.getLatitude(), lhs.getLongitude()); if (sortByDist) {
double d2 = MapUtils.getDistance(latLon, rhs.getLatitude(), rhs.getLongitude()); double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
if (d1 == d2) { lhs.getLongitude());
return 0; double rd = MapUtils.getDistance(latLon, rhs.getLatitude(),
} else if (d1 > d2) { rhs.getLongitude());
return 1; return Double.compare(ld, rd);
}
return -1;
} }
}); return inst.compare(lhs.getName(), rhs.getName());
this.sortByDist = false; }
} else { });
Collections.sort(favourites, new Comparator<FavouritePoint>() { sortByDist = !sortByDist;
@Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
return lhs.getName().compareTo(rhs.getName());
}
});
this.sortByDist = true;
}
} }
private void selectFavorite(FavouritePoint point) { void selectFavorite(FavouritePoint point) {
Bundle args = getArguments();
boolean target = args.getBoolean(TARGET);
boolean intermediate = args.getBoolean(INTERMEDIATE);
final MapRouteInfoMenu routeMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); final MapRouteInfoMenu routeMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
LatLon ll = new LatLon(point.getLatitude(), point.getLongitude()); LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
if (intermediate) { if (intermediate) {
routeMenu.getTargets().navigateToPoint(ll, true, routeMenu.getTargets().getIntermediatePoints().size(), point.getPointDescription()); targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription());
} else if (target) { } else if (target) {
routeMenu.getTargets().navigateToPoint(ll, true, -1, point.getPointDescription()); targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription());
} else { } else {
routeMenu.getTargets().setStartPoint(ll, true, point.getPointDescription()); targetPointsHelper.setStartPoint(ll, true, point.getPointDescription());
} }
if (!intermediate) { if (!intermediate && getActivity() instanceof MapActivity) {
routeMenu.updateFromIcon(); routeMenu.updateFromIcon();
} }
dismiss(); dismiss();
@ -240,4 +232,19 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
} }
} }
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
Parcelable savedRecyclerLayoutState = savedInstanceState.getParcelable(BUNDLE_RECYCLER_LAYOUT);
recyclerView.getLayoutManager().onRestoreInstanceState(savedRecyclerLayoutState);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(BUNDLE_RECYCLER_LAYOUT, recyclerView.getLayoutManager().onSaveInstanceState());
}
} }

View file

@ -81,6 +81,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
private OnDismissListener onDismissListener; private OnDismissListener onDismissListener;
private OnMarkerSelectListener onMarkerSelectListener; private OnMarkerSelectListener onMarkerSelectListener;
View.OnClickListener dismissListener;
private static final long SPINNER_MY_LOCATION_ID = 1; private static final long SPINNER_MY_LOCATION_ID = 1;
public static final long SPINNER_FAV_ID = 2; public static final long SPINNER_FAV_ID = 2;
@ -242,7 +243,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
ViewGroup vg = (ViewGroup) parentView.findViewById(R.id.app_modes); ViewGroup vg = (ViewGroup) parentView.findViewById(R.id.app_modes);
vg.removeAllViews(); vg.removeAllViews();
AppModeDialog.prepareAppModeView(mapActivity, selected, false, AppModeDialog.prepareAppModeView(mapActivity, selected, false,
vg, true, false,true, new View.OnClickListener() { vg, true, false, true, new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (selected.size() > 0) { if (selected.size() > 0) {
@ -338,7 +339,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
@Override @Override
public void run() { public void run() {
if (id == SPINNER_FAV_ID) { if (id == SPINNER_FAV_ID) {
selectFavorite(true, false); selectFavorite(parentView, true, false);
} else if (id == SPINNER_MAP_ID) { } else if (id == SPINNER_MAP_ID) {
selectOnScreen(true, false); selectOnScreen(true, false);
} else if (id == SPINNER_ADDRESS_ID) { } else if (id == SPINNER_ADDRESS_ID) {
@ -408,7 +409,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
} }
updateFromIcon(parentView); updateFromIcon(parentView);
} else if (id == SPINNER_FAV_ID) { } else if (id == SPINNER_FAV_ID) {
selectFavorite(false, false); selectFavorite(parentView, false, false);
} else if (id == SPINNER_MAP_ID) { } else if (id == SPINNER_MAP_ID) {
selectOnScreen(false, false); selectOnScreen(false, false);
} else if (id == SPINNER_ADDRESS_ID) { } else if (id == SPINNER_ADDRESS_ID) {
@ -470,7 +471,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
updateMenu(); updateMenu();
} }
public void selectFavorite(final boolean target, final boolean intermediate) { public void selectFavorite(@Nullable final View parentView, final boolean target, final boolean intermediate) {
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment(); FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -478,6 +479,12 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
args.putBoolean(FavouritesBottomSheetMenuFragment.INTERMEDIATE, intermediate); args.putBoolean(FavouritesBottomSheetMenuFragment.INTERMEDIATE, intermediate);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG); fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG);
if (target) {
setupToSpinner(parentView);
} else {
setupFromSpinner(parentView);
}
} }
public void selectMapMarker(final int index, final boolean target, final boolean intermediate) { public void selectMapMarker(final int index, final boolean target, final boolean intermediate) {
@ -846,7 +853,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
} }
} }
TargetPointsHelper getTargets() { private TargetPointsHelper getTargets() {
return mapActivity.getMyApplication().getTargetPointsHelper(); return mapActivity.getMyApplication().getTargetPointsHelper();
} }