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

Commit 35e8cca8 authored by Ellen Poe's avatar Ellen Poe
Browse files

feat: nearby filter chips

parent 4257b862
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ abstract class GeocodingService(private val locationRepository: LocationReposito
     * @param longitude The longitude coordinate
     * @return Place objects
     */
    suspend fun nearby(latitude: Double, longitude: Double): List<Place> {
        return convertResultsToPlaces(nearbyRaw(latitude, longitude))
    suspend fun nearby(latitude: Double, longitude: Double, selectedCategories: List<String>): List<Place> {
        return convertResultsToPlaces(nearbyRaw(latitude, longitude, selectedCategories))
    }

    /**
@@ -96,7 +96,11 @@ abstract class GeocodingService(private val locationRepository: LocationReposito
     * @param longitude The longitude coordinate
     * @return Raw nearby places
     */
    abstract suspend fun nearbyRaw(latitude: Double, longitude: Double): List<GeocodeResult>
    abstract suspend fun nearbyRaw(
        latitude: Double,
        longitude: Double,
        selectedCategories: List<String>
    ): List<GeocodeResult>
}

fun deduplicateSearchResults(results: List<GeocodeResult>): List<GeocodeResult> {
+7 −4
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import earth.maps.cardinal.data.AppPreferenceRepository
import earth.maps.cardinal.data.GeocodeResult
import earth.maps.cardinal.data.LatLng
import earth.maps.cardinal.data.LocationRepository
import kotlinx.coroutines.flow.Flow

class MultiplexedGeocodingService(
    private val appPreferenceRepository: AppPreferenceRepository,
@@ -50,11 +49,15 @@ class MultiplexedGeocodingService(
        }
    }

    override suspend fun nearbyRaw(latitude: Double, longitude: Double): List<GeocodeResult> {
    override suspend fun nearbyRaw(
        latitude: Double,
        longitude: Double,
        selectedCategories: List<String>
    ): List<GeocodeResult> {
        return if (appPreferenceRepository.offlineMode.value) {
            offlineGeocodingService.nearbyRaw(latitude, longitude)
            offlineGeocodingService.nearbyRaw(latitude, longitude, selectedCategories)
        } else {
            onlineGeocodingService.nearbyRaw(latitude, longitude)
            onlineGeocodingService.nearbyRaw(latitude, longitude, selectedCategories)
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -60,7 +60,11 @@ class OfflineGeocodingService(
        return emptyList()
    }

    override suspend fun nearbyRaw(latitude: Double, longitude: Double): List<GeocodeResult> {
    override suspend fun nearbyRaw(
        latitude: Double,
        longitude: Double,
        selectedCategories: List<String>
    ): List<GeocodeResult> {
        return emptyList()
    }

+8 −1
Original line number Diff line number Diff line
@@ -119,7 +119,11 @@ class PeliasGeocodingService(
        }
    }

    override suspend fun nearbyRaw(latitude: Double, longitude: Double): List<GeocodeResult> {
    override suspend fun nearbyRaw(
        latitude: Double,
        longitude: Double,
        selectedCategories: List<String>
    ): List<GeocodeResult> {
        try {
            Log.d(TAG, "Nearby: $latitude, $longitude")
            val config = appPreferenceRepository.peliasApiConfig.value
@@ -128,6 +132,9 @@ class PeliasGeocodingService(
                parameter("point.lon", longitude.toString())
                parameter("size", "50")
                parameter("layers", "venue")
                if (selectedCategories.isNotEmpty()) {
                    parameter("categories", selectedCategories.joinToString(","))
                }
                config.apiKey?.let { parameter("api_key", it) }
            }

+21 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
@@ -36,6 +37,7 @@ import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.FilterChip
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -44,7 +46,9 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
@@ -92,7 +96,24 @@ fun NearbyScreenContent(viewModel: NearbyViewModel, onPlaceSelected: (Place) ->
                    contentDescription = stringResource(string.refresh_nearby_places)
                )
            }
        }

        FlowRow {
            for (chipSpec in viewModel.allCategories) {
                var isSelected by remember { mutableStateOf(false) }
                FilterChip(
                    modifier = Modifier.padding(end = 8.dp),
                    selected = isSelected,
                    onClick = {
                        isSelected = !isSelected
                        viewModel.setCategorySelection(chipSpec.category, isSelected)
                    },
                    label = {
                        val label = stringResource(chipSpec.labelResource)
                        Text(text = label)
                    }
                )
            }
        }

        when {
Loading