diff --git a/app/src/main/kotlin/de/hbch/traewelling/api/models/polyline/Polyline.kt b/app/src/main/kotlin/de/hbch/traewelling/api/models/polyline/Polyline.kt index 66a11891..87bdc1fb 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/api/models/polyline/Polyline.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/api/models/polyline/Polyline.kt @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName data class Geometry( @SerializedName("type") val type: String?, - @SerializedName("coordinates") val coordinates: List>? + @SerializedName("coordinates") val coordinates: List>? ) data class Properties( diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/Map.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/Map.kt index 02750caf..1a0b9cc3 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/Map.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/Map.kt @@ -153,12 +153,15 @@ fun getPolyLinesFromFeatureCollection(featureCollection: FeatureCollection?, col feature.geometry?.coordinates?.forEach { coordinate -> polyline.addPoint( GeoPoint( - coordinate[1], - coordinate[0] + coordinate[1] ?: 0.0, + coordinate[0] ?: 0.0 ) ) } - polyLines.add(polyline) + // Skip erroneous polylines which have (0/0) as a point + if (!polyline.actualPoints.any { it.latitude == 0.0 && it.longitude == 0.0 }) { + polyLines.add(polyline) + } polyline.outlinePaint.color = color } diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt index a1865e45..4976e17d 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt @@ -87,6 +87,7 @@ fun StatusDetail( viewModelStoreOwner = LocalContext.current as ViewModelStoreOwner ) val displayTagsInCard by settingsViewModel.displayTagsInCard.observeAsState(true) + var displayMap by remember { mutableStateOf(null) } LaunchedEffect(status) { if (status == null) { @@ -112,23 +113,26 @@ fun StatusDetail( StatusDetailMap( modifier = mapModifier.align(Alignment.TopCenter), statusId = statusId, - statusDetailViewModel = statusDetailViewModel + statusDetailViewModel = statusDetailViewModel, + mapLoaded = { displayMap = it } ) - IconToggleButton( - modifier = Modifier.align(Alignment.TopEnd), - checked = mapExpanded, - onCheckedChange = { - mapExpanded = it - }, - colors = IconButtonDefaults.filledIconToggleButtonColors() - ) { - AnimatedContent(mapExpanded, label = "MapExpansionIcon") { - val iconSource = - if (it) R.drawable.ic_fullscreen_exit else R.drawable.ic_fullscreen - Icon( - painter = painterResource(id = iconSource), - contentDescription = null - ) + if (displayMap == true) { + IconToggleButton( + modifier = Modifier.align(Alignment.TopEnd), + checked = mapExpanded, + onCheckedChange = { + mapExpanded = it + }, + colors = IconButtonDefaults.filledIconToggleButtonColors() + ) { + AnimatedContent(mapExpanded, label = "MapExpansionIcon") { + val iconSource = + if (it) R.drawable.ic_fullscreen_exit else R.drawable.ic_fullscreen + Icon( + painter = painterResource(id = iconSource), + contentDescription = null + ) + } } } } @@ -161,6 +165,13 @@ fun StatusDetail( tags = status?.tags ?: listOf() ) } + if (displayMap == false) { + Text( + text = stringResource(R.string.no_map_for_check_in), + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Center + ) + } status?.likes?.let { if (it > 0) { StatusLikes( @@ -239,7 +250,8 @@ fun StatusDetail( private fun StatusDetailMap( modifier: Modifier = Modifier, statusId: Int, - statusDetailViewModel: StatusDetailViewModel + statusDetailViewModel: StatusDetailViewModel, + mapLoaded: (Boolean) -> Unit, ) { val color = PolylineColor.toArgb() val polyLines = remember { mutableStateListOf() } @@ -252,7 +264,11 @@ private fun StatusDetailMap( statusDetailViewModel.getPolylineForStatus( statusId = statusId, successfulCallback = { - polyLines.addAll(getPolyLinesFromFeatureCollection(it, color)) + val polylines = getPolyLinesFromFeatureCollection(it, color) + polyLines.addAll(polylines) + if (polylines.isEmpty()) { + mapLoaded(false) + } }, failureCallback = {} ) @@ -269,6 +285,7 @@ private fun StatusDetailMap( val bounds = getBoundingBoxFromPolyLines(polyLines) map.zoomToBoundingBox(bounds.increaseByScale(1.1f), false) + mapLoaded(true) } } diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 208aeb98..fc476e91 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -342,4 +342,5 @@ Der Dienst, der die Fahrplandaten bereitstellt, konnte nicht erreicht werden oder antwortet nicht. Bitte versuche es später erneut. Hinweis Aktuell gibt es vermehrt Probleme bei Träwelling (traewelling.de), daher ist die Funktionalität eingeschränkt. Bitte prüfe die Träwelling-Webseite. + Für diesen Check-In steht moment leider keine Kartenansicht zur Verfügung. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 805275cc..82352e61 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -370,4 +370,5 @@ Notice Currently there are ongoing service issues with Träwelling (traewelling.de). Please check the Träwelling website. traewelling.de + Currently there is no map view available for this check-in. \ No newline at end of file