Skip to content

Commit

Permalink
Feature branch: per-app language preferences (#21538)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury authored Dec 20, 2024
2 parents c540886 + 3c16073 commit 01f6aca
Show file tree
Hide file tree
Showing 121 changed files with 468 additions and 1,000 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public class JPScreenshotTest extends BaseTest {
@ClassRule
public static final RuleChain LOCALE_TEST_RULES = RuleChain
// Run fastlane's official LocaleTestRule (which switches device language + sets up screengrab) first
.outerRule(new LocaleTestRule())
// Run our own rule (which handles our in-app locale switching logic) second
.around(new WPLocaleTestRule());
.outerRule(new LocaleTestRule());

// Note: running this as a static @ClassRule as part of the above RuleChain doesn't seem to work
// (apparently that would make those run too early?), but running it as @Rule does fix the issue.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public class WPScreenshotTest extends BaseTest {
@ClassRule
public static final RuleChain LOCALE_TEST_RULES = RuleChain
// Run fastlane's official LocaleTestRule (which switches device language + sets up screengrab) first
.outerRule(new LocaleTestRule())
// Run our own rule (which handles our in-app locale switching logic) second
.around(new WPLocaleTestRule());
.outerRule(new LocaleTestRule());

// Note: running this as a static @ClassRule as part of the above RuleChain doesn't seem to work
// (apparently that would make those run too early?), but running it as @Rule does fix the issue.
Expand Down
25 changes: 1 addition & 24 deletions WordPress/src/main/java/org/wordpress/android/AppInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.EncryptedLogging
import org.wordpress.android.util.FluxCUtils
import org.wordpress.android.util.LocaleManager
import org.wordpress.android.util.NetworkUtils
import org.wordpress.android.util.PackageUtils
import org.wordpress.android.util.PerAppLocaleManager
Expand Down Expand Up @@ -950,13 +949,7 @@ 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)
}
// Do nothing
}

override fun onLowMemory() {
Expand Down Expand Up @@ -1091,21 +1084,5 @@ class AppInitializer @Inject constructor(
}
return bitmapCache as BitmapLruCache
}

/**
* Update locale of the static context when language is changed.
*
* When calling this method the application context **must** be already initialized.
* This is already the case in `Activity`, `Fragment` or `View`.
*
* When called from other places (E.g. a `TestRule`) we should provide it in the [appContext] parameter.
*/
fun updateContextLocale(appContext: Context? = null) {
val context = appContext ?: run {
check(context != null) { "Context must be initialized before calling updateContextLocale" }
return@run context
}
this.context = LocaleManager.setLocale(context)
}
}
}
7 changes: 0 additions & 7 deletions WordPress/src/main/java/org/wordpress/android/WordPress.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android

import android.app.Application
import android.content.Context
import coil.decode.VideoFrameDecoder
import com.android.volley.RequestQueue
import dagger.hilt.EntryPoints
Expand Down Expand Up @@ -59,12 +58,6 @@ abstract class WordPress : Application(), coil.ImageLoaderFactory {
@JvmStatic
fun getContext() = AppInitializer.context!!

@JvmStatic
@JvmOverloads
fun updateContextLocale(appContext: Context? = null) {
AppInitializer.updateContextLocale(appContext)
}

@JvmStatic
fun getRestClientUtils() = AppInitializer.restClientUtils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import android.os.Bundle
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import org.wordpress.android.ui.LocaleAwareActivity
import androidx.appcompat.app.AppCompatActivity
import org.wordpress.android.util.extensions.setContent

class DesignSystemActivity : LocaleAwareActivity() {
class DesignSystemActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import org.wordpress.android.localcontentmigration.LocalContentEntityData.UserFl
import org.wordpress.android.ui.prefs.AppPrefs.DeletablePrefKey
import org.wordpress.android.ui.prefs.AppPrefs.UndeletablePrefKey
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.viewmodel.ContextProvider
import javax.inject.Inject

class UserFlagsProviderHelper @Inject constructor(
private val appPrefsWrapper: AppPrefsWrapper,
contextProvider: ContextProvider,
localeManagerWrapper: LocaleManagerWrapper
) : LocalDataProviderHelper {
override fun getData(localEntityId: Int?): LocalContentEntityData =
UserFlagsData(
Expand Down Expand Up @@ -73,6 +71,5 @@ class UserFlagsProviderHelper @Inject constructor(
contextProvider.getContext().getString(R.string.pref_key_app_theme),
contextProvider.getContext().getString(R.string.pref_key_initial_screen),
contextProvider.getContext().getString(R.string.pref_key_send_crash),
localeManagerWrapper.getLocalePrefKeyString()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private void getNoteFromNoteId(String noteId, RestRequest.Listener listener,
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
Expand All @@ -44,7 +45,7 @@

import javax.inject.Inject;

public class AddQuickPressShortcutActivity extends LocaleAwareActivity {
public class AddQuickPressShortcutActivity extends AppCompatActivity {
public String[] blogNames;
public int[] siteIds;
public String[] blogUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.text.HtmlCompat;

Expand All @@ -35,7 +36,7 @@
/**
* views the activity log (see utils/AppLog.java)
*/
public class AppLogViewerActivity extends LocaleAwareActivity {
public class AppLogViewerActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import org.wordpress.android.R;
Expand Down Expand Up @@ -39,7 +40,7 @@
* <p>
* Redirects users to the stats activity if the jetpack connection was succesful
*/
public class JetpackConnectionResultActivity extends LocaleAwareActivity {
public class JetpackConnectionResultActivity extends AppCompatActivity {
private static final String ALREADY_CONNECTED = "already-connected";
private static final String REASON_PARAM = "reason";
private static final String SOURCE_PARAM = "source";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.TaskStackBuilder;
import androidx.preference.PreferenceManager;

Expand Down Expand Up @@ -43,7 +44,7 @@
* Moreover it lists what actions the user can perform and redirects the user to the activity,
* along with the content passed in the intent.
*/
public class ShareIntentReceiverActivity extends LocaleAwareActivity implements ShareIntentFragmentListener {
public class ShareIntentReceiverActivity extends AppCompatActivity implements ShareIntentFragmentListener {
private static final String SHARE_LAST_USED_BLOG_ID_KEY = "wp-settings-share-last-used-text-blogid";
private static final String KEY_SELECTED_SITE_LOCAL_ID = "KEY_SELECTED_SITE_LOCAL_ID";
private static final String KEY_SHARE_ACTION_ID = "KEY_SHARE_ACTION_ID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.wordpress.android.ui
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.wordpress.android.R
import org.wordpress.android.WordPress
Expand All @@ -12,7 +13,7 @@ import org.wordpress.android.util.ProfilingUtils
import org.wordpress.android.util.ToastUtils

@SuppressLint("CustomSplashScreen")
class WPLaunchActivity : LocaleAwareActivity() {
class WPLaunchActivity : AppCompatActivity() {
/*
* this the main (default) activity, which does nothing more than launch the
* previously active activity on startup - note that it's defined in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import org.wordpress.android.R;
Expand All @@ -25,7 +26,7 @@
/**
* Basic activity for displaying a WebView.
*/
public abstract class WebViewActivity extends LocaleAwareActivity {
public abstract class WebViewActivity extends AppCompatActivity {
/**
* Primary webview used to display content.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.automattic.about.model.AboutConfigProvider
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.LocaleAwareActivity
import androidx.appcompat.app.AppCompatActivity
import org.wordpress.android.ui.about.UnifiedAboutNavigationAction.Dismiss
import org.wordpress.android.ui.about.UnifiedAboutNavigationAction.OpenBlog
import org.wordpress.android.viewmodel.observeEvent
import javax.inject.Inject

class UnifiedAboutActivity : LocaleAwareActivity(), AboutConfigProvider {
class UnifiedAboutActivity : AppCompatActivity(), AboutConfigProvider {
@Inject
lateinit var viewModel: UnifiedAboutViewModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.wordpress.android.support.ZendeskHelper
import org.wordpress.android.ui.ActivityId
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.AppLogViewerActivity
import org.wordpress.android.ui.LocaleAwareActivity
import androidx.appcompat.app.AppCompatActivity
import org.wordpress.android.ui.debug.DebugSettingsActivity
import org.wordpress.android.ui.main.utils.MeGravatarLoader
import org.wordpress.android.ui.prefs.AppPrefs
Expand All @@ -50,7 +50,7 @@ import javax.inject.Inject
import android.R as AndroidR

@AndroidEntryPoint
class HelpActivity : LocaleAwareActivity() {
class HelpActivity : AppCompatActivity() {
@Inject
lateinit var accountStore: AccountStore

Expand Down
Loading

0 comments on commit 01f6aca

Please sign in to comment.