Add displaying favourites from group
This commit is contained in:
parent
51b2434f83
commit
b3aa0d262a
4 changed files with 97 additions and 23 deletions
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/ctx_menu_controller_button_bg_color_dark_n" />
|
||||
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/ctx_menu_controller_button_outline_color_dark_p" />
|
||||
|
||||
<corners android:radius="3dp" />
|
||||
|
||||
</shape>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/ctx_menu_controller_button_bg_color_light_n" />
|
||||
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/ctx_menu_controller_button_outline_color_light_p" />
|
||||
|
||||
<corners android:radius="3dp" />
|
||||
|
||||
</shape>
|
|
@ -26,6 +26,7 @@ import android.widget.Toast;
|
|||
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
|
@ -681,6 +682,10 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
|
||||
return getCollapsableItemsView(context, collapsed, nearestWiki, null);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableItemsView(Context context, boolean collapsed, final List items, Object selectedObject) {
|
||||
final LinearLayout view = new LinearLayout(context);
|
||||
view.setOrientation(LinearLayout.VERTICAL);
|
||||
view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
|
||||
|
@ -698,31 +703,57 @@ public class MenuBuilder {
|
|||
context.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n)
|
||||
}
|
||||
);
|
||||
for (final Amenity wiki : nearestWiki) {
|
||||
TextViewEx wikiButton = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
|
||||
for (final Object item : items) {
|
||||
TextViewEx button = new TextViewEx(new ContextThemeWrapper(view.getContext(), light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme));
|
||||
LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.context_menu_controller_height));
|
||||
llWikiButtonParams.setMargins(0, 0, 0, dpToPx(8f));
|
||||
wikiButton.setLayoutParams(llWikiButtonParams);
|
||||
wikiButton.setTypeface(FontCache.getRobotoMedium(context));
|
||||
wikiButton.setBackgroundResource(light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark);
|
||||
int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x);
|
||||
wikiButton.setPadding(paddingSides, 0, paddingSides, 0);
|
||||
wikiButton.setTextColor(buttonColorStateList);
|
||||
wikiButton.setText(wiki.getName(preferredMapAppLang, transliterateNames));
|
||||
button.setLayoutParams(llWikiButtonParams);
|
||||
button.setTypeface(FontCache.getRobotoMedium(context));
|
||||
|
||||
wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
||||
wikiButton.setSingleLine(true);
|
||||
wikiButton.setEllipsize(TextUtils.TruncateAt.END);
|
||||
wikiButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki);
|
||||
mapActivity.getContextMenu().show(
|
||||
new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()),
|
||||
pointDescription, wiki);
|
||||
}
|
||||
});
|
||||
view.addView(wikiButton);
|
||||
boolean selected = selectedObject != null && selectedObject.equals(item);
|
||||
int bg;
|
||||
if (selected) {
|
||||
bg = light ? R.drawable.context_menu_controller_bg_light_selected: R.drawable.context_menu_controller_bg_dark_selected;
|
||||
} else {
|
||||
bg = light ? R.drawable.context_menu_controller_bg_light : R.drawable.context_menu_controller_bg_dark;
|
||||
}
|
||||
button.setBackgroundResource(bg);
|
||||
int paddingSides = (int) context.getResources().getDimension(R.dimen.context_menu_button_padding_x);
|
||||
button.setPadding(paddingSides, 0, paddingSides, 0);
|
||||
button.setTextColor(buttonColorStateList);
|
||||
String name = "";
|
||||
if (item instanceof Amenity) {
|
||||
name = ((Amenity) item).getName(preferredMapAppLang, transliterateNames);
|
||||
} else if (item instanceof FavouritePoint) {
|
||||
name = ((FavouritePoint) item).getName();
|
||||
}
|
||||
button.setText(name);
|
||||
|
||||
button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
||||
button.setSingleLine(true);
|
||||
button.setEllipsize(TextUtils.TruncateAt.END);
|
||||
if (!selected) {
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LatLon latLon = null;
|
||||
PointDescription pointDescription = null;
|
||||
if (item instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) item;
|
||||
latLon = new LatLon(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude());
|
||||
pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(amenity);
|
||||
} else if (item instanceof FavouritePoint) {
|
||||
FavouritePoint fav = (FavouritePoint) item;
|
||||
latLon = new LatLon(fav.getLatitude(), fav.getLongitude());
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, fav.getName());
|
||||
}
|
||||
if (latLon != null && pointDescription != null) {
|
||||
mapActivity.getContextMenu().show(latLon, pointDescription, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
view.addView(button);
|
||||
}
|
||||
|
||||
return new CollapsableView(view, collapsed);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapcontextmenu.builders;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -9,10 +10,11 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.TransportStop;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -60,6 +62,21 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
builder.setLight(light);
|
||||
builder.buildInternal(view);
|
||||
}
|
||||
buildGroupFavsView(view);
|
||||
}
|
||||
|
||||
private void buildGroupFavsView(View view) {
|
||||
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
|
||||
List<FavouritePoint> groupFavs = favoriteGroup.points;
|
||||
if (groupFavs.size() > 0) {
|
||||
int color = favoriteGroup.color == 0 || favoriteGroup.color == Color.BLACK ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.color;
|
||||
int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark;
|
||||
color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor);
|
||||
String name = Algorithms.isEmpty(favoriteGroup.name) ? view.getResources().getString(R.string.shared_string_favorites) : favoriteGroup.name;
|
||||
buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), name, 0,
|
||||
true, getCollapsableItemsView(view.getContext(), true, groupFavs, fav),
|
||||
false, 0, false, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Amenity findAmenity(String nameStringEn, double lat, double lon) {
|
||||
|
|
Loading…
Reference in a new issue