From ea5507d1fdb2ac925e15552f2d0b1a95a554704b Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 25 Nov 2024 15:27:01 +0100 Subject: [PATCH] Add tags support in Kotlin RouteActivityHelper --- .../net/osmand/shared/gpx/RouteActivityHelper.kt | 12 +++++++++++- .../osmand/shared/gpx/primitives/RouteActivity.kt | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt index be00343dc93..877081cb40d 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt @@ -45,6 +45,15 @@ object RouteActivityHelper { return cachedActivities } + fun findActivityByTag(tag: String): RouteActivity? { + for (activity in getActivities()) { + if (activity.tags != null && activity.tags.contains(tag)) { + return activity + } + } + return null + } + fun saveRouteActivity(trackItems: Collection, routeActivity: RouteActivity?) { runAsync { trackItems.forEach { trackItem -> @@ -121,7 +130,8 @@ object RouteActivityHelper { val activityId = activityJson["id"]!!.jsonPrimitive.content val activityLabel = activityJson["label"]!!.jsonPrimitive.content val iconName = activityJson["icon_name"]!!.jsonPrimitive.content - val activity = RouteActivity(activityId, activityLabel, iconName, activitiesGroup) + val tags = activityJson["tags"]?.jsonArray?.map { it.jsonPrimitive.content }?.toSet() + val activity = RouteActivity(activityId, activityLabel, iconName, activitiesGroup, tags) cachedActivities.add(activity) activities.add(activity) } diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt index ffa8981e566..4df75a8906d 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt @@ -4,7 +4,8 @@ data class RouteActivity( val id: String, val label: String, val iconName: String, - val group: RouteActivityGroup + val group: RouteActivityGroup, + val tags: Set? = null ) { override fun toString(): String { return id