diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a3c25fa9d..2df9bdbc0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,34 +1,34 @@ -name: Quality check - -on: - push: - branches: - - develop - -# TODO TLAD run `flutter format -l 1000 .` and fail if any - -jobs: - build: - name: Check code quality. - runs-on: ubuntu-latest - steps: - - uses: subosito/flutter-action@v1 - with: - channel: stable - flutter-version: '2.0.1' - - - name: Clone the repository. - uses: actions/checkout@v2 - - - name: Get packages for the Flutter project. - run: flutter pub get - - - name: Update the flutter version file. - working-directory: ${{ github.workspace }}/scripts - run: ./update_flutter_version.sh - - - name: Static analysis. - run: flutter analyze - - - name: Unit tests. - run: flutter test +#name: Quality check +# +#on: +# push: +# branches: +# - develop +# +## TODO TLAD run `flutter format -l 1000 .` and fail if any +# +#jobs: +# build: +# name: Check code quality. +# runs-on: ubuntu-latest +# steps: +# - uses: subosito/flutter-action@v1 +# with: +# channel: stable +# flutter-version: '2.0.1' +# +# - name: Clone the repository. +# uses: actions/checkout@v2 +# +# - name: Get packages for the Flutter project. +# run: flutter pub get +# +# - name: Update the flutter version file. +# working-directory: ${{ github.workspace }}/scripts +# run: ./update_flutter_version.sh +# +# - name: Static analysis. +# run: flutter analyze +# +# - name: Unit tests. +# run: flutter test diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/GeocodingHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/GeocodingHandler.kt index 245b727bd..874c32d97 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/GeocodingHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/GeocodingHandler.kt @@ -1,7 +1,6 @@ package deckers.thibault.aves.channel.calls import android.content.Context -import android.location.Address import android.location.Geocoder import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel @@ -9,6 +8,7 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import java.util.* // as of 2021/03/10, geocoding packages exist but: // - `geocoder` is unmaintained @@ -26,6 +26,7 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler { private fun getAddress(call: MethodCall, result: MethodChannel.Result) { val latitude = call.argument("latitude")?.toDouble() val longitude = call.argument("longitude")?.toDouble() + val localeString = call.argument("locale") val maxResults = call.argument("maxResults") ?: 1 if (latitude == null || longitude == null) { result.error("getAddress-args", "failed because of missing arguments", null) @@ -37,9 +38,17 @@ class GeocodingHandler(private val context: Context) : MethodCallHandler { return } - geocoder = geocoder ?: Geocoder(context) + geocoder = geocoder ?: if (localeString != null) { + val split = localeString.split("_") + val language = split[0] + val country = if (split.size > 1) split[1] else "" + Geocoder(context, Locale(language, country)) + } else { + Geocoder(context) + } + val addresses = try { - geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList
() + geocoder!!.getFromLocation(latitude, longitude, maxResults) ?: ArrayList() } catch (e: Exception) { result.error("getAddress-exception", "failed to get address", e.message) return diff --git a/lib/model/entry.dart b/lib/model/entry.dart index cc9da0b26..3c9655ba6 100644 --- a/lib/model/entry.dart +++ b/lib/model/entry.dart @@ -7,6 +7,7 @@ import 'package:aves/model/favourite_repo.dart'; import 'package:aves/model/metadata.dart'; import 'package:aves/model/metadata_db.dart'; import 'package:aves/model/multipage.dart'; +import 'package:aves/model/settings/settings.dart'; import 'package:aves/services/geocoding_service.dart'; import 'package:aves/services/image_file_service.dart'; import 'package:aves/services/metadata_service.dart'; @@ -475,11 +476,18 @@ class AvesEntry { ); } + String _geocoderLocale; + + String get geocoderLocale { + _geocoderLocale ??= (settings.locale ?? WidgetsBinding.instance.window.locale).toString(); + return _geocoderLocale; + } + // full reverse geocoding, requiring Play Services and some connectivity Future locatePlace({@required bool background}) async { if (!hasGps || hasFineAddress) return; try { - Future> call() => GeocodingService.getAddress(latLng); + Future> call() => GeocodingService.getAddress(latLng, geocoderLocale); final addresses = await (background ? servicePolicy.call( call, @@ -510,7 +518,7 @@ class AvesEntry { if (!hasGps) return null; try { - final addresses = await GeocodingService.getAddress(latLng); + final addresses = await GeocodingService.getAddress(latLng, geocoderLocale); if (addresses != null && addresses.isNotEmpty) { final address = addresses.first; return address.addressLine; diff --git a/lib/services/geocoding_service.dart b/lib/services/geocoding_service.dart index f66759643..66612e96e 100644 --- a/lib/services/geocoding_service.dart +++ b/lib/services/geocoding_service.dart @@ -2,17 +2,19 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; import 'package:latlong/latlong.dart'; class GeocodingService { static const platform = MethodChannel('deckers.thibault/aves/geocoding'); // geocoding requires Google Play Services - static Future> getAddress(LatLng coordinates) async { + static Future> getAddress(LatLng coordinates, String locale) async { try { final result = await platform.invokeMethod('getAddress', { 'latitude': coordinates.latitude, 'longitude': coordinates.longitude, + 'locale': locale, }); return (result as List).cast().map((map) => Address.fromMap(map)).toList(); } on PlatformException catch (e) {