Merge pull request #8056 from osmandapp/personal_favs

Personal favs
This commit is contained in:
max-klaus 2019-12-11 16:53:33 +03:00 committed by GitHub
commit c44441c7db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 675 additions and 316 deletions

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="distance_and_address">%1$s • %2$s</string>
<string name="street_city">%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>
<string name="save_heading_descr">Save heading to each trackpoint while recording.</string>

View file

@ -3,12 +3,18 @@ package net.osmand.data;
import java.io.Serializable;
import android.content.Context;
import android.support.annotation.NonNull;
import net.osmand.GPXUtilities.WptPt;
public class FavouritePoint implements Serializable, LocationPoint {
private static final long serialVersionUID = 729654300829771466L;
private String name = "";
private String description;
private String category = "";
protected static final String HIDDEN = "hidden";
protected String name = "";
protected String description;
protected String category = "";
private String originObjectName = "";
private double latitude;
private double longitude;
@ -44,9 +50,13 @@ 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() {
return false;
}
@Override
public PointDescription getPointDescription(Context ctx) {
return getPointDescription();
@ -171,4 +181,49 @@ public class FavouritePoint implements Serializable, LocationPoint {
result = prime * result + ((originObjectName == null) ? 0 : originObjectName.hashCode());
return result;
}
public static FavouritePoint fromWpt(@NonNull Context ctx, @NonNull WptPt pt) {
String name = pt.name;
String categoryName = pt.category != null ? pt.category : "";
if (name == null) {
name = "";
}
FavouritePoint fp;
if (pt.getExtensionsToRead().containsKey(PersonalFavouritePoint.PERSONAL)) {
try {
fp = new PersonalFavouritePoint(ctx, name, pt.lat, pt.lon);
} catch (IllegalArgumentException e) {
fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName);
}
} else {
fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName);
}
fp.setDescription(pt.desc);
if (pt.comment != null) {
fp.setOriginObjectName(pt.comment);
}
fp.setColor(pt.getColor(0));
fp.setVisible(!pt.getExtensionsToRead().containsKey(HIDDEN));
return fp;
}
public WptPt toWpt() {
WptPt pt = new WptPt();
pt.lat = getLatitude();
pt.lon = getLongitude();
if (!isVisible()) {
pt.getExtensionsToWrite().put(HIDDEN, "true");
}
if (getColor() != 0) {
pt.setColor(getColor());
}
pt.name = getName();
pt.desc = getDescription();
if (getCategory().length() > 0)
pt.category = getCategory();
if (getOriginObjectName().length() > 0) {
pt.comment = getOriginObjectName();
}
return pt;
}
}

View file

@ -0,0 +1,115 @@
package net.osmand.data;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.R;
public class PersonalFavouritePoint extends FavouritePoint {
private Context ctx;
private PointType type;
static final String PERSONAL = "personal";
public enum PointType {
HOME("home", R.string.home_button, 1, R.drawable.ic_action_home_dark),
WORK("work", R.string.work_button, 2, R.drawable.ic_action_work),
PARKING("parking", R.string.map_widget_parking, 3, R.drawable.ic_action_parking_dark);
private String typeName;
@StringRes
private int resId;
private int order;
@DrawableRes
private int iconId;
PointType(@NonNull String typeName, @StringRes int resId, int order, @DrawableRes int iconId) {
this.typeName = typeName;
this.resId = resId;
this.order = order;
this.iconId = iconId;
}
public String getName() {
return typeName;
}
public int getOrder() {
return order;
}
public static PointType valueOfTypeName(@NonNull String typeName) {
for (PointType pt : values()) {
if (pt.typeName.equals(typeName)) {
return pt;
}
}
throw new IllegalArgumentException("Illegal PointType typeName");
}
public int getIconId() {
return iconId;
}
public String getHumanString(@NonNull Context ctx) {
return ctx.getString(resId);
}
}
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) {
super(latitude, longitude, type.typeName, PERSONAL);
this.ctx = ctx;
this.type = type;
}
PersonalFavouritePoint(@NonNull Context ctx, @NonNull String typeName, double latitude, double longitude) throws IllegalArgumentException {
this(ctx, PointType.valueOfTypeName(typeName), latitude, longitude);
}
@Override
public PointDescription getPointDescription() {
return new PointDescription(PointDescription.POINT_TYPE_LOCATION, getDescription());
}
@Override
public boolean isPersonal() {
return true;
}
public PointType getType() {
return type;
}
@Override
public String getName() {
return type.getHumanString(ctx);
}
@Override
public void setName(String name) {
throw new IllegalArgumentException("Personal name is readonly");
}
@Override
public String getCategory() {
return ctx.getString(R.string.personal_category_name);
}
@Override
public void setCategory(String category) {
throw new IllegalArgumentException("Personal category is readonly");
}
@Override
public WptPt toWpt() {
WptPt pt = super.toWpt();
pt.getExtensionsToWrite().put(PERSONAL, "true");
pt.name = type.typeName;
pt.desc = getDescription();
return pt;
}
}

View file

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

View file

@ -3,14 +3,17 @@ package net.osmand.plus;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.PersonalFavouritePoint;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
@ -30,11 +33,17 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
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 {
public interface FavoritesListener {
void onFavoritesLoaded();
void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint);
}
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class);
@ -44,16 +53,18 @@ public class FavouritesDbHelper {
public static final int BACKUP_CNT = 20; //$NON-NLS-1$
public static final String FILE_TO_BACKUP = "favourites_bak.gpx"; //$NON-NLS-1$
private List<FavouritePoint> cachedFavoritePoints = new ArrayList<FavouritePoint>();
private List<FavoriteGroup> favoriteGroups = new ArrayList<FavouritesDbHelper.FavoriteGroup>();
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<String, FavouritesDbHelper.FavoriteGroup>();
private List<FavouritePoint> cachedFavoritePoints = new ArrayList<>();
private List<FavouritePoint> cachedPersonalFavoritePoints = new ArrayList<>();
private List<FavoriteGroup> favoriteGroups = new ArrayList<>();
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<>();
private final OsmandApplication context;
protected static final String HIDDEN = "hidden";
private static final String DELIMETER = "__";
private Set<FavoritesListener> listeners = new HashSet<>();
private boolean favoritesLoaded;
private Map<FavouritePoint, AddressLookupRequest> addressRequestMap = new ConcurrentHashMap<>();
public FavouritesDbHelper(OsmandApplication context) {
this.context = context;
}
@ -62,6 +73,7 @@ public class FavouritesDbHelper {
public String name;
public boolean visible = true;
public int color;
public boolean personal = false;
public List<FavouritePoint> points = new ArrayList<FavouritePoint>();
}
@ -104,6 +116,31 @@ public class FavouritesDbHelper {
});
}
public FavouritePoint getWorkPoint() {
return getPersonalPoint(WORK);
}
public FavouritePoint getHomePoint() {
return getPersonalPoint(HOME);
}
public FavouritePoint getParkingPoint() {
return getPersonalPoint(PARKING);
}
public void deleteParkingPoint() {
deleteFavourite(getParkingPoint());
}
private FavouritePoint getPersonalPoint(PersonalFavouritePoint.PointType pointType) {
for (FavouritePoint fp : cachedPersonalFavoritePoints) {
if (((PersonalFavouritePoint) fp).getType() == pointType) {
return fp;
}
}
return null;
}
public boolean isFavoritesLoaded() {
return favoritesLoaded;
}
@ -192,6 +229,9 @@ public class FavouritesDbHelper {
runSyncWithMarkers(group);
}
cachedFavoritePoints.remove(p);
if (p.isPersonal()) {
cachedPersonalFavoritePoints.remove(p);
}
}
if (saveImmediately) {
saveCurrentPointsIntoFile();
@ -199,6 +239,45 @@ public class FavouritesDbHelper {
return true;
}
public void setHomePoint(@NonNull LatLon latLon, @Nullable String description) {
FavouritePoint homePoint = getHomePoint();
if (homePoint != null) {
editFavourite(homePoint, latLon.getLatitude(), latLon.getLongitude(), description);
} else {
homePoint = new PersonalFavouritePoint(context, HOME, latLon.getLatitude(), latLon.getLongitude());
homePoint.setDescription(description);
addFavourite(homePoint);
}
if (description == null) {
lookupAddress(homePoint);
}
}
public void setWorkPoint(@NonNull LatLon latLon, @Nullable String description) {
FavouritePoint workPoint = getWorkPoint();
if (workPoint != null) {
editFavourite(workPoint, latLon.getLatitude(), latLon.getLongitude(), description);
} else {
workPoint = new PersonalFavouritePoint(context, WORK, latLon.getLatitude(), latLon.getLongitude());
workPoint.setDescription(description);
addFavourite(workPoint);
}
if (description == null) {
lookupAddress(workPoint);
}
}
public void setParkingPoint(@NonNull LatLon latLon) {
FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null) {
editFavourite(parkingPoint, latLon.getLatitude(), latLon.getLongitude(), null);
} else {
parkingPoint = new PersonalFavouritePoint(context, PARKING, latLon.getLatitude(), latLon.getLongitude());
addFavourite(parkingPoint);
}
lookupAddress(parkingPoint);
}
public boolean addFavourite(FavouritePoint p) {
return addFavourite(p, true);
}
@ -216,6 +295,9 @@ public class FavouritesDbHelper {
group.points.add(p);
cachedFavoritePoints.add(p);
}
if (p.isPersonal()) {
cachedPersonalFavoritePoints.add(p);
}
if (saveImmediately) {
sortAll();
saveCurrentPointsIntoFile();
@ -225,6 +307,59 @@ public class FavouritesDbHelper {
return true;
}
public void lookupAddressAllPersonalPoints() {
if (!context.isApplicationInitializing()) {
FavouritePoint workPoint = getWorkPoint();
if (workPoint != null) {
lookupAddress(workPoint);
}
FavouritePoint homePoint = getHomePoint();
if (homePoint != null) {
lookupAddress(homePoint);
}
FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null) {
lookupAddress(parkingPoint);
}
}
}
private void lookupAddress(@NonNull final FavouritePoint p) {
AddressLookupRequest request = addressRequestMap.get(p);
double latitude = p.getLatitude();
double longitude = p.getLongitude();
if (request == null || !request.getLatLon().equals(new LatLon(latitude, longitude))) {
cancelAddressRequest(p);
request = new AddressLookupRequest(new LatLon(latitude, longitude),
new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
addressRequestMap.remove(p);
editFavouriteDescription(p, address);
context.runInUIThread(new Runnable() {
@Override
public void run() {
for (FavoritesListener listener : listeners) {
listener.onFavoriteAddressResolved(p);
}
}
});
}
}, null);
addressRequestMap.put(p, request);
context.getGeocodingLookupService().lookupAddress(request);
}
}
private void cancelAddressRequest(@NonNull FavouritePoint p) {
AddressLookupRequest request = addressRequestMap.get(p);
if (request != null) {
context.getGeocodingLookupService().cancel(request);
addressRequestMap.remove(p);
}
}
public static AlertDialog.Builder checkDuplicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) {
boolean emoticons = false;
String index = "";
@ -319,7 +454,15 @@ public class FavouritesDbHelper {
return true;
}
public boolean editFavouriteDescription(FavouritePoint p, String description) {
p.setDescription(description);
saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0));
return true;
}
public boolean editFavourite(FavouritePoint p, double lat, double lon) {
cancelAddressRequest(p);
p.setLatitude(lat);
p.setLongitude(lon);
saveCurrentPointsIntoFile();
@ -327,6 +470,16 @@ public class FavouritesDbHelper {
return true;
}
public boolean editFavourite(FavouritePoint p, double lat, double lon, String description) {
cancelAddressRequest(p);
p.setLatitude(lat);
p.setLongitude(lon);
p.setDescription(description);
saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0));
return true;
}
public void saveCurrentPointsIntoFile() {
try {
Map<String, FavouritePoint> deletedInMemory = new LinkedHashMap<String, FavouritePoint>();
@ -437,23 +590,7 @@ public class FavouritesDbHelper {
private GPXFile asGpxFile(List<FavouritePoint> favoritePoints) {
GPXFile gpx = new GPXFile(Version.getFullVersion(context));
for (FavouritePoint p : favoritePoints) {
WptPt pt = new WptPt();
pt.lat = p.getLatitude();
pt.lon = p.getLongitude();
if (!p.isVisible()) {
pt.getExtensionsToWrite().put(HIDDEN, "true");
}
if (p.getColor() != 0) {
pt.setColor(p.getColor());
}
pt.name = p.getName();
pt.desc = p.getDescription();
if (p.getCategory().length() > 0)
pt.category = p.getCategory();
if (p.getOriginObjectName().length() > 0) {
pt.comment = p.getOriginObjectName();
}
context.getSelectedGpxHelper().addPoint(pt, gpx);
context.getSelectedGpxHelper().addPoint(p.toWpt(), gpx);
}
return gpx;
}
@ -490,6 +627,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) {
@ -545,11 +702,16 @@ public class FavouritesDbHelper {
public void recalculateCachedFavPoints() {
ArrayList<FavouritePoint> temp = new ArrayList<FavouritePoint>();
List<FavouritePoint> allPoints = new ArrayList<>();
List<FavouritePoint> personalPoints = new ArrayList<>();
for (FavoriteGroup f : favoriteGroups) {
temp.addAll(f.points);
if (f.personal) {
personalPoints.addAll(f.points);
}
allPoints.addAll(f.points);
}
cachedFavoritePoints = temp;
cachedFavoritePoints = allPoints;
cachedPersonalFavoritePoints = personalPoints;
}
public void sortAll() {
@ -559,7 +721,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();
@ -569,15 +731,27 @@ public class FavouritesDbHelper {
if (cachedFavoritePoints != null) {
Collections.sort(cachedFavoritePoints, favoritesComparator);
}
if (cachedPersonalFavoritePoints != null) {
Collections.sort(cachedPersonalFavoritePoints, favoritesComparator);
}
}
public static Comparator<FavouritePoint> getComparator() {
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
Comparator<FavouritePoint> favoritesComparator = new Comparator<FavouritePoint>() {
return new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint o1, FavouritePoint o2) {
if (o1.isPersonal() && o2.isPersonal()) {
int x = ((PersonalFavouritePoint) o1).getType().getOrder();
int y = ((PersonalFavouritePoint) o2).getType().getOrder();
return Algorithms.compare(x, y);
} else if (o1.isPersonal()) {
return -1;
} else if (o2.isPersonal()) {
return 1;
}
String s1 = o1.getName();
String s2 = o2.getName();
int i1 = Algorithms.extractIntegerNumber(s1);
@ -602,10 +776,8 @@ public class FavouritesDbHelper {
}
};
return favoritesComparator;
}
private boolean loadGPXFile(File file, Map<String, FavouritePoint> points) {
if (!file.exists()) {
return false;
@ -615,20 +787,10 @@ public class FavouritesDbHelper {
return false;
}
for (WptPt p : res.getPoints()) {
int c;
String name = p.name;
String categoryName = p.category != null ? p.category : "";
if (name == null) {
name = "";
FavouritePoint fp = FavouritePoint.fromWpt(context, p);
if (fp != null) {
points.put(getKey(fp), fp);
}
FavouritePoint fp = new FavouritePoint(p.lat, p.lon, name, categoryName);
fp.setDescription(p.desc);
if (p.comment != null) {
fp.setOriginObjectName(p.comment);
}
fp.setColor(p.getColor(0));
fp.setVisible(!p.getExtensionsToRead().containsKey(HIDDEN));
points.put(getKey(fp), fp);
}
return true;
}
@ -690,6 +852,7 @@ public class FavouritesDbHelper {
group.name = p.getCategory();
group.visible = p.isVisible();
group.color = p.getColor();
group.personal = p.isPersonal();
flatGroups.put(group.name, group);
favoriteGroups.add(group);
if (group.color == 0) {

View file

@ -259,6 +259,29 @@ public class OsmandSettings {
}
}
void migrateHomeWorkParkingToFavorites() {
FavouritesDbHelper favorites = ctx.getFavorites();
LatLon homePoint = null;
float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0);
float lon = settingsAPI.getFloat(globalPreferences, "home_point_lon", 0);
if (lat != 0 || lon != 0) {
homePoint = new LatLon(lat, lon);
}
LatLon workPoint = null;
lat = settingsAPI.getFloat(globalPreferences, "work_point_lat", 0);
lon = settingsAPI.getFloat(globalPreferences, "work_point_lon", 0);
if (lat != 0 || lon != 0) {
workPoint = new LatLon(lat, lon);
}
if (homePoint != null) {
favorites.setHomePoint(homePoint, null);
}
if (workPoint != null) {
favorites.setWorkPoint(workPoint, null);
}
}
public Object getProfilePreferences(ApplicationMode mode) {
return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode));
}
@ -2393,13 +2416,6 @@ public class OsmandSettings {
public final static String MY_LOC_POINT_LON = "my_loc_point_lon";
public final static String MY_LOC_POINT_DESCRIPTION = "my_loc_point_description";
public final static String HOME_POINT_LAT = "home_point_lat";
public final static String HOME_POINT_LON = "home_point_lon";
public final static String HOME_POINT_DESCRIPTION = "home_point_description";
public final static String WORK_POINT_LAT = "work_point_lat";
public final static String WORK_POINT_LON = "work_point_lon";
public final static String WORK_POINT_DESCRIPTION = "work_point_description";
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
@ -2514,44 +2530,6 @@ public class OsmandSettings {
settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION_BACKUP, ""), getPointToNavigate());
}
public LatLon getHomePoint() {
float lat = settingsAPI.getFloat(globalPreferences, HOME_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, HOME_POINT_LON, 0);
if (lat == 0 && lon == 0) {
return null;
}
return new LatLon(lat, lon);
}
public PointDescription getHomePointDescription() {
return PointDescription.deserializeFromString(
settingsAPI.getString(globalPreferences, HOME_POINT_DESCRIPTION, ""), getHomePoint());
}
public LatLon getWorkPoint() {
float lat = settingsAPI.getFloat(globalPreferences, WORK_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, WORK_POINT_LON, 0);
if (lat == 0 && lon == 0) {
return null;
}
return new LatLon(lat, lon);
}
public PointDescription getWorkPointDescription() {
return PointDescription.deserializeFromString(
settingsAPI.getString(globalPreferences, WORK_POINT_DESCRIPTION, ""), getWorkPoint());
}
public void setHomePoint(double latitude, double longitude, PointDescription p) {
settingsAPI.edit(globalPreferences).putFloat(HOME_POINT_LAT, (float) latitude).putFloat(HOME_POINT_LON, (float) longitude).commit();
settingsAPI.edit(globalPreferences).putString(HOME_POINT_DESCRIPTION, PointDescription.serializeToString(p)).commit();
}
public void setWorkPoint(double latitude, double longitude, PointDescription p) {
settingsAPI.edit(globalPreferences).putFloat(WORK_POINT_LAT, (float) latitude).putFloat(WORK_POINT_LON, (float) longitude).commit();
settingsAPI.edit(globalPreferences).putString(WORK_POINT_DESCRIPTION, PointDescription.serializeToString(p)).commit();
}
public LatLon getMyLocationToStart() {
float lat = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LON, 0);

View file

@ -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);
}
@ -158,8 +155,6 @@ public class TargetPointsHelper {
for (TargetPoint targetPoint : intermediatePoints) {
lookupAddressForIntermediatePoint(targetPoint);
}
lookupAddressForHomePoint();
lookupAddressForWorkPoint();
lookupAddressForMyLocationPoint();
}
@ -177,25 +172,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 +248,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 +289,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 +663,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 +677,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) {

View file

@ -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;
@ -115,6 +116,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
public void onFavoritesLoaded() {
favouritesAdapter.synchronizeGroups();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
setAdapter(favouritesAdapter);
@ -738,7 +743,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
Filter myFilter;
private Set<?> filter;
public void synchronizeGroups() {
void synchronizeGroups() {
favoriteGroups.clear();
groups.clear();
List<FavoriteGroup> disablesGroups = new ArrayList<>();
@ -829,9 +834,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 +886,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 +942,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 +950,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.trim(), model.getDescription() != null ? model.getDescription() : "");
distanceText.setText(distanceWithAddress);
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
visible ? model.getColor() : getResources().getColor(disabledIconColor), false,
((PersonalFavouritePoint) model).getType()));
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 {

View file

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

View file

@ -9,14 +9,18 @@ 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.PointType;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import java.util.TreeMap;
@ -38,11 +42,16 @@ public class FavoriteImageDrawable extends Drawable {
private Paint paintInnerCircle = new Paint();
private ColorFilter colorFilter;
private ColorFilter grayFilter;
private Drawable personalPointBitmap;
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.synced = synced;
Resources res = ctx.getResources();
if (pointType != null) {
personalPointBitmap = UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, pointType.getIconId(), 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);
@ -71,6 +80,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);
if (personalPointBitmap != null) {
personalPointBitmap.setBounds(bounds);
}
}
}
@ -96,6 +108,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 (personalPointBitmap != null) {
personalPointBitmap.draw(canvas);
} else {
int min = Math.min(bs.width(), bs.height());
int r = (min * 4 / 10);
@ -132,23 +146,30 @@ 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, PointType pointType) {
int pointTypeId = 0;
if (pointType != null)
pointTypeId = pointType.ordinal();
color = color | 0xff000000;
int hash = (color << 2) + (withShadow ? 1 : 0) + (synced ? 3 : 0);
int hash = (color << 4) + ((withShadow ? 1 : 0) << 2) + ((synced ? 3 : 0) << 2) + pointTypeId;
FavoriteImageDrawable drawable = cache.get(hash);
if (drawable == null) {
drawable = new FavoriteImageDrawable(a, color, withShadow, synced);
drawable = new FavoriteImageDrawable(a, color, withShadow, synced, pointType);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
cache.put(hash, drawable);
}
return drawable;
}
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, PointType pointType) {
return getOrCreate(a, color, withShadow, false, pointType);
}
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) {
return getOrCreate(a, color, withShadow, false);
return getOrCreate(a, color, withShadow, false, null);
}
public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color) {
return getOrCreate(a, color, false, true);
return getOrCreate(a, color, false, true, null);
}
}

View file

@ -2,6 +2,7 @@ package net.osmand.plus.dashboard;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
@ -74,6 +75,10 @@ public class DashFavoritesFragment extends DashLocationFragment {
public void onFavoritesLoaded() {
setupFavorites();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
}

View file

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

View file

@ -561,12 +561,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
R.color.ctx_menu_buttons_icon_color));
((TextView) view.findViewById(R.id.context_menu_fav_text_view)).setText(menu.getFavActionStringId());
View favView = view.findViewById(R.id.context_menu_fav_view);
favView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menu.buttonFavoritePressed();
}
});
if (menu.isFavButtonEnabled()) {
favView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menu.buttonFavoritePressed();
}
});
} else {
deactivate(favView);
}
final ImageView imageWaypoint = (ImageView) view.findViewById(R.id.context_menu_route_image_view);
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;
}
public boolean isFavButtonEnabled() {
return true;
}
public int getWaypointActionIconId() {
return R.drawable.map_action_flag_dark;
}

View file

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

View file

@ -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;
@ -86,7 +85,9 @@ public class SelectCategoryDialogFragment extends DialogFragment {
} 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);

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -73,6 +74,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
loadFavorites();
adapter.notifyDataSetChanged();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
recyclerView = new RecyclerView(getContext());
@ -125,9 +130,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 +147,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 +160,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, null);
break;
case WORK:
targetPointsHelper.setWorkPoint(ll, point.getPointDescription());
favorites.setWorkPoint(ll, null);
break;
}
MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();

View file

@ -1,7 +1,9 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.NonNull;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
@ -38,6 +40,10 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
adapter.notifyDataSetChanged();
}
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
return new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());

View file

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

View file

@ -72,6 +72,7 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
plugin.showContextMenuIfNeeded(mapActivity, true);
mapActivity.refreshMap();
}
mapActivity.getMyApplication().getFavorites().setParkingPoint(plugin.getParkingPosition());
}
dismiss();
}

View file

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
@ -25,6 +26,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 +37,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;
@ -248,12 +251,12 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size());
break;
case HOME:
app.showShortToastMessage(R.string.add_intermediate_point);
targetPointsHelper.setHomePoint(ll, null);
app.showShortToastMessage(R.string.add_home);
app.getFavorites().setHomePoint(ll, null);
break;
case WORK:
app.showShortToastMessage(R.string.add_intermediate_point);
targetPointsHelper.setWorkPoint(ll, null);
app.showShortToastMessage(R.string.add_work);
app.getFavorites().setWorkPoint(ll, null);
break;
}
} else if (pointType == PointType.START) {
@ -358,17 +361,12 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private void loadFavoritesItems(List<Object> items, FavouritesDbHelper helper) {
items.clear();
addMainScrollItems(items);
addMainScrollItems(items, helper);
items.addAll(helper.getVisibleFavouritePoints());
if (items.isEmpty()) {
items.addAll(helper.getFavouritePoints());
}
}
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);
}
private void createFavoritesScrollItem() {
@ -381,16 +379,26 @@ 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() {
private void reloadFavoritesItems() {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
loadFavoritesItems(adapter.getItems(), helper);
adapter.notifyDataSetChanged();
}
}
@Override
public void onFavoritesLoaded() {
reloadFavoritesItems();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
reloadFavoritesItems();
}
});
}
BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder()
@ -424,7 +432,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) {
@ -434,6 +442,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
dismiss();
}
} else {
FavouritesDbHelper favorites = requiredMyApplication().getFavorites();
switch (pointType) {
case START:
helper.setStartPoint(ll, true, name);
@ -444,6 +453,15 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
case INTERMEDIATE:
helper.navigateToPoint(ll, true, helper.getIntermediatePoints().size(), name);
break;
case HOME:
favorites.setHomePoint(ll, null);
break;
case WORK:
favorites.setWorkPoint(ll, null);
break;
case PARKING:
favorites.setParkingPoint(ll);
break;
}
dismiss();
}
@ -452,7 +470,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 +478,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);
@ -583,8 +607,11 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private class FavoritesItemsAdapter extends ScrollItemsAdapter {
private FavouritesDbHelper favorites;
FavoritesItemsAdapter(OsmandApplication app, List<Object> items) {
super(app, items);
favorites = app.getFavorites();
}
@NonNull
@ -618,21 +645,15 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
favoriteViewHolder.icon.setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark));
favoriteViewHolder.description.setVisibility(View.GONE);
} else {
if (item instanceof PointType) {
final TargetPointsHelper helper = app.getTargetPointsHelper();
TargetPoint point = null;
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));
} 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));
}
favoriteViewHolder.description.setText(point != null ? point.getPointDescription(app).getSimpleName(app, false) : getString(R.string.shared_string_add));
if (item instanceof PersonalFavouritePoint) {
PersonalFavouritePoint point = (PersonalFavouritePoint) item;
boolean light = app.getSettings().isLightContent();
int iconColor = light ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
favoriteViewHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(point.getType().getIconId(), iconColor));
favoriteViewHolder.title.setText(point.getName());
favoriteViewHolder.description.setText(point.getDescription());
} else if (item instanceof FavouritePoint) {
FavouritePoint point = (FavouritePoint) getItem(position);
FavouritePoint point = (FavouritePoint) item;
favoriteViewHolder.title.setText(point.getName());
if (point.getCategory().equals("")) {
favoriteViewHolder.description.setText(R.string.shared_string_favorites);

View file

@ -19,6 +19,7 @@ import android.support.transition.Transition;
import android.support.transition.TransitionListenerAdapter;
import android.support.transition.TransitionManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
@ -39,10 +40,13 @@ import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.FavouritePoint;
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.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -115,7 +119,7 @@ import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener {
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener, FavoritesListener {
private static final Log LOG = PlatformUtil.getLog(MapRouteInfoMenu.class);
@ -183,7 +187,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
TARGET,
INTERMEDIATE,
HOME,
WORK
WORK,
PARKING
}
public MapRouteInfoMenu() {
@ -209,7 +214,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
app = mapActivity.getMyApplication();
portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity);
animationsHandler = new Handler();
mapActivity.getMyApplication().getRoutingHelper().addListener(this);
}
}
@ -261,6 +265,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 +277,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size());
break;
case HOME:
targets.setHomePoint(latlon, null);
favorites.setHomePoint(latlon, null);
break;
case WORK:
targets.setWorkPoint(latlon, null);
favorites.setWorkPoint(latlon, null);
break;
}
if (selectFromMapWaypoints) {
@ -1782,10 +1787,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
hide();
}
public void selectAddress(String name, LatLon l, PointType pointType) {
public void selectAddress(@Nullable String name, @NonNull LatLon l, PointType pointType) {
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 +1804,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, name);
break;
case WORK:
targets.setWorkPoint(l, pd);
favorites.setWorkPoint(l, name);
break;
}
updateMenu();
@ -1845,6 +1851,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 +1864,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, null);
break;
case WORK:
targets.setWorkPoint(point, m.getPointDescription(mapActivity));
favorites.setWorkPoint(point, null);
break;
}
updateMenu();
@ -2098,6 +2105,25 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public void routeWasFinished() {
}
public void onResume(Fragment fragment) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().addListener(this);
app.getFavorites().addListener(this);
}
addTargetPointListener();
}
public void onPause(Fragment fragment) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().removeListener(this);
app.getFavorites().removeListener(this);
}
removeTargetPointListener();
menuCards = new ArrayList<>();
}
public void onDismiss(Fragment fragment, int currentMenuState, Bundle arguments, boolean backPressed) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -2122,7 +2148,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (onDismissListener != null) {
onDismissListener.onDismiss(null);
}
removeTargetPointListener();
} else if (fragment instanceof ChooseRouteFragment) {
routeSelected = true;
MapRouteMenuStateHolder holder = new MapRouteMenuStateHolder(MapRouteMenuType.ROUTE_DETAILS, currentMenuState, fragment.getArguments());
@ -2201,12 +2226,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (fragmentRef != null) {
fragmentRef.get().dismiss();
}
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().removeListener(this);
}
removeTargetPointListener();
menuCards = new ArrayList<>();
}
public boolean needShowMenu() {
@ -2223,6 +2242,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
return menuBackStack.empty() ? 0 : menuBackStack.peek().getButtonImage();
}
@Override
public void onFavoritesLoaded() {
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
updateMenu();
}
public enum MapRouteMenuType {
ROUTE_INFO,
ROUTE_DETAILS

View file

@ -159,13 +159,16 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
updateRouteCalculationProgress(0);
}
}
menu.addTargetPointListener();
menu.onResume(this);
}
}
@Override
public void onPause() {
super.onPause();
if (menu != null) {
menu.onPause(this);
}
}
@Override

View file

@ -3,9 +3,11 @@ package net.osmand.plus.routepreparationmenu.cards;
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;
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 +26,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 +42,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(new LatLon(homePoint.getLatitude(), homePoint.getLongitude()),
true, -1, homePoint.getPointDescription());
}
}
});
@ -60,7 +62,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(new LatLon(workPoint.getLatitude(), workPoint.getLongitude()),
true, -1, workPoint.getPointDescription());
}
}
});

View file

@ -270,9 +270,16 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
OsmandApplication app = mapActivity.getMyApplication();
QuickSearchType searchType = dialogFragment.getSearchType();
if (searchType.isTargetPoint()) {
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
pointDescription != null ? pointDescription.getName() : null,
latitude, longitude, searchType);
String name = null;
if (pointDescription != null) {
String typeName = pointDescription.getTypeName();
if (!Algorithms.isEmpty(typeName)) {
name = mapActivity.getString(R.string.street_city, pointDescription.getName(), typeName);
} else {
name = pointDescription.getName();
}
}
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(name, latitude, longitude, searchType);
dialogFragment.dismiss();
mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoMenu();

View file

@ -1286,7 +1286,7 @@ public class MapControlsLayer extends OsmandMapLayer {
break;
}
if (pointType != null) {
mapRouteInfoMenu.selectAddress(name != null ? name : "", new LatLon(latitude, longitude), pointType);
mapRouteInfoMenu.selectAddress(name, new LatLon(latitude, longitude), pointType);
}
}