Move home/work/parking to favs begin
This commit is contained in:
parent
d6b8bf666c
commit
9a316c5f8a
4 changed files with 195 additions and 44 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<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>
|
||||
|
|
|
@ -3,12 +3,19 @@ package net.osmand.data;
|
|||
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 {
|
||||
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;
|
||||
|
@ -46,7 +53,11 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
public PointDescription getPointDescription() {
|
||||
return new PointDescription(PointDescription.POINT_TYPE_FAVORITE, name);
|
||||
}
|
||||
|
||||
|
||||
public boolean isPersonal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointDescription getPointDescription(Context ctx) {
|
||||
return getPointDescription();
|
||||
|
@ -171,4 +182,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;
|
||||
}
|
||||
}
|
102
OsmAnd/src/net/osmand/data/PersonalFavouritePoint.java
Normal file
102
OsmAnd/src/net/osmand/data/PersonalFavouritePoint.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package net.osmand.data;
|
||||
|
||||
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;
|
||||
|
||||
public class PersonalFavouritePoint extends FavouritePoint {
|
||||
|
||||
private Context ctx;
|
||||
|
||||
private PointType type;
|
||||
public static final String PERSONAL = "personal";
|
||||
|
||||
public enum PointType {
|
||||
HOME("home", R.string.home_button, 1),
|
||||
WORK("work", R.string.work_button, 2),
|
||||
PARKING("parking", R.string.map_widget_parking, 3);
|
||||
|
||||
private String name;
|
||||
@StringRes
|
||||
private int resId;
|
||||
private int order;
|
||||
|
||||
PointType(String name, @StringRes int resId, int order) {
|
||||
this.name = name;
|
||||
this.resId = resId;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public String getHumanString(@NonNull Context ctx) {
|
||||
return ctx.getString(resId);
|
||||
}
|
||||
}
|
||||
|
||||
private PersonalFavouritePoint() {
|
||||
}
|
||||
|
||||
private PersonalFavouritePoint(@NonNull Context ctx, @NonNull PointType type, double latitude, double longitude) {
|
||||
super(latitude, longitude, type.name, PERSONAL);
|
||||
this.ctx = ctx;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public PersonalFavouritePoint(@NonNull Context ctx, @NonNull String typeName, double latitude, double longitude) throws IllegalArgumentException {
|
||||
this(ctx, PointType.valueOf(typeName), latitude, longitude);
|
||||
}
|
||||
|
||||
public PersonalFavouritePoint(PersonalFavouritePoint favouritePoint) {
|
||||
super(favouritePoint);
|
||||
this.type = favouritePoint.type;
|
||||
}
|
||||
|
||||
@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.name;
|
||||
pt.desc = getDescription();
|
||||
return pt;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ 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.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
|
@ -44,11 +45,11 @@ 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<>();
|
||||
|
@ -62,6 +63,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>();
|
||||
}
|
||||
|
||||
|
@ -437,23 +439,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;
|
||||
}
|
||||
|
@ -545,11 +531,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() {
|
||||
|
@ -569,15 +560,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 +605,8 @@ public class FavouritesDbHelper {
|
|||
|
||||
}
|
||||
};
|
||||
return favoritesComparator;
|
||||
}
|
||||
|
||||
|
||||
private boolean loadGPXFile(File file, Map<String, FavouritePoint> points) {
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
|
@ -615,20 +616,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 +681,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) {
|
||||
|
|
Loading…
Reference in a new issue