Create VectorLocaleProvider, to just read the current Locale from the SharedPreference

This commit is contained in:
Benoit Marty 2022-09-16 15:20:23 +02:00 committed by Benoit Marty
parent d8436874e2
commit 0324927b04
13 changed files with 66 additions and 26 deletions

View file

@ -84,7 +84,7 @@ import im.vector.app.features.rageshake.RageShake
import im.vector.app.features.session.SessionListener
import im.vector.app.features.settings.FontScalePreferences
import im.vector.app.features.settings.FontScalePreferencesImpl
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.themes.ActivityOtherThemes
import im.vector.app.features.themes.ThemeUtils
@ -156,7 +156,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
@Inject lateinit var rageShake: RageShake
@Inject lateinit var buildMeta: BuildMeta
@Inject lateinit var fontScalePreferences: FontScalePreferences
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var vectorLocale: VectorLocaleProvider
// For debug only
@Inject lateinit var debugReceiver: DebugReceiver
@ -178,8 +178,10 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
private val restorables = ArrayList<Restorable>()
override fun attachBaseContext(base: Context) {
val fontScalePreferences = FontScalePreferencesImpl(PreferenceManager.getDefaultSharedPreferences(base), AndroidSystemSettingsProvider(base))
val vectorConfiguration = VectorConfiguration(this, fontScalePreferences, vectorLocale)
val preferences = PreferenceManager.getDefaultSharedPreferences(base)
val fontScalePreferences = FontScalePreferencesImpl(preferences, AndroidSystemSettingsProvider(base))
val vectorLocaleProvider = VectorLocaleProvider(preferences)
val vectorConfiguration = VectorConfiguration(this, fontScalePreferences, vectorLocaleProvider)
super.attachBaseContext(vectorConfiguration.getLocalisedContext(base))
}

View file

@ -25,7 +25,7 @@ import im.vector.app.core.utils.toBase32String
import im.vector.app.features.call.conference.jwt.JitsiJWTFactory
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.raw.wellknown.getElementWellknown
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.themes.ThemeProvider
import okhttp3.Request
import org.jitsi.meet.sdk.JitsiMeetUserInfo
@ -49,7 +49,7 @@ class JitsiService @Inject constructor(
private val themeProvider: ThemeProvider,
private val jitsiJWTFactory: JitsiJWTFactory,
private val clock: Clock,
private val vectorLocale: VectorLocale,
private val vectorLocale: VectorLocaleProvider,
) {
companion object {

View file

@ -25,7 +25,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.addChildFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetCallDialPadBinding
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import javax.inject.Inject
@AndroidEntryPoint
@ -44,7 +44,7 @@ class CallDialPadBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetCa
}
}
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var vectorLocale: VectorLocaleProvider
override val showExpanded = true

View file

@ -28,7 +28,6 @@ import im.vector.app.core.extensions.addFragment
import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.createdirect.DirectRoomHelper
import im.vector.app.features.settings.VectorLocale
import im.vector.lib.ui.styles.dialogs.MaterialProgressDialog
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session

View file

@ -22,13 +22,13 @@ import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.features.call.dialpad.DialPadFragment
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.userdirectory.UserListFragment
import im.vector.app.features.userdirectory.UserListFragmentArgs
class CallTransferPagerAdapter(
private val fragmentActivity: FragmentActivity,
private val vectorLocale: VectorLocale,
private val vectorLocale: VectorLocaleProvider,
) : FragmentStateAdapter(fragmentActivity) {
companion object {

View file

@ -22,7 +22,7 @@ import android.os.Build
import android.os.LocaleList
import androidx.annotation.RequiresApi
import im.vector.app.features.settings.FontScalePreferences
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.themes.ThemeUtils
import timber.log.Timber
import java.util.Locale
@ -34,7 +34,7 @@ import javax.inject.Inject
class VectorConfiguration @Inject constructor(
private val context: Context,
private val fontScalePreferences: FontScalePreferences,
private val vectorLocale: VectorLocale,
private val vectorLocale: VectorLocaleProvider,
) {
fun onConfigurationChanged() {

View file

@ -29,7 +29,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.hidePassword
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentKeysBackupSetupStep2Binding
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
@ -44,7 +44,7 @@ class KeysBackupSetupStep2Fragment :
private val zxcvbn = Zxcvbn()
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var vectorLocale: VectorLocaleProvider
private fun onPassphraseChanged() {
viewModel.passphrase.value = views.keysBackupSetupStep2PassphraseEnterEdittext.text.toString()

View file

@ -28,7 +28,7 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentBootstrapEnterPassphraseBinding
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.lib.core.utils.flow.throttleFirst
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -44,7 +44,7 @@ class BootstrapEnterPassphraseFragment :
return FragmentBootstrapEnterPassphraseBinding.inflate(inflater, container, false)
}
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var vectorLocale: VectorLocaleProvider
val sharedViewModel: BootstrapSharedViewModel by parentFragmentViewModel()

View file

@ -51,7 +51,7 @@ import im.vector.app.features.home.room.list.RoomListParams
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.popup.VerificationVectorAlert
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.VectorSettingsActivity.Companion.EXTRA_DIRECT_ACCESS_SECURITY_PRIVACY_MANAGE_SESSIONS
import im.vector.app.features.themes.ThemeUtils
@ -75,7 +75,7 @@ class HomeDetailFragment :
@Inject lateinit var callManager: WebRtcCallManager
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var spaceStateHandler: SpaceStateHandler
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var vectorLocale: VectorLocaleProvider
private val viewModel: HomeDetailViewModel by fragmentViewModel()
private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel()

View file

@ -19,7 +19,6 @@
package im.vector.app.features.notifications
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager

View file

@ -31,7 +31,7 @@ import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.getAllChildFragments
import im.vector.app.core.extensions.toOnOff
import im.vector.app.core.resources.BuildMeta
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorLocaleProvider
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.devtools.GossipingEventsSerializer
import im.vector.app.features.settings.locale.SystemLocaleProvider
@ -80,7 +80,7 @@ class BugReporter @Inject constructor(
private val buildMeta: BuildMeta,
private val processInfo: ProcessInfo,
private val sdkIntProvider: BuildVersionSdkIntProvider,
private val vectorLocale: VectorLocale,
private val vectorLocale: VectorLocaleProvider,
) {
var inMultiWindowMode = false

View file

@ -39,16 +39,15 @@ class VectorLocale @Inject constructor(
private val buildMeta: BuildMeta,
) {
companion object {
private const val APPLICATION_LOCALE_COUNTRY_KEY = "APPLICATION_LOCALE_COUNTRY_KEY"
private const val APPLICATION_LOCALE_VARIANT_KEY = "APPLICATION_LOCALE_VARIANT_KEY"
private const val APPLICATION_LOCALE_LANGUAGE_KEY = "APPLICATION_LOCALE_LANGUAGE_KEY"
const val APPLICATION_LOCALE_COUNTRY_KEY = "APPLICATION_LOCALE_COUNTRY_KEY"
const val APPLICATION_LOCALE_VARIANT_KEY = "APPLICATION_LOCALE_VARIANT_KEY"
const val APPLICATION_LOCALE_LANGUAGE_KEY = "APPLICATION_LOCALE_LANGUAGE_KEY"
private const val APPLICATION_LOCALE_SCRIPT_KEY = "APPLICATION_LOCALE_SCRIPT_KEY"
private const val ISO_15924_LATN = "Latn"
}
private val defaultLocale = Locale("en", "US")
/**
* The cache of supported application languages.
*/

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 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.app.features.settings
import android.content.SharedPreferences
import im.vector.app.core.di.DefaultPreferences
import java.util.Locale
import javax.inject.Inject
/**
* Class to provide the Locale choice of the user.
*/
class VectorLocaleProvider @Inject constructor(
@DefaultPreferences
private val preferences: SharedPreferences,
) {
/**
* Get the current local.
* SharedPref values has been initialized in [VectorLocale.init]
*/
val applicationLocale: Locale
get() = Locale(
preferences.getString(VectorLocale.APPLICATION_LOCALE_LANGUAGE_KEY, "")!!,
preferences.getString(VectorLocale.APPLICATION_LOCALE_COUNTRY_KEY, "")!!,
preferences.getString(VectorLocale.APPLICATION_LOCALE_VARIANT_KEY, "")!!
)
}