From 5c645d39c28be5a9a38b1ce8929818cec99cc2b6 Mon Sep 17 00:00:00 2001 From: HilaryN Date: Sat, 27 Apr 2024 23:27:27 +0100 Subject: [PATCH 1/7] Changed POI id to String and removed hashCode. --- .../src/main/java/net/cyclestreets/api/POI.java | 6 +++--- .../net/cyclestreets/api/client/geojson/PoiFactory.java | 2 +- .../net/cyclestreets/api/client/RetrofitApiClientTest.java | 4 ++-- .../main/java/net/cyclestreets/views/overlay/POIOverlay.kt | 6 +----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/POI.java b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/POI.java index 606c5c2cb..6fb0d71b5 100644 --- a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/POI.java +++ b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/POI.java @@ -6,7 +6,7 @@ public class POI { - private final int id; + private final String id; private final String name; private final String notes; private final String url; @@ -16,7 +16,7 @@ public class POI private POICategory category; - public POI(final int id, + public POI(final String id, final String name, final String notes, final String url, @@ -35,7 +35,7 @@ public POI(final int id, public void setCategory(final POICategory category) { this.category = category; } - public int id() { return id; } + public String id() { return id; } public String name() { return stringOrBlank(name); } public String notes() { return stringOrBlank(notes); } public String url() { return stringOrBlank(url); } diff --git a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/geojson/PoiFactory.java b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/geojson/PoiFactory.java index 4cb0bb1f8..c49ddac09 100644 --- a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/geojson/PoiFactory.java +++ b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/geojson/PoiFactory.java @@ -32,7 +32,7 @@ private static POI toPoi(Feature feature) { if (TextUtils.isEmpty(website)) website = osmTags.get("url"); - return new POI(Integer.parseInt(feature.getProperty("id")), + return new POI(feature.getProperty("id"), feature.getProperty("name"), feature.getProperty("notes"), website, diff --git a/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java b/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java index 440835de7..3a5e974e9 100644 --- a/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java +++ b/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java @@ -193,7 +193,7 @@ private static void validatePois(List pois) { // happy path POI poi = pois.get(0); - assertThat(poi.id()).isEqualTo(101399); + assertThat(poi.id()).isEqualTo("101399"); assertThat(poi.name()).isEqualTo("Chris's Bikes"); assertThat(poi.notes()).isEqualTo("The notes section"); assertThat(poi.phone()).isEqualTo("01234 567890"); @@ -203,7 +203,7 @@ private static void validatePois(List pois) { // website provided within `osmTags.url`, but not in `website` poi = pois.get(6); - assertThat(poi.id()).isEqualTo(113267); + assertThat(poi.id()).isEqualTo("113267"); assertThat(poi.name()).isEqualTo("Bicycle Ambulance"); assertThat(poi.notes()).isEqualTo(""); assertThat(poi.phone()).isEqualTo(""); diff --git a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt index 5e61953ec..ced64726d 100644 --- a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt +++ b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt @@ -360,7 +360,7 @@ class POIOverlay(mapView: CycleMapView) : LiveItemOverlay(mapVi } - class POIOverlayItem(val poi: POI) : OverlayItem(poi.id().toString(), poi.name(), + class POIOverlayItem(val poi: POI) : OverlayItem(poi.id(), poi.name(), poi.notes(), poi.position()) { init { @@ -378,10 +378,6 @@ class POIOverlay(mapView: CycleMapView) : LiveItemOverlay(mapVi return (poi.id() == other.poi.id()) } - override fun hashCode(): Int { - return poi.id() - } - override fun toString(): String { return "POIItem [poi=${poi}]" } From d624a7114b9bffd4af4ac5d8264957d94962de02 Mon Sep 17 00:00:00 2001 From: HilaryN Date: Sat, 27 Apr 2024 23:43:13 +0100 Subject: [PATCH 2/7] Added hashCode on POI ID string. --- .../main/java/net/cyclestreets/views/overlay/POIOverlay.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt index ced64726d..cf23d7405 100644 --- a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt +++ b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt @@ -378,6 +378,10 @@ class POIOverlay(mapView: CycleMapView) : LiveItemOverlay(mapVi return (poi.id() == other.poi.id()) } + override fun hashCode(): Int { + return poi.id().hashCode() + } + override fun toString(): String { return "POIItem [poi=${poi}]" } From e52ed291df7323eb409b5c3d0bdd526e574a1dfa Mon Sep 17 00:00:00 2001 From: HilaryN Date: Mon, 6 May 2024 19:50:44 +0100 Subject: [PATCH 3/7] Changed circularRoutePoi id to String. --- .../main/java/net/cyclestreets/api/client/dto/PoiTypesDto.kt | 4 ++-- .../src/main/java/net/cyclestreets/routing/Journey.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/dto/PoiTypesDto.kt b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/dto/PoiTypesDto.kt index 74b254468..78e1373db 100644 --- a/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/dto/PoiTypesDto.kt +++ b/libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/dto/PoiTypesDto.kt @@ -42,8 +42,8 @@ class PoiTypesDto { } -fun poiIcon(context: Context, id: String): Drawable { - val key = "poi_${id}" +fun poiIcon(context: Context, type: String): Drawable { + val key = "poi_${type}" val res = context.resources val resPackage = res.getResourcePackageName(defaultResId) diff --git a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/routing/Journey.kt b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/routing/Journey.kt index 7d57a879c..82ad08fb2 100644 --- a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/routing/Journey.kt +++ b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/routing/Journey.kt @@ -212,7 +212,7 @@ class Journey private constructor(wp: Waypoints? = null) { // For circular route pois, the id isn't returned in the API, so will create an artificial one. var id = 0 for (poi in jdo.pois) { - val circularRoutePoi = POI(id, + val circularRoutePoi = POI(id.toString(), poi.name, "", poi.website, From cc1b9b7ff9c37300bc7290914e9573d4a1c2634f Mon Sep 17 00:00:00 2001 From: HilaryN Date: Mon, 6 May 2024 21:30:59 +0100 Subject: [PATCH 4/7] Changed to null-safe Objects.hashCode() --- .../src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt index f045e4be0..77b98340a 100644 --- a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt +++ b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/overlay/POIOverlay.kt @@ -28,6 +28,7 @@ import org.osmdroid.events.ZoomEvent import org.osmdroid.util.BoundingBox import org.osmdroid.views.MapView import org.osmdroid.views.overlay.OverlayItem +import java.util.Objects private val TAG = Logging.getTag(POIOverlay::class.java) @@ -381,7 +382,7 @@ class POIOverlay(mapView: CycleMapView) : LiveItemOverlay(mapVi } override fun hashCode(): Int { - return poi.id().hashCode() + return Objects.hashCode(poi.id()) } override fun toString(): String { From 91021766a2ec2c1de0ff8421327d9649ad361500 Mon Sep 17 00:00:00 2001 From: HilaryN Date: Mon, 6 May 2024 22:04:08 +0100 Subject: [PATCH 5/7] Added to beta.txt and whatsnew.html --- cyclestreets.app/src/main/assets/whatsnew.html | 1 + cyclestreets.app/src/main/play/release-notes/en-GB/beta.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cyclestreets.app/src/main/assets/whatsnew.html b/cyclestreets.app/src/main/assets/whatsnew.html index 2087f894c..cf599ce30 100644 --- a/cyclestreets.app/src/main/assets/whatsnew.html +++ b/cyclestreets.app/src/main/assets/whatsnew.html @@ -8,6 +8,7 @@

Release 3.12

There are no new features in this release. We are updated a number of our dependencies, including our underlying maps display. +
  • POI issue fixed.
  • Release 3.11

    Features diff --git a/cyclestreets.app/src/main/play/release-notes/en-GB/beta.txt b/cyclestreets.app/src/main/play/release-notes/en-GB/beta.txt index 1550ba64d..34c157c21 100644 --- a/cyclestreets.app/src/main/play/release-notes/en-GB/beta.txt +++ b/cyclestreets.app/src/main/play/release-notes/en-GB/beta.txt @@ -1,2 +1,3 @@ There are no new features in this release. We are updated a number of our -dependencies, including our underlying maps display. \ No newline at end of file +dependencies, including our underlying maps display. +POI issue fixed. \ No newline at end of file From 7421f7cd8299fb172702ca590f6acf21095f302e Mon Sep 17 00:00:00 2001 From: Oliver Lockwood Date: Tue, 7 May 2024 10:23:01 +0100 Subject: [PATCH 6/7] Add non-numeric characters into the 'id' of sample POIs used for unit testing --- .../cyclestreets-core/src/test/resources/__files/pois.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/cyclestreets-core/src/test/resources/__files/pois.json b/libraries/cyclestreets-core/src/test/resources/__files/pois.json index 5adec0922..c4d7fb90b 100644 --- a/libraries/cyclestreets-core/src/test/resources/__files/pois.json +++ b/libraries/cyclestreets-core/src/test/resources/__files/pois.json @@ -4,7 +4,7 @@ { "type": "Feature", "properties": { - "id": "101399", + "id": "alpha_101399", "name": "Chris's Bikes", "notes": "The notes section", "osmTags": { @@ -113,7 +113,7 @@ { "type": "Feature", "properties": { - "id": "113267", + "id": "some-other-characters-113267", "name": "Bicycle Ambulance", "notes": "", "osmTags": { From 402785e28174c8d24e2ccf9e66190792696b820e Mon Sep 17 00:00:00 2001 From: Oliver Lockwood Date: Tue, 7 May 2024 12:14:33 +0100 Subject: [PATCH 7/7] Update test expectations --- .../net/cyclestreets/api/client/RetrofitApiClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java b/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java index 3a5e974e9..8e3cbfa65 100644 --- a/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java +++ b/libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientTest.java @@ -193,7 +193,7 @@ private static void validatePois(List pois) { // happy path POI poi = pois.get(0); - assertThat(poi.id()).isEqualTo("101399"); + assertThat(poi.id()).isEqualTo("alpha_101399"); assertThat(poi.name()).isEqualTo("Chris's Bikes"); assertThat(poi.notes()).isEqualTo("The notes section"); assertThat(poi.phone()).isEqualTo("01234 567890"); @@ -203,7 +203,7 @@ private static void validatePois(List pois) { // website provided within `osmTags.url`, but not in `website` poi = pois.get(6); - assertThat(poi.id()).isEqualTo("113267"); + assertThat(poi.id()).isEqualTo("some-other-characters-113267"); assertThat(poi.name()).isEqualTo("Bicycle Ambulance"); assertThat(poi.notes()).isEqualTo(""); assertThat(poi.phone()).isEqualTo("");