integrate with OS app language settings on Android >=14
This commit is contained in:
parent
0dee00dbca
commit
2f5e959fb0
4 changed files with 37 additions and 0 deletions
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
## <a id="unreleased"></a>[Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- integrate with OS app language settings on Android >=14
|
||||
|
||||
## <a id="v1.11.18"></a>[v1.11.18] - 2024-11-18
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package deckers.thibault.aves.channel.calls
|
||||
|
||||
import android.app.LocaleConfig
|
||||
import android.app.LocaleManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.location.Geocoder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import android.provider.MediaStore
|
||||
import android.provider.Settings
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
|
@ -32,6 +35,7 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
|
|||
"getCapabilities" -> defaultScope.launch { safe(call, result, ::getCapabilities) }
|
||||
"getDefaultTimeZoneRawOffsetMillis" -> safe(call, result, ::getDefaultTimeZoneRawOffsetMillis)
|
||||
"getLocales" -> safe(call, result, ::getLocales)
|
||||
"setLocaleConfig" -> safe(call, result, ::setLocaleConfig)
|
||||
"getPerformanceClass" -> safe(call, result, ::getPerformanceClass)
|
||||
"isLocked" -> safe(call, result, ::isLocked)
|
||||
"isSystemFilePickerEnabled" -> safe(call, result, ::isSystemFilePickerEnabled)
|
||||
|
@ -88,6 +92,21 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
|
|||
result.success(locales)
|
||||
}
|
||||
|
||||
private fun setLocaleConfig(call: MethodCall, result: MethodChannel.Result) {
|
||||
val locales = call.argument<List<String>>("locales")
|
||||
if (locales.isNullOrEmpty()) {
|
||||
result.error("setLocaleConfig-args", "missing arguments", null)
|
||||
return
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
val lm = context.getSystemService(Context.LOCALE_SERVICE) as? LocaleManager
|
||||
lm?.overrideLocaleConfig = LocaleConfig(LocaleList.forLanguageTags(locales.joinToString(",")))
|
||||
}
|
||||
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
private fun getPerformanceClass(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val performanceClass = Build.VERSION.MEDIA_PERFORMANCE_CLASS
|
||||
|
|
|
@ -12,6 +12,8 @@ abstract class DeviceService {
|
|||
|
||||
Future<List<Locale>> getLocales();
|
||||
|
||||
Future<void> setLocaleConfig(List<Locale> locales);
|
||||
|
||||
Future<int> getPerformanceClass();
|
||||
|
||||
Future<bool> isLocked();
|
||||
|
@ -80,6 +82,17 @@ class PlatformDeviceService implements DeviceService {
|
|||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setLocaleConfig(List<Locale> locales) async {
|
||||
try {
|
||||
await _platform.invokeMethod('setLocaleConfig', <String, dynamic>{
|
||||
'locales': locales.map((v) => v.toLanguageTag()).toList(),
|
||||
});
|
||||
} on PlatformException catch (e, stack) {
|
||||
await reportService.recordError(e, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> getPerformanceClass() async {
|
||||
try {
|
||||
|
|
|
@ -502,6 +502,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
|||
_monitorSettings();
|
||||
videoControllerFactory.init();
|
||||
|
||||
unawaited(deviceService.setLocaleConfig(AvesApp.supportedLocales));
|
||||
unawaited(storageService.deleteTempDirectory());
|
||||
unawaited(_setupErrorReporting());
|
||||
|
||||
|
|
Loading…
Reference in a new issue