From 4e43dba7f43d279a76918afa3f2df4a6d70ee566 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 15 May 2020 14:34:40 +0300 Subject: [PATCH] Fix #8943 --- .../src/net/osmand/data/FavouritePoint.java | 20 +++++++++++++++---- .../net/osmand/plus/FavouritesDbHelper.java | 4 ++-- .../plus/base/FavoriteImageDrawable.java | 2 +- .../parkingpoint/ParkingPositionPlugin.java | 9 ++++++--- .../ParkingTypeBottomSheetDialogFragment.java | 7 ++++--- .../AddPointBottomSheetDialog.java | 2 +- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 95236d4815..29a852a1ea 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -8,7 +8,11 @@ import androidx.annotation.StringRes; import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings.BooleanPreference; +import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; +import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.util.Algorithms; import java.io.Serializable; @@ -97,7 +101,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public String getIconEntryName(Context ctx) { - return ctx.getResources().getResourceEntryName(getOverlayIconId()); + return ctx.getResources().getResourceEntryName(getOverlayIconId(ctx)); } public void setIconId(int iconId) { @@ -137,9 +141,9 @@ public class FavouritePoint implements Serializable, LocationPoint { this.originObjectName = originObjectName; } - public int getOverlayIconId() { + public int getOverlayIconId(Context ctx) { if (isSpecialPoint()) { - return specialPointType.getIconId(); + return specialPointType.getIconId(ctx); } return getIconId(); } @@ -284,7 +288,15 @@ public class FavouritePoint implements Serializable, LocationPoint { return typeName; } - public int getIconId() { + public int getIconId(@NonNull Context ctx) { + if (this == PARKING) { + OsmandApplication app = (OsmandApplication) ctx.getApplicationContext(); + OsmandPreference parkingType = app.getSettings().getPreference(ParkingPositionPlugin.PARKING_TYPE); + if (parkingType instanceof BooleanPreference && ((BooleanPreference) parkingType).get()) { + return R.drawable.mm_special_parking_time_limited; + } + return iconId; + } return iconId; } diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 3decf9e607..e87a8fbe6d 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -290,12 +290,12 @@ public class FavouritesDbHelper { public void setSpecialPoint(@NonNull LatLon latLon, FavouritePoint.SpecialPointType specialType, @Nullable String address) { FavouritePoint point = getSpecialPoint(specialType); if (point != null) { - point.setIconId(specialType.getIconId()); + point.setIconId(specialType.getIconId(context)); editFavourite(point, latLon.getLatitude(), latLon.getLongitude(), address); } else { point = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), specialType.getName(), specialType.getCategory()); point.setAddress(address); - point.setIconId(specialType.getIconId()); + point.setIconId(specialType.getIconId(context)); addFavourite(point); } } diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 5999468241..9336693734 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -48,7 +48,7 @@ public class FavoriteImageDrawable extends Drawable { this.synced = synced; Resources res = ctx.getResources(); UiUtilities uiUtilities = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities(); - int overlayIconId = point != null ? point.getOverlayIconId() : 0; + int overlayIconId = point != null ? point.getOverlayIconId(ctx) : 0; int uiIconId; if (overlayIconId != 0) { favIcon = uiUtilities.getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index 822c5819c5..8b38d111e5 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -18,6 +18,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentManager; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.SpecialPointType; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.ApplicationMode; @@ -285,7 +286,7 @@ public class ParkingPositionPlugin extends OsmandPlugin { showDeleteEventWarning(activity); cancelParking(); if (activity instanceof MapActivity) { - FavouritePoint pnt = app.getFavorites().getSpecialPoint(FavouritePoint.SpecialPointType.PARKING); + FavouritePoint pnt = app.getFavorites().getSpecialPoint(SpecialPointType.PARKING); if(pnt != null) { app.getFavorites().deleteFavourite(pnt); } @@ -305,7 +306,8 @@ public class ParkingPositionPlugin extends OsmandPlugin { * @param choose */ void showSetTimeLimitDialog(final MapActivity mapActivity, final DialogInterface choose) { - boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final OsmandApplication app = mapActivity.getMyApplication(); + boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); final View setTimeParking = UiUtilities.getInflater(mapActivity, nightMode).inflate(R.layout.parking_set_time_limit, null); AlertDialog.Builder setTime = new AlertDialog.Builder(mapActivity); setTime.setView(setTimeParking); @@ -370,7 +372,8 @@ public class ParkingPositionPlugin extends OsmandPlugin { } else { addOrRemoveParkingEvent(false); } - showContextMenuIfNeeded(mapActivity,false); + app.getFavorites().setSpecialPoint(getParkingPosition(), SpecialPointType.PARKING, null); + showContextMenuIfNeeded(mapActivity, false); } }); setTime.create(); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingTypeBottomSheetDialogFragment.java index 6c48241ec6..0c1ba98b9a 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingTypeBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingTypeBottomSheetDialogFragment.java @@ -4,7 +4,7 @@ import android.app.Dialog; import android.os.Bundle; import android.view.View; -import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.SpecialPointType; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -71,10 +71,11 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF plugin.addOrRemoveParkingEvent(false); plugin.setParkingPosition(latitude, longitude, false); plugin.showContextMenuIfNeeded(mapActivity, true); + + mapActivity.getMyApplication().getFavorites().setSpecialPoint( + plugin.getParkingPosition(), SpecialPointType.PARKING, null); mapActivity.refreshMap(); } - mapActivity.getMyApplication().getFavorites().setSpecialPoint( - plugin.getParkingPosition(), FavouritePoint.SpecialPointType.PARKING, null); } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 0eccdcfd09..e58892fa2d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -649,7 +649,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { int iconColor = app.getSettings().isLightContent() ? R.color.icon_color_default_light : R.color.icon_color_default_dark; favoriteViewHolder.icon.setImageDrawable(app.getUIUtilities().getIcon( - ((FavouritePoint) item).getSpecialPointType().getIconId(), iconColor)); + ((FavouritePoint) item).getSpecialPointType().getIconId(app), iconColor)); favoriteViewHolder.description.setText(point.getDescription()); } else { if (point.getCategory().equals("")) {