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

Commit 41c4daa6 authored by mitulsheth's avatar mitulsheth
Browse files

fix(favorites): removing places from the favorites

- There was inconsistent place id
parent 6b327bb8
Loading
Loading
Loading
Loading
Loading
+9 −0
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.security.MessageDigest
import javax.inject.Inject
import javax.inject.Singleton

@@ -464,7 +465,10 @@ 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)
        return Place(
            id = deterministicId,
            name = result.displayName,
            description = mapOsmTagsToDescription(result.properties),
            icon = "search",
@@ -476,6 +480,11 @@ class LocationRepository @Inject constructor(
            openingHours = openingHours,
        )
    }
    private fun generateStableId(input: String): String {
        return MessageDigest.getInstance("SHA-256")
            .digest(input.toByteArray())
            .fold("") { str, it -> str + "%02x".format(it) }
    }

    fun mapOsmTagsToDescription(properties: Map<String, String>): String {
        Log.d("LocationRepository", "$properties")
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ data class RecentSearch(
            val timestamp = System.currentTimeMillis()

            return RecentSearch(
                id = UUID.randomUUID().toString(),
                id = place.id ?: UUID.randomUUID().toString(),
                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 = UUID.randomUUID().toString(),
                id = place.id ?: UUID.randomUUID().toString(),
                placeId = 0,
                customName = null,
                customDescription = null,