Migrating from TargetPoint to PersonalFavoritePoint
This commit is contained in:
parent
9a316c5f8a
commit
3fef243a85
16 changed files with 453 additions and 201 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="distance_and_address">%1$s• %2$s</string>
|
||||
<string name="personal_category_name">Personal</string>
|
||||
<string name="add_new_profile_q">Add new profile \'%1$s\'?</string>
|
||||
<string name="save_heading">Include heading</string>
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.io.Serializable;
|
|||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
|
||||
public class FavouritePoint implements Serializable, LocationPoint {
|
||||
|
@ -51,7 +50,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
}
|
||||
|
||||
public PointDescription getPointDescription() {
|
||||
return new PointDescription(PointDescription.POINT_TYPE_FAVORITE, name);
|
||||
return new PointDescription(PointDescription.POINT_TYPE_FAVORITE, getName());
|
||||
}
|
||||
|
||||
public boolean isPersonal() {
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
|
@ -57,6 +56,11 @@ public class PersonalFavouritePoint extends FavouritePoint {
|
|||
this(ctx, PointType.valueOf(typeName), latitude, longitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointDescription getPointDescription() {
|
||||
return new PointDescription(PointDescription.POINT_TYPE_LOCATION, getDescription());
|
||||
}
|
||||
|
||||
public PersonalFavouritePoint(PersonalFavouritePoint favouritePoint) {
|
||||
super(favouritePoint);
|
||||
this.type = favouritePoint.type;
|
||||
|
@ -95,7 +99,7 @@ public class PersonalFavouritePoint extends FavouritePoint {
|
|||
public WptPt toWpt() {
|
||||
WptPt pt = super.toWpt();
|
||||
pt.getExtensionsToWrite().put(PERSONAL, "true");
|
||||
pt.name = type.name;
|
||||
pt.name = type.toString();
|
||||
pt.desc = getDescription();
|
||||
return pt;
|
||||
}
|
||||
|
|
|
@ -196,6 +196,10 @@ public class AppInitializer implements IProgress {
|
|||
app.getSettings().migratePreferences();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")) {
|
||||
app.getSettings().migrateHomeWorkParkingToFavorites();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
||||
}
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
appVersionChanged = true;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.data.PersonalFavouritePoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
|
@ -32,8 +33,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.data.PersonalFavouritePoint.PointType.HOME;
|
||||
import static net.osmand.data.PersonalFavouritePoint.PointType.PARKING;
|
||||
import static net.osmand.data.PersonalFavouritePoint.PointType.WORK;
|
||||
|
||||
public class FavouritesDbHelper {
|
||||
|
||||
private GeocodingLookupService.AddressLookupRequest workPointRequest;
|
||||
private GeocodingLookupService.AddressLookupRequest homePointRequest;
|
||||
private GeocodingLookupService.AddressLookupRequest parkingPointRequest;
|
||||
|
||||
public interface FavoritesListener {
|
||||
void onFavoritesLoaded();
|
||||
}
|
||||
|
@ -106,6 +115,74 @@ 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) {
|
||||
boolean hasPersonalPoint = false;
|
||||
for (FavouritePoint fp : cachedPersonalFavoritePoints) {
|
||||
if (fp instanceof PersonalFavouritePoint) {
|
||||
if (((PersonalFavouritePoint) fp).getType() == pointType) {
|
||||
hasPersonalPoint = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasPersonalPoint;
|
||||
}
|
||||
|
||||
public FavouritePoint getWorkPoint() {
|
||||
return getPersonalPoint(WORK);
|
||||
}
|
||||
|
||||
public FavouritePoint getHomePoint() {
|
||||
return getPersonalPoint(HOME);
|
||||
}
|
||||
|
||||
public FavouritePoint getParkingPoint() {
|
||||
return getPersonalPoint(PARKING);
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
public boolean isFavoritesLoaded() {
|
||||
return favoritesLoaded;
|
||||
}
|
||||
|
@ -201,6 +278,48 @@ public class FavouritesDbHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void setHomePoint(@NonNull LatLon latLon, @NonNull PointDescription description) {
|
||||
if (hasHomePoint()) {
|
||||
getHomePoint().setDescription(description.getName());
|
||||
editFavourite(getHomePoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME.toString(),
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedHomePoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedHomePoint);
|
||||
addFavourite(cachedHomePoint);
|
||||
}
|
||||
lookupAllPersonalPointsAddresses();
|
||||
}
|
||||
|
||||
public void setWorkPoint(@NonNull LatLon latLon, @NonNull PointDescription description) {
|
||||
if (hasWorkPoint()) {
|
||||
getWorkPoint().setDescription(description.getName());
|
||||
editFavourite(getWorkPoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK.toString(),
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedWorkPoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedWorkPoint);
|
||||
addFavourite(cachedWorkPoint);
|
||||
}
|
||||
lookupAllPersonalPointsAddresses();
|
||||
}
|
||||
|
||||
public void setParkingPoint(@NonNull LatLon latLon, @NonNull PointDescription description) {
|
||||
if (hasParkingPoint()) {
|
||||
getParkingPoint().setDescription(description.getName());
|
||||
editFavourite(getParkingPoint(), latLon.getLatitude(), latLon.getLongitude());
|
||||
} else {
|
||||
FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING.toString(),
|
||||
latLon.getLatitude(), latLon.getLongitude());
|
||||
cachedParkingPoint.setDescription(description.getName());
|
||||
cachedPersonalFavoritePoints.add(cachedParkingPoint);
|
||||
addFavourite(cachedParkingPoint);
|
||||
}
|
||||
lookupAllPersonalPointsAddresses();
|
||||
}
|
||||
|
||||
public boolean addFavourite(FavouritePoint p) {
|
||||
return addFavourite(p, true);
|
||||
}
|
||||
|
@ -227,6 +346,91 @@ public class FavouritesDbHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void lookupAllPersonalPointsAddresses() {
|
||||
if (!context.isApplicationInitializing()) {
|
||||
lookupAddressForHomePoint();
|
||||
lookupAddressForWorkPoint();
|
||||
lookupAddressForParkingPoint();
|
||||
}
|
||||
}
|
||||
|
||||
void lookupAddressForWorkPoint() {
|
||||
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
|
||||
final FavouritePoint workPoint = getWorkPoint();
|
||||
if (workPoint != null && (workPointRequest == null ||
|
||||
!workPointRequest.getLatLon().equals(new LatLon(workPoint.getLatitude(), workPoint.getLongitude())))) {
|
||||
cancelWorkPointAddressRequest();
|
||||
workPointRequest = new GeocodingLookupService.AddressLookupRequest(
|
||||
new LatLon(workPoint.getLatitude(), workPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
workPoint.setDescription(address);
|
||||
targetPointsHelper.updateRouteAndRefresh(false);
|
||||
}
|
||||
}, null);
|
||||
context.getGeocodingLookupService().lookupAddress(workPointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
void lookupAddressForHomePoint() {
|
||||
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
|
||||
final FavouritePoint homePoint = getHomePoint();
|
||||
if (homePoint != null && (homePointRequest == null ||
|
||||
!homePointRequest.getLatLon().equals(new LatLon(homePoint.getLatitude(), homePoint.getLongitude())))) {
|
||||
cancelHomePointAddressRequest();
|
||||
homePointRequest = new GeocodingLookupService.AddressLookupRequest(
|
||||
new LatLon(homePoint.getLatitude(), homePoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
homePointRequest = null;
|
||||
homePoint.setDescription(address);
|
||||
targetPointsHelper.updateRouteAndRefresh(false);
|
||||
}
|
||||
}, null);
|
||||
context.getGeocodingLookupService().lookupAddress(homePointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
void lookupAddressForParkingPoint() {
|
||||
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
|
||||
final FavouritePoint parkingPoint = getParkingPoint();
|
||||
if (parkingPoint != null && (parkingPointRequest == null ||
|
||||
!parkingPointRequest.getLatLon().equals(new LatLon(parkingPoint.getLatitude(), parkingPoint.getLongitude())))) {
|
||||
cancelParkingPointAddressRequest();
|
||||
parkingPointRequest = new GeocodingLookupService.AddressLookupRequest(
|
||||
new LatLon(parkingPoint.getLatitude(), parkingPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
parkingPointRequest = null;
|
||||
parkingPoint.setDescription(address);
|
||||
targetPointsHelper.updateRouteAndRefresh(false);
|
||||
}
|
||||
}, null);
|
||||
context.getGeocodingLookupService().lookupAddress(parkingPointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelHomePointAddressRequest() {
|
||||
if (homePointRequest != null) {
|
||||
context.getGeocodingLookupService().cancel(homePointRequest);
|
||||
homePointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelParkingPointAddressRequest() {
|
||||
if (parkingPointRequest != null) {
|
||||
context.getGeocodingLookupService().cancel(parkingPointRequest);
|
||||
parkingPointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelWorkPointAddressRequest() {
|
||||
if (workPointRequest != null) {
|
||||
context.getGeocodingLookupService().cancel(workPointRequest);
|
||||
workPointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder checkDuplicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) {
|
||||
boolean emoticons = false;
|
||||
String index = "";
|
||||
|
@ -476,6 +680,26 @@ public class FavouritesDbHelper {
|
|||
return fp;
|
||||
}
|
||||
|
||||
public List<FavouritePoint> getNonPersonalVisibleFavouritePoints() {
|
||||
List<FavouritePoint> fp = new ArrayList<>();
|
||||
for (FavouritePoint p : getNonPersonalFavouritePoints()) {
|
||||
if (p.isVisible()) {
|
||||
fp.add(p);
|
||||
}
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
public List<FavouritePoint> getNonPersonalFavouritePoints() {
|
||||
List<FavouritePoint> fp = new ArrayList<>();
|
||||
for (FavouritePoint p : cachedFavoritePoints) {
|
||||
if (!p.isPersonal()) {
|
||||
fp.add(p);
|
||||
}
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FavouritePoint getVisibleFavByLatLon(@NonNull LatLon latLon) {
|
||||
for (FavouritePoint fav : cachedFavoritePoints) {
|
||||
|
@ -550,7 +774,7 @@ public class FavouritesDbHelper {
|
|||
|
||||
@Override
|
||||
public int compare(FavoriteGroup lhs, FavoriteGroup rhs) {
|
||||
return collator.compare(lhs.name, rhs.name);
|
||||
return lhs.personal ? -1 : rhs.personal ? 1 : collator.compare(lhs.name, rhs.name);
|
||||
}
|
||||
});
|
||||
Comparator<FavouritePoint> favoritesComparator = getComparator();
|
||||
|
|
|
@ -259,6 +259,16 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
void migrateHomeWorkParkingToFavorites() {
|
||||
FavouritesDbHelper favorites = ctx.getFavorites();
|
||||
if (getHomePoint() != null) {
|
||||
favorites.setHomePoint(getHomePoint(), getHomePointDescription());
|
||||
}
|
||||
if (getWorkPoint() != null) {
|
||||
favorites.setWorkPoint(getWorkPoint(), getWorkPointDescription());
|
||||
}
|
||||
}
|
||||
|
||||
public Object getProfilePreferences(ApplicationMode mode) {
|
||||
return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode));
|
||||
}
|
||||
|
@ -2361,6 +2371,12 @@ public class OsmandSettings {
|
|||
edit.commit();
|
||||
objectToShow = toShow;
|
||||
if (addToHistory) {
|
||||
if (pointDescription.isFavorite()) {
|
||||
// int localeNameID = PersonalFavouritePoint.PersonalPoint.getLocalName(pointDescription.getName());
|
||||
// if (localeNameID != 0) {
|
||||
// pointDescription.setName(ctx.getString(localeNameID));
|
||||
// }
|
||||
}
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, pointDescription);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,15 +31,12 @@ public class TargetPointsHelper {
|
|||
private List<StateChangedListener<Void>> listeners = new ArrayList<>();
|
||||
private List<TargetPointChangedListener> pointListeners = new ArrayList<>();
|
||||
private OsmandApplication ctx;
|
||||
private TargetPoint homePoint = null;
|
||||
private TargetPoint workPoint = null;
|
||||
|
||||
private AddressLookupRequest startPointRequest;
|
||||
private AddressLookupRequest targetPointRequest;
|
||||
private AddressLookupRequest homePointRequest;
|
||||
private AddressLookupRequest workPointRequest;
|
||||
private AddressLookupRequest myLocationPointRequest;
|
||||
|
||||
|
||||
public interface TargetPointChangedListener {
|
||||
void onTargetPointChanged(TargetPoint targetPoint);
|
||||
}
|
||||
|
@ -153,13 +150,15 @@ public class TargetPointsHelper {
|
|||
}
|
||||
|
||||
public void lookupAddessAll() {
|
||||
FavouritesDbHelper favorites = ctx.getFavorites();
|
||||
lookupAddressForPointToNavigate();
|
||||
lookupAddessForStartPoint();
|
||||
for (TargetPoint targetPoint : intermediatePoints) {
|
||||
lookupAddressForIntermediatePoint(targetPoint);
|
||||
}
|
||||
lookupAddressForHomePoint();
|
||||
lookupAddressForWorkPoint();
|
||||
favorites.lookupAddressForHomePoint();
|
||||
favorites.lookupAddressForWorkPoint();
|
||||
favorites.lookupAddressForParkingPoint();
|
||||
lookupAddressForMyLocationPoint();
|
||||
}
|
||||
|
||||
|
@ -177,25 +176,11 @@ public class TargetPointsHelper {
|
|||
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), i);
|
||||
intermediatePoints.add(targetPoint);
|
||||
}
|
||||
homePoint = settings.getHomePoint() != null ?
|
||||
TargetPoint.create(settings.getHomePoint(), settings.getHomePointDescription()) : null;
|
||||
workPoint = settings.getWorkPoint() != null ?
|
||||
TargetPoint.create(settings.getWorkPoint(), settings.getWorkPointDescription()) : null;
|
||||
|
||||
if (!ctx.isApplicationInitializing()) {
|
||||
lookupAddessAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void readHomeWorkFromSettings() {
|
||||
homePoint = TargetPoint.create(settings.getHomePoint(), settings.getHomePointDescription());
|
||||
workPoint = TargetPoint.create(settings.getWorkPoint(), settings.getWorkPointDescription());
|
||||
if (!ctx.isApplicationInitializing()) {
|
||||
lookupAddressForHomePoint();
|
||||
lookupAddressForWorkPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private void readMyLocationPointFromSettings() {
|
||||
myLocationToStart = TargetPoint.create(settings.getMyLocationToStart(), settings.getMyLocationToStartDescription());
|
||||
if (!ctx.isApplicationInitializing()) {
|
||||
|
@ -267,52 +252,10 @@ public class TargetPointsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void lookupAddressForHomePoint() {
|
||||
if (homePoint != null && homePoint.isSearchingAddress(ctx)
|
||||
&& (homePointRequest == null || !homePointRequest.getLatLon().equals(homePoint.point))) {
|
||||
cancelHomePointAddressRequest();
|
||||
homePointRequest = new AddressLookupRequest(homePoint.point, new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
homePointRequest = null;
|
||||
if (homePoint != null) {
|
||||
homePoint.pointDescription.setName(address);
|
||||
settings.setHomePoint(homePoint.point.getLatitude(), homePoint.point.getLongitude(),
|
||||
homePoint.pointDescription);
|
||||
updateRouteAndRefresh(false);
|
||||
updateTargetPoint(homePoint);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
ctx.getGeocodingLookupService().lookupAddress(homePointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private void lookupAddressForWorkPoint() {
|
||||
if (workPoint != null && workPoint.isSearchingAddress(ctx)
|
||||
&& (workPointRequest == null || !workPointRequest.getLatLon().equals(workPoint.point))) {
|
||||
cancelWorkPointAddressRequest();
|
||||
workPointRequest = new AddressLookupRequest(workPoint.point, new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
workPointRequest = null;
|
||||
if (workPoint != null) {
|
||||
workPoint.pointDescription.setName(address);
|
||||
settings.setWorkPoint(workPoint.point.getLatitude(), workPoint.point.getLongitude(),
|
||||
workPoint.pointDescription);
|
||||
updateRouteAndRefresh(false);
|
||||
updateTargetPoint(workPoint);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
ctx.getGeocodingLookupService().lookupAddress(workPointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private void lookupAddressForMyLocationPoint() {
|
||||
if (myLocationToStart != null && myLocationToStart.isSearchingAddress(ctx)
|
||||
&& (myLocationPointRequest == null || !myLocationPointRequest.getLatLon().equals(myLocationToStart.point))) {
|
||||
cancelWorkPointAddressRequest();
|
||||
cancelMyLocationPointAddressRequest();
|
||||
myLocationPointRequest = new AddressLookupRequest(myLocationToStart.point, new GeocodingLookupService.OnAddressLookupResult() {
|
||||
@Override
|
||||
public void geocodingDone(String address) {
|
||||
|
@ -350,46 +293,6 @@ public class TargetPointsHelper {
|
|||
return myLocationToStart;
|
||||
}
|
||||
|
||||
public PointDescription getStartPointDescription(){
|
||||
return settings.getStartPointDescription();
|
||||
}
|
||||
|
||||
public TargetPoint getHomePoint() {
|
||||
return homePoint;
|
||||
}
|
||||
|
||||
public TargetPoint getWorkPoint() {
|
||||
return workPoint;
|
||||
}
|
||||
|
||||
public void setHomePoint(LatLon latLon, PointDescription name) {
|
||||
final PointDescription pointDescription;
|
||||
if (name == null) {
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
|
||||
} else {
|
||||
pointDescription = name;
|
||||
}
|
||||
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
|
||||
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
|
||||
}
|
||||
settings.setHomePoint(latLon.getLatitude(), latLon.getLongitude(), pointDescription);
|
||||
readHomeWorkFromSettings();
|
||||
}
|
||||
|
||||
public void setWorkPoint(LatLon latLon, PointDescription name) {
|
||||
final PointDescription pointDescription;
|
||||
if (name == null) {
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
|
||||
} else {
|
||||
pointDescription = name;
|
||||
}
|
||||
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
|
||||
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
|
||||
}
|
||||
settings.setWorkPoint(latLon.getLatitude(), latLon.getLongitude(), pointDescription);
|
||||
readHomeWorkFromSettings();
|
||||
}
|
||||
|
||||
public List<TargetPoint> getIntermediatePoints() {
|
||||
return intermediatePoints;
|
||||
}
|
||||
|
@ -764,6 +667,13 @@ public class TargetPointsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void cancelMyLocationPointAddressRequest() {
|
||||
if (startPointRequest != null) {
|
||||
ctx.getGeocodingLookupService().cancel(startPointRequest);
|
||||
startPointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelTargetPointAddressRequest() {
|
||||
if (targetPointRequest != null) {
|
||||
ctx.getGeocodingLookupService().cancel(targetPointRequest);
|
||||
|
@ -771,20 +681,6 @@ public class TargetPointsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void cancelHomePointAddressRequest() {
|
||||
if (homePointRequest != null) {
|
||||
ctx.getGeocodingLookupService().cancel(homePointRequest);
|
||||
homePointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelWorkPointAddressRequest() {
|
||||
if (workPointRequest != null) {
|
||||
ctx.getGeocodingLookupService().cancel(workPointRequest);
|
||||
workPointRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAllIntermediatePointsAddressRequests() {
|
||||
List<LatLon> intermediatePointsLatLon = getIntermediatePointsLatLon();
|
||||
for (LatLon latLon : intermediatePointsLatLon) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.widget.Toast;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PersonalFavouritePoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
|
@ -44,6 +45,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
|
|||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -52,6 +54,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.myplaces.FavoritesFragmentStateHolder;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
|
@ -739,6 +742,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
private Set<?> filter;
|
||||
|
||||
public void synchronizeGroups() {
|
||||
ParkingPositionPlugin plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
|
||||
boolean parkingPluginEnable = plugin != null;
|
||||
favoriteGroups.clear();
|
||||
groups.clear();
|
||||
List<FavoriteGroup> disablesGroups = new ArrayList<>();
|
||||
|
@ -747,14 +752,37 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
for (FavoriteGroup key : gs) {
|
||||
boolean empty = true;
|
||||
if (flt == null || flt.contains(key)) {
|
||||
empty = false;
|
||||
favoriteGroups.put(key, new ArrayList<>(key.points));
|
||||
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;
|
||||
favoriteGroups.put(key, new ArrayList<>(key.points));
|
||||
}
|
||||
} else {
|
||||
ArrayList<FavouritePoint> list = new ArrayList<>();
|
||||
for (FavouritePoint p : key.points) {
|
||||
if (flt.contains(p)) {
|
||||
list.add(p);
|
||||
empty = false;
|
||||
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);
|
||||
|
@ -829,9 +857,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
int disabledColor = light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark;
|
||||
row.findViewById(R.id.group_divider).setVisibility(groupPosition == 0 ? View.GONE : View.VISIBLE);
|
||||
int color = model.color == 0 || model.color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : model.color;
|
||||
setCategoryIcon(app, app.getUIUtilities().getPaintedIcon(
|
||||
R.drawable.ic_action_fav_dark, visible ? (color | 0xff000000) : getResources().getColor(disabledColor)),
|
||||
groupPosition, isExpanded, row, light);
|
||||
if (!model.personal) {
|
||||
setCategoryIcon(app, app.getUIUtilities().getPaintedIcon(
|
||||
R.drawable.ic_action_fav_dark, visible ? (color | 0xff000000) : getResources().getColor(disabledColor)),
|
||||
groupPosition, isExpanded, row, light);
|
||||
}
|
||||
adjustIndicator(app, groupPosition, isExpanded, row, light);
|
||||
TextView label = (TextView) row.findViewById(R.id.category_name);
|
||||
label.setTextColor(getResources().getColor(visible ? enabledColor : disabledColor));
|
||||
|
@ -879,16 +909,18 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
}
|
||||
final View ch = row.findViewById(R.id.options);
|
||||
if (!selectionMode) {
|
||||
((ImageView) ch).setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setContentDescription(getString(R.string.shared_string_settings));
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditFavoriteGroupDialogFragment.showInstance(getChildFragmentManager(), model.name);
|
||||
}
|
||||
if (!model.personal) {
|
||||
((ImageView) ch).setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setContentDescription(getString(R.string.shared_string_settings));
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditFavoriteGroupDialogFragment.showInstance(getChildFragmentManager(), model.name);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ch.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -933,8 +965,6 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
}
|
||||
});
|
||||
}
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
|
||||
visible ? model.getColor() : getResources().getColor(disabledIconColor), false));
|
||||
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
|
||||
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(),
|
||||
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
|
||||
|
@ -943,6 +973,17 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
|
|||
name.setTypeface(Typeface.DEFAULT, visible ? Typeface.NORMAL : Typeface.ITALIC);
|
||||
name.setTextColor(getResources().getColor(visible ? enabledColor : disabledColor));
|
||||
distanceText.setText(distance);
|
||||
if (model instanceof PersonalFavouritePoint) {
|
||||
String distanceWithAddress = String.format(getString(R.string.distance_and_address), distance, model.getDescription() != null ? model.getDescription() : "");
|
||||
distanceText.setText(distanceWithAddress);
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
|
||||
visible ? model.getColor() : getResources().getColor(disabledIconColor), false,
|
||||
((PersonalFavouritePoint) model).getType().getOrder() - 1));
|
||||
name.setText((model.getName()));
|
||||
} else {
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
|
||||
visible ? model.getColor() : getResources().getColor(disabledIconColor), false));
|
||||
}
|
||||
if (visible) {
|
||||
distanceText.setTextColor(getResources().getColor(R.color.color_distance));
|
||||
} else {
|
||||
|
|
|
@ -9,21 +9,27 @@ import android.graphics.Color;
|
|||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
|
||||
import net.osmand.data.PersonalFavouritePoint;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class FavoriteImageDrawable extends Drawable {
|
||||
|
||||
private static final int MAX_PERSONAL_POINT = PersonalFavouritePoint.PointType.values().length;
|
||||
private boolean withShadow;
|
||||
private boolean synced;
|
||||
private int position;
|
||||
private boolean history;
|
||||
private Bitmap favIcon;
|
||||
private Bitmap favBackground;
|
||||
|
@ -38,11 +44,20 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
private Paint paintInnerCircle = new Paint();
|
||||
private ColorFilter colorFilter;
|
||||
private ColorFilter grayFilter;
|
||||
private Drawable[] personalPointBitmaps;
|
||||
|
||||
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced) {
|
||||
this.withShadow = withShadow;
|
||||
this.synced = synced;
|
||||
Resources res = ctx.getResources();
|
||||
personalPointBitmaps = new Drawable[]{
|
||||
UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, R.drawable.ic_action_home_dark, null),
|
||||
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;
|
||||
favIcon = BitmapFactory.decodeResource(res, R.drawable.map_favorite);
|
||||
favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield);
|
||||
|
@ -57,6 +72,11 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
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) {
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(Style.FILL_AND_STROKE);
|
||||
|
@ -71,6 +91,9 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
//bs.inset((int) (4 * density), (int) (4 * density));
|
||||
bs.inset(bs.width() / 4, bs.height() / 4);
|
||||
listDrawable.setBounds(bs);
|
||||
for (Drawable drawable : personalPointBitmaps) {
|
||||
drawable.setBounds(bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,6 +119,8 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
} else if (withShadow) {
|
||||
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);
|
||||
} else if (position < MAX_PERSONAL_POINT) {
|
||||
personalPointBitmaps[position].draw(canvas);
|
||||
} else {
|
||||
int min = Math.min(bs.width(), bs.height());
|
||||
int r = (min * 4 / 10);
|
||||
|
@ -117,7 +142,7 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return 0;
|
||||
return PixelFormat.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,23 +157,27 @@ public class FavoriteImageDrawable extends Drawable {
|
|||
|
||||
private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>();
|
||||
|
||||
private static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced) {
|
||||
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced, int position) {
|
||||
color = color | 0xff000000;
|
||||
int hash = (color << 2) + (withShadow ? 1 : 0) + (synced ? 3 : 0);
|
||||
int hash = (color << 3) + (withShadow ? 1 : 0) + (synced ? 3 : 0) + (position + 4);
|
||||
FavoriteImageDrawable drawable = cache.get(hash);
|
||||
if (drawable == null) {
|
||||
drawable = new FavoriteImageDrawable(a, color, withShadow, synced);
|
||||
drawable = new FavoriteImageDrawable(a, color, withShadow, synced, position);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
cache.put(hash, drawable);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, int position) {
|
||||
return getOrCreate(a, color, withShadow, false, position);
|
||||
}
|
||||
|
||||
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) {
|
||||
return getOrCreate(a, color, withShadow, false);
|
||||
return getOrCreate(a, color, withShadow, false, MAX_PERSONAL_POINT);
|
||||
}
|
||||
|
||||
public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color) {
|
||||
return getOrCreate(a, color, false, true);
|
||||
return getOrCreate(a, color, false, true, MAX_PERSONAL_POINT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import android.widget.LinearLayout;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -79,14 +78,18 @@ public class SelectCategoryDialogFragment extends DialogFragment {
|
|||
if (gpxFile != null) {
|
||||
if (gpxCategories != null) {
|
||||
for (Map.Entry<String, Integer> e : gpxCategories.entrySet()) {
|
||||
String categoryName = e.getKey();
|
||||
addCategory(activity, ll, categoryName, e.getValue());
|
||||
if (!e.getKey().equals(getContext().getString(R.string.personal_category_name))) {
|
||||
String categoryName = e.getKey();
|
||||
addCategory(activity, ll, categoryName, e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<FavouritesDbHelper.FavoriteGroup> gs = helper.getFavoriteGroups();
|
||||
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
|
||||
addCategory(activity, ll, category.name, category.color);
|
||||
if (!category.personal) {
|
||||
addCategory(activity, ll, category.name, category.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
View itemView = activity.getLayoutInflater().inflate(R.layout.favorite_category_dialog_item, null);
|
||||
|
|
|
@ -125,9 +125,9 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
|
||||
private void loadFavorites() {
|
||||
favouritePoints.clear();
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getVisibleFavouritePoints());
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getNonPersonalVisibleFavouritePoints());
|
||||
if (favouritePoints.isEmpty()) {
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getFavouritePoints());
|
||||
favouritePoints.addAll(getMyApplication().getFavorites().getNonPersonalFavouritePoints());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
|
||||
private void selectFavorite(FavouritePoint point) {
|
||||
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
FavouritesDbHelper favorites = getMyApplication().getFavorites();
|
||||
LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
switch (pointType) {
|
||||
case START:
|
||||
|
@ -154,10 +155,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
|||
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription());
|
||||
break;
|
||||
case HOME:
|
||||
targetPointsHelper.setHomePoint(ll, point.getPointDescription());
|
||||
favorites.setHomePoint(ll, point.getPointDescription());
|
||||
break;
|
||||
case WORK:
|
||||
targetPointsHelper.setWorkPoint(ll, point.getPointDescription());
|
||||
favorites.setWorkPoint(ll, point.getPointDescription());
|
||||
break;
|
||||
}
|
||||
MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.app.Dialog;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.data.PersonalFavouritePoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -72,6 +74,8 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
plugin.showContextMenuIfNeeded(mapActivity, true);
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
mapActivity.getMyApplication().getFavorites().setParkingPoint(plugin.getParkingPosition(),
|
||||
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, PersonalFavouritePoint.PointType.PARKING.name()));
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PersonalFavouritePoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
|
@ -35,6 +36,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem;
|
||||
|
@ -249,11 +251,11 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
break;
|
||||
case HOME:
|
||||
app.showShortToastMessage(R.string.add_intermediate_point);
|
||||
targetPointsHelper.setHomePoint(ll, null);
|
||||
app.getFavorites().setHomePoint(ll, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
case WORK:
|
||||
app.showShortToastMessage(R.string.add_intermediate_point);
|
||||
targetPointsHelper.setWorkPoint(ll, null);
|
||||
app.getFavorites().setWorkPoint(ll, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
}
|
||||
} else if (pointType == PointType.START) {
|
||||
|
@ -358,17 +360,24 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
|
||||
private void loadFavoritesItems(List<Object> items, FavouritesDbHelper helper) {
|
||||
items.clear();
|
||||
addMainScrollItems(items);
|
||||
items.addAll(helper.getVisibleFavouritePoints());
|
||||
addMainScrollItems(items, helper);
|
||||
items.addAll(helper.getNonPersonalVisibleFavouritePoints());
|
||||
if (items.isEmpty()) {
|
||||
items.addAll(helper.getFavouritePoints());
|
||||
items.addAll(helper.getNonPersonalFavouritePoints());
|
||||
}
|
||||
}
|
||||
|
||||
private void addMainScrollItems(List<Object> items) {
|
||||
private void addMainScrollItems(List<Object> items, FavouritesDbHelper favorites) {
|
||||
items.add(FAVORITES);
|
||||
items.add(PointType.HOME);
|
||||
items.add(PointType.WORK);
|
||||
if (favorites.hasHomePoint()) {
|
||||
items.add(PointType.HOME);
|
||||
}
|
||||
if (favorites.hasWorkPoint()) {
|
||||
items.add(PointType.WORK);
|
||||
}
|
||||
if (favorites.hasParkingPoint()) {
|
||||
items.add(PointType.PARKING);
|
||||
}
|
||||
}
|
||||
|
||||
private void createFavoritesScrollItem() {
|
||||
|
@ -381,7 +390,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
if (helper.isFavoritesLoaded()) {
|
||||
loadFavoritesItems(items, helper);
|
||||
} else {
|
||||
addMainScrollItems(items);
|
||||
addMainScrollItems(items, helper);
|
||||
helper.addListener(new FavouritesDbHelper.FavoritesListener() {
|
||||
@Override
|
||||
public void onFavoritesLoaded() {
|
||||
|
@ -424,7 +433,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
dismiss();
|
||||
} else {
|
||||
TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
Pair<LatLon, PointDescription> pair = getLocationAndDescrFromItem(item, helper);
|
||||
Pair<LatLon, PointDescription> pair = getLocationAndDescrFromItem(item);
|
||||
LatLon ll = pair.first;
|
||||
PointDescription name = pair.second;
|
||||
if (ll == null) {
|
||||
|
@ -452,7 +461,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
};
|
||||
}
|
||||
|
||||
private Pair<LatLon, PointDescription> getLocationAndDescrFromItem(Object item, TargetPointsHelper helper) {
|
||||
private Pair<LatLon, PointDescription> getLocationAndDescrFromItem(Object item) {
|
||||
PointDescription name = null;
|
||||
LatLon ll = null;
|
||||
if (item instanceof FavouritePoint) {
|
||||
|
@ -460,15 +469,21 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
ll = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
name = point.getPointDescription();
|
||||
} else if (item instanceof PointType) {
|
||||
TargetPoint point = null;
|
||||
if (item == PointType.HOME) {
|
||||
point = helper.getHomePoint();
|
||||
} else if (item == PointType.WORK) {
|
||||
point = helper.getWorkPoint();
|
||||
}
|
||||
if (point != null) {
|
||||
ll = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
name = point.getOriginalPointDescription();
|
||||
MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null) {
|
||||
FavouritesDbHelper favorites = mapActivity.getMyApplication().getFavorites();
|
||||
FavouritePoint point = null;
|
||||
if (item == PointType.HOME) {
|
||||
point = favorites.getHomePoint();
|
||||
} else if (item == PointType.WORK) {
|
||||
point = favorites.getWorkPoint();
|
||||
} else if (item == PointType.PARKING) {
|
||||
point = favorites.getParkingPoint();
|
||||
}
|
||||
if (point != null) {
|
||||
ll = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
name = point.getPointDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Pair<>(ll, name);
|
||||
|
@ -619,18 +634,24 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
|
|||
favoriteViewHolder.description.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (item instanceof PointType) {
|
||||
final TargetPointsHelper helper = app.getTargetPointsHelper();
|
||||
TargetPoint point = null;
|
||||
PersonalFavouritePoint.PointType pointType = PersonalFavouritePoint.PointType.valueOf(((PointType) item).name());
|
||||
final FavouritesDbHelper favorites = app.getFavorites();
|
||||
FavouritePoint point = null;
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
int disabledIconColor = light ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
|
||||
if (item == PointType.HOME) {
|
||||
point = helper.getHomePoint();
|
||||
favoriteViewHolder.title.setText(getString(R.string.home_button));
|
||||
favoriteViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_home_dark));
|
||||
point = favorites.getHomePoint();
|
||||
} else if (item == PointType.WORK) {
|
||||
point = helper.getWorkPoint();
|
||||
favoriteViewHolder.title.setText(getString(R.string.work_button));
|
||||
favoriteViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_work));
|
||||
point = favorites.getWorkPoint();
|
||||
} else if (item == PointType.PARKING) {
|
||||
point = favorites.getParkingPoint();
|
||||
}
|
||||
favoriteViewHolder.description.setText(point != null ? point.getPointDescription(app).getSimpleName(app, false) : getString(R.string.shared_string_add));
|
||||
favoriteViewHolder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
|
||||
getResources().getColor(disabledIconColor), false, (pointType.ordinal())));
|
||||
favoriteViewHolder.title.setText(point.getName());
|
||||
favoriteViewHolder.description.setText(point != null
|
||||
? point.getPointDescription().getSimpleName(app, false)
|
||||
: getString(R.string.shared_string_add));
|
||||
} else if (item instanceof FavouritePoint) {
|
||||
FavouritePoint point = (FavouritePoint) getItem(position);
|
||||
favoriteViewHolder.title.setText(point.getName());
|
||||
|
|
|
@ -43,6 +43,7 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.GeocodingLookupService;
|
||||
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
|
@ -183,7 +184,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
TARGET,
|
||||
INTERMEDIATE,
|
||||
HOME,
|
||||
WORK
|
||||
WORK,
|
||||
PARKING
|
||||
}
|
||||
|
||||
public MapRouteInfoMenu() {
|
||||
|
@ -261,6 +263,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||
selectFromMapTouch = false;
|
||||
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||
FavouritesDbHelper favorites = app.getFavorites();
|
||||
switch (selectFromMapPointType) {
|
||||
case START:
|
||||
targets.setStartPoint(latlon, true, null);
|
||||
|
@ -272,10 +275,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size());
|
||||
break;
|
||||
case HOME:
|
||||
targets.setHomePoint(latlon, null);
|
||||
favorites.setHomePoint(latlon, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
case WORK:
|
||||
targets.setWorkPoint(latlon, null);
|
||||
favorites.setWorkPoint(latlon, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
}
|
||||
if (selectFromMapWaypoints) {
|
||||
|
@ -1786,6 +1789,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name);
|
||||
FavouritesDbHelper favorites = mapActivity.getMyApplication().getFavorites();
|
||||
TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
switch (pointType) {
|
||||
case START:
|
||||
|
@ -1798,10 +1802,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
targets.navigateToPoint(l, true, targets.getIntermediatePoints().size(), pd);
|
||||
break;
|
||||
case HOME:
|
||||
targets.setHomePoint(l, pd);
|
||||
favorites.setHomePoint(l, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
case WORK:
|
||||
targets.setWorkPoint(l, pd);
|
||||
favorites.setWorkPoint(l, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, ""));
|
||||
break;
|
||||
}
|
||||
updateMenu();
|
||||
|
@ -1845,6 +1849,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
if (mapActivity != null) {
|
||||
if (m != null) {
|
||||
LatLon point = new LatLon(m.getLatitude(), m.getLongitude());
|
||||
FavouritesDbHelper favorites = mapActivity.getMyApplication().getFavorites();
|
||||
TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
switch (pointType) {
|
||||
case START:
|
||||
|
@ -1857,10 +1862,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
targets.navigateToPoint(point, true, targets.getIntermediatePoints().size(), m.getPointDescription(mapActivity));
|
||||
break;
|
||||
case HOME:
|
||||
targets.setHomePoint(point, m.getPointDescription(mapActivity));
|
||||
favorites.setHomePoint(point, m.getPointDescription(mapActivity));
|
||||
break;
|
||||
case WORK:
|
||||
targets.setWorkPoint(point, m.getPointDescription(mapActivity));
|
||||
favorites.setWorkPoint(point, m.getPointDescription(mapActivity));
|
||||
break;
|
||||
}
|
||||
updateMenu();
|
||||
|
|
|
@ -3,9 +3,10 @@ package net.osmand.plus.routepreparationmenu.cards;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType;
|
||||
|
@ -24,15 +25,14 @@ public class HomeWorkCard extends BaseCard {
|
|||
@Override
|
||||
protected void updateContent() {
|
||||
final TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
final TargetPoint homePoint = targetPointsHelper.getHomePoint();
|
||||
final TargetPoint workPoint = targetPointsHelper.getWorkPoint();
|
||||
final FavouritesDbHelper favorites = getMyApplication().getFavorites();
|
||||
final FavouritePoint homePoint = favorites.getHomePoint();
|
||||
final FavouritePoint workPoint = favorites.getWorkPoint();
|
||||
|
||||
TextView homeDescr = (TextView) view.findViewById(R.id.home_button_descr);
|
||||
final TextView workDescr = (TextView) view.findViewById(R.id.work_button_descr);
|
||||
homeDescr.setText(homePoint != null ? homePoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false) :
|
||||
mapActivity.getString(R.string.shared_string_add));
|
||||
workDescr.setText(workPoint != null ? workPoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false) :
|
||||
mapActivity.getString(R.string.shared_string_add));
|
||||
TextView homeDescr = view.findViewById(R.id.home_button_descr);
|
||||
final TextView workDescr = view.findViewById(R.id.work_button_descr);
|
||||
homeDescr.setText(homePoint != null ? homePoint.getDescription() : mapActivity.getString(R.string.shared_string_add));
|
||||
workDescr.setText(workPoint != null ? workPoint.getDescription() : mapActivity.getString(R.string.shared_string_add));
|
||||
|
||||
View homeButton = view.findViewById(R.id.home_button);
|
||||
homeButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -41,7 +41,8 @@ public class HomeWorkCard extends BaseCard {
|
|||
if (homePoint == null) {
|
||||
AddPointBottomSheetDialog.showInstance(mapActivity, PointType.HOME);
|
||||
} else {
|
||||
targetPointsHelper.navigateToPoint(homePoint.point, true, -1, homePoint.getOriginalPointDescription());
|
||||
targetPointsHelper.navigateToPoint(favorites.getHomePointLatLon(),
|
||||
true, -1, homePoint.getPointDescription());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -60,7 +61,8 @@ public class HomeWorkCard extends BaseCard {
|
|||
if (workPoint == null) {
|
||||
AddPointBottomSheetDialog.showInstance(mapActivity, PointType.WORK);
|
||||
} else {
|
||||
targetPointsHelper.navigateToPoint(workPoint.point, true, -1, workPoint.getOriginalPointDescription());
|
||||
targetPointsHelper.navigateToPoint(favorites.getWorkPointLatLon(),
|
||||
true, -1, workPoint.getPointDescription());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -102,6 +102,8 @@ public class QuickSearchListItem {
|
|||
case LOCATION:
|
||||
LatLon latLon = searchResult.location;
|
||||
return PointDescription.getLocationNamePlain(app, latLon.getLatitude(), latLon.getLongitude());
|
||||
case FAVORITE:
|
||||
return ((FavouritePoint) searchResult.object).getName();
|
||||
}
|
||||
return searchResult.localeName;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue