Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78729699 authored by mitulsheth's avatar mitulsheth
Browse files

fix(favorites): removing places from the favorites

- Using geocodeId for online place search and using foll back option for offline
- Code review changes
parent 0d5d8e2c
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ package earth.maps.cardinal.data
import kotlin.math.abs

data class GeocodeResult(
    val gId: String,
    val geocodeId: String,
    val latitude: Double,
    val longitude: Double,
    val displayName: String,
+1 −1
Original line number Diff line number Diff line
@@ -466,7 +466,7 @@ class LocationRepository @Inject constructor(
        val openingHours = result.properties["opening_hours"]

        return Place(
            id = result.gId,
            id = result.geocodeId,
            name = result.displayName,
            description = mapOsmTagsToDescription(result.properties),
            icon = "search",
+19 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import java.nio.ByteBuffer
import java.security.MessageDigest

/**
 * * A utility for generating deterministic, stable identifiers for geographical places.
 * A utility for generating deterministic, stable identifiers for geographical places.
 *
 * This generator uses a combination of coordinates and the place's display name to create
 * a SHA-256 hash. Using raw byte buffers for coordinates ensures that the ID remains
@@ -57,6 +57,24 @@ object PlaceIdGenerator {
        return hashBytesToHex(buffer.array())
    }

    /**
     * Returns a stable identifier for the given [place].
     *
     * If the [place] already contains a valid ID (e.g., from an online provider like Pelias),
     * that ID is returned. If the ID is null or blank (common with offline geocoding results),
     * a deterministic ID is generated based on the place's coordinates and name.
     *
     * @param place The place object to get or generate an ID for.
     * @return The existing ID if present, otherwise a generated SHA-256 hex string.
     */
    fun generateId(place: Place): String {
        return if (place.id.isNullOrBlank()) generateId(
            latitude = place.latLng.latitude,
            longitude = place.latLng.longitude,
            name = place.name
        ) else place.id
    }

    /**
     * Hashes a byte array using SHA-256 and converts it to a hex string.
     *
+1 −7
Original line number Diff line number Diff line
@@ -45,14 +45,8 @@ data class RecentSearch(
        fun fromPlace(place: Place): RecentSearch {
            val timestamp = System.currentTimeMillis()

            val deterministicId = if (place.id.isNullOrBlank()) PlaceIdGenerator.generateId(
                latitude = place.latLng.latitude,
                longitude = place.latLng.longitude,
                name = place.name
            ) else place.id

            return RecentSearch(
                id = deterministicId,
                id = PlaceIdGenerator.generateId(place),
                name = place.name,
                description = place.description,
                icon = place.icon,
+1 −6
Original line number Diff line number Diff line
@@ -53,13 +53,8 @@ data class SavedPlace(
    companion object {
        fun fromPlace(place: Place): SavedPlace {
            val timestamp = System.currentTimeMillis()
            val deterministicId = if (place.id.isNullOrBlank()) PlaceIdGenerator.generateId(
                latitude = place.latLng.latitude,
                longitude = place.latLng.longitude,
                name = place.name
            ) else place.id
            return SavedPlace(
                id = deterministicId,
                id = PlaceIdGenerator.generateId(place),
                placeId = 0,
                customName = null,
                customDescription = null,
Loading