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

Commit 49367ce6 authored by mitulsheth's avatar mitulsheth
Browse files

fix(favorites): removing places from the favorites

- AI code review changes
parent 41c4daa6
Loading
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -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
@@ -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,
@@ -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 {
+1 −1
Original line number Diff line number Diff line
@@ -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,
+1 −1
Original line number Diff line number Diff line
@@ -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,