Skip to content

Commit

Permalink
Fix places without name tag shown as "Unknown"
Browse files Browse the repository at this point in the history
- Fixes issue #13 in which places without name tag are shown as "Unknown" (like parking spots).

- Adds new defaultName property to PlaceCategory to work as fallback if there is no name tag for a place. This had to be hardcoded string so that Android context would not be required to inject to utility class like ApiDataConverter.

Fixes #13
  • Loading branch information
AaroKoinsaari committed Oct 14, 2024
1 parent e82df0b commit 8d01100
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import com.aarokoinsaari.accessibilitymap.utils.PlaceCategory.Companion.mapApiTa
object ApiDataConverter {
fun convertMapMarkersToPlace(apiMarker: ApiMapMarker): Place? {
val tags = apiMarker.tags ?: return null
val name = tags["name"] ?: "Unknown"
val amenity = tags["amenity"] ?: "default"
val category = mapApiTagToCategory(amenity)
val name = tags["name"] ?: category.defaultName

return Place(
id = apiMarker.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,87 @@ import com.aarokoinsaari.accessibilitymap.R
enum class PlaceCategory(
val amenityTag: String,
@DrawableRes val iconResId: Int,
@StringRes val nameResId: Int
@StringRes val nameResId: Int,
val defaultName: String // Fallback when place does not have a name tag
) {
CAFE("cafe", R.drawable.ic_cafe, R.string.category_cafe),
RESTAURANT("restaurant", R.drawable.ic_restaurant, R.string.category_restaurant),
TOILETS("toilets", R.drawable.ic_wc, R.string.category_toilets),
BUS_STATION("bus_station", R.drawable.ic_bus_station, R.string.category_bus_station),
TRAIN_STATION("train_station", R.drawable.ic_train_station, R.string.category_train_station),
SUBWAY_STATION("subway_station", R.drawable.ic_subway_station, R.string.category_subway_station),
PARKING("parking", R.drawable.ic_parking_area, R.string.category_parking),
SUPERMARKET("supermarket", R.drawable.ic_grocery_store, R.string.category_supermarket),
SHOP("shop", R.drawable.ic_shop, R.string.category_shop),
PHARMACY("pharmacy", R.drawable.ic_pharmacy, R.string.category_pharmacy),
HOSPITAL("hospital", R.drawable.ic_hospital, R.string.category_hospital),
BEACH("beach", R.drawable.ic_beach, R.string.category_beach),
DEFAULT("default", R.drawable.ic_default_marker, R.string.category_default);
CAFE(
"cafe",
R.drawable.ic_cafe,
R.string.category_cafe,
"Cafe"
),
RESTAURANT(
"restaurant",
R.drawable.ic_restaurant,
R.string.category_restaurant,
"Restaurant"
),
TOILETS(
"toilets",
R.drawable.ic_wc,
R.string.category_toilets,
"Toilets"
),
BUS_STATION(
"bus_station",
R.drawable.ic_bus_station,
R.string.category_bus_station,
"Bus Station"
),
TRAIN_STATION(
"train_station",
R.drawable.ic_train_station,
R.string.category_train_station,
"Train Station"
),
SUBWAY_STATION(
"subway_station",
R.drawable.ic_subway_station,
R.string.category_subway_station,
"Subway Station"
),
PARKING(
"parking",
R.drawable.ic_parking_area,
R.string.category_parking,
"Parking Area"
),
SUPERMARKET(
"supermarket",
R.drawable.ic_grocery_store,
R.string.category_supermarket,
"Supermarket"
),
SHOP(
"shop",
R.drawable.ic_shop,
R.string.category_shop,
"Shop"
),
PHARMACY(
"pharmacy",
R.drawable.ic_pharmacy,
R.string.category_pharmacy,
"Pharmacy"
),
HOSPITAL(
"hospital",
R.drawable.ic_hospital,
R.string.category_hospital,
"Hospital"
),
BEACH(
"beach",
R.drawable.ic_beach,
R.string.category_beach,
"Beach"
),
DEFAULT(
"default",
R.drawable.ic_default_marker,
R.string.category_default,
"Unknown"
);

companion object {
fun mapApiTagToCategory(apiTag: String): PlaceCategory =
Expand Down

0 comments on commit 8d01100

Please sign in to comment.