This commit is contained in:
Vitaliy 2020-05-15 14:34:40 +03:00
parent bfaa204404
commit 4e43dba7f4
6 changed files with 30 additions and 14 deletions

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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();

View file

@ -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();
}

View file

@ -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("")) {