refactored some code and deleted onClickListener
This commit is contained in:
parent
35bc18bb42
commit
583b3659ee
4 changed files with 45 additions and 56 deletions
|
@ -89,6 +89,7 @@
|
||||||
android:textColor="?android:textColorSecondary"
|
android:textColor="?android:textColorSecondary"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
tools:text="Amsterdam Weekend" />
|
tools:text="Amsterdam Weekend" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -13,6 +13,7 @@ import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.IconsCache;
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
|
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.activities.MapActivity;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
|
@ -23,9 +24,9 @@ import java.util.List;
|
||||||
|
|
||||||
public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private FavouritesAdapterListener listener;
|
private View.OnClickListener listener;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final List<FavouritePoint> FavouritePoints;
|
private final List<FavouritePoint> favouritePoints;
|
||||||
|
|
||||||
private LatLon location;
|
private LatLon location;
|
||||||
private Float heading;
|
private Float heading;
|
||||||
|
@ -38,89 +39,80 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
final TextView description;
|
final TextView description;
|
||||||
final TextView distance;
|
final TextView distance;
|
||||||
final ImageView arrowImage;
|
final ImageView arrowImage;
|
||||||
final ImageView FavouriteImage;
|
final ImageView favouriteImage;
|
||||||
|
|
||||||
public FavouritesViewHolder(View itemView) {
|
public FavouritesViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
FavouriteImage = itemView.findViewById(R.id.favourite_icon);
|
favouriteImage = (ImageView) itemView.findViewById(R.id.favourite_icon);
|
||||||
title = itemView.findViewById(R.id.favourite_title);
|
title = (TextView) itemView.findViewById(R.id.favourite_title);
|
||||||
description = itemView.findViewById(R.id.favourite_description);
|
description = (TextView) itemView.findViewById(R.id.favourite_description);
|
||||||
distance = itemView.findViewById(R.id.favourite_distance);
|
distance = (TextView) itemView.findViewById(R.id.favourite_distance);
|
||||||
arrowImage = itemView.findViewById(R.id.favourite_direction_icon);
|
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;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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.bottom_sheet_item_favourite, viewGroup, false);
|
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.favourite_list_item, viewGroup, false);
|
||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onItemClick(view);
|
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) {
|
||||||
MapActivity mapActivity;
|
OsmandApplication app = ((MapActivity) context).getMyApplication();
|
||||||
if (context instanceof MapActivity) {
|
IconsCache iconsCache = app.getIconsCache();
|
||||||
mapActivity = (MapActivity) context;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
IconsCache iconsCache = mapActivity.getMyApplication().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("")) {
|
|
||||||
favouritesViewHolder.description.setText(favouritePoint.getCategory());
|
if (favouritePoint.getCategory().equals("")) {
|
||||||
} else {
|
|
||||||
favouritesViewHolder.description.setText(R.string.shared_string_favorites);
|
favouritesViewHolder.description.setText(R.string.shared_string_favorites);
|
||||||
|
} else {
|
||||||
|
favouritesViewHolder.description.setText(favouritePoint.getCategory());
|
||||||
}
|
}
|
||||||
Location myloc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
Location myloc = app.getLocationProvider().getLastKnownLocation();
|
||||||
if (myloc == null) {
|
if (myloc == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
|
float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
|
||||||
|
|
||||||
favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
|
||||||
favouritesViewHolder.FavouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(mapActivity, favouritePoint.getColor(), false));
|
favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
|
||||||
favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
|
favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
|
||||||
|
|
||||||
DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage,
|
DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage,
|
||||||
favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(),
|
favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(),
|
||||||
screenOrientation, mapActivity.getMyApplication(), mapActivity);
|
screenOrientation, app, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return FavouritePoints.size();
|
return favouritePoints.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FavouritePoint getItem(int position) {
|
private FavouritePoint getItem(int position) {
|
||||||
return FavouritePoints.get(position);
|
return favouritePoints.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdapterListener(FavouritesAdapterListener listener) {
|
public void setAdapterListener(View.OnClickListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface FavouritesAdapterListener {
|
|
||||||
void onItemClick(View view);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScreenOrientation(int screenOrientation) {
|
public void setScreenOrientation(int screenOrientation) {
|
||||||
this.screenOrientation = screenOrientation;
|
this.screenOrientation = screenOrientation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.R;
|
||||||
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.dashboard.DashLocationFragment;
|
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
list = favouritesDbHelper.getVisibleFavouritePoints();
|
list = favouritesDbHelper.getVisibleFavouritePoints();
|
||||||
|
|
||||||
View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||||
R.layout.bottom_sheet_item_favourite_title, null);
|
R.layout.favourite_title_list_item, null);
|
||||||
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||||
R.layout.fragment_marker_add_group_bottom_sheet_dialog, null);
|
R.layout.fragment_marker_add_group_bottom_sheet_dialog, null);
|
||||||
|
|
||||||
|
@ -79,17 +80,16 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light));
|
nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light));
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
items.add(new TitleItem.Builder()
|
||||||
items.add(new BaseBottomSheetItem.Builder()
|
|
||||||
.setCustomView(titleView)
|
.setCustomView(titleView)
|
||||||
.create());
|
.create());
|
||||||
|
|
||||||
createAdapter();
|
adapter = new FavouritesAdapter(mapActivity, list);
|
||||||
adapter.setAdapterListener(new FavouritesAdapter.FavouritesAdapterListener() {
|
adapter.setAdapterListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(View view) {
|
public void onClick(View v) {
|
||||||
int position = recyclerView.getChildAdapterPosition(view);
|
int position = recyclerView.getChildAdapterPosition(v);
|
||||||
if (position == RecyclerView.NO_POSITION) {
|
if (position == RecyclerView.NO_POSITION) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -158,10 +158,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAdapter() {
|
|
||||||
adapter = new FavouritesAdapter(mapActivity, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
Loading…
Reference in a new issue