From 3863459df67888835ac387996af64b2672902e35 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Tue, 17 Dec 2024 15:35:07 -0500 Subject: [PATCH] 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 }