diff --git a/build.gradle b/build.gradle index cc33bf2..9a67868 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ task clean(type: Delete) { ext { versionCode = 1 - versionName = '0.1.3' + versionName = '0.1.5' minSdkVersion = 16 targetSdkVersion = 27 diff --git a/library/src/main/java/net/sharewire/googlemapsclustering/ClusterRenderer.java b/library/src/main/java/net/sharewire/googlemapsclustering/ClusterRenderer.java index b7876d3..e401938 100644 --- a/library/src/main/java/net/sharewire/googlemapsclustering/ClusterRenderer.java +++ b/library/src/main/java/net/sharewire/googlemapsclustering/ClusterRenderer.java @@ -16,6 +16,7 @@ import com.google.android.gms.maps.model.MarkerOptions; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,9 +84,19 @@ void render(@NonNull List> clusters) { } } - for (Cluster cluster : mMarkers.keySet()) { - if (!clusters.contains(cluster)) { - clustersToRemove.add(cluster); + for (Cluster existingCluster : mMarkers.keySet()) { + int indexOfExistingCluster = clusters.indexOf(existingCluster); + boolean newClustersContainsExistingCluster = indexOfExistingCluster >= 0; + + if (!newClustersContainsExistingCluster) { + clustersToRemove.add(existingCluster); + } else { + Cluster clusterWithNewData = clusters.get(indexOfExistingCluster); + boolean itemsAreEqual = existingCluster.getItems().containsAll(clusterWithNewData.getItems()); + if(!itemsAreEqual) { + clustersToRemove.add(existingCluster); + clustersToAdd.add(clusterWithNewData); + } } }