diff --git a/WordPress/src/main/java/org/wordpress/android/models/recommend/RecommendApiCallsProvider.kt b/WordPress/src/main/java/org/wordpress/android/models/recommend/RecommendApiCallsProvider.kt index e324f64e5679..4499cf941e28 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/recommend/RecommendApiCallsProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/models/recommend/RecommendApiCallsProvider.kt @@ -12,8 +12,8 @@ import org.wordpress.android.models.recommend.RecommendApiCallsProvider.Recommen import org.wordpress.android.models.recommend.RecommendApiCallsProvider.RecommendCallResult.Success import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T -import org.wordpress.android.util.LocaleManagerWrapper import org.wordpress.android.util.NetworkUtilsWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.RestClientProvider import org.wordpress.android.util.VolleyUtils import org.wordpress.android.util.analytics.AnalyticsUtils.RecommendAppSource @@ -28,7 +28,7 @@ class RecommendApiCallsProvider @Inject constructor( private val analyticsUtilsWrapper: AnalyticsUtilsWrapper, private val networkUtilsWrapper: NetworkUtilsWrapper, private val restClientProvider: RestClientProvider, - private val localeManagerWrapper: LocaleManagerWrapper + private val perAppLocaleManager: PerAppLocaleManager ) { suspend fun getRecommendTemplate( appName: String, @@ -38,7 +38,7 @@ class RecommendApiCallsProvider @Inject constructor( logErrorAndTrack(source, "getRecommendTemplate > No Network available") cont.resume(Failure(contextProvider.getContext().getString(R.string.no_network_message))) } else { - val language = localeManagerWrapper.getLanguage() + val language = perAppLocaleManager.getCurrentLocaleLanguageCode() val endPointPath = "/mobile/share-app-link?app=$appName&locale=$language" val listener = Listener { jsonObject -> 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 2e2922fd02a6..bf3810430ee1 100644 --- a/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java +++ b/WordPress/src/main/java/org/wordpress/android/push/NotificationsProcessingService.java @@ -44,7 +44,7 @@ import org.wordpress.android.ui.quickstart.QuickStartTracker; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; -import org.wordpress.android.util.LocaleManager; +import org.wordpress.android.util.PerAppLocaleManager; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; import org.wordpress.android.util.analytics.AnalyticsUtils.QuickActionTrackPropertyValue; @@ -97,6 +97,7 @@ public class NotificationsProcessingService extends Service { @Inject SystemNotificationsTracker mSystemNotificationsTracker; @Inject GCMMessageHandler mGCMMessageHandler; @Inject QuickStartTracker mQuickStartTracker; + @Inject PerAppLocaleManager mPerAppLocaleManager; /* * Use this if you want the service to handle a background note Like. @@ -532,7 +533,7 @@ private void getNoteFromNoteId(String noteId, RestRequest.Listener listener, } HashMap params = new HashMap<>(); - params.put("locale", LocaleManager.getLanguage()); + params.put("locale", mPerAppLocaleManager.getCurrentLocaleLanguageCode()); WordPress.getRestClientUtils().getNotification(params, noteId, listener, errorListener); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSlice.kt index dab700fd2656..581e75b80845 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSlice.kt @@ -12,7 +12,7 @@ import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.utils.ListItemInteraction import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.DateTimeUtilsWrapper -import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.config.WpSotw2023NudgeFeatureConfig import org.wordpress.android.viewmodel.Event import java.time.Instant @@ -22,7 +22,7 @@ class WpSotw2023NudgeCardViewModelSlice @Inject constructor( private val featureConfig: WpSotw2023NudgeFeatureConfig, private val appPrefsWrapper: AppPrefsWrapper, private val dateTimeUtilsWrapper: DateTimeUtilsWrapper, - private val localeManagerWrapper: LocaleManagerWrapper, + private val perAppLocaleManager: PerAppLocaleManager, private val tracker: WpSotw2023NudgeCardAnalyticsTracker, ) { private val _onNavigation = MutableLiveData>() @@ -75,7 +75,7 @@ class WpSotw2023NudgeCardViewModelSlice @Inject constructor( val now = dateTimeUtilsWrapper.getInstantNow() val isDateEligible = now.isAfter(eventTime) - val currentLanguage = localeManagerWrapper.getLanguage() + val currentLanguage = perAppLocaleManager.getCurrentLocaleLanguageCode() val isLanguageEligible = currentLanguage.startsWith(TARGET_LANGUAGE, ignoreCase = true) return featureConfig.isEnabled() && 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 6a40704dc184..339fc2295ce7 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 @@ -5,14 +5,21 @@ import org.wordpress.android.ui.notifications.NotificationsListFragment; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManager; +import org.wordpress.android.util.PerAppLocaleManager; + +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; import static org.wordpress.android.ui.notifications.services.NotificationsUpdateServiceStarter.IS_TAPPED_ON_NOTIFICATION; +@AndroidEntryPoint public class NotificationsUpdateJobService extends JobService implements NotificationsUpdateLogic.ServiceCompletionListener { private NotificationsUpdateLogic mNotificationsUpdateLogic; + @Inject PerAppLocaleManager mPerAppLocaleManager; + @Override public boolean onStartJob(JobParameters params) { String noteId = null; @@ -36,7 +43,10 @@ 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); + mNotificationsUpdateLogic = new NotificationsUpdateLogic( + mPerAppLocaleManager.getCurrentLocaleLanguageCode(), + 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 d1a037e0644f..0084d6e581a7 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 @@ -6,13 +6,20 @@ import org.wordpress.android.ui.notifications.NotificationsListFragment; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManager; +import org.wordpress.android.util.PerAppLocaleManager; + +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; import static org.wordpress.android.ui.notifications.services.NotificationsUpdateServiceStarter.IS_TAPPED_ON_NOTIFICATION; +@AndroidEntryPoint public class NotificationsUpdateService extends Service implements NotificationsUpdateLogic.ServiceCompletionListener { private NotificationsUpdateLogic mNotificationsUpdateLogic; + @Inject PerAppLocaleManager mPerAppLocaleManager; + @Override public IBinder onBind(Intent intent) { return null; @@ -22,7 +29,10 @@ 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); + mNotificationsUpdateLogic = new NotificationsUpdateLogic( + mPerAppLocaleManager.getCurrentLocaleLanguageCode(), + 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 a0909e541fdd..7fd33a2b426c 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 @@ -215,10 +215,9 @@ import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.util.DateTimeUtilsWrapper import org.wordpress.android.util.DisplayUtils import org.wordpress.android.util.FluxCUtils -import org.wordpress.android.util.LocaleManager -import org.wordpress.android.util.LocaleManagerWrapper import org.wordpress.android.util.MediaUtils import org.wordpress.android.util.NetworkUtils +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.PermissionUtils import org.wordpress.android.util.ReblogUtils import org.wordpress.android.util.ShortcutUtils @@ -364,7 +363,7 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag @Inject lateinit var editorMedia: EditorMedia - @Inject lateinit var localeManagerWrapper: LocaleManagerWrapper + @Inject lateinit var perAppLocaleManager: PerAppLocaleManager @Inject internal lateinit var editPostRepository: EditPostRepository @@ -2571,7 +2570,7 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag get() { val postType = if (isPage) "page" else "post" val featuredImageId = editPostRepository.featuredImageId.toInt() - val languageString = LocaleManager.getLanguage() + val languageString = perAppLocaleManager.getCurrentLocaleLanguageCode() 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 6d9fcf91c0f2..2bc319f1c6c2 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(PerAppLocaleManager.Companion.getCurrentLocaleDisplayName()); + mLanguagePreference.setSummary(mPerAppLocaleManager.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 20f5935adcdf..4dd50467ed38 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 @@ -16,7 +16,7 @@ import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsViewMod import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsViewModel.UiState.InitialLoadingUiState import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel import org.wordpress.android.ui.utils.UiHelpers -import org.wordpress.android.util.LocaleManager +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -31,6 +31,9 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo private lateinit var viewModel: ReaderInterestsViewModel private var parentViewModel: ReaderViewModel? = null + @Inject + lateinit var perAppLocaleManager: PerAppLocaleManager + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (requireActivity().application as WordPress).component().inject(this) @@ -109,7 +112,7 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo } viewModel.start( - LocaleManager.getLanguage(), + perAppLocaleManager.getCurrentLocaleLanguageCode(), parentViewModel, entryPoint ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderPostRepository.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderPostRepository.kt index 503682566dbb..3b6364737d9b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderPostRepository.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderPostRepository.kt @@ -22,7 +22,7 @@ import org.wordpress.android.ui.reader.services.post.ReaderPostServiceStarter import org.wordpress.android.ui.reader.sources.ReaderPostLocalSource import org.wordpress.android.ui.reader.utils.ReaderUtils import org.wordpress.android.util.AppLog -import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.UrlUtils import java.util.Locale import javax.inject.Inject @@ -32,7 +32,7 @@ import kotlin.coroutines.resumeWithException @Reusable class ReaderPostRepository @Inject constructor( - private val localeManagerWrapper: LocaleManagerWrapper, + private val perAppLocaleManager: PerAppLocaleManager, private val localSource: ReaderPostLocalSource, @Named(IO_THREAD) private val ioDispatcher: CoroutineDispatcher, ) { @@ -93,7 +93,7 @@ class ReaderPostRepository @Inject constructor( sb.append("&before=").append(UrlUtils.urlEncode(beforeDate)) } sb.append("&meta=site,likes") - sb.append("&lang=").append(localeManagerWrapper.getLanguage()) + sb.append("&lang=").append(perAppLocaleManager.getCurrentLocaleLanguageCode()) val listener = RestRequest.Listener { jsonObject: JSONObject? -> // remember when this tag was updated if newer posts were requested diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt index 8678093db272..8c187636daf0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt @@ -46,7 +46,7 @@ import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.Dis import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.DiscoverTasks.REQUEST_MORE import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.READER -import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.config.ReaderDiscoverNewEndpointFeatureConfig import javax.inject.Inject @@ -60,7 +60,7 @@ class ReaderDiscoverLogic @Inject constructor( private val getDiscoverCardsUseCase: GetDiscoverCardsUseCase, private val appPrefsWrapper: AppPrefsWrapper, private val readerDiscoverNewEndpointFeatureConfig: ReaderDiscoverNewEndpointFeatureConfig, - private val localeManagerWrapper: LocaleManagerWrapper, + private val perAppLocaleManager: PerAppLocaleManager, ) { enum class DiscoverTasks { REQUEST_MORE, REQUEST_FIRST_PAGE @@ -120,7 +120,7 @@ class ReaderDiscoverLogic @Inject constructor( AppLog.e(READER, volleyError) resultListener.onUpdateResult(FAILED) } - params["_locale"] = localeManagerWrapper.getLanguage() + params["_locale"] = perAppLocaleManager.getCurrentLocaleLanguageCode() val endpoint = if (readerDiscoverNewEndpointFeatureConfig.isEnabled()) { "read/streams/discover" } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchJobService.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchJobService.java index f5fd3f46892d..fc872841fa05 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchJobService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchJobService.java @@ -5,7 +5,7 @@ import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManagerWrapper; +import org.wordpress.android.util.PerAppLocaleManager; import javax.inject.Inject; @@ -22,7 +22,7 @@ public class ReaderSearchJobService extends JobService implements ServiceCompletionListener { private ReaderSearchLogic mReaderSearchLogic; - @Inject LocaleManagerWrapper mLocaleManagerWrapper; + @Inject PerAppLocaleManager mPerAppLocaleManager; @Override public boolean onStartJob(JobParameters params) { if (params.getExtras() != null && params.getExtras().getString(ARG_QUERY) != null) { @@ -42,7 +42,7 @@ public class ReaderSearchJobService extends JobService implements ServiceComplet @Override public void onCreate() { super.onCreate(); - mReaderSearchLogic = new ReaderSearchLogic(this, mLocaleManagerWrapper); + mReaderSearchLogic = new ReaderSearchLogic(this, mPerAppLocaleManager); AppLog.i(AppLog.T.READER, "reader search job service > created"); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchLogic.java index b865a00e28ec..ea708de839c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchLogic.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchLogic.java @@ -14,7 +14,7 @@ import org.wordpress.android.ui.reader.ReaderEvents; import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManagerWrapper; +import org.wordpress.android.util.PerAppLocaleManager; import org.wordpress.android.util.UrlUtils; import static org.wordpress.android.ui.reader.utils.ReaderUtils.getTagForSearchQuery; @@ -22,13 +22,13 @@ public class ReaderSearchLogic { private final ServiceCompletionListener mCompletionListener; - private final LocaleManagerWrapper mLocaleManagerWrapper; + private final PerAppLocaleManager mPerAppLocaleManager; private Object mListenerCompanion; public ReaderSearchLogic(@NonNull final ServiceCompletionListener listener, - final @NonNull LocaleManagerWrapper localeManagerWrapper) { + final @NonNull PerAppLocaleManager perAppLocaleManager) { mCompletionListener = listener; - mLocaleManagerWrapper = localeManagerWrapper; + mPerAppLocaleManager = perAppLocaleManager; } public void startSearch(@NonNull final String query, final int offset, Object companion) { @@ -38,7 +38,7 @@ public void startSearch(@NonNull final String query, final int offset, Object co + "&number=" + ReaderConstants.READER_MAX_SEARCH_RESULTS_TO_REQUEST + "&offset=" + offset + "&meta=site,likes" - + "&lang=" + mLocaleManagerWrapper.getLanguage(); + + "&lang=" + mPerAppLocaleManager.getCurrentLocaleLanguageCode(); RestRequest.Listener listener = jsonObject -> { if (jsonObject != null) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchService.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchService.java index 200bd615e43c..2411d5135b9b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/search/ReaderSearchService.java @@ -6,7 +6,7 @@ import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.LocaleManagerWrapper; +import org.wordpress.android.util.PerAppLocaleManager; import org.wordpress.android.util.StringUtils; import javax.inject.Inject; @@ -24,7 +24,7 @@ public class ReaderSearchService extends Service implements ServiceCompletionLis private ReaderSearchLogic mReaderSearchLogic; - @Inject LocaleManagerWrapper mLocaleManagerWrapper; + @Inject PerAppLocaleManager mPerAppLocaleManager; @Override public IBinder onBind(Intent intent) { @@ -34,7 +34,7 @@ public IBinder onBind(Intent intent) { @Override public void onCreate() { super.onCreate(); - mReaderSearchLogic = new ReaderSearchLogic(this, mLocaleManagerWrapper); + mReaderSearchLogic = new ReaderSearchLogic(this, mPerAppLocaleManager); AppLog.i(AppLog.T.READER, "reader search service > created"); } 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 d6ea3d0a2455..3342b6bab616 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 @@ -29,7 +29,7 @@ import org.wordpress.android.ui.reader.services.ServiceCompletionListener; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.JSONUtils; -import org.wordpress.android.util.LocaleManager; +import org.wordpress.android.util.PerAppLocaleManager; import java.util.Date; import java.util.EnumSet; @@ -60,11 +60,12 @@ public enum UpdateTask { @Inject AccountStore mAccountStore; @Inject TagUpdateClientUtilsProvider mClientUtilsProvider; + @Inject PerAppLocaleManager mPerAppLocaleManager; public ReaderUpdateLogic(Context context, WordPress app, ServiceCompletionListener listener) { mCompletionListener = listener; app.component().inject(this); - mLanguage = LocaleManager.getLanguage(); + mLanguage = mPerAppLocaleManager.getCurrentLocaleLanguageCode(); 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 ff1c1534e89d..07796d28d9a3 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.kt @@ -19,19 +19,6 @@ object LocaleManager { private const val MIN_LANGUAGE_CODE_LENGTH = 2 private const val MAX_LANGUAGE_CODE_LENGTH = 6 - - @Suppress("ForbiddenComment") - /** - * 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(): String { - return PerAppLocaleManager.getCurrentLocaleLanguageCode() - } - /** * Convert the device language code (codes defined by ISO 639-1) to a Language ID. * Language IDs, used only by WordPress, are integer values that map to a language code. 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 0e24a3281caa..cf0e1d224eb0 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManagerWrapper.kt @@ -11,5 +11,4 @@ class LocaleManagerWrapper fun getLocale(): Locale = Locale.getDefault() fun getTimeZone(): TimeZone = TimeZone.getDefault() fun getCurrentCalendar(): Calendar = Calendar.getInstance(getLocale()) - fun getLanguage(): String = LocaleManager.getLanguage() } 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 dc51b00f2b7d..6cc225f74fc3 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -31,6 +31,19 @@ class PerAppLocaleManager @Inject constructor( private val siteStore: SiteStore, private val accountStore: AccountStore, ) { + 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 + 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 @@ -107,18 +120,5 @@ class PerAppLocaleManager @Inject constructor( companion object { // 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 { - 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 } } diff --git a/WordPress/src/test/java/org/wordpress/android/models/recommend/RecommendApiCallsProviderTest.kt b/WordPress/src/test/java/org/wordpress/android/models/recommend/RecommendApiCallsProviderTest.kt index ddf347895251..400fe4b57f20 100644 --- a/WordPress/src/test/java/org/wordpress/android/models/recommend/RecommendApiCallsProviderTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/models/recommend/RecommendApiCallsProviderTest.kt @@ -23,8 +23,8 @@ import org.wordpress.android.R import org.wordpress.android.models.recommend.RecommendApiCallsProvider.RecommendAppName.WordPress import org.wordpress.android.models.recommend.RecommendApiCallsProvider.RecommendCallResult.Failure import org.wordpress.android.networking.RestClientUtils -import org.wordpress.android.util.LocaleManagerWrapper import org.wordpress.android.util.NetworkUtilsWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.RestClientProvider import org.wordpress.android.util.analytics.AnalyticsUtils.RecommendAppSource.ME import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper @@ -51,7 +51,7 @@ class RecommendApiCallsProviderTest : BaseUnitTest() { lateinit var restClientUtils: RestClientUtils @Mock - lateinit var localeManagerWrapper: LocaleManagerWrapper + lateinit var perAppLocaleManager: PerAppLocaleManager @Mock lateinit var jsonObject: JSONObject @@ -67,12 +67,12 @@ class RecommendApiCallsProviderTest : BaseUnitTest() { analyticsUtilsWrapper, networkUtilsWrapper, restClientProvider, - localeManagerWrapper + perAppLocaleManager ) whenever(networkUtilsWrapper.isNetworkAvailable()).thenReturn(true) whenever(contextProvider.getContext()).thenReturn(context) whenever(restClientProvider.getRestClientUtilsV2()).thenReturn(restClientUtils) - whenever(localeManagerWrapper.getLanguage()).thenReturn("en") + whenever(perAppLocaleManager.getCurrentLocaleLanguageCode()).thenReturn("en") whenever(jsonObject.optString("name")).thenReturn("wordpress") listenerCaptor = argumentCaptor() diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSliceTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSliceTest.kt index 2886c4708dbe..92c5535ea72b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSliceTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/sotw2023/WpSotw2023NudgeCardViewModelSliceTest.kt @@ -13,7 +13,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem import org.wordpress.android.ui.mysite.SiteNavigationAction.OpenExternalUrl import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.DateTimeUtilsWrapper -import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.PerAppLocaleManager import org.wordpress.android.util.config.WpSotw2023NudgeFeatureConfig import java.time.Instant @@ -29,7 +29,7 @@ class WpSotw2023NudgeCardViewModelSliceTest : BaseUnitTest() { lateinit var dateTimeUtilsWrapper: DateTimeUtilsWrapper @Mock - lateinit var localeManagerWrapper: LocaleManagerWrapper + lateinit var perAppLocaleManager: PerAppLocaleManager @Mock lateinit var tracker: WpSotw2023NudgeCardAnalyticsTracker @@ -44,7 +44,7 @@ class WpSotw2023NudgeCardViewModelSliceTest : BaseUnitTest() { featureConfig, appPrefsWrapper, dateTimeUtilsWrapper, - localeManagerWrapper, + perAppLocaleManager, tracker, ) viewModelSlice.initialize(testScope()) @@ -165,7 +165,7 @@ class WpSotw2023NudgeCardViewModelSliceTest : BaseUnitTest() { val date = if (isDateAfterEvent) "2023-12-12T00:00:01Z" else "2021-12-11T00:00:00Z" whenever(dateTimeUtilsWrapper.getInstantNow()).thenReturn(Instant.parse(date)) val language = if (isLanguageEnglish) "en_US" else "fr_FR" - whenever(localeManagerWrapper.getLanguage()).thenReturn(language) + whenever(perAppLocaleManager.getCurrentLocaleLanguageCode()).thenReturn(language) } }