Skip to content

Commit 1f79a45

Browse files
committed
Update mapbox sdk version and add localization plugin(Fixed commons-app#2335)
Update mapbox sdk version to 7.1.2 and add localization plugin. With this change the nearby map can display place labels in android system language which can be changed by the user.
1 parent 00b95ea commit 1f79a45

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ dependencies {
3333
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
3434
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
3535
implementation 'com.github.pedrovgs:renderers:3.3.3'
36-
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.8.0'
36+
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.1.2'
37+
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.8.0'
3738
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
3839
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
3940
implementation 'com.karumi:dexter:5.0.0'

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
4343
import com.mapbox.mapboxsdk.camera.CameraPosition;
4444
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
45-
import com.mapbox.mapboxsdk.constants.Style;
4645
import com.mapbox.mapboxsdk.geometry.LatLng;
4746
import com.mapbox.mapboxsdk.maps.MapView;
4847
import com.mapbox.mapboxsdk.maps.MapboxMap;
4948
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
49+
import com.mapbox.mapboxsdk.maps.Style;
50+
import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin;
5051

5152
import java.lang.reflect.Type;
5253
import java.util.ArrayList;
@@ -517,7 +518,6 @@ private void setupMapView(Bundle savedInstanceState) {
517518
MapboxMapOptions options = new MapboxMapOptions()
518519
.compassGravity(Gravity.BOTTOM | Gravity.LEFT)
519520
.compassMargins(new int[]{12, 0, 0, 24})
520-
.styleUrl(Style.OUTDOORS)
521521
.logoEnabled(false)
522522
.attributionEnabled(false)
523523
.camera(new CameraPosition.Builder()
@@ -531,10 +531,20 @@ private void setupMapView(Bundle savedInstanceState) {
531531
mapView.onCreate(savedInstanceState);
532532
mapView.getMapAsync(mapboxMap -> {
533533
NearbyMapFragment.this.mapboxMap = mapboxMap;
534+
535+
mapboxMap.setStyle(Style.OUTDOORS,
536+
(Style style) -> {
537+
LocalizationPlugin localizationPlugin = new LocalizationPlugin(mapView, mapboxMap, mapboxMap.getStyle());
538+
try {
539+
localizationPlugin.matchMapLanguageWithDeviceDefault();
540+
} catch (RuntimeException exception) {
541+
Timber.d("mapbox set localization failed: " + exception.toString());
542+
}
543+
});
544+
534545
addMapMovementListeners();
535546
updateMapSignificantlyForCurrentLocation();
536547
});
537-
mapView.setStyleUrl("asset://mapstyle.json");
538548
}
539549
}
540550

0 commit comments

Comments
 (0)