added title with button and refactored some code
This commit is contained in:
parent
583b3659ee
commit
4458c514a5
7 changed files with 267 additions and 167 deletions
43
OsmAnd/res/layout/bottom_sheet_item_title_with_button.xml
Normal file
43
OsmAnd/res/layout/bottom_sheet_item_title_with_button.xml
Normal 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>
|
|
@ -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>
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1086,7 +1086,7 @@ public class WaypointDialogHelper {
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (id == MapRouteInfoMenu.SPINNER_FAV_ID) {
|
||||
routeMenu.selectFavorite(false, true);
|
||||
routeMenu.selectFavorite(null,false, true);
|
||||
} else if (id == MapRouteInfoMenu.SPINNER_MAP_ID) {
|
||||
routeMenu.selectOnScreen(false, true);
|
||||
} else if (id == MapRouteInfoMenu.SPINNER_ADDRESS_ID) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapcontextmenu.other;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -15,7 +16,6 @@ import net.osmand.plus.IconsCache;
|
|||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
@ -24,32 +24,15 @@ import java.util.List;
|
|||
|
||||
public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private View.OnClickListener listener;
|
||||
private final Context context;
|
||||
private final List<FavouritePoint> favouritePoints;
|
||||
|
||||
private View.OnClickListener listener;
|
||||
private LatLon location;
|
||||
private Float heading;
|
||||
private boolean useCenter;
|
||||
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) {
|
||||
this.favouritePoints = FavouritePoints;
|
||||
|
@ -59,26 +42,18 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.favourite_list_item, viewGroup, false);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.onClick(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
view.setOnClickListener(listener);
|
||||
return new FavouritesViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof FavouritesViewHolder) {
|
||||
OsmandApplication app = ((MapActivity) context).getMyApplication();
|
||||
OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
|
||||
FavouritePoint favouritePoint = getItem(position);
|
||||
favouritesViewHolder.title.setText(favouritePoint.getName());
|
||||
|
||||
if (favouritePoint.getCategory().equals("")) {
|
||||
favouritesViewHolder.description.setText(R.string.shared_string_favorites);
|
||||
} else {
|
||||
|
@ -109,7 +84,7 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
return favouritePoints.get(position);
|
||||
}
|
||||
|
||||
public void setAdapterListener(View.OnClickListener listener) {
|
||||
public void setItemClickListener(View.OnClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
@ -128,5 +103,23 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
public void setUseCenter(boolean 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package net.osmand.plus.mapcontextmenu.other;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.Location;
|
||||
|
@ -16,13 +16,15 @@ import net.osmand.plus.FavouritesDbHelper;
|
|||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
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.util.MapUtils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -33,70 +35,71 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
public static final String TARGET = "target";
|
||||
public static final String INTERMEDIATE = "intermediate";
|
||||
public static final String TAG = "FavouritesBottomSheetMenuFragment";
|
||||
private static final String BUNDLE_RECYCLER_LAYOUT = "FavouritesBottomSheetMenuFragment.recycler";
|
||||
|
||||
boolean target;
|
||||
boolean intermediate;
|
||||
|
||||
private MapActivity mapActivity;
|
||||
|
||||
private Location location;
|
||||
private Float heading;
|
||||
private List<FavouritePoint> favouritePoints;
|
||||
private FavouritesAdapter adapter;
|
||||
private RecyclerView recyclerView;
|
||||
private boolean sortByDist = false;
|
||||
|
||||
private boolean locationUpdateStarted;
|
||||
private boolean compassUpdateAllowed = true;
|
||||
private List<FavouritePoint> list;
|
||||
private FavouritesAdapter adapter;
|
||||
|
||||
@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;
|
||||
|
||||
FavouritesDbHelper favouritesDbHelper = getMyApplication().getFavorites();
|
||||
mapActivity = (MapActivity) getActivity();
|
||||
list = favouritesDbHelper.getVisibleFavouritePoints();
|
||||
favouritePoints = favouritesDbHelper.getVisibleFavouritePoints();
|
||||
|
||||
View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.favourite_title_list_item, null);
|
||||
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.fragment_marker_add_group_bottom_sheet_dialog, null);
|
||||
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);
|
||||
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()));
|
||||
sortText.setText(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());
|
||||
textButton.setText(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name);
|
||||
|
||||
adapter = new FavouritesAdapter(mapActivity, list);
|
||||
adapter.setAdapterListener(new View.OnClickListener() {
|
||||
final TitleWithButtonItem 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)
|
||||
.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
|
||||
public void onClick(View v) {
|
||||
int position = recyclerView.getChildAdapterPosition(v);
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
selectFavorite(list.get(position));
|
||||
selectFavorite(favouritePoints.get(position));
|
||||
}
|
||||
});
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mapActivity, LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
|
@ -106,53 +109,42 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
}
|
||||
});
|
||||
items.add(new BaseBottomSheetItem.Builder().
|
||||
setCustomView(mainView).
|
||||
setCustomView(recyclerView).
|
||||
create());
|
||||
}
|
||||
|
||||
private void sortFavourites(boolean sortByDist, List<FavouritePoint> favourites) {
|
||||
if (sortByDist) {
|
||||
Collections.sort(favourites, new Comparator<FavouritePoint>() {
|
||||
@Override
|
||||
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
||||
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
|
||||
double d1 = MapUtils.getDistance(latLon, lhs.getLatitude(), lhs.getLongitude());
|
||||
double d2 = MapUtils.getDistance(latLon, rhs.getLatitude(), rhs.getLongitude());
|
||||
if (d1 == d2) {
|
||||
return 0;
|
||||
} else if (d1 > d2) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
private void sortFavourites() {
|
||||
final Collator inst = Collator.getInstance();
|
||||
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
|
||||
@Override
|
||||
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
||||
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
|
||||
if (sortByDist) {
|
||||
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
|
||||
lhs.getLongitude());
|
||||
double rd = MapUtils.getDistance(latLon, rhs.getLatitude(),
|
||||
rhs.getLongitude());
|
||||
return Double.compare(ld, rd);
|
||||
}
|
||||
});
|
||||
this.sortByDist = false;
|
||||
} else {
|
||||
Collections.sort(favourites, new Comparator<FavouritePoint>() {
|
||||
@Override
|
||||
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
||||
return lhs.getName().compareTo(rhs.getName());
|
||||
}
|
||||
});
|
||||
this.sortByDist = true;
|
||||
}
|
||||
return inst.compare(lhs.getName(), rhs.getName());
|
||||
}
|
||||
});
|
||||
sortByDist = !sortByDist;
|
||||
}
|
||||
|
||||
private void selectFavorite(FavouritePoint point) {
|
||||
Bundle args = getArguments();
|
||||
boolean target = args.getBoolean(TARGET);
|
||||
boolean intermediate = args.getBoolean(INTERMEDIATE);
|
||||
void selectFavorite(FavouritePoint point) {
|
||||
final MapRouteInfoMenu routeMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
|
||||
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
|
||||
LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
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) {
|
||||
routeMenu.getTargets().navigateToPoint(ll, true, -1, point.getPointDescription());
|
||||
targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription());
|
||||
} else {
|
||||
routeMenu.getTargets().setStartPoint(ll, true, point.getPointDescription());
|
||||
targetPointsHelper.setStartPoint(ll, true, point.getPointDescription());
|
||||
}
|
||||
if (!intermediate) {
|
||||
if (!intermediate && getActivity() instanceof MapActivity) {
|
||||
routeMenu.updateFromIcon();
|
||||
}
|
||||
dismiss();
|
||||
|
@ -240,4 +232,19 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
private OnDismissListener onDismissListener;
|
||||
|
||||
private OnMarkerSelectListener onMarkerSelectListener;
|
||||
View.OnClickListener dismissListener;
|
||||
|
||||
private static final long SPINNER_MY_LOCATION_ID = 1;
|
||||
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);
|
||||
vg.removeAllViews();
|
||||
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
|
||||
vg, true, false,true, new View.OnClickListener() {
|
||||
vg, true, false, true, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (selected.size() > 0) {
|
||||
|
@ -338,7 +339,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
@Override
|
||||
public void run() {
|
||||
if (id == SPINNER_FAV_ID) {
|
||||
selectFavorite(true, false);
|
||||
selectFavorite(parentView, true, false);
|
||||
} else if (id == SPINNER_MAP_ID) {
|
||||
selectOnScreen(true, false);
|
||||
} else if (id == SPINNER_ADDRESS_ID) {
|
||||
|
@ -408,7 +409,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
}
|
||||
updateFromIcon(parentView);
|
||||
} else if (id == SPINNER_FAV_ID) {
|
||||
selectFavorite(false, false);
|
||||
selectFavorite(parentView, false, false);
|
||||
} else if (id == SPINNER_MAP_ID) {
|
||||
selectOnScreen(false, false);
|
||||
} else if (id == SPINNER_ADDRESS_ID) {
|
||||
|
@ -470,7 +471,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
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();
|
||||
FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
@ -478,6 +479,12 @@ 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 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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue