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]
|
## <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
|
## <a id="v1.11.18"></a>[v1.11.18] - 2024-11-18
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package deckers.thibault.aves.channel.calls
|
package deckers.thibault.aves.channel.calls
|
||||||
|
|
||||||
|
import android.app.LocaleConfig
|
||||||
|
import android.app.LocaleManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.location.Geocoder
|
import android.location.Geocoder
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.LocaleList
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
|
@ -32,6 +35,7 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
|
||||||
"getCapabilities" -> defaultScope.launch { safe(call, result, ::getCapabilities) }
|
"getCapabilities" -> defaultScope.launch { safe(call, result, ::getCapabilities) }
|
||||||
"getDefaultTimeZoneRawOffsetMillis" -> safe(call, result, ::getDefaultTimeZoneRawOffsetMillis)
|
"getDefaultTimeZoneRawOffsetMillis" -> safe(call, result, ::getDefaultTimeZoneRawOffsetMillis)
|
||||||
"getLocales" -> safe(call, result, ::getLocales)
|
"getLocales" -> safe(call, result, ::getLocales)
|
||||||
|
"setLocaleConfig" -> safe(call, result, ::setLocaleConfig)
|
||||||
"getPerformanceClass" -> safe(call, result, ::getPerformanceClass)
|
"getPerformanceClass" -> safe(call, result, ::getPerformanceClass)
|
||||||
"isLocked" -> safe(call, result, ::isLocked)
|
"isLocked" -> safe(call, result, ::isLocked)
|
||||||
"isSystemFilePickerEnabled" -> safe(call, result, ::isSystemFilePickerEnabled)
|
"isSystemFilePickerEnabled" -> safe(call, result, ::isSystemFilePickerEnabled)
|
||||||
|
@ -88,6 +92,21 @@ class DeviceHandler(private val context: Context) : MethodCallHandler {
|
||||||
result.success(locales)
|
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) {
|
private fun getPerformanceClass(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
val performanceClass = Build.VERSION.MEDIA_PERFORMANCE_CLASS
|
val performanceClass = Build.VERSION.MEDIA_PERFORMANCE_CLASS
|
||||||
|
|
|
@ -12,6 +12,8 @@ abstract class DeviceService {
|
||||||
|
|
||||||
Future<List<Locale>> getLocales();
|
Future<List<Locale>> getLocales();
|
||||||
|
|
||||||
|
Future<void> setLocaleConfig(List<Locale> locales);
|
||||||
|
|
||||||
Future<int> getPerformanceClass();
|
Future<int> getPerformanceClass();
|
||||||
|
|
||||||
Future<bool> isLocked();
|
Future<bool> isLocked();
|
||||||
|
@ -80,6 +82,17 @@ class PlatformDeviceService implements DeviceService {
|
||||||
return [];
|
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
|
@override
|
||||||
Future<int> getPerformanceClass() async {
|
Future<int> getPerformanceClass() async {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -502,6 +502,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
|
||||||
_monitorSettings();
|
_monitorSettings();
|
||||||
videoControllerFactory.init();
|
videoControllerFactory.init();
|
||||||
|
|
||||||
|
unawaited(deviceService.setLocaleConfig(AvesApp.supportedLocales));
|
||||||
unawaited(storageService.deleteTempDirectory());
|
unawaited(storageService.deleteTempDirectory());
|
||||||
unawaited(_setupErrorReporting());
|
unawaited(_setupErrorReporting());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue