Loading cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt +17 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import java.nio.ByteBuffer import java.security.MessageDigest import javax.inject.Inject import javax.inject.Singleton Loading Loading @@ -465,8 +466,18 @@ class LocationRepository @Inject constructor( fun createSearchResultPlace(result: GeocodeResult): Place { val openingHours = result.properties["opening_hours"] val rawIdSource = "${result.displayName}_${"%.5f".format(result.latitude)}_${"%.5f".format(result.longitude)}" val deterministicId = generateStableId(rawIdSource) val osmId = result.properties["osm_id"] val osmType = result.properties["osm_type"] val deterministicId = if (osmId != null) { "osm:$osmType:$osmId" } else { // 2. Fallback: Use a binary hash of coordinates (Locale Independent) // We use Long bits to ensure 1.11.111 is different from 11.1.111 val buffer = ByteBuffer.allocate(16) buffer.putDouble(result.latitude) buffer.putDouble(result.longitude) generateStableIdFromBytes(buffer.array()) } return Place( id = deterministicId, name = result.displayName, Loading @@ -480,10 +491,11 @@ class LocationRepository @Inject constructor( openingHours = openingHours, ) } private fun generateStableId(input: String): String { private fun generateStableIdFromBytes(bytes: ByteArray): String { return MessageDigest.getInstance("SHA-256") .digest(input.toByteArray()) .fold("") { str, it -> str + "%02x".format(it) } .digest(bytes) .joinToString("") { "%02x".format(it) } } fun mapOsmTagsToDescription(properties: Map<String, String>): String { Loading cardinal-android/app/src/main/java/earth/maps/cardinal/data/room/RecentSearch.kt +1 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ data class RecentSearch( val timestamp = System.currentTimeMillis() return RecentSearch( id = place.id ?: UUID.randomUUID().toString(), id = if (place.id.isNullOrBlank()) UUID.randomUUID().toString() else place.id, name = place.name, description = place.description, icon = place.icon, Loading cardinal-android/app/src/main/java/earth/maps/cardinal/data/room/SavedPlace.kt +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ data class SavedPlace( val timestamp = System.currentTimeMillis() return SavedPlace( id = place.id ?: UUID.randomUUID().toString(), id = if (place.id.isNullOrBlank()) UUID.randomUUID().toString() else place.id, placeId = 0, customName = null, customDescription = null, Loading Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt +17 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import java.nio.ByteBuffer import java.security.MessageDigest import javax.inject.Inject import javax.inject.Singleton Loading Loading @@ -465,8 +466,18 @@ class LocationRepository @Inject constructor( fun createSearchResultPlace(result: GeocodeResult): Place { val openingHours = result.properties["opening_hours"] val rawIdSource = "${result.displayName}_${"%.5f".format(result.latitude)}_${"%.5f".format(result.longitude)}" val deterministicId = generateStableId(rawIdSource) val osmId = result.properties["osm_id"] val osmType = result.properties["osm_type"] val deterministicId = if (osmId != null) { "osm:$osmType:$osmId" } else { // 2. Fallback: Use a binary hash of coordinates (Locale Independent) // We use Long bits to ensure 1.11.111 is different from 11.1.111 val buffer = ByteBuffer.allocate(16) buffer.putDouble(result.latitude) buffer.putDouble(result.longitude) generateStableIdFromBytes(buffer.array()) } return Place( id = deterministicId, name = result.displayName, Loading @@ -480,10 +491,11 @@ class LocationRepository @Inject constructor( openingHours = openingHours, ) } private fun generateStableId(input: String): String { private fun generateStableIdFromBytes(bytes: ByteArray): String { return MessageDigest.getInstance("SHA-256") .digest(input.toByteArray()) .fold("") { str, it -> str + "%02x".format(it) } .digest(bytes) .joinToString("") { "%02x".format(it) } } fun mapOsmTagsToDescription(properties: Map<String, String>): String { Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/data/room/RecentSearch.kt +1 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ data class RecentSearch( val timestamp = System.currentTimeMillis() return RecentSearch( id = place.id ?: UUID.randomUUID().toString(), id = if (place.id.isNullOrBlank()) UUID.randomUUID().toString() else place.id, name = place.name, description = place.description, icon = place.icon, Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/data/room/SavedPlace.kt +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ data class SavedPlace( val timestamp = System.currentTimeMillis() return SavedPlace( id = place.id ?: UUID.randomUUID().toString(), id = if (place.id.isNullOrBlank()) UUID.randomUUID().toString() else place.id, placeId = 0, customName = null, customDescription = null, Loading