Skip to content

Commit

Permalink
Removed experimental feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Dec 11, 2024
1 parent 3916b30 commit d7294cd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,31 +48,26 @@
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;
import org.wordpress.android.util.AppLog;
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;
import org.wordpress.android.util.analytics.AnalyticsUtils;
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;
Expand All @@ -86,7 +80,6 @@ public class AppSettingsFragment extends PreferenceFragment

private WPPreference mLanguagePreference;
private ListPreference mAppThemePreference;
private ListPreference mInitialScreenPreference;

// This Device settings
private WPSwitchPreference mOptimizedImage;
Expand All @@ -101,7 +94,6 @@ public class AppSettingsFragment extends PreferenceFragment
private WPSwitchPreference mOpenWebLinksWithJetpack;

private Preference mWhatsNew;
private Boolean mIsPerAppLanguagePrefsEnabled;

@Inject SiteStore mSiteStore;
@Inject AccountStore mAccountStore;
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<String, Object> properties = new HashMap<>();
Expand Down Expand Up @@ -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<String, Object> 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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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<String, Any?> = 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))
}*/
}
1 change: 0 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@
<string name="experimental_features_screen_title">Experimental Features</string>
<string name="experimental_block_editor">Experimental block editor</string>
<string name="experimental_block_editor_theme_styles">Experimental block editor styles</string>
<string name="experimental_per_app_language_prefs">Experimental per-app language preferences</string>

<!-- Debug settings -->
<string name="preference_open_debug_settings" translatable="false">Debug Settings</string>
Expand Down

0 comments on commit d7294cd

Please sign in to comment.