mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
android: re-apply custom language when webview appears (#5022)
* android: re-apply custom language when webview appears There is a bug on Android related to including WebView. App language changes to system language regardless of what was set before in context's configuration. Re-set needed to be done twice: after creating of WebView and after removing it from a view * add link to bug --------- Co-authored-by: Evgeny <evgeny@poberezkin.com>
This commit is contained in:
committed by
GitHub
parent
ec014d721e
commit
e3528d3ffe
+1
-2
@@ -31,8 +31,7 @@ private fun Activity.applyLocale(locale: Locale) {
|
||||
Locale.setDefault(locale)
|
||||
val appConf = Configuration(androidAppContext.resources.configuration).apply { setLocale(locale) }
|
||||
val activityConf = Configuration(resources.configuration).apply { setLocale(locale) }
|
||||
@Suppress("DEPRECATION")
|
||||
androidAppContext.resources.updateConfiguration(appConf, resources.displayMetrics)
|
||||
androidAppContext = androidAppContext.createConfigurationContext(appConf)
|
||||
@Suppress("DEPRECATION")
|
||||
resources.updateConfiguration(activityConf, resources.displayMetrics)
|
||||
}
|
||||
|
||||
+14
-1
@@ -41,8 +41,10 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.*
|
||||
import androidx.webkit.WebViewAssetLoader
|
||||
import androidx.webkit.WebViewClientCompat
|
||||
import chat.simplex.common.helpers.applyAppLocale
|
||||
import chat.simplex.common.helpers.showAllowPermissionInSettingsAlert
|
||||
import chat.simplex.common.model.*
|
||||
import chat.simplex.common.model.ChatController.appPrefs
|
||||
import chat.simplex.common.platform.*
|
||||
import chat.simplex.common.ui.theme.*
|
||||
import chat.simplex.common.views.helpers.*
|
||||
@@ -702,9 +704,10 @@ fun WebRTCView(callCommand: SnapshotStateList<WCallCommand>, onResponse: (WVAPIM
|
||||
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
AndroidView(
|
||||
factory = { AndroidViewContext ->
|
||||
factory = {
|
||||
try {
|
||||
(staticWebView ?: WebView(androidAppContext)).apply {
|
||||
reapplyLocale()
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
@@ -775,6 +778,16 @@ private fun updateActiveCall(initial: Call, transform: (Call) -> Call) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Creating WebView automatically drops user's custom app locale to default system locale.
|
||||
* Preventing it by re-applying custom locale
|
||||
* https://issuetracker.google.com/issues/109833940
|
||||
* */
|
||||
private fun reapplyLocale() {
|
||||
mainActivity.get()?.applyAppLocale(appPrefs.appLanguage)
|
||||
callActivity.get()?.applyAppLocale(appPrefs.appLanguage)
|
||||
}
|
||||
|
||||
private class LocalContentWebViewClient(val webView: MutableState<WebView?>, private val assetLoader: WebViewAssetLoader) : WebViewClientCompat() {
|
||||
override fun shouldInterceptRequest(
|
||||
view: WebView,
|
||||
|
||||
Reference in New Issue
Block a user