diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/UserFlagsProviderHelper.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/UserFlagsProviderHelper.kt index 5d8a75087824..747a7cefeca9 100644 --- a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/UserFlagsProviderHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/UserFlagsProviderHelper.kt @@ -8,14 +8,12 @@ import org.wordpress.android.localcontentmigration.LocalContentEntityData.UserFl import org.wordpress.android.ui.prefs.AppPrefs.DeletablePrefKey import org.wordpress.android.ui.prefs.AppPrefs.UndeletablePrefKey import org.wordpress.android.ui.prefs.AppPrefsWrapper -import org.wordpress.android.util.LocaleManagerWrapper import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject class UserFlagsProviderHelper @Inject constructor( private val appPrefsWrapper: AppPrefsWrapper, contextProvider: ContextProvider, - localeManagerWrapper: LocaleManagerWrapper ) : LocalDataProviderHelper { override fun getData(localEntityId: Int?): LocalContentEntityData = UserFlagsData( @@ -73,6 +71,5 @@ class UserFlagsProviderHelper @Inject constructor( contextProvider.getContext().getString(R.string.pref_key_app_theme), contextProvider.getContext().getString(R.string.pref_key_initial_screen), contextProvider.getContext().getString(R.string.pref_key_send_crash), - localeManagerWrapper.getLocalePrefKeyString() ) } diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt index 9fb71953e684..1ebda071db9b 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -6,6 +6,7 @@ import android.content.res.Configuration import android.text.TextUtils import androidx.preference.PreferenceManager import org.wordpress.android.R +import org.wordpress.android.util.PerAppLocaleManager.Companion.OLD_LOCALE_PREF_KEY_STRING import java.text.Collator import java.util.Locale import java.util.regex.Pattern @@ -16,11 +17,6 @@ import java.util.regex.Pattern * android version. */ object LocaleManager { - /** - * Key used for saving the language selection to shared preferences. - */ - private const val LOCALE_PREF_KEY_STRING: String = "language-pref" - /** * Pattern to split a language string (to parse the language and region values). */ @@ -56,7 +52,7 @@ object LocaleManager { @JvmStatic fun getLanguage(context: Context): String { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(LOCALE_PREF_KEY_STRING, LanguageUtils.getCurrentDeviceLanguageCode())!! + return prefs.getString(OLD_LOCALE_PREF_KEY_STRING, LanguageUtils.getCurrentDeviceLanguageCode())!! } /** @@ -237,7 +233,4 @@ object LocaleManager { displayLanguage } } - - @JvmStatic - fun getLocalePrefKeyString(): String = LOCALE_PREF_KEY_STRING } diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt index 60e3c47b0f7d..e4331f27c23c 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt @@ -12,7 +12,6 @@ class LocaleManagerWrapper fun getTimeZone(): TimeZone = TimeZone.getDefault() fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale()) fun getLanguage(): String = LocaleManager.getLanguage(context) - fun getLocalePrefKeyString(): String = LocaleManager.getLocalePrefKeyString() fun isSameLanguage(language: String): Boolean = LocaleManager.isSameLanguage(language) fun setLocale(context: Context): Context = LocaleManager.setLocale(context) } diff --git a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt index 0067c1fbfacb..c29766aa4b14 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -61,11 +61,10 @@ class PerAppLocaleManager @Inject constructor( * this once the per-app language pref is no longer experimental. */ fun checkAndUpdateOldLanguagePrefKey() { - val prefKey = LocaleManager.getLocalePrefKeyString() - val inAppLanguage = appPrefsWrapper.getPrefString(prefKey, "") + val inAppLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") val perAppLanguage = getCurrentLocale().language if (perAppLanguage.isNotEmpty() && inAppLanguage.equals(perAppLanguage).not()) { - appPrefsWrapper.setPrefString(prefKey, perAppLanguage) + appPrefsWrapper.setPrefString(OLD_LOCALE_PREF_KEY_STRING, perAppLanguage) appLogWrapper.d( AppLog.T.SETTINGS, "PerAppLocaleManager: changed inAppLanguage from $inAppLanguage to $perAppLanguage" @@ -94,8 +93,7 @@ class PerAppLocaleManager @Inject constructor( */ fun performMigrationIfNecessary() { if (isApplicationLocaleEmpty()) { - val prefKey = LocaleManager.getLocalePrefKeyString() - val previousLanguage = appPrefsWrapper.getPrefString(prefKey, "") + val previousLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") if (previousLanguage?.isNotEmpty() == true) { appLogWrapper.d( AppLog.T.SETTINGS, @@ -155,4 +153,9 @@ class PerAppLocaleManager @Inject constructor( // update Reader tags as they need be localized ReaderUpdateServiceStarter.startService(getContext(), EnumSet.of(UpdateTask.TAGS)) } + + companion object { + // Key previously used for saving the language selection to shared preferences. + const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" + } }