Skip to content

Commit

Permalink
Removed setLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Dec 17, 2024
1 parent 715af69 commit 3863459
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 3863459

Please sign in to comment.