From a75a91b46760476d16518b0e94eaf41f916e8e1c Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 14:27:10 -0500 Subject: [PATCH 01/12] First pass at removing language shared preference --- .../UserFlagsProviderHelper.kt | 3 --- .../org/wordpress/android/util/LocaleManager.kt | 11 ++--------- .../wordpress/android/util/LocaleManagerWrapper.kt | 1 - .../wordpress/android/util/PerAppLocaleManager.kt | 13 ++++++++----- 4 files changed, 10 insertions(+), 18 deletions(-) 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" + } } From 0ec991d2319b242d0322457e0c4787631828388d Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 14:46:02 -0500 Subject: [PATCH 02/12] Second pass at removing language shared preference --- .../android/util/PerAppLocaleManager.kt | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) 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 c29766aa4b14..64b3b415eb70 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -31,29 +31,6 @@ class PerAppLocaleManager @Inject constructor( private val siteStore: SiteStore, private val accountStore: AccountStore, ) { - private fun getCurrentLocale(): Locale { - return if (isApplicationLocaleEmpty()) { - Locale.getDefault() - } else { - getApplicationLocaleList()[0] ?: Locale.getDefault() - } - } - - fun getCurrentLocaleDisplayName(): String = getCurrentLocale().displayName - - private fun getCurrentLocaleLanguageCode(): String = getCurrentLocale().language - - /** - * Important: this should only be called after Activity.onCreate() - * https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#getApplicationLocales() - */ - private fun getApplicationLocaleList() = AppCompatDelegate.getApplicationLocales() - - private fun isApplicationLocaleEmpty(): Boolean { - val locales = getApplicationLocaleList() - return (locales.isEmpty || locales == LocaleListCompat.getEmptyLocaleList()) - } - /** * We want to make sure the language pref for the in-app locale (old implementation) is set * to the same locale as the AndroidX per-app locale. This way LocaleManager.getLanguage - @@ -92,7 +69,8 @@ class PerAppLocaleManager @Inject constructor( * Previously the app locale was stored in SharedPreferences, so here we migrate to AndroidX per-app language prefs */ fun performMigrationIfNecessary() { - if (isApplicationLocaleEmpty()) { + val locales = AppCompatDelegate.getApplicationLocales() + if (locales.isEmpty || locales == LocaleListCompat.getEmptyLocaleList()) { val previousLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") if (previousLanguage?.isNotEmpty() == true) { appLogWrapper.d( @@ -157,5 +135,18 @@ class PerAppLocaleManager @Inject constructor( companion object { // Key previously used for saving the language selection to shared preferences. const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" + + private fun getCurrentLocale(): Locale { + val locales = AppCompatDelegate.getApplicationLocales() + return if (locales.isEmpty || locales == LocaleListCompat.getEmptyLocaleList()) { + Locale.getDefault() + } else { + locales[0] ?: Locale.getDefault() + } + } + + fun getCurrentLocaleDisplayName(): String = getCurrentLocale().displayName + + fun getCurrentLocaleLanguageCode(): String = getCurrentLocale().language } } From 715af69323984fbf0f560e6663235e913ad7fd7c Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:16:16 -0500 Subject: [PATCH 03/12] Changed LocaleManager to rely on PerAppLocaleManager for the current language code --- .../push/NotificationsProcessingService.java | 2 +- .../services/NotificationsUpdateJobService.java | 2 +- .../services/NotificationsUpdateService.java | 2 +- .../wordpress/android/ui/posts/EditPostActivity.kt | 2 +- .../android/ui/prefs/AppSettingsFragment.java | 2 +- .../discover/interests/ReaderInterestsFragment.kt | 2 +- .../reader/services/update/ReaderUpdateLogic.java | 2 +- .../org/wordpress/android/util/LocaleManager.kt | 14 ++++++-------- .../wordpress/android/util/LocaleManagerWrapper.kt | 2 +- .../wordpress/android/util/PerAppLocaleManager.kt | 1 + 10 files changed, 15 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java b/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java index 54db41f9624e..2e2922fd02a6 100644 --- a/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java +++ b/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java @@ -532,7 +532,7 @@ private void getNoteFromNoteId(String noteId, RestRequest.Listener listener, } HashMap params = new HashMap<>(); - params.put("locale", LocaleManager.getLanguage(mContext)); + params.put("locale", LocaleManager.getLanguage()); WordPress.getRestClientUtils().getNotification(params, noteId, listener, errorListener); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java index f2ed15e62076..b677a56eb16f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java @@ -42,7 +42,7 @@ public boolean onStopJob(JobParameters params) { public void onCreate() { super.onCreate(); AppLog.i(AppLog.T.NOTIFS, "notifications update job service > created"); - mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(this), this); + mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(), this); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java index a674050a24cc..c5a4b6015e11 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java @@ -28,7 +28,7 @@ public IBinder onBind(Intent intent) { public void onCreate() { super.onCreate(); AppLog.i(AppLog.T.NOTIFS, "notifications update service > created"); - mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(this), this); + mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(), this); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt index 8a3dd57e2a5a..a0909e541fdd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt @@ -2571,7 +2571,7 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag get() { val postType = if (isPage) "page" else "post" val featuredImageId = editPostRepository.featuredImageId.toInt() - val languageString = LocaleManager.getLanguage(this@EditPostActivity) + val languageString = LocaleManager.getLanguage() val wpcomLocaleSlug = languageString.replace("_", "-").lowercase() // this.mIsXPostsCapable may return true for non-WP.com sites, but the app only supports xPosts for P2-based diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsFragment.java index 2bc319f1c6c2..6d9fcf91c0f2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsFragment.java @@ -248,7 +248,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, mLanguagePreference = (WPPreference) findPreference(getString(R.string.pref_key_language)); mLanguagePreference.setOnPreferenceChangeListener(this); mLanguagePreference.setOnPreferenceClickListener(this); - mLanguagePreference.setSummary(mPerAppLocaleManager.getCurrentLocaleDisplayName()); + mLanguagePreference.setSummary(PerAppLocaleManager.Companion.getCurrentLocaleDisplayName()); return view; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt index cad0696f0433..20f5935adcdf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt @@ -109,7 +109,7 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo } viewModel.start( - LocaleManager.getLanguage(WordPress.getContext()), + LocaleManager.getLanguage(), parentViewModel, entryPoint ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java index 9af7b113c7db..d6ea3d0a2455 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java @@ -64,7 +64,7 @@ public enum UpdateTask { public ReaderUpdateLogic(Context context, WordPress app, ServiceCompletionListener listener) { mCompletionListener = listener; app.component().inject(this); - mLanguage = LocaleManager.getLanguage(app); + mLanguage = LocaleManager.getLanguage(); mContext = context; } 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 1ebda071db9b..4ed6ea34137a 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -4,9 +4,7 @@ import android.annotation.SuppressLint import android.content.Context 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 @@ -29,7 +27,7 @@ object LocaleManager { */ @JvmStatic fun setLocale(context: Context): Context { - return updateResources(context, getLanguage(context)) + return updateResources(context, getLanguage()) } /** @@ -43,16 +41,16 @@ object LocaleManager { return Locale.getDefault().toString() == newLocale.toString() } + @Suppress("ForbiddenComment") /** - * If the user has selected a language other than the device default, return that - * language code, else just return the device default language code. + * This is simply a wrapper for the per-app language code. + * TODO: Remove this and directly call PerAppLocaleManager * * @return The 2-letter language code (example "en") */ @JvmStatic - fun getLanguage(context: Context): String { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(OLD_LOCALE_PREF_KEY_STRING, LanguageUtils.getCurrentDeviceLanguageCode())!! + fun getLanguage(): String { + return PerAppLocaleManager.getCurrentLocaleLanguageCode() } /** 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 e4331f27c23c..25afbb0d14a3 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt @@ -11,7 +11,7 @@ class LocaleManagerWrapper fun getLocale(): Locale = Locale.getDefault() fun getTimeZone(): TimeZone = TimeZone.getDefault() fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale()) - fun getLanguage(): String = LocaleManager.getLanguage(context) + fun getLanguage(): String = LocaleManager.getLanguage() 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 64b3b415eb70..39a359fa7e51 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -132,6 +132,7 @@ class PerAppLocaleManager @Inject constructor( 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" From 3863459df67888835ac387996af64b2672902e35 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:35:07 -0500 Subject: [PATCH 04/12] Removed setLocale --- .../NotificationsUpdateJobService.java | 6 ---- .../services/NotificationsUpdateService.java | 6 ---- .../discover/ReaderDiscoverJobService.kt | 6 ---- .../discover/ReaderDiscoverService.kt | 6 ---- .../update/ReaderUpdateJobService.java | 7 ---- .../services/update/ReaderUpdateService.java | 7 ---- .../wordpress/android/util/LocaleManager.kt | 33 ------------------- .../android/util/LocaleManagerWrapper.kt | 1 - .../android/viewmodel/ContextProvider.kt | 5 --- 9 files changed, 77 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java index b677a56eb16f..6a40704dc184 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateJobService.java @@ -2,7 +2,6 @@ import android.app.job.JobParameters; import android.app.job.JobService; -import android.content.Context; import org.wordpress.android.ui.notifications.NotificationsListFragment; import org.wordpress.android.util.AppLog; @@ -14,11 +13,6 @@ public class NotificationsUpdateJobService extends JobService implements NotificationsUpdateLogic.ServiceCompletionListener { private NotificationsUpdateLogic mNotificationsUpdateLogic; - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleManager.setLocale(newBase)); - } - @Override public boolean onStartJob(JobParameters params) { String noteId = null; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java index c5a4b6015e11..d1a037e0644f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/services/NotificationsUpdateService.java @@ -1,7 +1,6 @@ package org.wordpress.android.ui.notifications.services; import android.app.Service; -import android.content.Context; import android.content.Intent; import android.os.IBinder; @@ -14,11 +13,6 @@ public class NotificationsUpdateService extends Service implements NotificationsUpdateLogic.ServiceCompletionListener { private NotificationsUpdateLogic mNotificationsUpdateLogic; - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleManager.setLocale(newBase)); - } - @Override public IBinder onBind(Intent intent) { return null; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt index 418b14ae67f5..c248d653939c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt @@ -2,7 +2,6 @@ package org.wordpress.android.ui.reader.services.discover import android.app.job.JobParameters import android.app.job.JobService -import android.content.Context import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope @@ -12,7 +11,6 @@ import org.wordpress.android.ui.reader.services.ServiceCompletionListener import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.DiscoverTasks import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.READER -import org.wordpress.android.util.LocaleManager import javax.inject.Inject import javax.inject.Named import kotlin.coroutines.CoroutineContext @@ -31,10 +29,6 @@ class ReaderDiscoverJobService : JobService(), ServiceCompletionListener, Corout override val coroutineContext: CoroutineContext get() = ioDispatcher + job - override fun attachBaseContext(newBase: Context) { - super.attachBaseContext(LocaleManager.setLocale(newBase)) - } - override fun onStartJob(params: JobParameters): Boolean { AppLog.i(READER, "reader discover job service > started") diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt index d34ca7f8da7e..e480981ff643 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt @@ -1,7 +1,6 @@ package org.wordpress.android.ui.reader.services.discover import android.app.Service -import android.content.Context import android.content.Intent import android.os.IBinder import dagger.hilt.android.AndroidEntryPoint @@ -14,7 +13,6 @@ import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.Dis import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverServiceStarter.ARG_DISCOVER_TASK import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.READER -import org.wordpress.android.util.LocaleManager import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject import javax.inject.Named @@ -41,10 +39,6 @@ class ReaderDiscoverService : Service(), ServiceCompletionListener, CoroutineSco return null } - override fun attachBaseContext(newBase: Context) { - super.attachBaseContext(LocaleManager.setLocale(newBase)) - } - override fun onCreate() { super.onCreate() AppLog.i(READER, "reader discover service > created") diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateJobService.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateJobService.java index 64058405812e..a2f153cf2c3f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateJobService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateJobService.java @@ -2,12 +2,10 @@ import android.app.job.JobParameters; import android.app.job.JobService; -import android.content.Context; import org.wordpress.android.WordPress; import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManager; import java.util.EnumSet; @@ -16,11 +14,6 @@ public class ReaderUpdateJobService extends JobService implements ServiceCompletionListener { private ReaderUpdateLogic mReaderUpdateLogic; - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleManager.setLocale(newBase)); - } - @Override public boolean onStartJob(JobParameters params) { AppLog.i(AppLog.T.READER, "reader job service > started"); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateService.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateService.java index 5569b40bfc58..aa4451f84640 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateService.java @@ -1,14 +1,12 @@ package org.wordpress.android.ui.reader.services.update; import android.app.Service; -import android.content.Context; import android.content.Intent; import android.os.IBinder; import org.wordpress.android.WordPress; import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManager; import java.util.EnumSet; @@ -28,11 +26,6 @@ public IBinder onBind(Intent intent) { return null; } - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleManager.setLocale(newBase)); - } - @Override public void onCreate() { super.onCreate(); 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 4ed6ea34137a..89990a305eef 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -1,8 +1,6 @@ package org.wordpress.android.util -import android.annotation.SuppressLint import android.content.Context -import android.content.res.Configuration import android.text.TextUtils import org.wordpress.android.R import java.text.Collator @@ -20,16 +18,6 @@ object LocaleManager { */ private val LANGUAGE_SPLITTER: Pattern = Pattern.compile("_") - /** - * Activate the locale associated with the provided context. - * - * @param context The current context. - */ - @JvmStatic - fun setLocale(context: Context): Context { - return updateResources(context, getLanguage()) - } - /** * Compare the language for the current context with another language. * @@ -78,27 +66,6 @@ object LocaleManager { return langID ?: deviceLanguageCode } - /** - * Update resources for the current session. - * - * @param context The current active context - * @param language The 2-letter language code (example "en") - * @return The modified context containing the updated localized resources - */ - @SuppressLint("AppBundleLocaleChanges") - private fun updateResources(context: Context, language: String): Context { - val locale = languageLocale(language) - Locale.setDefault(locale) - - val res = context.resources - val config = Configuration(res.configuration) - - // NOTE: Earlier versions of Android require both of these to be set, otherwise - // RTL may not be implemented properly. - config.setLocale(locale) - return context.createConfigurationContext(config) - } - /** * Method gets around a bug in the java.util.Formatter for API 7.x as detailed here * [https://bugs.openjdk.java.net/browse/JDK-8167567]. Any strings that contain 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 25afbb0d14a3..151fae6a8758 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt @@ -13,5 +13,4 @@ class LocaleManagerWrapper fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale()) fun getLanguage(): String = LocaleManager.getLanguage() 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/viewmodel/ContextProvider.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/ContextProvider.kt index 04c0af3557f4..001054380da9 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/ContextProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/ContextProvider.kt @@ -1,16 +1,11 @@ package org.wordpress.android.viewmodel import android.content.Context -import org.wordpress.android.util.LocaleManager import javax.inject.Inject import javax.inject.Singleton @Singleton class ContextProvider @Inject constructor(private var context: Context) { - fun refreshContext() { - this.context = LocaleManager.setLocale(this.context) - } - fun getContext(): Context = context } From 5bd1ed3eacc330409f16a15849a6cd0459fee66d Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:38:01 -0500 Subject: [PATCH 05/12] Updated comment --- .../src/main/java/org/wordpress/android/util/LocaleManager.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 89990a305eef..714980c87ad2 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -8,9 +8,7 @@ import java.util.Locale import java.util.regex.Pattern /** - * Helper class for working with localized strings. Ensures updates to the users - * selected language is properly saved and resources appropriately updated for the - * android version. + * Helper class for working with localized strings */ object LocaleManager { /** From 5fa7c80a96febaa57c9a74240b1f6a338978a9d1 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:39:29 -0500 Subject: [PATCH 06/12] Removed updating the language shared pref --- .../org/wordpress/android/AppInitializer.kt | 3 +-- .../android/util/PerAppLocaleManager.kt | 23 +------------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt index abbcc8a7ea95..a5af3e64975a 100644 --- a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt +++ b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt @@ -949,8 +949,7 @@ class AppInitializer @Inject constructor( */ private inner class MemoryAndConfigChangeMonitor : ComponentCallbacks2 { override fun onConfigurationChanged(newConfig: Configuration) { - // Make sure the in-app locale is correct - perAppLocaleManager.checkAndUpdateOldLanguagePrefKey() + // Do nothing } override fun onLowMemory() { 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 39a359fa7e51..e97c37c1990a 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -31,24 +31,6 @@ class PerAppLocaleManager @Inject constructor( private val siteStore: SiteStore, private val accountStore: AccountStore, ) { - /** - * We want to make sure the language pref for the in-app locale (old implementation) is set - * to the same locale as the AndroidX per-app locale. This way LocaleManager.getLanguage - - * which is used throughout the app - returns the correct language code. We can remove - * this once the per-app language pref is no longer experimental. - */ - fun checkAndUpdateOldLanguagePrefKey() { - val inAppLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") - val perAppLanguage = getCurrentLocale().language - if (perAppLanguage.isNotEmpty() && inAppLanguage.equals(perAppLanguage).not()) { - appPrefsWrapper.setPrefString(OLD_LOCALE_PREF_KEY_STRING, perAppLanguage) - appLogWrapper.d( - AppLog.T.SETTINGS, - "PerAppLocaleManager: changed inAppLanguage from $inAppLanguage to $perAppLanguage" - ) - } - } - /** * This routine can be helpful during development to reset the app locale */ @@ -62,7 +44,6 @@ class PerAppLocaleManager @Inject constructor( // on pre-Android 13 devices val appLocale = LocaleListCompat.forLanguageTags(languageCode.replace("_", "-")) AppCompatDelegate.setApplicationLocales(appLocale) - checkAndUpdateOldLanguagePrefKey() } /** @@ -85,8 +66,6 @@ class PerAppLocaleManager @Inject constructor( ) setCurrentLocaleByLanguageCode(Locale.getDefault().language) } - } else { - checkAndUpdateOldLanguagePrefKey() } } @@ -135,7 +114,7 @@ class PerAppLocaleManager @Inject constructor( companion object { // Key previously used for saving the language selection to shared preferences. - const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" + private const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" private fun getCurrentLocale(): Locale { val locales = AppCompatDelegate.getApplicationLocales() From 03cac31113f80df9439370bc229cf5b814878f84 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:52:55 -0500 Subject: [PATCH 07/12] Added TODO --- .../src/main/java/org/wordpress/android/util/LocaleManager.kt | 4 +++- .../java/org/wordpress/android/util/PerAppLocaleManager.kt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) 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 714980c87ad2..0d86ebe605c1 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -64,6 +64,7 @@ object LocaleManager { return langID ?: deviceLanguageCode } + @Suppress("ForbiddenComment") /** * Method gets around a bug in the java.util.Formatter for API 7.x as detailed here * [https://bugs.openjdk.java.net/browse/JDK-8167567]. Any strings that contain @@ -74,7 +75,8 @@ object LocaleManager { * An example of a string that contains locale-specific grouping separators: * ` * %,d likes - ` * + `* + * TODO: This is a workaround for a bug in API 7, which we no longer support. Investigate removing this. */ @JvmStatic fun getSafeLocale(context: Context?): Locale { 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 e97c37c1990a..084cc65e1f09 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -111,9 +111,8 @@ class PerAppLocaleManager @Inject constructor( ReaderUpdateServiceStarter.startService(getContext(), EnumSet.of(UpdateTask.TAGS)) } - companion object { - // Key previously used for saving the language selection to shared preferences. + // Key previously used for saving the language selection to shared preferences private const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" private fun getCurrentLocale(): Locale { From 394943fead0144ec21a52c3fedde0129847e6ba2 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 16:01:18 -0500 Subject: [PATCH 08/12] Remove language pref during migration --- .../java/org/wordpress/android/ui/prefs/AppPrefsWrapper.kt | 4 ++-- .../java/org/wordpress/android/util/PerAppLocaleManager.kt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefsWrapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefsWrapper.kt index 2300c40b1437..4c0e962cc801 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefsWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefsWrapper.kt @@ -460,8 +460,8 @@ class AppPrefsWrapper @Inject constructor(val buildConfigWrapper: BuildConfigWra return AppPrefs.prefs().getString(key, defValue) } - fun setPrefString(key: String, value: String) { - AppPrefs.prefs().edit().putString(key, value).apply() + fun removePref(key: String) { + AppPrefs.prefs().edit().remove(key).apply() } fun getDebugBooleanPref(key: String, default: Boolean = false) = 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 084cc65e1f09..f157a6d7e217 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -59,6 +59,7 @@ class PerAppLocaleManager @Inject constructor( "PerAppLocaleManager: performing migration to AndroidX per-app language prefs" ) setCurrentLocaleByLanguageCode(previousLanguage) + appPrefsWrapper.removePref(OLD_LOCALE_PREF_KEY_STRING) } else { appLogWrapper.d( AppLog.T.SETTINGS, From ca88e3728faedc1e80fb0a0ba22852105d173fd4 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 18 Dec 2024 07:27:37 -0500 Subject: [PATCH 09/12] Minor cleanup --- .../android/util/PerAppLocaleManager.kt | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) 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 f157a6d7e217..0e6e6d52ce81 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -31,14 +31,6 @@ class PerAppLocaleManager @Inject constructor( private val siteStore: SiteStore, private val accountStore: AccountStore, ) { - /** - * This routine can be helpful during development to reset the app locale - */ - @Suppress("unused") - fun resetApplicationLocale() { - AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList()) - } - private fun setCurrentLocaleByLanguageCode(languageCode: String) { // We shouldn't have to replace "_" with "-" but this is in order to work with our existing language picker // on pre-Android 13 devices @@ -50,23 +42,14 @@ class PerAppLocaleManager @Inject constructor( * Previously the app locale was stored in SharedPreferences, so here we migrate to AndroidX per-app language prefs */ fun performMigrationIfNecessary() { - val locales = AppCompatDelegate.getApplicationLocales() - if (locales.isEmpty || locales == LocaleListCompat.getEmptyLocaleList()) { - val previousLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") - if (previousLanguage?.isNotEmpty() == true) { - appLogWrapper.d( - AppLog.T.SETTINGS, - "PerAppLocaleManager: performing migration to AndroidX per-app language prefs" - ) - setCurrentLocaleByLanguageCode(previousLanguage) - appPrefsWrapper.removePref(OLD_LOCALE_PREF_KEY_STRING) - } else { - appLogWrapper.d( - AppLog.T.SETTINGS, - "PerAppLocaleManager: setting default locale" - ) - setCurrentLocaleByLanguageCode(Locale.getDefault().language) - } + val previousLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") + if (previousLanguage?.isNotEmpty() == true) { + appLogWrapper.d( + AppLog.T.SETTINGS, + "PerAppLocaleManager: performing migration to AndroidX per-app language prefs" + ) + setCurrentLocaleByLanguageCode(previousLanguage) + appPrefsWrapper.removePref(OLD_LOCALE_PREF_KEY_STRING) } } @@ -87,7 +70,7 @@ class PerAppLocaleManager @Inject constructor( @Suppress("ForbiddenComment") /** * Called when the device language is changed from our in-app language picker - * TODO: Detect when language changed from app settings dialog + * TODO: Detect when language changed from system app settings dialog */ fun onLanguageChanged(languageCode: String) { if (languageCode.isEmpty()) { @@ -112,8 +95,16 @@ class PerAppLocaleManager @Inject constructor( ReaderUpdateServiceStarter.startService(getContext(), EnumSet.of(UpdateTask.TAGS)) } + /** + * This routine can be helpful during development to reset the app locale + */ + @Suppress("unused") + fun resetApplicationLocale() { + AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList()) + } + companion object { - // Key previously used for saving the language selection to shared preferences + // Key previously used for saving the language selection to shared preferences private const val OLD_LOCALE_PREF_KEY_STRING: String = "language-pref" private fun getCurrentLocale(): Locale { From 826d2270545a39fd1980dc306a570b8d3e30a9ca Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Thu, 19 Dec 2024 10:01:40 -0500 Subject: [PATCH 10/12] Removed language detection from PersonalizationViewModel, removed isSameLanguage --- .../personalization/PersonalizationViewModel.kt | 12 ------------ .../java/org/wordpress/android/util/LocaleManager.kt | 10 ---------- .../wordpress/android/util/LocaleManagerWrapper.kt | 1 - 3 files changed, 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/personalization/PersonalizationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/personalization/PersonalizationViewModel.kt index 8df784930ae2..082efe6b6de0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/personalization/PersonalizationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/personalization/PersonalizationViewModel.kt @@ -7,7 +7,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineDispatcher import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.mysite.SelectedSiteRepository -import org.wordpress.android.util.LocaleManagerWrapper import org.wordpress.android.viewmodel.ScopedViewModel import javax.inject.Inject import javax.inject.Named @@ -20,7 +19,6 @@ class PersonalizationViewModel @Inject constructor( private val selectedSiteRepository: SelectedSiteRepository, private val shortcutsPersonalizationViewModelSlice: ShortcutsPersonalizationViewModelSlice, private val dashboardCardPersonalizationViewModelSlice: DashboardCardPersonalizationViewModelSlice, - private val localeManagerWrapper: LocaleManagerWrapper ) : ScopedViewModel(bgDispatcher) { val uiState = dashboardCardPersonalizationViewModelSlice.uiState val shortcutsState = shortcutsPersonalizationViewModelSlice.uiState @@ -32,7 +30,6 @@ class PersonalizationViewModel @Inject constructor( val appLanguage = _appLanguage as LiveData init { - emitLanguageRefreshIfNeeded(localeManagerWrapper.getLanguage()) shortcutsPersonalizationViewModelSlice.initialize(viewModelScope) dashboardCardPersonalizationViewModelSlice.initialize(viewModelScope) } @@ -67,13 +64,4 @@ class PersonalizationViewModel @Inject constructor( val siteId = selectedSiteRepository.getSelectedSite()!!.siteId shortcutsPersonalizationViewModelSlice.addShortcut(shortcutState,siteId) } - - private fun emitLanguageRefreshIfNeeded(languageCode: String) { - if (languageCode.isNotEmpty()) { - val shouldEmitLanguageRefresh = !localeManagerWrapper.isSameLanguage(languageCode) - if (shouldEmitLanguageRefresh) { - _appLanguage.value = languageCode - } - } - } } 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 a13a7ab50e4b..21dd06286d0f 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -19,16 +19,6 @@ object LocaleManager { private const val MIN_LANGUAGE_CODE_LENGTH = 2 private const val MAX_LANGUAGE_CODE_LENGTH = 6 - /** - * Compare the language for the current context with another language. - * - * @param language The language to compare - * @return True if the languages are the same, else false - */ - fun isSameLanguage(language: String): Boolean { - val newLocale = languageLocale(language) - return Locale.getDefault().toString() == newLocale.toString() - } @Suppress("ForbiddenComment") /** 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 151fae6a8758..0e24a3281caa 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt @@ -12,5 +12,4 @@ class LocaleManagerWrapper fun getTimeZone(): TimeZone = TimeZone.getDefault() fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale()) fun getLanguage(): String = LocaleManager.getLanguage() - fun isSameLanguage(language: String): Boolean = LocaleManager.isSameLanguage(language) } From 0dbf35b92b9a590f887fdc071675cf9b19916cdd Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Thu, 19 Dec 2024 10:12:18 -0500 Subject: [PATCH 11/12] Updated comment --- .../java/org/wordpress/android/util/PerAppLocaleManager.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 0e6e6d52ce81..dc51b00f2b7d 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -39,7 +39,8 @@ class PerAppLocaleManager @Inject constructor( } /** - * Previously the app locale was stored in SharedPreferences, so here we migrate to AndroidX per-app language prefs + * Previously the app locale was stored in SharedPreferences, so here we migrate to AndroidX per-app language prefs. + * This was added in our Jan 2025 release and can be removed after a few subsequent releases. */ fun performMigrationIfNecessary() { val previousLanguage = appPrefsWrapper.getPrefString(OLD_LOCALE_PREF_KEY_STRING, "") From 6c20c6aeaea472261a6959cbd468dd069b071d7e Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Fri, 20 Dec 2024 07:40:04 -0500 Subject: [PATCH 12/12] Simplify splitting language display name and code --- .../main/java/org/wordpress/android/util/LocaleManager.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 21dd06286d0f..ff1c1534e89d 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -152,10 +152,7 @@ object LocaleManager { for (i in entryStrings.indices) { // now, we can split the sorted array to extract the display string and the language code - val split = entryStrings[i] - .split("__".toRegex()) - .dropLastWhile { it.isEmpty() } - .toTypedArray() + val split = entryStrings[i].split("__") sortedEntries[i] = split[0] sortedValues[i] = split[1] detailStrings[i] =