Merge pull request #4397 from osmandapp/sasha_pasha_branch
Sasha pasha branch
This commit is contained in:
commit
c2ab9ff665
10 changed files with 404 additions and 50 deletions
|
@ -78,7 +78,8 @@
|
|||
android:text="•"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_sub_text_size"
|
||||
android:visibility="gone"/>
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/map_marker_description"
|
||||
|
@ -101,12 +102,12 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginLeft="14dp"
|
||||
android:layout_marginRight="14dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:focusableInTouchMode="true"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="14dp"
|
||||
android:paddingRight="14dp"
|
||||
android:paddingTop="16dp"
|
||||
tools:src="@drawable/ic_overflow_menu_white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -818,7 +818,7 @@ public class OsmandAidlApi {
|
|||
if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
|
||||
PointDescription pd = new PointDescription(
|
||||
PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
|
||||
MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index);
|
||||
MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.creationDate, m.index);
|
||||
markersHelper.moveMapMarker(marker, latLonNew);
|
||||
refreshMap();
|
||||
return true;
|
||||
|
|
|
@ -35,13 +35,15 @@ public class MapMarkersHelper {
|
|||
public boolean history;
|
||||
public boolean selected;
|
||||
public int dist;
|
||||
public long creationDate;
|
||||
|
||||
public MapMarker(LatLon point, PointDescription name, int colorIndex,
|
||||
boolean selected, int index) {
|
||||
boolean selected, long creationDate, int index) {
|
||||
this.point = point;
|
||||
this.pointDescription = name;
|
||||
this.colorIndex = colorIndex;
|
||||
this.selected = selected;
|
||||
this.creationDate = creationDate;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
@ -169,6 +171,7 @@ public class MapMarkersHelper {
|
|||
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
|
||||
List<Integer> colors = settings.getMapMarkersColors(ips.size());
|
||||
List<Boolean> selections = settings.getMapMarkersSelections(ips.size());
|
||||
List<Long> creationDates = settings.getMapMarkersCreationDates(ips.size());
|
||||
int colorIndex = 0;
|
||||
for (int i = 0; i < ips.size(); i++) {
|
||||
if (colors.size() > i) {
|
||||
|
@ -176,15 +179,21 @@ public class MapMarkersHelper {
|
|||
}
|
||||
MapMarker mapMarker = new MapMarker(ips.get(i),
|
||||
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex,
|
||||
selections.get(i), i);
|
||||
selections.get(i), creationDates.get(i), i);
|
||||
mapMarkers.add(mapMarker);
|
||||
}
|
||||
|
||||
ips = settings.getMapMarkersHistoryPoints();
|
||||
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
|
||||
colors = settings.getMapMarkersHistoryColors(ips.size());
|
||||
creationDates = settings.getMapMarkersHistoryCreationDates(ips.size());
|
||||
for (int i = 0; i < ips.size(); i++) {
|
||||
if (colors.size() > i) {
|
||||
colorIndex = colors.get(i);
|
||||
}
|
||||
MapMarker mapMarker = new MapMarker(ips.get(i),
|
||||
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), 0, false, i);
|
||||
PointDescription.deserializeFromString(desc.get(i), ips.get(i)),
|
||||
colorIndex, false, creationDates.get(i), i);
|
||||
mapMarker.history = true;
|
||||
mapMarkersHistory.add(mapMarker);
|
||||
}
|
||||
|
@ -207,10 +216,10 @@ public class MapMarkersHelper {
|
|||
}
|
||||
if (history) {
|
||||
settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
|
||||
mapMarker.pointDescription, mapMarker.colorIndex);
|
||||
mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.creationDate);
|
||||
} else {
|
||||
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
|
||||
mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected);
|
||||
mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.selected, mapMarker.creationDate);
|
||||
}
|
||||
updateMarker(mapMarker);
|
||||
}
|
||||
|
@ -312,6 +321,12 @@ public class MapMarkersHelper {
|
|||
refresh();
|
||||
}
|
||||
|
||||
public void addMapMarker(MapMarker marker, int index) {
|
||||
settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription,
|
||||
marker.colorIndex, marker.selected, marker.creationDate, index);
|
||||
readFromSettings();
|
||||
}
|
||||
|
||||
public void addMapMarker(LatLon point, PointDescription historyName) {
|
||||
List<LatLon> points = new ArrayList<>(1);
|
||||
List<PointDescription> historyNames = new ArrayList<>(1);
|
||||
|
@ -376,7 +391,7 @@ public class MapMarkersHelper {
|
|||
public void updateMapMarker(MapMarker marker, boolean refresh) {
|
||||
if (marker != null) {
|
||||
settings.updateMapMarker(marker.getLatitude(), marker.getLongitude(),
|
||||
marker.pointDescription, marker.colorIndex, marker.selected);
|
||||
marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate);
|
||||
if (refresh) {
|
||||
readFromSettings();
|
||||
refresh();
|
||||
|
@ -387,7 +402,7 @@ public class MapMarkersHelper {
|
|||
public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) {
|
||||
if (marker != null) {
|
||||
settings.moveMapMarker(new LatLon(marker.getLatitude(), marker.getLongitude()), latLon,
|
||||
marker.pointDescription, marker.colorIndex, marker.selected);
|
||||
marker.pointDescription, marker.colorIndex, marker.selected, marker.creationDate);
|
||||
marker.point = new LatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
readFromSettings();
|
||||
refresh();
|
||||
|
@ -404,7 +419,8 @@ public class MapMarkersHelper {
|
|||
|
||||
public void addMapMarkerHistory(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, marker.colorIndex, 0);
|
||||
settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(),
|
||||
marker.pointDescription, marker.colorIndex, marker.creationDate, 0);
|
||||
readFromSettings();
|
||||
refresh();
|
||||
}
|
||||
|
@ -424,25 +440,29 @@ public class MapMarkersHelper {
|
|||
List<String> names = new ArrayList<>(markers.size());
|
||||
List<Integer> colors = new ArrayList<>(markers.size());
|
||||
List<Boolean> selections = new ArrayList<>(markers.size());
|
||||
List<Long> creationDates = new ArrayList<>(markers.size());
|
||||
for (MapMarker marker : markers) {
|
||||
ls.add(marker.point);
|
||||
names.add(PointDescription.serializeToString(marker.pointDescription));
|
||||
colors.add(marker.colorIndex);
|
||||
selections.add(marker.selected);
|
||||
creationDates.add(marker.creationDate);
|
||||
}
|
||||
settings.saveMapMarkers(ls, names, colors, selections);
|
||||
settings.saveMapMarkers(ls, names, colors, selections, creationDates);
|
||||
}
|
||||
|
||||
if (markersHistory != null) {
|
||||
List<LatLon> ls = new ArrayList<>(markersHistory.size());
|
||||
List<String> names = new ArrayList<>(markersHistory.size());
|
||||
List<Integer> colors = new ArrayList<>(markersHistory.size());
|
||||
List<Long> creationDates = new ArrayList<>(markersHistory.size());
|
||||
for (MapMarker marker : markersHistory) {
|
||||
ls.add(marker.point);
|
||||
names.add(PointDescription.serializeToString(marker.pointDescription));
|
||||
colors.add(marker.colorIndex);
|
||||
creationDates.add(marker.creationDate);
|
||||
}
|
||||
settings.saveMapMarkersHistory(ls, names, colors);
|
||||
settings.saveMapMarkersHistory(ls, names, colors, creationDates);
|
||||
}
|
||||
|
||||
if (markers != null || markersHistory != null) {
|
||||
|
|
|
@ -1783,8 +1783,11 @@ public class OsmandSettings {
|
|||
public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_CREATION_DATE = "map_markers_creation_date"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
|
||||
public final static String MAP_MARKERS_HISTORY_CREATION_DATE = "map_markers_history_creation_date"; //$NON-NLS-1$
|
||||
public final static int MAP_MARKERS_HISTORY_LIMIT = 30;
|
||||
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
|
||||
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
|
||||
|
@ -1896,6 +1899,7 @@ public class OsmandSettings {
|
|||
.remove(MAP_MARKERS_DESCRIPTION)
|
||||
.remove(MAP_MARKERS_COLOR)
|
||||
.remove(MAP_MARKERS_SELECTION)
|
||||
.remove(MAP_MARKERS_CREATION_DATE)
|
||||
.commit();
|
||||
}
|
||||
|
||||
|
@ -1903,6 +1907,8 @@ public class OsmandSettings {
|
|||
return settingsAPI.edit(globalPreferences)
|
||||
.remove(MAP_MARKERS_HISTORY_POINT)
|
||||
.remove(MAP_MARKERS_HISTORY_DESCRIPTION)
|
||||
.remove(MAP_MARKERS_HISTORY_COLOR)
|
||||
.remove(MAP_MARKERS_HISTORY_CREATION_DATE)
|
||||
.commit();
|
||||
}
|
||||
|
||||
|
@ -1927,18 +1933,175 @@ public class OsmandSettings {
|
|||
|
||||
private class MapMarkersHistoryStorage extends MapPointsStorage {
|
||||
|
||||
protected String colorsKey;
|
||||
protected String creationDatesKey;
|
||||
|
||||
public MapMarkersHistoryStorage() {
|
||||
pointsKey = MAP_MARKERS_HISTORY_POINT;
|
||||
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
|
||||
colorsKey = MAP_MARKERS_HISTORY_COLOR;
|
||||
creationDatesKey = MAP_MARKERS_HISTORY_CREATION_DATE;
|
||||
}
|
||||
|
||||
public List<Integer> getColors(int sz) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
String ip = settingsAPI.getString(globalPreferences, colorsKey, "");
|
||||
if (ip.trim().length() > 0) {
|
||||
StringTokenizer tok = new StringTokenizer(ip, ",");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String colorStr = tok.nextToken();
|
||||
list.add(Integer.parseInt(colorStr));
|
||||
}
|
||||
}
|
||||
while (list.size() > sz) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
int i = 0;
|
||||
while (list.size() < sz) {
|
||||
list.add(i % MapMarkersHelper.MAP_MARKERS_COLORS_COUNT);
|
||||
i++;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Long> getCreationDates(int sz) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
|
||||
if (ip.trim().length() > 0) {
|
||||
StringTokenizer tok = new StringTokenizer(ip, ",");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String creationDateStr = tok.nextToken();
|
||||
list.add(Long.parseLong(creationDateStr));
|
||||
}
|
||||
}
|
||||
while (list.size() > sz) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
while (list.size() < sz) {
|
||||
list.add(0L);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Long> cds) {
|
||||
while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
|
||||
ps.remove(ps.size() - 1);
|
||||
ds.remove(ds.size() - 1);
|
||||
cs.remove(cs.size() - 1);
|
||||
cds.remove(cds.size() - 1);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < ps.size(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
|
||||
}
|
||||
StringBuilder tb = new StringBuilder();
|
||||
for (int i = 0; i < ds.size(); i++) {
|
||||
if (i > 0) {
|
||||
tb.append("--");
|
||||
}
|
||||
if (ds.get(i) == null) {
|
||||
tb.append("");
|
||||
} else {
|
||||
tb.append(ds.get(i));
|
||||
}
|
||||
}
|
||||
StringBuilder cb = new StringBuilder();
|
||||
for (int i = 0; i < cs.size(); i++) {
|
||||
if (i > 0) {
|
||||
cb.append(",");
|
||||
}
|
||||
cb.append(Integer.toString(cs.get(i)));
|
||||
}
|
||||
StringBuilder cdb = new StringBuilder();
|
||||
if (cds != null) {
|
||||
for (int i = 0; i < cds.size(); i++) {
|
||||
if (i > 0) {
|
||||
cdb.append(",");
|
||||
}
|
||||
cdb.append(Long.toString(cds.get(i)));
|
||||
}
|
||||
}
|
||||
return settingsAPI.edit(globalPreferences)
|
||||
.putString(pointsKey, sb.toString())
|
||||
.putString(descriptionsKey, tb.toString())
|
||||
.putString(colorsKey, cb.toString())
|
||||
.putString(creationDatesKey, cdb.toString())
|
||||
.commit();
|
||||
}
|
||||
|
||||
public boolean insertPoint(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
long creationDate, int index) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
ps.add(index, new LatLon(latitude, longitude));
|
||||
ds.add(index, PointDescription.serializeToString(historyDescription));
|
||||
cs.add(index, colorIndex);
|
||||
cds.add(index, creationDate);
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
|
||||
}
|
||||
return savePoints(ps, ds, cs, cds);
|
||||
}
|
||||
|
||||
public boolean updatePoint(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
long creationDate) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
int index = ps.indexOf(new LatLon(latitude, longitude));
|
||||
if (index != -1) {
|
||||
ds.set(index, PointDescription.serializeToString(historyDescription));
|
||||
if (cs.size() > index) {
|
||||
cs.set(index, colorIndex);
|
||||
}
|
||||
if (cds.size() > index) {
|
||||
cds.set(index, creationDate);
|
||||
}
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
|
||||
}
|
||||
return savePoints(ps, ds, cs, cds);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePoint(int index) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
ps.remove(index);
|
||||
ds.remove(index);
|
||||
cds.remove(index);
|
||||
if (cs.size() > index) {
|
||||
cs.remove(index);
|
||||
}
|
||||
return savePoints(ps, ds, cs, cds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean savePoints(List<LatLon> ps, List<String> ds) {
|
||||
while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
|
||||
ps.remove(ps.size() - 1);
|
||||
ds.remove(ds.size() - 1);
|
||||
}
|
||||
return super.savePoints(ps, ds);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1946,12 +2109,14 @@ public class OsmandSettings {
|
|||
|
||||
protected String colorsKey;
|
||||
protected String selectionKey;
|
||||
protected String creationDatesKey;
|
||||
|
||||
public MapMarkersStorage() {
|
||||
pointsKey = MAP_MARKERS_POINT;
|
||||
descriptionsKey = MAP_MARKERS_DESCRIPTION;
|
||||
colorsKey = MAP_MARKERS_COLOR;
|
||||
selectionKey = MAP_MARKERS_SELECTION;
|
||||
creationDatesKey = MAP_MARKERS_CREATION_DATE;
|
||||
}
|
||||
|
||||
public List<Integer> getColors(int sz) {
|
||||
|
@ -1994,21 +2159,42 @@ public class OsmandSettings {
|
|||
return list;
|
||||
}
|
||||
|
||||
public List<Long> getCreationDates(int sz) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
|
||||
if (ip.trim().length() > 0) {
|
||||
StringTokenizer tok = new StringTokenizer(ip, ",");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String creationDateStr = tok.nextToken();
|
||||
list.add(Long.parseLong(creationDateStr));
|
||||
}
|
||||
}
|
||||
while (list.size() > sz) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
while (list.size() < sz) {
|
||||
list.add(0L);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean insertPoint(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex, int pos,
|
||||
boolean selected, int index) {
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
boolean selected, long creationDate, int index) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
ps.add(index, new LatLon(latitude, longitude));
|
||||
ds.add(index, PointDescription.serializeToString(historyDescription));
|
||||
cs.add(index, colorIndex);
|
||||
bs.add(index, selected);
|
||||
cds.add(index, creationDate == 0 ? System.currentTimeMillis() : creationDate);
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
|
||||
}
|
||||
return savePoints(ps, ds, cs, bs);
|
||||
return savePoints(ps, ds, cs, bs, cds);
|
||||
}
|
||||
|
||||
public boolean insertPoints(double[] latitudes, double[] longitudes,
|
||||
|
@ -2018,6 +2204,7 @@ public class OsmandSettings {
|
|||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
for (int i = 0; i < latitudes.length; i++) {
|
||||
double latitude = latitudes[i];
|
||||
double longitude = longitudes[i];
|
||||
|
@ -2029,20 +2216,22 @@ public class OsmandSettings {
|
|||
ds.add(index, PointDescription.serializeToString(historyDescription));
|
||||
cs.add(index, colorIndex);
|
||||
bs.add(index, selected);
|
||||
cds.add(index, System.currentTimeMillis());
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
|
||||
}
|
||||
}
|
||||
return savePoints(ps, ds, cs, bs);
|
||||
return savePoints(ps, ds, cs, bs, cds);
|
||||
}
|
||||
|
||||
public boolean updatePoint(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
boolean selected) {
|
||||
boolean selected, long creationDate) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
int index = ps.indexOf(new LatLon(latitude, longitude));
|
||||
if (index != -1) {
|
||||
ds.set(index, PointDescription.serializeToString(historyDescription));
|
||||
|
@ -2052,10 +2241,13 @@ public class OsmandSettings {
|
|||
if (bs.size() > index) {
|
||||
bs.set(index, selected);
|
||||
}
|
||||
if (cds.size() > index) {
|
||||
cds.set(index, creationDate);
|
||||
}
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
|
||||
}
|
||||
return savePoints(ps, ds, cs, bs);
|
||||
return savePoints(ps, ds, cs, bs, cds);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -2065,11 +2257,13 @@ public class OsmandSettings {
|
|||
LatLon latLonNew,
|
||||
PointDescription historyDescription,
|
||||
int colorIndex,
|
||||
boolean selected) {
|
||||
boolean selected,
|
||||
long creationDate) {
|
||||
List<LatLon> ps = getPoints();
|
||||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
int index = ps.indexOf(latLonEx);
|
||||
if (index != -1) {
|
||||
if (ps.size() > index) {
|
||||
|
@ -2082,12 +2276,15 @@ public class OsmandSettings {
|
|||
if (bs.size() > index) {
|
||||
bs.set(index, selected);
|
||||
}
|
||||
if (cds.size() > index) {
|
||||
cds.set(index, creationDate);
|
||||
}
|
||||
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
|
||||
double lat = latLonNew.getLatitude();
|
||||
double lon = latLonNew.getLongitude();
|
||||
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(lat, lon, historyDescription);
|
||||
}
|
||||
return savePoints(ps, ds, cs, bs);
|
||||
return savePoints(ps, ds, cs, bs, cds);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -2099,19 +2296,21 @@ public class OsmandSettings {
|
|||
List<String> ds = getPointDescriptions(ps.size());
|
||||
List<Integer> cs = getColors(ps.size());
|
||||
List<Boolean> bs = getSelections(ps.size());
|
||||
List<Long> cds = getCreationDates(ps.size());
|
||||
ps.remove(index);
|
||||
ds.remove(index);
|
||||
cds.remove(index);
|
||||
if (cs.size() > index) {
|
||||
cs.remove(index);
|
||||
}
|
||||
if (bs.size() > index) {
|
||||
bs.remove(index);
|
||||
}
|
||||
return savePoints(ps, ds, cs, bs);
|
||||
return savePoints(ps, ds, cs, bs, cds);
|
||||
}
|
||||
|
||||
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs,
|
||||
List<Boolean> bs) {
|
||||
List<Boolean> bs, List<Long> cds) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < ps.size(); i++) {
|
||||
if (i > 0) {
|
||||
|
@ -2146,11 +2345,21 @@ public class OsmandSettings {
|
|||
bb.append(Boolean.toString(bs.get(i)));
|
||||
}
|
||||
}
|
||||
StringBuilder cdb = new StringBuilder();
|
||||
if (cds != null) {
|
||||
for (int i = 0; i < cds.size(); i++) {
|
||||
if (i > 0) {
|
||||
cdb.append(",");
|
||||
}
|
||||
cdb.append(Long.toString(cds.get(i)));
|
||||
}
|
||||
}
|
||||
return settingsAPI.edit(globalPreferences)
|
||||
.putString(pointsKey, sb.toString())
|
||||
.putString(descriptionsKey, tb.toString())
|
||||
.putString(colorsKey, cb.toString())
|
||||
.putString(selectionKey, bb.toString())
|
||||
.putString(creationDatesKey, cdb.toString())
|
||||
.commit();
|
||||
}
|
||||
|
||||
|
@ -2344,15 +2553,19 @@ public class OsmandSettings {
|
|||
return mapMarkersStorage.getSelections(sz);
|
||||
}
|
||||
|
||||
public List<Long> getMapMarkersCreationDates(int sz) {
|
||||
return mapMarkersStorage.getCreationDates(sz);
|
||||
}
|
||||
|
||||
public List<LatLon> getMapMarkersPoints() {
|
||||
return mapMarkersStorage.getPoints();
|
||||
}
|
||||
|
||||
public boolean insertMapMarker(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex, int pos,
|
||||
boolean selected, int index) {
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
boolean selected, long creationDate, int index) {
|
||||
return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex,
|
||||
index, selected, pos);
|
||||
selected, creationDate, index);
|
||||
}
|
||||
|
||||
public boolean insertMapMarkers(double[] latitudes, double[] longitudes,
|
||||
|
@ -2363,24 +2576,27 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
public boolean updateMapMarker(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex, boolean selected) {
|
||||
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected);
|
||||
PointDescription historyDescription, int colorIndex, boolean selected,
|
||||
long creationDate) {
|
||||
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, selected, creationDate);
|
||||
}
|
||||
|
||||
public boolean moveMapMarker(LatLon latLonEx,
|
||||
LatLon latLonNew,
|
||||
PointDescription historyDescription,
|
||||
int colorIndex,
|
||||
boolean selected) {
|
||||
return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected);
|
||||
boolean selected,
|
||||
long creationDate) {
|
||||
return mapMarkersStorage.movePoint(latLonEx, latLonNew, historyDescription, colorIndex, selected, creationDate);
|
||||
}
|
||||
|
||||
public boolean deleteMapMarker(int index) {
|
||||
return mapMarkersStorage.deletePoint(index);
|
||||
}
|
||||
|
||||
public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Boolean> bs) {
|
||||
return mapMarkersStorage.savePoints(ps, ds, cs, bs);
|
||||
public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Boolean> bs,
|
||||
List<Long> cds) {
|
||||
return mapMarkersStorage.savePoints(ps, ds, cs, bs, cds);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2392,22 +2608,31 @@ public class OsmandSettings {
|
|||
return mapMarkersHistoryStorage.getPoints();
|
||||
}
|
||||
|
||||
public List<Long> getMapMarkersHistoryCreationDates(int sz) {
|
||||
return mapMarkersHistoryStorage.getCreationDates(sz);
|
||||
}
|
||||
|
||||
public List<Integer> getMapMarkersHistoryColors(int sz) {
|
||||
return mapMarkersHistoryStorage.getColors(sz);
|
||||
}
|
||||
|
||||
public boolean insertMapMarkerHistory(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex, int index) {
|
||||
return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, index);
|
||||
PointDescription historyDescription, int colorIndex,
|
||||
long creationDate, int index) {
|
||||
return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, creationDate, index);
|
||||
}
|
||||
|
||||
public boolean updateMapMarkerHistory(double latitude, double longitude,
|
||||
PointDescription historyDescription, int colorIndex) {
|
||||
return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription);
|
||||
PointDescription historyDescription, int colorIndex, long creationDate) {
|
||||
return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription, colorIndex, creationDate);
|
||||
}
|
||||
|
||||
public boolean deleteMapMarkerHistory(int index) {
|
||||
return mapMarkersHistoryStorage.deletePoint(index);
|
||||
}
|
||||
|
||||
public boolean saveMapMarkersHistory(List<LatLon> ps, List<String> ds, List<Integer> cs) {
|
||||
return mapMarkersHistoryStorage.savePoints(ps, ds);
|
||||
public boolean saveMapMarkersHistory(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Long> cds) {
|
||||
return mapMarkersHistoryStorage.savePoints(ps, ds, cs, cds);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -121,6 +121,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
|||
return null;
|
||||
}
|
||||
|
||||
void updateAdapter() {
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLocationUi() {
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null) {
|
||||
|
|
|
@ -78,11 +78,17 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
switch (menuItem.getItemId()) {
|
||||
case R.id.action_active:
|
||||
((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 0) {
|
||||
((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter();
|
||||
}
|
||||
viewPager.setCurrentItem(0);
|
||||
optionsButton.setVisibility(View.VISIBLE);
|
||||
return true;
|
||||
case R.id.action_history:
|
||||
((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 1) {
|
||||
((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter();
|
||||
}
|
||||
viewPager.setCurrentItem(1);
|
||||
optionsButton.setVisibility(View.GONE);
|
||||
return true;
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -9,11 +10,15 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
|
||||
|
||||
public class MapMarkersHistoryFragment extends Fragment {
|
||||
|
||||
MapMarkersHistoryAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -21,8 +26,27 @@ public class MapMarkersHistoryFragment extends Fragment {
|
|||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
|
||||
recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication()));
|
||||
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
|
||||
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
int pos = recyclerView.indexOfChild(view);
|
||||
MapMarker marker = adapter.getItem(pos);
|
||||
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
|
||||
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION, marker.getPointDescription(mapActivity).getName()),
|
||||
false, null);
|
||||
MapActivity.launchMapActivityMoveToTop(mapActivity);
|
||||
((DialogFragment) getParentFragment()).dismiss();
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
return recyclerView;
|
||||
}
|
||||
|
||||
void updateAdapter() {
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
final TextView distance;
|
||||
final TextView point;
|
||||
final TextView description;
|
||||
final ImageButton options;
|
||||
final ImageButton optionsBtn;
|
||||
|
||||
public MapMarkerItemViewHolder(View view) {
|
||||
super(view);
|
||||
|
@ -28,6 +28,6 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
distance = (TextView) view.findViewById(R.id.map_marker_distance);
|
||||
point = (TextView) view.findViewById(R.id.map_marker_point_text_view);
|
||||
description = (TextView) view.findViewById(R.id.map_marker_description);
|
||||
options = (ImageButton) view.findViewById(R.id.map_marker_options_button);
|
||||
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers.adapters;
|
||||
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -87,6 +88,42 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
|||
|
||||
holder.title.setText(marker.getName(mapActivity));
|
||||
|
||||
holder.description.setText(marker.creationDate + "");
|
||||
|
||||
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
|
||||
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int position = holder.getAdapterPosition();
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
final MapMarker marker = markers.get(position);
|
||||
final boolean[] undone = new boolean[1];
|
||||
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().removeMapMarker(marker.index);
|
||||
notifyItemRemoved(position);
|
||||
|
||||
Snackbar.make(holder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
undone[0] = true;
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().addMapMarker(marker, position);
|
||||
notifyItemInserted(position);
|
||||
}
|
||||
})
|
||||
.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onDismissed(Snackbar transientBottomBar, int event) {
|
||||
if (!undone[0]) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().addMapMarkerHistory(marker);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
|
||||
DashLocationFragment.updateLocationView(useCenter, location,
|
||||
heading, holder.iconDirection, holder.distance,
|
||||
marker.getLatitude(), marker.getLongitude(),
|
||||
|
|
|
@ -16,20 +16,31 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
|
|||
|
||||
private OsmandApplication app;
|
||||
private List<MapMarker> markers;
|
||||
private MapMarkersHistoryAdapterListener listener;
|
||||
|
||||
public MapMarkersHistoryAdapter(OsmandApplication app) {
|
||||
this.app = app;
|
||||
markers = app.getMapMarkersHelper().getMapMarkersHistory();
|
||||
}
|
||||
|
||||
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
listener.onItemClick(view);
|
||||
}
|
||||
});
|
||||
return new MapMarkerItemViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) {
|
||||
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
MapMarker marker = markers.get(pos);
|
||||
|
||||
|
@ -39,10 +50,34 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
|
|||
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
|
||||
|
||||
holder.title.setText(marker.getName(app));
|
||||
|
||||
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_refresh_dark));
|
||||
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int position = holder.getAdapterPosition();
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
MapMarker marker = markers.get(position);
|
||||
app.getMapMarkersHelper().removeMapMarkerHistory(marker);
|
||||
app.getMapMarkersHelper().addMapMarker(marker, 0);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return markers.size();
|
||||
}
|
||||
|
||||
public MapMarker getItem(int position) {
|
||||
return markers.get(position);
|
||||
}
|
||||
|
||||
public interface MapMarkersHistoryAdapterListener {
|
||||
|
||||
void onItemClick(View view);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue