Fix pointName, get rid getHomePointLatLon getHomePointLatLon
This commit is contained in:
parent
fe9755b11f
commit
eaf6ae30fc
3 changed files with 29 additions and 53 deletions
|
@ -19,41 +19,47 @@ public class PersonalFavouritePoint extends FavouritePoint {
|
|||
WORK("work", R.string.work_button, 2),
|
||||
PARKING("parking", R.string.map_widget_parking, 3);
|
||||
|
||||
private String name;
|
||||
private String pointName;
|
||||
@StringRes
|
||||
private int resId;
|
||||
private int order;
|
||||
|
||||
PointType(String name, @StringRes int resId, int order) {
|
||||
this.name = name;
|
||||
PointType(String pointName, @StringRes int resId, int order) {
|
||||
this.pointName = pointName;
|
||||
this.resId = resId;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return pointName;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public static PointType valueOfPointName(@NonNull String typeName){
|
||||
|
||||
for (PointType pt:values()) {
|
||||
if(pt.pointName.equals(typeName))
|
||||
return pt;
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal PointType pointName");
|
||||
}
|
||||
|
||||
public String getHumanString(@NonNull Context ctx) {
|
||||
return ctx.getString(resId);
|
||||
}
|
||||
}
|
||||
|
||||
private PersonalFavouritePoint() {
|
||||
}
|
||||
|
||||
private PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) {
|
||||
super(latitude, longitude, type.name, PERSONAL);
|
||||
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) {
|
||||
super(latitude, longitude, type.pointName, PERSONAL);
|
||||
this.ctx = ctx;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull String typeName, double latitude, double longitude) throws IllegalArgumentException {
|
||||
this(ctx, PointType.valueOf(typeName), latitude, longitude);
|
||||
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull String pointName, double latitude, double longitude) throws IllegalArgumentException {
|
||||
this(ctx, PointType.valueOfPointName(pointName), latitude, longitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,11 +67,6 @@ public class PersonalFavouritePoint extends FavouritePoint {
|
|||
return new PointDescription(PointDescription.POINT_TYPE_LOCATION, getDescription());
|
||||
}
|
||||
|
||||
public PersonalFavouritePoint(PersonalFavouritePoint favouritePoint) {
|
||||
super(favouritePoint);
|
||||
this.type = favouritePoint.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPersonal() {
|
||||
return true;
|
||||
|
@ -99,7 +100,7 @@ public class PersonalFavouritePoint extends FavouritePoint {
|
|||
public WptPt toWpt() {
|
||||
WptPt pt = super.toWpt();
|
||||
pt.getExtensionsToWrite().put(PERSONAL, "true");
|
||||
pt.name = type.toString();
|
||||
pt.name = type.pointName;
|
||||
pt.desc = getDescription();
|
||||
return pt;
|
||||
}
|
||||
|
|
|
@ -128,15 +128,12 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
private boolean hasPersonalPoint(PersonalFavouritePoint.PointType pointType) {
|
||||
boolean hasPersonalPoint = false;
|
||||
for (FavouritePoint fp : cachedPersonalFavoritePoints) {
|
||||
if (fp instanceof PersonalFavouritePoint) {
|
||||
if (((PersonalFavouritePoint) fp).getType() == pointType) {
|
||||
hasPersonalPoint = true;
|
||||
}
|
||||
if (((PersonalFavouritePoint) fp).getType() == pointType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return hasPersonalPoint;
|
||||
return false;
|
||||
}
|
||||
|
||||
public FavouritePoint getWorkPoint() {
|
||||
|
@ -152,35 +149,12 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
private FavouritePoint getPersonalPoint(PersonalFavouritePoint.PointType pointType) {
|
||||
FavouritePoint personalPoint = null;
|
||||
for (FavouritePoint fp : cachedPersonalFavoritePoints) {
|
||||
if (fp instanceof PersonalFavouritePoint) {
|
||||
if (((PersonalFavouritePoint) fp).getType() == pointType) {
|
||||
personalPoint = fp;
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return personalPoint;
|
||||
}
|
||||
|
||||
public LatLon getWorkPointLatLon() {
|
||||
LatLon workPointLatLon;
|
||||
if (hasWorkPoint()) {
|
||||
workPointLatLon = new LatLon(getWorkPoint().getLatitude(), getWorkPoint().getLongitude());
|
||||
} else {
|
||||
workPointLatLon = null;
|
||||
}
|
||||
return workPointLatLon;
|
||||
}
|
||||
|
||||
public LatLon getHomePointLatLon() {
|
||||
LatLon homePointLatLon;
|
||||
if (hasHomePoint()) {
|
||||
homePointLatLon = new LatLon(getHomePoint().getLatitude(), getHomePoint().getLongitude());
|
||||
} else {
|
||||
homePointLatLon = null;
|
||||
}
|
||||
return homePointLatLon;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isFavoritesLoaded() {
|
||||
|
@ -283,7 +257,7 @@ public class FavouritesDbHelper {
|
|||
getHomePoint().setDescription(description.getName());
|
||||
editFavourite(getHomePoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME.toString(),
|
||||
FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME,
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedHomePoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedHomePoint);
|
||||
|
@ -297,7 +271,7 @@ public class FavouritesDbHelper {
|
|||
getWorkPoint().setDescription(description.getName());
|
||||
editFavourite(getWorkPoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK.toString(),
|
||||
FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK,
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedWorkPoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedWorkPoint);
|
||||
|
@ -311,7 +285,7 @@ public class FavouritesDbHelper {
|
|||
getParkingPoint().setDescription(description.getName());
|
||||
editFavourite(getParkingPoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING.toString(),
|
||||
FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING,
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedParkingPoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedParkingPoint);
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.view.View;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
|
@ -41,7 +42,7 @@ public class HomeWorkCard extends BaseCard {
|
|||
if (homePoint == null) {
|
||||
AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME);
|
||||
} else {
|
||||
targetPointsHelper.navigateToPoint(favorites.getHomePointLatLon(),
|
||||
targetPointsHelper.navigateToPoint(new LatLon(homePoint.getLatitude(), homePoint.getLongitude()),
|
||||
true, -1, homePoint.getPointDescription());
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ public class HomeWorkCard extends BaseCard {
|
|||
if (workPoint == null) {
|
||||
AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK);
|
||||
} else {
|
||||
targetPointsHelper.navigateToPoint(favorites.getWorkPointLatLon(),
|
||||
targetPointsHelper.navigateToPoint(new LatLon(workPoint.getLatitude(), workPoint.getLongitude()),
|
||||
true, -1, workPoint.getPointDescription());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue