From 654d3ba2af8bb49d079bdb0f387ecd5b366b3bc2 Mon Sep 17 00:00:00 2001 From: Kiryl Dzehtsiarenka Date: Fri, 8 Mar 2024 18:05:09 +0200 Subject: [PATCH] Fix attribution links not opening in some scenarios (#2301) --- CHANGELOG.md | 7 +++-- .../attribution/MapAttributionScope.kt | 29 ++++++++++--------- .../AttributionDialogManagerImpl.kt | 16 +++++----- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 748252a401..72256d00a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,14 +3,15 @@ Mapbox welcomes participation and contributions from everyone. # main -## Features ✨ and improvements 🏁 -* Added Attribution and Telemetry pop-up dialogs and compass view content description translations for Arabic, Bulgarian, Catalan, Chinese Simplified, Chinese Traditional, Czech, Danish, Dutch, French, Galician, German, Hebrew, Italian, Japanese, Korean, Lithuanian, Norwegian, Polish, Belarusian, Russian, Spanish, Swedish, Ukranian and Vietnamese. - ## Breaking changes ⚠️ * [compose] Replace `MapboxMap.compassSettings`, `MapboxMap.scaleBarSettings`, `MapboxMap.logoSettings`, `MapboxMap.attributionSettings` with composable functions in dedicated scopes: `MapCompassScope.Compass()`, `MapScaleBarScope.ScaleBar()`, `MapLogoScope.Logo()`, `MapAttributionScope.Attribution()`. +## Features ✨ and improvements 🏁 +* Added Attribution and Telemetry pop-up dialogs and compass view content description translations for Arabic, Bulgarian, Catalan, Chinese Simplified, Chinese Traditional, Czech, Danish, Dutch, French, Galician, German, Hebrew, Italian, Japanese, Korean, Lithuanian, Norwegian, Polish, Belarusian, Russian, Spanish, Swedish, Ukranian and Vietnamese. + ## Bug fixes 🐞 * [compose] Fix `ViewAnnotation` not cleared when it leaves composition. +* Fix attribution links not opening in some scenarios. # 11.2.0 February 29, 2024 ## Features ✨ and improvements 🏁 diff --git a/extension-compose/src/main/java/com/mapbox/maps/extension/compose/ornaments/attribution/MapAttributionScope.kt b/extension-compose/src/main/java/com/mapbox/maps/extension/compose/ornaments/attribution/MapAttributionScope.kt index f372d95070..6308e7cc15 100644 --- a/extension-compose/src/main/java/com/mapbox/maps/extension/compose/ornaments/attribution/MapAttributionScope.kt +++ b/extension-compose/src/main/java/com/mapbox/maps/extension/compose/ornaments/attribution/MapAttributionScope.kt @@ -1,6 +1,5 @@ package com.mapbox.maps.extension.compose.ornaments.attribution -import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.net.Uri @@ -334,18 +333,22 @@ public class MapAttributionScope internal constructor( } private fun showWebPage(url: String) { - if (mapView.context is Activity) { - try { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(url) - mapView.context.startActivity(intent) - } catch (exception: ActivityNotFoundException) { // explicitly handling if the device hasn't have a web browser installed. #8899 - Toast.makeText( - mapView.context, - R.string.mapbox_attributionErrorNoBrowser, - Toast.LENGTH_LONG - ).show() - } + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + mapView.context.startActivity(intent) + } catch (exception: ActivityNotFoundException) { + Toast.makeText( + mapView.context, + R.string.mapbox_attributionErrorNoBrowser, + Toast.LENGTH_LONG + ).show() + } catch (t: Throwable) { + Toast.makeText( + mapView.context, + t.localizedMessage, + Toast.LENGTH_LONG + ).show() } } diff --git a/plugin-attribution/src/main/java/com/mapbox/maps/plugin/attribution/AttributionDialogManagerImpl.kt b/plugin-attribution/src/main/java/com/mapbox/maps/plugin/attribution/AttributionDialogManagerImpl.kt index 5a2b56f816..5e3ebb8882 100644 --- a/plugin-attribution/src/main/java/com/mapbox/maps/plugin/attribution/AttributionDialogManagerImpl.kt +++ b/plugin-attribution/src/main/java/com/mapbox/maps/plugin/attribution/AttributionDialogManagerImpl.kt @@ -148,14 +148,14 @@ class AttributionDialogManagerImpl( } private fun showWebPage(url: String) { - if (context is Activity) { - try { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(url) - context.startActivity(intent) - } catch (exception: ActivityNotFoundException) { // explicitly handling if the device hasn't have a web browser installed. #8899 - Toast.makeText(context, R.string.mapbox_attributionErrorNoBrowser, Toast.LENGTH_LONG).show() - } + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + context.applicationContext.startActivity(intent) + } catch (exception: ActivityNotFoundException) { + Toast.makeText(context, R.string.mapbox_attributionErrorNoBrowser, Toast.LENGTH_LONG).show() + } catch (t: Throwable) { + Toast.makeText(context, t.localizedMessage, Toast.LENGTH_LONG).show() } }