Skip to content

Commit 46f0326

Browse files
committed
Attempt to set/reset locale without requiring restart
1 parent 93191a6 commit 46f0326

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
367367
InstallationReferrerServiceStarter.startService(this, null);
368368
}
369369

370-
mLocaleHelper.performMigrationIfNecessary(this);
370+
mLocaleHelper.performMigrationIfNecessary();
371371

372372
if (FluxCUtils.isSignedInWPComOrHasWPOrgSite(mAccountStore, mSiteStore)
373373
&& !AppPrefs.getIsJetpackMigrationInProgress()) {

WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsFragment.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import android.preference.PreferenceFragment;
1414
import android.preference.PreferenceScreen;
1515
import android.preference.SwitchPreference;
16-
import android.provider.Settings;
1716
import android.text.TextUtils;
1817
import android.view.LayoutInflater;
1918
import android.view.MenuItem;

WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import androidx.compose.ui.tooling.preview.Preview
3232
import androidx.lifecycle.ViewModel
3333
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3434
import dagger.hilt.android.AndroidEntryPoint
35+
import dagger.hilt.android.lifecycle.HiltViewModel
3536
import kotlinx.coroutines.flow.MutableStateFlow
3637
import kotlinx.coroutines.flow.StateFlow
3738
import kotlinx.coroutines.flow.asStateFlow
@@ -41,6 +42,7 @@ import org.wordpress.android.ui.compose.theme.AppThemeM3
4142
import org.wordpress.android.ui.compose.unit.Margin
4243
import org.wordpress.android.ui.prefs.language.LocaleHelper
4344
import org.wordpress.android.util.extensions.setContent
45+
import javax.inject.Inject
4446

4547
val experimentalFeatures = listOf(
4648
Feature(key = "experimental_block_editor"),
@@ -53,7 +55,10 @@ data class Feature(
5355
val key: String,
5456
)
5557

56-
class FeatureViewModel : ViewModel() {
58+
@HiltViewModel
59+
class FeatureViewModel @Inject constructor(
60+
private val localeHelper: LocaleHelper
61+
) : ViewModel() {
5762
private val _switchStates = MutableStateFlow<Map<String, Feature>>(emptyMap())
5863
val switchStates: StateFlow<Map<String, Feature>> = _switchStates.asStateFlow()
5964

@@ -71,6 +76,14 @@ class FeatureViewModel : ViewModel() {
7176
AppPrefs.setManualFeatureConfig(enabled, key)
7277
}
7378
}
79+
80+
if (key == LocaleHelper.EXPERIMENTAL_PER_APP_LANGUAGE_PREF_KEY) {
81+
if (enabled) {
82+
localeHelper.performMigrationIfNecessary()
83+
} else {
84+
localeHelper.resetApplicationLocale()
85+
}
86+
}
7487
}
7588
}
7689

WordPress/src/main/java/org/wordpress/android/ui/prefs/language/LocaleHelper.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.provider.Settings
88
import androidx.appcompat.app.AppCompatDelegate
99
import androidx.core.os.LocaleListCompat
1010
import org.wordpress.android.R
11+
import org.wordpress.android.WordPress
1112
import org.wordpress.android.fluxc.utils.AppLogWrapper
1213
import org.wordpress.android.ui.prefs.AppPrefsWrapper
1314
import org.wordpress.android.util.AppLog
@@ -60,9 +61,10 @@ class LocaleHelper @Inject constructor(
6061
/**
6162
* Previously the app locale was stored in SharedPreferences, so here we migrate to AndroidX per-app language prefs
6263
*/
63-
fun performMigrationIfNecessary(context: Context) {
64+
fun performMigrationIfNecessary() {
65+
resetApplicationLocale() // TODO remove
6466
if (isPerAppLanguagePrefsEnabled() && isApplicationLocaleEmpty()) {
65-
val languagePrefKey = context.getString(R.string.pref_key_language)
67+
val languagePrefKey = WordPress.getContext().getString(R.string.pref_key_language)
6668
val previousLanguage = appPrefsWrapper.prefs().getString(languagePrefKey, "")
6769
if (previousLanguage?.isNotEmpty() == true) {
6870
appLogWrapper.d(

0 commit comments

Comments
 (0)