Skip to content

Commit

Permalink
Non-static locale (#21549)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury authored Dec 20, 2024
2 parents 01f6aca + 3e407f7 commit 194cad2
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -532,7 +533,7 @@ private void getNoteFromNoteId(String noteId, RestRequest.Listener listener,
}

HashMap<String, String> params = new HashMap<>();
params.put("locale", LocaleManager.getLanguage());
params.put("locale", mPerAppLocaleManager.getCurrentLocaleLanguageCode());
WordPress.getRestClientUtils().getNotification(params, noteId, listener, errorListener);
}

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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -109,7 +112,7 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo
}

viewModel.start(
LocaleManager.getLanguage(),
perAppLocaleManager.getCurrentLocaleLanguageCode(),
parentViewModel,
entryPoint
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand All @@ -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) {
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
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;

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

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

Expand Down
Loading

0 comments on commit 194cad2

Please sign in to comment.