Merge pull request #10280 from osmandapp/PaulsBranch
Fix avoid road import
This commit is contained in:
commit
e9ababdfab
2 changed files with 21 additions and 23 deletions
|
@ -417,7 +417,9 @@ public class AvoidSpecificRoads {
|
||||||
AvoidRoadInfo other = (AvoidRoadInfo) obj;
|
AvoidRoadInfo other = (AvoidRoadInfo) obj;
|
||||||
return Math.abs(latitude - other.latitude) < 0.00001
|
return Math.abs(latitude - other.latitude) < 0.00001
|
||||||
&& Math.abs(longitude - other.longitude) < 0.00001
|
&& Math.abs(longitude - other.longitude) < 0.00001
|
||||||
&& Algorithms.objectEquals(name, other.name);
|
&& Algorithms.objectEquals(name, other.name)
|
||||||
|
&& Algorithms.objectEquals(appModeKey, other.appModeKey)
|
||||||
|
&& id == other.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,13 +68,9 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
||||||
appliedItems = new ArrayList<>(newItems);
|
appliedItems = new ArrayList<>(newItems);
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo duplicate : duplicateItems) {
|
for (AvoidSpecificRoads.AvoidRoadInfo duplicate : duplicateItems) {
|
||||||
if (shouldReplace) {
|
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
||||||
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
if (settings.removeImpassableRoad(latLon)) {
|
||||||
if (settings.removeImpassableRoad(latLon)) {
|
settings.addImpassableRoad(duplicate);
|
||||||
settings.addImpassableRoad(duplicate);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
settings.addImpassableRoad(renameItem(duplicate));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : appliedItems) {
|
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : appliedItems) {
|
||||||
|
@ -87,7 +83,12 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDuplicate(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
public boolean isDuplicate(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
||||||
return existingItems.contains(item);
|
for (AvoidSpecificRoads.AvoidRoadInfo roadInfo : existingItems) {
|
||||||
|
if (roadInfo.id == item.id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,22 +96,15 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldShowDuplicates() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AvoidSpecificRoads.AvoidRoadInfo renameItem(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
public AvoidSpecificRoads.AvoidRoadInfo renameItem(@NonNull AvoidSpecificRoads.AvoidRoadInfo item) {
|
||||||
int number = 0;
|
return item;
|
||||||
while (true) {
|
|
||||||
number++;
|
|
||||||
AvoidSpecificRoads.AvoidRoadInfo renamedItem = new AvoidSpecificRoads.AvoidRoadInfo();
|
|
||||||
renamedItem.name = item.name + "_" + number;
|
|
||||||
if (!isDuplicate(renamedItem)) {
|
|
||||||
renamedItem.id = item.id;
|
|
||||||
renamedItem.latitude = item.latitude;
|
|
||||||
renamedItem.longitude = item.longitude;
|
|
||||||
renamedItem.appModeKey = item.appModeKey;
|
|
||||||
return renamedItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,8 +120,9 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
double longitude = object.optDouble("longitude");
|
double longitude = object.optDouble("longitude");
|
||||||
String name = object.optString("name");
|
String name = object.optString("name");
|
||||||
String appModeKey = object.optString("appModeKey");
|
String appModeKey = object.optString("appModeKey");
|
||||||
|
long id = object.optLong("roadId");
|
||||||
AvoidSpecificRoads.AvoidRoadInfo roadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
|
AvoidSpecificRoads.AvoidRoadInfo roadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
|
||||||
roadInfo.id = 0;
|
roadInfo.id = id;
|
||||||
roadInfo.latitude = latitude;
|
roadInfo.latitude = latitude;
|
||||||
roadInfo.longitude = longitude;
|
roadInfo.longitude = longitude;
|
||||||
roadInfo.name = name;
|
roadInfo.name = name;
|
||||||
|
@ -155,6 +150,7 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidSpecific
|
||||||
jsonObject.put("longitude", avoidRoad.longitude);
|
jsonObject.put("longitude", avoidRoad.longitude);
|
||||||
jsonObject.put("name", avoidRoad.name);
|
jsonObject.put("name", avoidRoad.name);
|
||||||
jsonObject.put("appModeKey", avoidRoad.appModeKey);
|
jsonObject.put("appModeKey", avoidRoad.appModeKey);
|
||||||
|
jsonObject.put("roadId", avoidRoad.id);
|
||||||
jsonArray.put(jsonObject);
|
jsonArray.put(jsonObject);
|
||||||
}
|
}
|
||||||
json.put("items", jsonArray);
|
json.put("items", jsonArray);
|
||||||
|
|
Loading…
Reference in a new issue