Fix all remarks, fix block edit personal favorite points, add delete parking point when parking plugin is disabled

This commit is contained in:
Dima-1 2019-12-10 15:03:26 +02:00
parent eaf6ae30fc
commit 6e4b7d5464
18 changed files with 133 additions and 159 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.data; package net.osmand.data;
import android.content.Context; import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
@ -12,39 +13,46 @@ public class PersonalFavouritePoint extends FavouritePoint {
private Context ctx; private Context ctx;
private PointType type; private PointType type;
public static final String PERSONAL = "personal"; static final String PERSONAL = "personal";
public enum PointType { public enum PointType {
HOME("home", R.string.home_button, 1), HOME("home", R.string.home_button, 1, R.drawable.ic_action_home_dark),
WORK("work", R.string.work_button, 2), WORK("work", R.string.work_button, 2, R.drawable.ic_action_work),
PARKING("parking", R.string.map_widget_parking, 3); PARKING("parking", R.string.map_widget_parking, 3, R.drawable.ic_action_parking_dark);
private String pointName; private String typeName;
@StringRes @StringRes
private int resId; private int resId;
private int order; private int order;
@DrawableRes
private int iconID;
PointType(String pointName, @StringRes int resId, int order) { PointType(@NonNull String typeName, @StringRes int resId, int order, @DrawableRes int iconID) {
this.pointName = pointName; this.typeName = typeName;
this.resId = resId; this.resId = resId;
this.order = order; this.order = order;
this.iconID = iconID;
} }
public String getName() { public String getName() {
return pointName; return typeName;
} }
public int getOrder() { public int getOrder() {
return order; return order;
} }
public static PointType valueOfPointName(@NonNull String typeName){ public static PointType valueOfTypeName(@NonNull String typeName) {
for (PointType pt:values()) { for (PointType pt:values()) {
if(pt.pointName.equals(typeName)) if (pt.typeName.equals(typeName))
return pt; return pt;
} }
throw new IllegalArgumentException("Illegal PointType pointName"); throw new IllegalArgumentException("Illegal PointType typeName");
}
public int getIconID() {
return iconID;
} }
public String getHumanString(@NonNull Context ctx) { public String getHumanString(@NonNull Context ctx) {
@ -53,13 +61,13 @@ public class PersonalFavouritePoint extends FavouritePoint {
} }
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) { public PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) {
super(latitude, longitude, type.pointName, PERSONAL); super(latitude, longitude, type.typeName, PERSONAL);
this.ctx = ctx; this.ctx = ctx;
this.type = type; this.type = type;
} }
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull String pointName, double latitude, double longitude) throws IllegalArgumentException { PersonalFavouritePoint(@NonNull Context ctx, @NonNull String typeName, double latitude, double longitude) throws IllegalArgumentException {
this(ctx, PointType.valueOfPointName(pointName), latitude, longitude); this(ctx, PointType.valueOfTypeName(typeName), latitude, longitude);
} }
@Override @Override
@ -100,7 +108,7 @@ public class PersonalFavouritePoint extends FavouritePoint {
public WptPt toWpt() { public WptPt toWpt() {
WptPt pt = super.toWpt(); WptPt pt = super.toWpt();
pt.getExtensionsToWrite().put(PERSONAL, "true"); pt.getExtensionsToWrite().put(PERSONAL, "true");
pt.name = type.pointName; pt.name = type.typeName;
pt.desc = getDescription(); pt.desc = getDescription();
return pt; return pt;
} }

View file

@ -12,7 +12,6 @@ import net.osmand.data.LatLon;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.PersonalFavouritePoint; import net.osmand.data.PersonalFavouritePoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
@ -115,27 +114,6 @@ public class FavouritesDbHelper {
}); });
} }
public boolean hasWorkPoint() {
return hasPersonalPoint(WORK);
}
public boolean hasHomePoint() {
return hasPersonalPoint(HOME);
}
public boolean hasParkingPoint() {
return hasPersonalPoint(PARKING);
}
private boolean hasPersonalPoint(PersonalFavouritePoint.PointType pointType) {
for (FavouritePoint fp : cachedPersonalFavoritePoints) {
if (((PersonalFavouritePoint) fp).getType() == pointType) {
return true;
}
}
return false;
}
public FavouritePoint getWorkPoint() { public FavouritePoint getWorkPoint() {
return getPersonalPoint(WORK); return getPersonalPoint(WORK);
} }
@ -148,6 +126,10 @@ public class FavouritesDbHelper {
return getPersonalPoint(PARKING); return getPersonalPoint(PARKING);
} }
public void deleteParkingPoint() {
deleteFavourite(getParkingPoint());
}
private FavouritePoint getPersonalPoint(PersonalFavouritePoint.PointType pointType) { private FavouritePoint getPersonalPoint(PersonalFavouritePoint.PointType pointType) {
for (FavouritePoint fp : cachedPersonalFavoritePoints) { for (FavouritePoint fp : cachedPersonalFavoritePoints) {
if (((PersonalFavouritePoint) fp).getType() == pointType) { if (((PersonalFavouritePoint) fp).getType() == pointType) {
@ -245,6 +227,9 @@ public class FavouritesDbHelper {
runSyncWithMarkers(group); runSyncWithMarkers(group);
} }
cachedFavoritePoints.remove(p); cachedFavoritePoints.remove(p);
if (p.isPersonal()) {
cachedPersonalFavoritePoints.remove(p);
}
} }
if (saveImmediately) { if (saveImmediately) {
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
@ -252,49 +237,46 @@ public class FavouritesDbHelper {
return true; return true;
} }
public void setHomePoint(@NonNull LatLon latLon, @NonNull PointDescription description) { public void setHomePoint(@NonNull LatLon latLon) {
if (hasHomePoint()) { FavouritePoint homePoint = getHomePoint();
getHomePoint().setDescription(description.getName()); if (homePoint != null) {
editFavourite(getHomePoint(), latLon.getLatitude(), latLon.getLongitude()); editFavourite(homePoint, latLon.getLatitude(), latLon.getLongitude());
} else { } else {
FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME, FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME,
latLon.getLatitude(), latLon.getLongitude()); latLon.getLatitude(), latLon.getLongitude());
cachedHomePoint.setDescription(description.getName());
cachedPersonalFavoritePoints.add(cachedHomePoint);
addFavourite(cachedHomePoint); addFavourite(cachedHomePoint);
} }
lookupAllPersonalPointsAddresses(); lookupAddressAllPersonalPoints();
} }
public void setWorkPoint(@NonNull LatLon latLon, @NonNull PointDescription description) { public void setWorkPoint(@NonNull LatLon latLon) {
if (hasWorkPoint()) { FavouritePoint workPoint = getWorkPoint();
getWorkPoint().setDescription(description.getName()); if (workPoint != null) {
editFavourite(getWorkPoint(), latLon.getLatitude(), latLon.getLongitude()); editFavourite(workPoint, latLon.getLatitude(), latLon.getLongitude());
} else { } else {
FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK, FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK,
latLon.getLatitude(), latLon.getLongitude()); latLon.getLatitude(), latLon.getLongitude());
cachedWorkPoint.setDescription(description.getName());
cachedPersonalFavoritePoints.add(cachedWorkPoint);
addFavourite(cachedWorkPoint); addFavourite(cachedWorkPoint);
} }
lookupAllPersonalPointsAddresses(); lookupAddressAllPersonalPoints();
} }
public void setParkingPoint(@NonNull LatLon latLon, @NonNull PointDescription description) { public void setParkingPoint(@NonNull LatLon latLon) {
if (hasParkingPoint()) { FavouritePoint parkingPoint = getParkingPoint();
getParkingPoint().setDescription(description.getName()); if (parkingPoint != null) {
editFavourite(getParkingPoint(), latLon.getLatitude(), latLon.getLongitude()); editFavourite(parkingPoint, latLon.getLatitude(), latLon.getLongitude());
} else { } else {
FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING, FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING,
latLon.getLatitude(), latLon.getLongitude()); latLon.getLatitude(), latLon.getLongitude());
cachedParkingPoint.setDescription(description.getName());
cachedPersonalFavoritePoints.add(cachedParkingPoint);
addFavourite(cachedParkingPoint); addFavourite(cachedParkingPoint);
} }
lookupAllPersonalPointsAddresses(); lookupAddressAllPersonalPoints();
} }
public boolean addFavourite(FavouritePoint p) { public boolean addFavourite(FavouritePoint p) {
if (p instanceof PersonalFavouritePoint) {
cachedPersonalFavoritePoints.add(p);
}
return addFavourite(p, true); return addFavourite(p, true);
} }
@ -320,7 +302,7 @@ public class FavouritesDbHelper {
return true; return true;
} }
private void lookupAllPersonalPointsAddresses() { public void lookupAddressAllPersonalPoints() {
if (!context.isApplicationInitializing()) { if (!context.isApplicationInitializing()) {
lookupAddressForHomePoint(); lookupAddressForHomePoint();
lookupAddressForWorkPoint(); lookupAddressForWorkPoint();
@ -328,7 +310,7 @@ public class FavouritesDbHelper {
} }
} }
void lookupAddressForWorkPoint() { private void lookupAddressForWorkPoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint workPoint = getWorkPoint(); final FavouritePoint workPoint = getWorkPoint();
if (workPoint != null && (workPointRequest == null || if (workPoint != null && (workPointRequest == null ||
@ -338,6 +320,7 @@ public class FavouritesDbHelper {
new LatLon(workPoint.getLatitude(), workPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() { new LatLon(workPoint.getLatitude(), workPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
@Override @Override
public void geocodingDone(String address) { public void geocodingDone(String address) {
workPointRequest = null;
workPoint.setDescription(address); workPoint.setDescription(address);
targetPointsHelper.updateRouteAndRefresh(false); targetPointsHelper.updateRouteAndRefresh(false);
} }
@ -346,7 +329,7 @@ public class FavouritesDbHelper {
} }
} }
void lookupAddressForHomePoint() { private void lookupAddressForHomePoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint homePoint = getHomePoint(); final FavouritePoint homePoint = getHomePoint();
if (homePoint != null && (homePointRequest == null || if (homePoint != null && (homePointRequest == null ||
@ -365,7 +348,7 @@ public class FavouritesDbHelper {
} }
} }
void lookupAddressForParkingPoint() { private void lookupAddressForParkingPoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint parkingPoint = getParkingPoint(); final FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null && (parkingPointRequest == null || if (parkingPoint != null && (parkingPointRequest == null ||

View file

@ -262,10 +262,10 @@ public class OsmandSettings {
void migrateHomeWorkParkingToFavorites() { void migrateHomeWorkParkingToFavorites() {
FavouritesDbHelper favorites = ctx.getFavorites(); FavouritesDbHelper favorites = ctx.getFavorites();
if (getHomePoint() != null) { if (getHomePoint() != null) {
favorites.setHomePoint(getHomePoint(), getHomePointDescription()); favorites.setHomePoint(getHomePoint());
} }
if (getWorkPoint() != null) { if (getWorkPoint() != null) {
favorites.setWorkPoint(getWorkPoint(), getWorkPointDescription()); favorites.setWorkPoint(getWorkPoint());
} }
} }

View file

@ -150,15 +150,11 @@ public class TargetPointsHelper {
} }
public void lookupAddessAll() { public void lookupAddessAll() {
FavouritesDbHelper favorites = ctx.getFavorites();
lookupAddressForPointToNavigate(); lookupAddressForPointToNavigate();
lookupAddessForStartPoint(); lookupAddessForStartPoint();
for (TargetPoint targetPoint : intermediatePoints) { for (TargetPoint targetPoint : intermediatePoints) {
lookupAddressForIntermediatePoint(targetPoint); lookupAddressForIntermediatePoint(targetPoint);
} }
favorites.lookupAddressForHomePoint();
favorites.lookupAddressForWorkPoint();
favorites.lookupAddressForParkingPoint();
lookupAddressForMyLocationPoint(); lookupAddressForMyLocationPoint();
} }

View file

@ -45,7 +45,6 @@ import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
@ -54,7 +53,6 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesFragmentStateHolder; import net.osmand.plus.myplaces.FavoritesFragmentStateHolder;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -741,9 +739,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
Filter myFilter; Filter myFilter;
private Set<?> filter; private Set<?> filter;
public void synchronizeGroups() { void synchronizeGroups() {
ParkingPositionPlugin plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
boolean parkingPluginEnable = plugin != null;
favoriteGroups.clear(); favoriteGroups.clear();
groups.clear(); groups.clear();
List<FavoriteGroup> disablesGroups = new ArrayList<>(); List<FavoriteGroup> disablesGroups = new ArrayList<>();
@ -752,37 +748,14 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
for (FavoriteGroup key : gs) { for (FavoriteGroup key : gs) {
boolean empty = true; boolean empty = true;
if (flt == null || flt.contains(key)) { if (flt == null || flt.contains(key)) {
if (key.name.equals(PersonalFavouritePoint.PERSONAL)) {
ArrayList<FavouritePoint> list = new ArrayList<>();
for (FavouritePoint p : key.points) {
if (p.getName().equals(PersonalFavouritePoint.PointType.PARKING.name())) {
if (parkingPluginEnable) {
list.add(p);
empty = false;
}
} else {
list.add(p);
empty = false;
}
}
favoriteGroups.put(key, list);
} else {
empty = false; empty = false;
favoriteGroups.put(key, new ArrayList<>(key.points)); favoriteGroups.put(key, new ArrayList<>(key.points));
}
} else { } else {
ArrayList<FavouritePoint> list = new ArrayList<>(); ArrayList<FavouritePoint> list = new ArrayList<>();
for (FavouritePoint p : key.points) { for (FavouritePoint p : key.points) {
if (flt.contains(p)) { if (flt.contains(p)) {
if (p.getName().equals(PersonalFavouritePoint.PointType.PARKING.name())) { list.add(p);
if (parkingPluginEnable) { empty = false;
list.add(p);
empty = false;
}
} else {
list.add(p);
empty = false;
}
} }
} }
favoriteGroups.put(key, list); favoriteGroups.put(key, list);
@ -978,7 +951,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
distanceText.setText(distanceWithAddress); distanceText.setText(distanceWithAddress);
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
visible ? model.getColor() : getResources().getColor(disabledIconColor), false, visible ? model.getColor() : getResources().getColor(disabledIconColor), false,
((PersonalFavouritePoint) model).getType().getOrder() - 1)); ((PersonalFavouritePoint) model).getType()));
name.setText((model.getName())); name.setText((model.getName()));
} else { } else {
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),

View file

@ -425,6 +425,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (dashboardOnMap != null) { if (dashboardOnMap != null) {
dashboardOnMap.updateLocation(true, true, false); dashboardOnMap.updateLocation(true, true, false);
} }
app.getFavorites().lookupAddressAllPersonalPoints();
app.getTargetPointsHelper().lookupAddessAll(); app.getTargetPointsHelper().lookupAddessAll();
app.getMapMarkersHelper().lookupAddressAll(); app.getMapMarkersHelper().lookupAddressAll();
} }

View file

@ -18,7 +18,7 @@ import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat; import android.support.v4.content.res.ResourcesCompat;
import net.osmand.data.PersonalFavouritePoint; import net.osmand.data.PersonalFavouritePoint.PointType;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -26,10 +26,8 @@ import java.util.TreeMap;
public class FavoriteImageDrawable extends Drawable { public class FavoriteImageDrawable extends Drawable {
private static final int MAX_PERSONAL_POINT = PersonalFavouritePoint.PointType.values().length;
private boolean withShadow; private boolean withShadow;
private boolean synced; private boolean synced;
private int position;
private boolean history; private boolean history;
private Bitmap favIcon; private Bitmap favIcon;
private Bitmap favBackground; private Bitmap favBackground;
@ -44,20 +42,16 @@ public class FavoriteImageDrawable extends Drawable {
private Paint paintInnerCircle = new Paint(); private Paint paintInnerCircle = new Paint();
private ColorFilter colorFilter; private ColorFilter colorFilter;
private ColorFilter grayFilter; private ColorFilter grayFilter;
private Drawable[] personalPointBitmaps; private Drawable personalPointBitmaps;
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced) { public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced, PointType pointType) {
this.withShadow = withShadow; this.withShadow = withShadow;
this.synced = synced; this.synced = synced;
Resources res = ctx.getResources(); Resources res = ctx.getResources();
personalPointBitmaps = new Drawable[]{ if (pointType != null) {
UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, R.drawable.ic_action_home_dark, null), personalPointBitmaps = UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, pointType.getIconID(), null),
ContextCompat.getColor(ctx, R.color.icon_color_default_light)), ContextCompat.getColor(ctx, R.color.icon_color_default_light));
UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, R.drawable.ic_action_work, null), }
ContextCompat.getColor(ctx, R.color.icon_color_default_light)),
UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, R.drawable.ic_action_parking_dark, null),
ContextCompat.getColor(ctx, R.color.icon_color_default_light))
};
int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color;
favIcon = BitmapFactory.decodeResource(res, R.drawable.map_favorite); favIcon = BitmapFactory.decodeResource(res, R.drawable.map_favorite);
favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield);
@ -72,11 +66,6 @@ public class FavoriteImageDrawable extends Drawable {
grayFilter = new PorterDuffColorFilter(res.getColor(R.color.color_favorite_gray), PorterDuff.Mode.MULTIPLY); grayFilter = new PorterDuffColorFilter(res.getColor(R.color.color_favorite_gray), PorterDuff.Mode.MULTIPLY);
} }
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced, int position) {
this(ctx, color, withShadow, synced);
this.position = position;
}
private void initSimplePaint(Paint paint, int color) { private void initSimplePaint(Paint paint, int color) {
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setStyle(Style.FILL_AND_STROKE); paint.setStyle(Style.FILL_AND_STROKE);
@ -91,8 +80,8 @@ public class FavoriteImageDrawable extends Drawable {
//bs.inset((int) (4 * density), (int) (4 * density)); //bs.inset((int) (4 * density), (int) (4 * density));
bs.inset(bs.width() / 4, bs.height() / 4); bs.inset(bs.width() / 4, bs.height() / 4);
listDrawable.setBounds(bs); listDrawable.setBounds(bs);
for (Drawable drawable : personalPointBitmaps) { if (personalPointBitmaps != null) {
drawable.setBounds(bounds); personalPointBitmaps.setBounds(bounds);
} }
} }
} }
@ -119,8 +108,8 @@ public class FavoriteImageDrawable extends Drawable {
} else if (withShadow) { } else if (withShadow) {
canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground); canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground);
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon); canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
} else if (position < MAX_PERSONAL_POINT) { } else if (personalPointBitmaps != null) {
personalPointBitmaps[position].draw(canvas); personalPointBitmaps.draw(canvas);
} else { } else {
int min = Math.min(bs.width(), bs.height()); int min = Math.min(bs.width(), bs.height());
int r = (min * 4 / 10); int r = (min * 4 / 10);
@ -157,27 +146,30 @@ public class FavoriteImageDrawable extends Drawable {
private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>(); private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>();
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced, int position) { public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced, PointType pointType) {
int order = 0;
if (pointType != null)
order = pointType.getOrder();
color = color | 0xff000000; color = color | 0xff000000;
int hash = (color << 3) + (withShadow ? 1 : 0) + (synced ? 3 : 0) + (position + 4); int hash = (color << 4) + (withShadow ? 0b0100 : 0) + (synced ? 0b1100 : 0) + order;
FavoriteImageDrawable drawable = cache.get(hash); FavoriteImageDrawable drawable = cache.get(hash);
if (drawable == null) { if (drawable == null) {
drawable = new FavoriteImageDrawable(a, color, withShadow, synced, position); drawable = new FavoriteImageDrawable(a, color, withShadow, synced, pointType);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
cache.put(hash, drawable); cache.put(hash, drawable);
} }
return drawable; return drawable;
} }
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, int position) { public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, PointType pointType) {
return getOrCreate(a, color, withShadow, false, position); return getOrCreate(a, color, withShadow, false, pointType);
} }
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) { public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) {
return getOrCreate(a, color, withShadow, false, MAX_PERSONAL_POINT); return getOrCreate(a, color, withShadow, false, null);
} }
public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color) { public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color) {
return getOrCreate(a, color, false, true, MAX_PERSONAL_POINT); return getOrCreate(a, color, false, true, null);
} }
} }

View file

@ -871,6 +871,14 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return R.string.shared_string_add; return R.string.shared_string_add;
} }
boolean isFavButtonEnabled() {
MenuController menuController = getMenuController();
if (menuController != null) {
return menuController.isFavButtonEnabled();
}
return true;
}
public int getWaypointActionIconId() { public int getWaypointActionIconId() {
return waypointActionIconId; return waypointActionIconId;
} }

View file

@ -561,12 +561,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
R.color.ctx_menu_buttons_icon_color)); R.color.ctx_menu_buttons_icon_color));
((TextView) view.findViewById(R.id.context_menu_fav_text_view)).setText(menu.getFavActionStringId()); ((TextView) view.findViewById(R.id.context_menu_fav_text_view)).setText(menu.getFavActionStringId());
View favView = view.findViewById(R.id.context_menu_fav_view); View favView = view.findViewById(R.id.context_menu_fav_view);
favView.setOnClickListener(new View.OnClickListener() { if (menu.isFavButtonEnabled()) {
@Override favView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { @Override
menu.buttonFavoritePressed(); public void onClick(View v) {
} menu.buttonFavoritePressed();
}); }
});
} else {
deactivate(favView);
}
final ImageView imageWaypoint = (ImageView) view.findViewById(R.id.context_menu_route_image_view); final ImageView imageWaypoint = (ImageView) view.findViewById(R.id.context_menu_route_image_view);
imageWaypoint.setImageDrawable(getIcon(menu.getWaypointActionIconId(), imageWaypoint.setImageDrawable(getIcon(menu.getWaypointActionIconId(),

View file

@ -504,6 +504,10 @@ public abstract class MenuController extends BaseMenuController implements Colla
return R.string.shared_string_add; return R.string.shared_string_add;
} }
public boolean isFavButtonEnabled() {
return true;
}
public int getWaypointActionIconId() { public int getWaypointActionIconId() {
return R.drawable.map_action_flag_dark; return R.drawable.map_action_flag_dark;
} }

View file

@ -143,6 +143,11 @@ public class FavouritePointMenuController extends MenuController {
return R.string.shared_string_edit; return R.string.shared_string_edit;
} }
@Override
public boolean isFavButtonEnabled() {
return !fav.isPersonal();
}
@NonNull @NonNull
@Override @Override
public String getTypeStr() { public String getTypeStr() {

View file

@ -78,10 +78,8 @@ public class SelectCategoryDialogFragment extends DialogFragment {
if (gpxFile != null) { if (gpxFile != null) {
if (gpxCategories != null) { if (gpxCategories != null) {
for (Map.Entry<String, Integer> e : gpxCategories.entrySet()) { for (Map.Entry<String, Integer> e : gpxCategories.entrySet()) {
if (!e.getKey().equals(getContext().getString(R.string.personal_category_name))) { String categoryName = e.getKey();
String categoryName = e.getKey(); addCategory(activity, ll, categoryName, e.getValue());
addCategory(activity, ll, categoryName, e.getValue());
}
} }
} }
} else { } else {

View file

@ -155,10 +155,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription()); targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription());
break; break;
case HOME: case HOME:
favorites.setHomePoint(ll, point.getPointDescription()); favorites.setHomePoint(ll);
break; break;
case WORK: case WORK:
favorites.setWorkPoint(ll, point.getPointDescription()); favorites.setWorkPoint(ll);
break; break;
} }
MapRouteInfoMenu routeMenu = getMapRouteInfoMenu(); MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();

View file

@ -118,7 +118,13 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public long getStartParkingTime() { public long getStartParkingTime() {
return parkingStartTime.get(); return parkingStartTime.get();
} }
@Override
public void disable(OsmandApplication app) {
super.disable(app);
app.getFavorites().deleteParkingPoint();
}
public boolean clearParkingPosition() { public boolean clearParkingPosition() {
parkingLat.resetToDefault(); parkingLat.resetToDefault();
parkingLon.resetToDefault(); parkingLon.resetToDefault();
@ -292,6 +298,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
showDeleteEventWarning(activity); showDeleteEventWarning(activity);
cancelParking(); cancelParking();
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
app.getFavorites().deleteParkingPoint();
((MapActivity) activity).getContextMenu().close(); ((MapActivity) activity).getContextMenu().close();
} }
} }

View file

@ -4,8 +4,6 @@ import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import net.osmand.data.PersonalFavouritePoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -74,8 +72,7 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
plugin.showContextMenuIfNeeded(mapActivity, true); plugin.showContextMenuIfNeeded(mapActivity, true);
mapActivity.refreshMap(); mapActivity.refreshMap();
} }
mapActivity.getMyApplication().getFavorites().setParkingPoint(plugin.getParkingPosition(), mapActivity.getMyApplication().getFavorites().setParkingPoint(plugin.getParkingPosition());
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, PersonalFavouritePoint.PointType.PARKING.name()));
} }
dismiss(); dismiss();
} }

View file

@ -251,11 +251,11 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
break; break;
case HOME: case HOME:
app.showShortToastMessage(R.string.add_intermediate_point); app.showShortToastMessage(R.string.add_intermediate_point);
app.getFavorites().setHomePoint(ll, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); app.getFavorites().setHomePoint(ll);
break; break;
case WORK: case WORK:
app.showShortToastMessage(R.string.add_intermediate_point); app.showShortToastMessage(R.string.add_intermediate_point);
app.getFavorites().setWorkPoint(ll, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); app.getFavorites().setWorkPoint(ll);
break; break;
} }
} else if (pointType == PointType.START) { } else if (pointType == PointType.START) {
@ -369,13 +369,13 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private void addMainScrollItems(List<Object> items, FavouritesDbHelper favorites) { private void addMainScrollItems(List<Object> items, FavouritesDbHelper favorites) {
items.add(FAVORITES); items.add(FAVORITES);
if (favorites.hasHomePoint()) { if (favorites.getHomePoint() != null) {
items.add(PointType.HOME); items.add(PointType.HOME);
} }
if (favorites.hasWorkPoint()) { if (favorites.getWorkPoint() != null) {
items.add(PointType.WORK); items.add(PointType.WORK);
} }
if (favorites.hasParkingPoint()) { if (favorites.getParkingPoint() != null) {
items.add(PointType.PARKING); items.add(PointType.PARKING);
} }
} }
@ -647,7 +647,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
point = favorites.getParkingPoint(); point = favorites.getParkingPoint();
} }
favoriteViewHolder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), favoriteViewHolder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
getResources().getColor(disabledIconColor), false, (pointType.ordinal()))); getResources().getColor(disabledIconColor), false, pointType));
favoriteViewHolder.title.setText(point.getName()); favoriteViewHolder.title.setText(point.getName());
favoriteViewHolder.description.setText(point != null favoriteViewHolder.description.setText(point != null
? point.getPointDescription().getSimpleName(app, false) ? point.getPointDescription().getSimpleName(app, false)

View file

@ -275,10 +275,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size()); targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size());
break; break;
case HOME: case HOME:
favorites.setHomePoint(latlon, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); favorites.setHomePoint(latlon);
break; break;
case WORK: case WORK:
favorites.setWorkPoint(latlon, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); favorites.setWorkPoint(latlon);
break; break;
} }
if (selectFromMapWaypoints) { if (selectFromMapWaypoints) {
@ -1802,10 +1802,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(l, true, targets.getIntermediatePoints().size(), pd); targets.navigateToPoint(l, true, targets.getIntermediatePoints().size(), pd);
break; break;
case HOME: case HOME:
favorites.setHomePoint(l, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); favorites.setHomePoint(l);
break; break;
case WORK: case WORK:
favorites.setWorkPoint(l, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, "")); favorites.setWorkPoint(l);
break; break;
} }
updateMenu(); updateMenu();
@ -1862,10 +1862,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(point, true, targets.getIntermediatePoints().size(), m.getPointDescription(mapActivity)); targets.navigateToPoint(point, true, targets.getIntermediatePoints().size(), m.getPointDescription(mapActivity));
break; break;
case HOME: case HOME:
favorites.setHomePoint(point, m.getPointDescription(mapActivity)); favorites.setHomePoint(point);
break; break;
case WORK: case WORK:
favorites.setWorkPoint(point, m.getPointDescription(mapActivity)); favorites.setWorkPoint(point);
break; break;
} }
updateMenu(); updateMenu();

View file

@ -102,8 +102,6 @@ public class QuickSearchListItem {
case LOCATION: case LOCATION:
LatLon latLon = searchResult.location; LatLon latLon = searchResult.location;
return PointDescription.getLocationNamePlain(app, latLon.getLatitude(), latLon.getLongitude()); return PointDescription.getLocationNamePlain(app, latLon.getLatitude(), latLon.getLongitude());
case FAVORITE:
return ((FavouritePoint) searchResult.object).getName();
} }
return searchResult.localeName; return searchResult.localeName;
} }