From 02074cd2071881af35f1063fb6f0738e9af4dec4 Mon Sep 17 00:00:00 2001 From: Azamat Cherchesov Date: Mon, 22 Jan 2024 17:16:37 +0300 Subject: [PATCH] ISSUE-389: returned fix for st-Lant screenshots (#622) --- .../kaspresso/device/languages/LanguageImpl.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt index f923ecf0b..7260644c0 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt @@ -49,6 +49,24 @@ class LanguageImpl( ConfigurationCompat.getLocales(instrumentation.targetContext.resources.configuration).get(0) private fun applyCurrentLocaleToContext(locale: Locale) { + // For issue DocLocScreenshotTestCase does not change locale to sr-Latn-RS: https://github.com/KasperskyLab/Kaspresso/issues/389 + // added hotfix. For next releases we will find more correct solution. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (locale.country.equals("Latn", true) && + locale.language.equals("sr", true) + ) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + val localeManager = instrumentation.targetContext.getSystemService(Context.LOCALE_SERVICE) as LocaleManager + localeManager.applicationLocales = LocaleList.forLanguageTags(Locale.Builder().setLanguage("sr").setScript("Latn").build().toLanguageTag()) + } else { + Handler(instrumentation.targetContext.mainLooper).post { + AppCompatDelegate.setApplicationLocales(LocaleListCompat.create(Locale.Builder().setLanguage("sr").setScript("Latn").build())) + } + } + return + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val localeManager = instrumentation.targetContext.getSystemService(Context.LOCALE_SERVICE) as LocaleManager localeManager.applicationLocales = LocaleList.forLanguageTags(locale.toLanguageTag())