diff --git a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt index 47794b4c4e30..ffb4fff4ed24 100644 --- a/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt +++ b/WordPress/src/main/java/org/wordpress/android/AppInitializer.kt @@ -950,13 +950,8 @@ class AppInitializer @Inject constructor( */ private inner class MemoryAndConfigChangeMonitor : ComponentCallbacks2 { override fun onConfigurationChanged(newConfig: Configuration) { - // If per-app locale is enabled make sure the in-app locale is correct, - // otherwise reapply in-app locale on configuration change - if (perAppLocaleManager.isPerAppLanguagePrefsEnabled()) { - perAppLocaleManager.checkAndUpdateOldLanguagePrefKey() - } else { - LocaleManager.setLocale(context) - } + // make sure the in-app locale is correct + perAppLocaleManager.checkAndUpdateOldLanguagePrefKey() } override fun onLowMemory() { 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 f7226a5d2a3a..8c9c1577c625 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 @@ -13,7 +13,6 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -49,11 +48,8 @@ import org.wordpress.android.ui.deeplinks.DeepLinkOpenWebLinksWithJetpackHelper; import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper; import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment; -import org.wordpress.android.util.PerAppLocaleManager; import org.wordpress.android.ui.prefs.language.LocalePickerBottomSheet; import org.wordpress.android.ui.prefs.language.LocalePickerBottomSheet.LocalePickerCallback; -import org.wordpress.android.ui.reader.services.update.ReaderUpdateLogic; -import org.wordpress.android.ui.reader.services.update.ReaderUpdateServiceStarter; import org.wordpress.android.ui.utils.UiHelpers; import org.wordpress.android.ui.whatsnew.FeatureAnnouncementDialogFragment; import org.wordpress.android.ui.whatsnew.FeatureAnnouncementProvider; @@ -61,9 +57,9 @@ import org.wordpress.android.util.AppThemeUtils; import org.wordpress.android.util.BuildConfigWrapper; import org.wordpress.android.util.JetpackBrandingUtils; -import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.LocaleProvider; import org.wordpress.android.util.NetworkUtils; +import org.wordpress.android.util.PerAppLocaleManager; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.WPActivityUtils; import org.wordpress.android.util.WPPrefUtils; @@ -71,9 +67,7 @@ import org.wordpress.android.viewmodel.ContextProvider; import java.util.Collections; -import java.util.EnumSet; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import javax.inject.Inject; @@ -86,7 +80,6 @@ public class AppSettingsFragment extends PreferenceFragment private WPPreference mLanguagePreference; private ListPreference mAppThemePreference; - private ListPreference mInitialScreenPreference; // This Device settings private WPSwitchPreference mOptimizedImage; @@ -101,7 +94,6 @@ public class AppSettingsFragment extends PreferenceFragment private WPSwitchPreference mOpenWebLinksWithJetpack; private Preference mWhatsNew; - private Boolean mIsPerAppLanguagePrefsEnabled; @Inject SiteStore mSiteStore; @Inject AccountStore mAccountStore; @@ -110,7 +102,6 @@ public class AppSettingsFragment extends PreferenceFragment @Inject FeatureAnnouncementProvider mFeatureAnnouncementProvider; @Inject BuildConfigWrapper mBuildConfigWrapper; @Inject JetpackBrandingUtils mJetpackBrandingUtils; - @Inject LocaleProvider mLocaleProvider; @Inject DeepLinkOpenWebLinksWithJetpackHelper mOpenWebLinksWithJetpackHelper; @Inject UiHelpers mUiHelpers; @Inject JetpackFeatureRemovalPhaseHelper mJetpackFeatureRemovalPhaseHelper; @@ -125,8 +116,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); mDispatcher.register(this); - mIsPerAppLanguagePrefsEnabled = mPerAppLocaleManager.isPerAppLanguagePrefsEnabled(); - addPreferencesFromResource(R.xml.app_settings); findPreference(getString(R.string.pref_key_send_usage)).setOnPreferenceChangeListener( @@ -259,11 +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); - if (mIsPerAppLanguagePrefsEnabled) { - mLanguagePreference.setSummary(mPerAppLocaleManager.getCurrentLocaleDisplayName()); - } else { - mLanguagePreference.setSummary(mLocaleProvider.getAppLanguageDisplayString()); - } + mLanguagePreference.setSummary(mPerAppLocaleManager.getCurrentLocaleDisplayName()); return view; } @@ -436,10 +421,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { return false; } - if (preference == mLanguagePreference) { - changeLanguage(newValue.toString()); - return false; - } else if (preference == mOptimizedImage) { + if (preference == mOptimizedImage) { AppPrefs.setImageOptimize((Boolean) newValue); mImageMaxSizePref.setEnabled((Boolean) newValue); Map properties = new HashMap<>(); @@ -503,39 +485,6 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { return super.onOptionsItemSelected(item); } - private void changeLanguage(String languageCode) { - if (mLanguagePreference == null || TextUtils.isEmpty(languageCode)) { - return; - } - - if (LocaleManager.isSameLanguage(languageCode)) { - return; - } - - LocaleManager.setNewLocale(WordPress.getContext(), languageCode); - WordPress.updateContextLocale(); - mContextProvider.refreshContext(); - - // Track language change on Analytics because we have both the device language and app selected language - // data in Tracks metadata. - Map properties = new HashMap<>(); - properties.put("app_locale", Locale.getDefault()); - AnalyticsTracker.track(Stat.ACCOUNT_SETTINGS_LANGUAGE_CHANGED, properties); - - // Language is now part of metadata, so we need to refresh them - AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore); - - // Refresh the app - Intent refresh = new Intent(getActivity(), getActivity().getClass()); - startActivity(refresh); - getActivity().setResult(LANGUAGE_CHANGED); - getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); - getActivity().finish(); - - // update Reader tags as they need be localized - ReaderUpdateServiceStarter.startService(WordPress.getContext(), EnumSet.of(ReaderUpdateLogic.UpdateTask.TAGS)); - } - private boolean handleDevicePreferenceClick() { try { // open specific app info screen @@ -648,9 +597,8 @@ private boolean handleFeatureAnnouncementClick() { } private boolean handleAppLocalePickerClick() { - // if per-app language preferences are enabled and the device is on API 33+, take the user to the - // system app settings to change the language - if (mIsPerAppLanguagePrefsEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + // if the device is on API 33+, take the user to the system app settings to change the language + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { mPerAppLocaleManager.openAppLanguageSettings(getContext()); return true; } else if (getActivity() instanceof AppCompatActivity) { @@ -678,11 +626,7 @@ private void reattachLocalePickerCallback() { @Override public void onLocaleSelected(@NonNull String languageCode) { - if (mIsPerAppLanguagePrefsEnabled) { - mPerAppLocaleManager.setCurrentLocaleByLanguageCode(languageCode); - } else { - onPreferenceChange(mLanguagePreference, languageCode); - } + mPerAppLocaleManager.setCurrentLocaleByLanguageCode(languageCode); } private void handleOpenLinksInJetpack(Boolean newValue) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt index 5ab5227464f4..b521fda1f202 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt @@ -47,7 +47,6 @@ import javax.inject.Inject val experimentalFeatures = listOf( Feature(key = "experimental_block_editor"), Feature(key = "experimental_block_editor_theme_styles"), - Feature(key = PerAppLocaleManager.EXPERIMENTAL_PER_APP_LANGUAGE_PREF_KEY) ) data class Feature( @@ -76,18 +75,6 @@ class FeatureViewModel @Inject constructor( AppPrefs.setManualFeatureConfig(enabled, key) } } - - featureToggled(key, enabled) - } - - private fun featureToggled(key: String, enabled: Boolean) { - if (key == PerAppLocaleManager.EXPERIMENTAL_PER_APP_LANGUAGE_PREF_KEY) { - if (enabled) { - perAppLocaleManager.performMigrationIfNecessary() - } else { - perAppLocaleManager.resetApplicationLocale() - } - } } } 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 d6958dcde54b..66a596d2d5aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PerAppLocaleManager.kt @@ -77,33 +77,27 @@ 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 (isPerAppLanguagePrefsEnabled()) { - if (isApplicationLocaleEmpty()) { - val prefKey = LocaleManager.getLocalePrefKeyString() - val previousLanguage = appPrefsWrapper.getPrefString(prefKey, "") - if (previousLanguage?.isNotEmpty() == true) { - appLogWrapper.d( - AppLog.T.SETTINGS, - "PerAppLocaleManager: performing migration to AndroidX per-app language prefs" - ) - setCurrentLocaleByLanguageCode(previousLanguage) - } else { - appLogWrapper.d( - AppLog.T.SETTINGS, - "PerAppLocaleManager: setting default locale" - ) - setCurrentLocaleByLanguageCode(Locale.getDefault().language) - } + if (isApplicationLocaleEmpty()) { + val prefKey = LocaleManager.getLocalePrefKeyString() + val previousLanguage = appPrefsWrapper.getPrefString(prefKey, "") + if (previousLanguage?.isNotEmpty() == true) { + appLogWrapper.d( + AppLog.T.SETTINGS, + "PerAppLocaleManager: performing migration to AndroidX per-app language prefs" + ) + setCurrentLocaleByLanguageCode(previousLanguage) } else { - checkAndUpdateOldLanguagePrefKey() + appLogWrapper.d( + AppLog.T.SETTINGS, + "PerAppLocaleManager: setting default locale" + ) + setCurrentLocaleByLanguageCode(Locale.getDefault().language) } + } else { + checkAndUpdateOldLanguagePrefKey() } } - fun isPerAppLanguagePrefsEnabled(): Boolean { - return appPrefsWrapper.getManualFeatureConfig(EXPERIMENTAL_PER_APP_LANGUAGE_PREF_KEY) - } - /** * Open the app settings dialog so the user can change the app language. * Note that the per-app language setting is only available in API 33+ @@ -118,7 +112,21 @@ class PerAppLocaleManager @Inject constructor( } } - companion object { - const val EXPERIMENTAL_PER_APP_LANGUAGE_PREF_KEY = "experimental_per_app_language_prefs" - } + /** + * TODO - this was previously done in settings + fun onLanguageChanged() { + // Track language change on Analytics because we have both the device language and app selected language + // data in Tracks metadata. + val properties: MutableMap = HashMap() + properties["app_locale"] = Locale.getDefault() + AnalyticsTracker.track(AnalyticsTracker.Stat.ACCOUNT_SETTINGS_LANGUAGE_CHANGED, properties) + + + // Language is now part of metadata, so we need to refresh them + AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore) + + + // update Reader tags as they need be localized + ReaderUpdateServiceStarter.startService(getContext(), EnumSet.of(UpdateTask.TAGS)) + }*/ } diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index f684997cc9d3..76db2f186275 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -963,7 +963,6 @@ Experimental Features Experimental block editor Experimental block editor styles - Experimental per-app language preferences Debug Settings