mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Create SystemLocaleProvider
This commit is contained in:
parent
8ac2cb0530
commit
a00ddca188
5 changed files with 56 additions and 29 deletions
|
@ -33,9 +33,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.fragment.app.Fragment
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.features.notifications.NotificationUtils
|
||||
import im.vector.riotx.features.settings.VectorLocale
|
||||
import timber.log.Timber
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Tells if the application ignores battery optimizations.
|
||||
|
@ -94,24 +91,6 @@ fun copyToClipboard(context: Context, text: CharSequence, showToast: Boolean = t
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the device locale
|
||||
*
|
||||
* @return the device locale
|
||||
*/
|
||||
fun getDeviceLocale(context: Context): Locale {
|
||||
return try {
|
||||
val packageManager = context.packageManager
|
||||
val resources = packageManager.getResourcesForApplication("android")
|
||||
@Suppress("DEPRECATION")
|
||||
resources.configuration.locale
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## getDeviceLocale() failed")
|
||||
// Fallback to application locale
|
||||
VectorLocale.applicationLocale
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows notification settings for the current app.
|
||||
* In android O will directly opens the notification settings, in lower version it will show the App settings
|
||||
|
|
|
@ -31,9 +31,9 @@ import im.vector.riotx.BuildConfig
|
|||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
import im.vector.riotx.core.extensions.toOnOff
|
||||
import im.vector.riotx.core.utils.getDeviceLocale
|
||||
import im.vector.riotx.features.settings.VectorLocale
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import im.vector.riotx.features.settings.locale.SystemLocaleProvider
|
||||
import im.vector.riotx.features.themes.ThemeUtils
|
||||
import im.vector.riotx.features.version.VersionProvider
|
||||
import okhttp3.Call
|
||||
|
@ -58,10 +58,13 @@ import javax.inject.Singleton
|
|||
* BugReporter creates and sends the bug reports.
|
||||
*/
|
||||
@Singleton
|
||||
class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val versionProvider: VersionProvider,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val vectorFileLogger: VectorFileLogger) {
|
||||
class BugReporter @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val versionProvider: VersionProvider,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val vectorFileLogger: VectorFileLogger,
|
||||
private val systemLocaleProvider: SystemLocaleProvider
|
||||
) {
|
||||
var inMultiWindowMode = false
|
||||
|
||||
companion object {
|
||||
|
@ -240,7 +243,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes
|
|||
+ Build.VERSION.INCREMENTAL + "-" + Build.VERSION.CODENAME)
|
||||
.addFormDataPart("locale", Locale.getDefault().toString())
|
||||
.addFormDataPart("app_language", VectorLocale.applicationLocale.toString())
|
||||
.addFormDataPart("default_app_language", getDeviceLocale(context).toString())
|
||||
.addFormDataPart("default_app_language", systemLocaleProvider.getSystemLocale().toString())
|
||||
.addFormDataPart("theme", ThemeUtils.getApplicationTheme(context))
|
||||
|
||||
val buildNumber = context.getString(R.string.build_number)
|
||||
|
|
|
@ -60,7 +60,7 @@ class LocalePickerController @Inject constructor(
|
|||
title(stringProvider.getString(R.string.choose_locale_other_locales_title))
|
||||
}
|
||||
list
|
||||
.filter { it != data.currentLocale }
|
||||
.filter { it.toString() != data.currentLocale.toString() }
|
||||
.forEach {
|
||||
localeItem {
|
||||
id(it.toString())
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
package im.vector.riotx.features.settings.locale
|
||||
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import im.vector.riotx.features.settings.VectorLocale
|
||||
import java.util.Locale
|
||||
|
||||
data class LocalePickerViewState(
|
||||
val currentLocale: Locale = Locale.getDefault(),
|
||||
val currentLocale: Locale = VectorLocale.applicationLocale,
|
||||
val locales: List<Locale> = emptyList()
|
||||
) : MvRxState
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.settings.locale
|
||||
|
||||
import android.content.Context
|
||||
import timber.log.Timber
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class SystemLocaleProvider @Inject constructor(
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
/**
|
||||
* Provides the device locale
|
||||
*
|
||||
* @return the device locale, or null in case of error
|
||||
*/
|
||||
fun getSystemLocale(): Locale? {
|
||||
return try {
|
||||
val packageManager = context.packageManager
|
||||
val resources = packageManager.getResourcesForApplication("android")
|
||||
@Suppress("DEPRECATION")
|
||||
resources.configuration.locale
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## getDeviceLocale() failed")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue