From 918da4d26407bf541133e689cc3e2e4c811b5776 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Tue, 6 Mar 2018 21:50:39 -0700 Subject: [PATCH 01/12] Fix custom app language selection issues across various android versions * Retain custom language selection across application kill/restarts on devices running api 24 and above. * Instantly apply the language selection and update all views on devices running api 23 and less. * Change to the app language now consistent across all versions of android. * Update the title of MediaBrowserActivity to use the localized string. Tickets: #7267, #7265 --- WordPress/src/main/AndroidManifest.xml | 4 + .../org/wordpress/android/BaseActivity.java | 14 ++ .../wordpress/android/BaseListActivity.java | 14 ++ .../java/org/wordpress/android/WordPress.java | 12 +- .../ui/AddQuickPressShortcutActivity.java | 3 +- .../android/ui/AppLogViewerActivity.java | 4 +- .../ui/DeepLinkingIntentReceiverActivity.java | 4 +- .../android/ui/HelpshiftDeepLinkReceiver.java | 5 +- .../ui/ShareIntentReceiverActivity.java | 4 +- .../ui/VisualEditorOptionsReceiver.java | 4 +- .../android/ui/WPLaunchActivity.java | 4 +- .../wordpress/android/ui/WebViewActivity.java | 4 +- .../android/ui/accounts/HelpActivity.java | 4 +- .../android/ui/accounts/LoginActivity.java | 4 +- .../ui/accounts/LoginEpilogueActivity.java | 4 +- .../android/ui/accounts/NewBlogActivity.java | 4 +- .../ui/accounts/SignupEpilogueActivity.java | 4 +- .../ui/accounts/SiteCreationActivity.java | 4 +- .../android/ui/comments/CommentsActivity.java | 4 +- .../ui/comments/CommentsDetailActivity.java | 4 +- .../ui/comments/EditCommentActivity.java | 4 +- .../android/ui/main/SitePickerActivity.java | 4 +- .../android/ui/main/WPMainActivity.java | 4 +- .../ui/media/MediaBrowserActivity.java | 5 +- .../ui/media/MediaPreviewActivity.java | 4 +- .../ui/media/MediaSettingsActivity.java | 4 +- .../NotificationsDetailActivity.java | 4 +- .../ui/people/PeopleManagementActivity.java | 4 +- .../ui/photopicker/PhotoPickerActivity.java | 4 +- .../android/ui/plans/PlansActivity.java | 4 +- .../ui/plugins/PluginBrowserActivity.java | 4 +- .../ui/plugins/PluginDetailActivity.java | 4 +- .../android/ui/posts/EditPostActivity.java | 4 +- .../android/ui/posts/PostPreviewActivity.java | 4 +- .../ui/posts/PostSettingsTagsActivity.java | 4 +- .../android/ui/posts/PostsListActivity.java | 4 +- .../ui/posts/SelectCategoriesActivity.java | 4 +- .../android/ui/prefs/AboutActivity.java | 4 +- .../ui/prefs/AccountSettingsActivity.java | 4 +- .../android/ui/prefs/AppSettingsActivity.java | 4 +- .../android/ui/prefs/AppSettingsFragment.java | 38 +---- .../ui/prefs/BlogPreferencesActivity.java | 4 +- .../android/ui/prefs/MyProfileActivity.java | 4 +- .../NotificationsSettingsActivity.java | 4 +- .../ui/publicize/PublicizeListActivity.java | 4 +- .../ui/reader/ReaderCommentListActivity.java | 4 +- .../ui/reader/ReaderPhotoViewerActivity.java | 4 +- .../ui/reader/ReaderPostListActivity.java | 4 +- .../ui/reader/ReaderPostPagerActivity.java | 4 +- .../android/ui/reader/ReaderSubsActivity.java | 4 +- .../ui/reader/ReaderUserListActivity.java | 4 +- .../ui/reader/ReaderVideoViewerActivity.java | 4 +- .../android/ui/reader/utils/ReaderUtils.java | 3 +- .../android/ui/stats/StatsActivity.java | 4 +- .../ui/stats/StatsConnectJetpackActivity.java | 4 +- .../stats/StatsSingleItemDetailsActivity.java | 4 +- .../ui/stats/StatsViewAllActivity.java | 4 +- .../stats/StatsWidgetConfigureActivity.java | 4 +- .../ui/themes/ThemeBrowserActivity.java | 4 +- .../wordpress/android/util/LocaleManager.java | 146 ++++++++++++++++++ .../android/util/WPActivityUtils.java | 35 ----- 61 files changed, 302 insertions(+), 177 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/BaseActivity.java create mode 100644 WordPress/src/main/java/org/wordpress/android/BaseListActivity.java create mode 100644 WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index e5c377cde5b7..0589cb66f0c8 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -509,6 +509,10 @@ + + + + = Build.VERSION_CODES.JELLY_BEAN_MR1) { - conf.setLayoutDirection(newLocale); - } - res.updateConfiguration(conf, res.getDisplayMetrics()); - // 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", conf.locale.toString()); + properties.put("app_locale", newContext.getResources().getConfiguration().locale.toString()); 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().finish(); + // Restart the app to apply the new language. + System.exit(0); } private void updateLanguagePreference(String languageCode) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java index ed1334eac2a9..e2d3f25ce0b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java @@ -4,12 +4,12 @@ import android.app.FragmentManager; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import org.apache.commons.text.StringEscapeUtils; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -29,7 +29,7 @@ /** * Activity for configuring blog specific settings. */ -public class BlogPreferencesActivity extends AppCompatActivity { +public class BlogPreferencesActivity extends BaseActivity { private static final String KEY_SETTINGS_FRAGMENT = "settings-fragment"; private SiteModel mSite; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java index e8af9e866756..899ebde7c3b0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java @@ -3,9 +3,9 @@ import android.app.FragmentManager; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -13,7 +13,7 @@ import javax.inject.Inject; -public class MyProfileActivity extends AppCompatActivity { +public class MyProfileActivity extends BaseActivity { private static final String KEY_MY_PROFILE_FRAGMENT = "my-profile-fragment"; @Inject Dispatcher mDispatcher; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java index 4f8496041f06..59074c055e14 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java @@ -4,7 +4,6 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.Toolbar; @@ -16,6 +15,7 @@ import android.widget.TextView; import android.widget.Toast; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.ui.notifications.NotificationEvents; @@ -23,7 +23,7 @@ import de.greenrobot.event.EventBus; // Simple wrapper activity for NotificationsSettingsFragment -public class NotificationsSettingsActivity extends AppCompatActivity { +public class NotificationsSettingsActivity extends BaseActivity { private TextView mMessageTextView; private View mMessageContainer; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index e3ca559cfd3e..41855b2188ef 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -8,10 +8,10 @@ import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; @@ -27,7 +27,7 @@ import de.greenrobot.event.EventBus; -public class PublicizeListActivity extends AppCompatActivity +public class PublicizeListActivity extends BaseActivity implements PublicizeActions.OnPublicizeActionListener, PublicizeServiceAdapter.OnServiceClickListener, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index c4eb5c2583d0..ebe55cf5d5b9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -6,7 +6,6 @@ import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.Toolbar; import android.text.TextUtils; @@ -17,6 +16,7 @@ import android.widget.ProgressBar; import android.widget.TextView; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -62,7 +62,7 @@ import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; -public class ReaderCommentListActivity extends AppCompatActivity { +public class ReaderCommentListActivity extends BaseActivity { private static final String KEY_REPLY_TO_COMMENT_ID = "reply_to_comment_id"; private static final String KEY_HAS_UPDATED_COMMENTS = "has_updated_comments"; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java index 1a72c2f47023..1b088c6ef1b6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java @@ -7,11 +7,11 @@ import android.support.annotation.NonNull; import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.TextView; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.ui.reader.models.ReaderImageList; import org.wordpress.android.ui.reader.utils.ReaderImageScanner; @@ -26,7 +26,7 @@ * Full-screen photo viewer - uses a ViewPager to enable scrolling between images in a blog * post, but also supports viewing a single image */ -public class ReaderPhotoViewerActivity extends AppCompatActivity +public class ReaderPhotoViewerActivity extends BaseActivity implements PhotoViewListener { private String mInitialImageUrl; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java index 64827b358e54..386cf53c4f37 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java @@ -6,11 +6,11 @@ import android.support.design.widget.AppBarLayout; import android.support.design.widget.CoordinatorLayout; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.datasets.ReaderBlogTable; import org.wordpress.android.models.ReaderTag; @@ -20,7 +20,7 @@ * serves as the host for ReaderPostListFragment when showing blog preview & tag preview */ -public class ReaderPostListActivity extends AppCompatActivity { +public class ReaderPostListActivity extends BaseActivity { private ReaderPostListType mPostListType; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java index 6d19a17aaf31..e8bb5db2270c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java @@ -11,7 +11,6 @@ import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.SparseArray; @@ -20,6 +19,7 @@ import android.view.ViewGroup; import android.widget.ProgressBar; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -71,7 +71,7 @@ * * Will also handle jumping to the comments section, liking a commend and liking a post directly */ -public class ReaderPostPagerActivity extends AppCompatActivity +public class ReaderPostPagerActivity extends BaseActivity implements ReaderInterfaces.AutoHideToolbarListener { /** diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 16cb45bab961..08666b1548ff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -10,7 +10,6 @@ import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Gravity; @@ -24,6 +23,7 @@ import android.widget.TextView; import android.widget.Toast; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.datasets.ReaderBlogTable; @@ -57,7 +57,7 @@ * activity which shows the user's subscriptions and recommended subscriptions - includes * followed tags, followed blogs, and recommended blogs */ -public class ReaderSubsActivity extends AppCompatActivity +public class ReaderSubsActivity extends BaseActivity implements ReaderTagAdapter.TagDeletedListener { private EditText mEditAdd; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java index 9272c2e4f6f7..b3e902b9780a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java @@ -2,11 +2,11 @@ import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.Toolbar; import android.view.View; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.datasets.ReaderCommentTable; import org.wordpress.android.datasets.ReaderPostTable; @@ -21,7 +21,7 @@ /* * displays a list of users who like a specific reader post */ -public class ReaderUserListActivity extends AppCompatActivity { +public class ReaderUserListActivity extends BaseActivity { private ReaderRecyclerView mRecyclerView; private ReaderUserAdapter mAdapter; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java index e7a3bc051a8e..41cf7b577f79 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java @@ -3,12 +3,12 @@ import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.ProgressBar; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; @@ -16,7 +16,7 @@ * Full screen landscape video player for the reader */ -public class ReaderVideoViewerActivity extends AppCompatActivity { +public class ReaderVideoViewerActivity extends BaseActivity { private String mVideoUrl; private WebView mWebView; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java index a69910863830..5757b75cf103 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java @@ -15,6 +15,7 @@ import org.wordpress.android.models.ReaderTag; import org.wordpress.android.models.ReaderTagType; import org.wordpress.android.util.FormatUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.UrlUtils; @@ -97,7 +98,7 @@ public static String getLongLikeLabelText(Context context, int numLikes, boolean return context.getString(R.string.reader_likes_one); } else { String likes = context.getString(R.string.reader_likes_multi); - return String.format(likes, numLikes); + return String.format(LocaleManager.getSafeLocale(context), likes, numLikes); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java index 20b7e46e3477..f627773059b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDialogFragment; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; @@ -22,6 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -59,7 +59,7 @@ * By pressing a spinner on the action bar, the user can select which timeframe they wish to see. *

*/ -public class StatsActivity extends AppCompatActivity +public class StatsActivity extends BaseActivity implements NestedScrollViewExt.ScrollViewListener, StatsVisitorsAndViewsFragment.OnDateChangeListener, StatsVisitorsAndViewsFragment.OnOverviewItemChangeListener, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java index a5685c48f5c0..71653f35d014 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java @@ -3,12 +3,12 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -26,7 +26,7 @@ * It offers a link to the Jetpack connection flow. */ -public class StatsConnectJetpackActivity extends AppCompatActivity { +public class StatsConnectJetpackActivity extends BaseActivity { @Inject AccountStore mAccountStore; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java index 0571206f2741..23af65ba3c53 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.MenuItem; @@ -25,6 +24,7 @@ import org.json.JSONException; import org.json.JSONObject; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -52,7 +52,7 @@ /** * Single item details activity. */ -public class StatsSingleItemDetailsActivity extends AppCompatActivity +public class StatsSingleItemDetailsActivity extends BaseActivity implements StatsBarGraph.OnGestureListener{ public static final String ARG_REMOTE_BLOG_ID = "ARG_REMOTE_BLOG_ID"; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java index 623befa2c1f6..eccbba5b7c78 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java @@ -4,12 +4,12 @@ import android.app.FragmentTransaction; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; import android.widget.TextView; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.analytics.AnalyticsTracker.Stat; @@ -33,7 +33,7 @@ /** * Single item details activity. */ -public class StatsViewAllActivity extends AppCompatActivity { +public class StatsViewAllActivity extends BaseActivity { public static final String ARG_STATS_VIEW_ALL_TITLE = "arg_stats_view_all_title"; private static final String SAVED_STATS_SCROLL_POSITION = "SAVED_STATS_SCROLL_POSITION"; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java index bf0d636a3337..1767ee153d30 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java @@ -9,12 +9,12 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.MenuItem; import android.view.View; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.SiteModel; @@ -27,7 +27,7 @@ import javax.inject.Inject; -public class StatsWidgetConfigureActivity extends AppCompatActivity +public class StatsWidgetConfigureActivity extends BaseActivity implements StatsWidgetConfigureAdapter.OnSiteClickListener { private StatsWidgetConfigureAdapter mAdapter; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index bd1f676236ba..02014e8ff6d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -7,13 +7,13 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.MenuItem; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker.Stat; @@ -38,7 +38,7 @@ import javax.inject.Inject; -public class ThemeBrowserActivity extends AppCompatActivity implements ThemeBrowserFragmentCallback { +public class ThemeBrowserActivity extends BaseActivity implements ThemeBrowserFragmentCallback { public static boolean isAccessible(SiteModel site) { // themes are only accessible to admin wordpress.com users diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java new file mode 100644 index 000000000000..fbfa815e0736 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -0,0 +1,146 @@ +package org.wordpress.android.util; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; +import android.preference.PreferenceManager; + +import org.wordpress.android.WordPress; + +import java.util.Locale; + +import javax.annotation.Nullable; + +/** + * Helper class for working with localized strings. Ensures updates to the users + * selected language is properly saved and resources appropriately updated for the + * android version. + */ +public abstract class LocaleManager { + + private static final String LANGUAGE_KEY = "language-pref"; + + /** + * Activate the locale associated with the provided context. + * @param context The current context. + */ + public static Context setLocale(Context context) { + return updateResources(context, getLanguage(context)); + } + + /** + * Change the active locale to the language provided. Save the updated language + * settings to sharedPreferences. + * @param context The current context + * @param language The language to change to + */ + public static Context setNewLocale(Context context, String language) { + Locale newLocale = WPPrefUtils.languageLocale(language); + + if (Locale.getDefault().toString().equals(newLocale.toString())) { + removePersistedLanguage(context); + } else { + saveLanguageToPref(context, language); + } + return updateResources(context, language); + } + + /** + * Compare the language for the current context with another language. + * @param context The current context + * @param language The language to compare + * @return True if the languages are the same, else false + */ + public static boolean isDifferentLanguage(Context context, String language) { + Locale currentLocale = LanguageUtils.getCurrentDeviceLanguage(WordPress.getContext()); + Locale newLocale = WPPrefUtils.languageLocale(language); + + return !currentLocale.getLanguage().equals(newLocale.getLanguage()); + } + + /** + * If the user has selected a language other than the device default, return that + * language code, else just return the device default language code. + * @return The 2-letter language code + */ + private static String getLanguage(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.contains(LANGUAGE_KEY)) { + return prefs.getString(LANGUAGE_KEY, ""); + } + return LanguageUtils.getCurrentDeviceLanguageCode(context); + } + + /** + * Save the updated language to SharedPreferences. + * Use commit() instead of apply() to ensure the language preference is saved instantly + * as the app may be restarted immediately. + * @param context The current context + * @param language The 2-letter language code (example "en") + */ + @SuppressLint("ApplySharedPref") + private static void saveLanguageToPref(Context context, String language) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putString(LANGUAGE_KEY, language).commit(); + } + + /** + * Remove any saved custom language selection from SharedPreferences. + * Use commit() instead of apply() to ensure the language preference is saved instantly + * as the app may be restarted immediately. + * @param context The current context + */ + @SuppressLint("ApplySharedPref") + private static void removePersistedLanguage(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().remove(LANGUAGE_KEY).commit(); + } + + private static Context updateResources(Context context, String language) { + Locale locale = new Locale(language); + Locale.setDefault(locale); + + Resources res = context.getResources(); + Configuration config = new Configuration(res.getConfiguration()); + if (Build.VERSION.SDK_INT >= 17) { + config.setLocale(locale); + context = context.createConfigurationContext(config); + } else { + config.locale = locale; + res.updateConfiguration(config, res.getDisplayMetrics()); + } + return context; + } + + /** + * Method gets around a bug in the java.util.Formatter for API 7.x as detailed here + * [https://bugs.openjdk.java.net/browse/JDK-8167567]. Any strings that contain + * locale-specific grouping separators should use: + * + * String.format(LocaleManager.getSafeLocale(context), baseString, val) + * + * + * An example of a string that contains locale-specific grouping separators: + * + * %,d likes + * + */ + public static Locale getSafeLocale(@Nullable Context context) { + Locale baseLocale; + if (context == null) { + baseLocale = Locale.getDefault(); + } else { + Configuration config = context.getResources().getConfiguration(); + baseLocale = Build.VERSION.SDK_INT >= 24 ? config.getLocales().get(0) : config.locale; + } + + if (Build.VERSION.SDK_INT >= 24) { + return WPPrefUtils.languageLocale(baseLocale.getLanguage()); + } else { + return baseLocale; + } + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/util/WPActivityUtils.java b/WordPress/src/main/java/org/wordpress/android/util/WPActivityUtils.java index e763057ff2ec..883faa49759a 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/WPActivityUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/util/WPActivityUtils.java @@ -6,18 +6,12 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.res.Configuration; -import android.content.res.Resources; import android.os.Build; -import android.preference.PreferenceManager; -import android.support.v4.text.TextUtilsCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,10 +20,8 @@ import android.widget.TextView; import org.wordpress.android.R; -import org.wordpress.android.ui.prefs.AppSettingsFragment; import java.util.List; -import java.util.Locale; public class WPActivityUtils { // Hack! PreferenceScreens don't show the toolbar, so we'll manually add one @@ -98,33 +90,6 @@ public static void setStatusBarColor(Window window, int color) { } } - public static void applyLocale(Context context) { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - - if (sharedPreferences.contains(AppSettingsFragment.LANGUAGE_PREF_KEY)) { - Locale contextLocale = context.getResources().getConfiguration().locale; - String contextLanguage = contextLocale.getLanguage(); - contextLanguage = LanguageUtils.patchDeviceLanguageCode(contextLanguage); - String contextCountry = contextLocale.getCountry(); - String locale = sharedPreferences.getString(AppSettingsFragment.LANGUAGE_PREF_KEY, ""); - - if (!TextUtils.isEmpty(contextCountry)) { - contextLanguage += "_" + contextCountry; - } - - if (!locale.equals(contextLanguage)) { - Resources resources = context.getResources(); - Configuration conf = resources.getConfiguration(); - Locale newLocale = WPPrefUtils.languageLocale(locale); - conf.locale = newLocale; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - conf.setLayoutDirection(newLocale); - } - resources.updateConfiguration(conf, resources.getDisplayMetrics()); - } - } - } - public static Context getThemedContext(Context context) { if (context instanceof AppCompatActivity) { ActionBar actionBar = ((AppCompatActivity)context).getSupportActionBar(); From 7eca3d5cafa1f87669c09ac98df8924ae5d298a6 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Tue, 6 Mar 2018 22:30:00 -0700 Subject: [PATCH 02/12] Fix other possible places that may run into the bug as defined here: https://bugs.openjdk.java.net/browse/JDK-8167567 --- .../android/ui/reader/utils/ReaderUtils.java | 3 ++- .../ui/reader/views/ReaderSiteHeaderView.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java index 5757b75cf103..e3e4ae4e0e2f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/utils/ReaderUtils.java @@ -91,7 +91,8 @@ public static String getLongLikeLabelText(Context context, int numLikes, boolean return context.getString(R.string.reader_likes_you_and_one); default: String youAndMultiLikes = context.getString(R.string.reader_likes_you_and_multi); - return String.format(youAndMultiLikes, numLikes - 1); + return String.format( + LocaleManager.getSafeLocale(context), youAndMultiLikes, numLikes - 1); } } else { if (numLikes == 1) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java index 44c29fb9f0bc..9756d89b75cf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java @@ -14,6 +14,7 @@ import org.wordpress.android.models.ReaderBlog; import org.wordpress.android.ui.reader.actions.ReaderActions; import org.wordpress.android.ui.reader.actions.ReaderBlogActions; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UrlUtils; @@ -132,11 +133,15 @@ private void showBlogInfo(ReaderBlog blogInfo) { } try { - txtFollowCount.setText(String.format(getContext().getString(R.string.reader_label_follow_count), blogInfo.numSubscribers)); + txtFollowCount.setText(String.format( + LocaleManager.getSafeLocale(getContext()), + getContext().getString(R.string.reader_label_follow_count), + blogInfo.numSubscribers)); } catch (ArithmeticException exception) { - // See https://github.com/wordpress-mobile/WordPress-Android/issues/5568 - // In case of a "ArithmeticException: divide by zero", force the use of "US" locale to format the string. - txtFollowCount.setText(String.format(Locale.US, getContext().getString(R.string.reader_label_follow_count), blogInfo.numSubscribers)); + txtFollowCount.setText(String.format( + LocaleManager.getSafeLocale(getContext()), + getContext().getString(R.string.reader_label_follow_count), + blogInfo.numSubscribers)); } if (!mAccountStore.hasAccessToken()) { From 2aa4018c42f8070fbd9e42a5684454697ec9b9b0 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Wed, 7 Mar 2018 12:57:54 -0700 Subject: [PATCH 03/12] Fix checkstyle errors. --- WordPress/src/main/java/org/wordpress/android/BaseActivity.java | 1 - .../src/main/java/org/wordpress/android/BaseListActivity.java | 1 - .../org/wordpress/android/ui/AddQuickPressShortcutActivity.java | 1 - .../org/wordpress/android/ui/prefs/AppSettingsFragment.java | 2 +- .../wordpress/android/ui/reader/views/ReaderSiteHeaderView.java | 2 -- .../android/ui/stats/StatsSingleItemDetailsActivity.java | 2 +- .../src/main/java/org/wordpress/android/util/LocaleManager.java | 1 - 7 files changed, 2 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/BaseActivity.java b/WordPress/src/main/java/org/wordpress/android/BaseActivity.java index b5340e29132f..9c1a38e6fa26 100644 --- a/WordPress/src/main/java/org/wordpress/android/BaseActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/BaseActivity.java @@ -6,7 +6,6 @@ import org.wordpress.android.util.LocaleManager; public class BaseActivity extends AppCompatActivity { - @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(LocaleManager.setLocale(newBase)); diff --git a/WordPress/src/main/java/org/wordpress/android/BaseListActivity.java b/WordPress/src/main/java/org/wordpress/android/BaseListActivity.java index 618d38549315..199a7d7b87f7 100644 --- a/WordPress/src/main/java/org/wordpress/android/BaseListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/BaseListActivity.java @@ -6,7 +6,6 @@ import org.wordpress.android.util.LocaleManager; public class BaseListActivity extends ListActivity { - @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(LocaleManager.setLocale(newBase)); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java index 0064110c3b1e..1b749d739389 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java @@ -1,7 +1,6 @@ package org.wordpress.android.ui; import android.app.AlertDialog; -import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; 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 5f4c43059feb..7a1d3f7ab340 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 @@ -35,7 +35,7 @@ import javax.inject.Inject; -public class AppSettingsFragment extends PreferenceFragment +public class AppSettingsFragment extends PreferenceFragment implements OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public static final int LANGUAGE_CHANGED = 1000; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java index 679389f373d2..74c7268e5019 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java @@ -19,8 +19,6 @@ import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UrlUtils; -import java.util.Locale; - import javax.inject.Inject; /** diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java index 5a00cd44e839..5e6e36a942c3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java @@ -52,7 +52,7 @@ * Single item details activity. */ public class StatsSingleItemDetailsActivity extends BaseActivity - implements StatsBarGraph.OnGestureListener{ + implements StatsBarGraph.OnGestureListener { public static final String ARG_REMOTE_BLOG_ID = "ARG_REMOTE_BLOG_ID"; public static final String ARG_REMOTE_ITEM_ID = "ARG_REMOTE_ITEM_ID"; public static final String ARG_REMOTE_ITEM_TYPE = "ARG_REMOTE_ITEM_TYPE"; diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index fbfa815e0736..a184c8523293 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -20,7 +20,6 @@ * android version. */ public abstract class LocaleManager { - private static final String LANGUAGE_KEY = "language-pref"; /** From 7ea384a377462aca57b72b33b143b04f02afcc0f Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Wed, 7 Mar 2018 21:33:13 -0700 Subject: [PATCH 04/12] Cleaner fix for applying app language changes during runtime across API levels * Remove need for forcing an app restart using System.exit(0) and force WPMainActivity to recreate itself. * Contrary to the docs, API 17 & 19 require locale updates to happen using both the old way. Tickets: #7267, #7265 --- .../android/ui/main/WPMainActivity.java | 9 +++++- .../android/ui/prefs/AppSettingsFragment.java | 9 ++++-- .../wordpress/android/util/LocaleManager.java | 28 +++++++++++-------- .../wordpress/android/util/WPPrefUtils.java | 3 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 67bc0fe81f59..80994160f096 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -653,7 +653,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { break; case RequestCodes.APP_SETTINGS: if (resultCode == AppSettingsFragment.LANGUAGE_CHANGED) { - resetFragments(); + appLanguageChanged(); } break; case RequestCodes.NOTE_DETAIL: @@ -669,6 +669,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } + private void appLanguageChanged() { + // Recreate this activity (much like a configuration change) + recreate(); + + resetFragments(); + } + private void startWithNewAccount() { startService(new Intent(this, GCMRegistrationIntentService.class)); resetFragments(); 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 7a1d3f7ab340..82f0e06c4c12 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 @@ -277,7 +277,7 @@ private void changeLanguage(String languageCode) { return; } - if (!LocaleManager.isDifferentLanguage(WordPress.getContext(), languageCode)) { + if (!LocaleManager.isDifferentLanguage(languageCode)) { return; } @@ -293,8 +293,11 @@ private void changeLanguage(String languageCode) { // Language is now part of metadata, so we need to refresh them AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore); - // Restart the app to apply the new language. - System.exit(0); + // Refresh the app + Intent refresh = new Intent(getActivity(), getActivity().getClass()); + startActivity(refresh); + getActivity().setResult(LANGUAGE_CHANGED); + getActivity().finish(); } private void updateLanguagePreference(String languageCode) { diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index a184c8523293..025dfabc8ceb 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -8,8 +8,6 @@ import android.os.Build; import android.preference.PreferenceManager; -import org.wordpress.android.WordPress; - import java.util.Locale; import javax.annotation.Nullable; @@ -34,7 +32,7 @@ public static Context setLocale(Context context) { * Change the active locale to the language provided. Save the updated language * settings to sharedPreferences. * @param context The current context - * @param language The language to change to + * @param language The 2-letter language code (example "en") to switch to */ public static Context setNewLocale(Context context, String language) { Locale newLocale = WPPrefUtils.languageLocale(language); @@ -49,21 +47,18 @@ public static Context setNewLocale(Context context, String language) { /** * Compare the language for the current context with another language. - * @param context The current context * @param language The language to compare * @return True if the languages are the same, else false */ - public static boolean isDifferentLanguage(Context context, String language) { - Locale currentLocale = LanguageUtils.getCurrentDeviceLanguage(WordPress.getContext()); + public static boolean isDifferentLanguage(String language) { Locale newLocale = WPPrefUtils.languageLocale(language); - - return !currentLocale.getLanguage().equals(newLocale.getLanguage()); + return !Locale.getDefault().getLanguage().equals(newLocale.getLanguage()); } /** * If the user has selected a language other than the device default, return that * language code, else just return the device default language code. - * @return The 2-letter language code + * @return The 2-letter language code (example "en") */ private static String getLanguage(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -98,16 +93,27 @@ private static void removePersistedLanguage(Context context) { prefs.edit().remove(LANGUAGE_KEY).commit(); } + /** + * Update resources for the current session. + * + * @param context The current active context + * @param language The 2-letter language code (example "en") + * @return The modified context containing the updated localized resources + */ private static Context updateResources(Context context, String language) { Locale locale = new Locale(language); Locale.setDefault(locale); Resources res = context.getResources(); Configuration config = new Configuration(res.getConfiguration()); - if (Build.VERSION.SDK_INT >= 17) { + + // NOTE: Earlier versions of Android require both of these to be set, otherwise + // RTL may not be implemented properly. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { config.setLocale(locale); context = context.createConfigurationContext(config); - } else { + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) { config.locale = locale; res.updateConfiguration(config, res.getDisplayMetrics()); } diff --git a/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java b/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java index 2581921d123f..ab26e0244764 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java @@ -13,7 +13,6 @@ import android.widget.TextView; import org.wordpress.android.R; -import org.wordpress.android.WordPress; import java.text.Collator; import java.util.ArrayList; @@ -193,7 +192,7 @@ public static void setTextViewAttributes(TextView textView, int size, int colorR */ public static Locale languageLocale(String languageCode) { if (TextUtils.isEmpty(languageCode)) { - return LanguageUtils.getCurrentDeviceLanguage(WordPress.getContext()); + return Locale.getDefault(); } if (languageCode.length() > NO_REGION_LANG_CODE_LEN) { From 89715ae202aa039f5870a12fd18d2c6cecbedf1b Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Wed, 7 Mar 2018 22:06:09 -0700 Subject: [PATCH 05/12] Remove base activity classes and manually replicate attachToBase(...) method across all activities. * This method is required for app-level localization to work in later versions of Android. Tickets: #7267, #7265 --- WordPress/src/main/AndroidManifest.xml | 4 ---- .../java/org/wordpress/android/BaseActivity.java | 13 ------------- .../org/wordpress/android/BaseListActivity.java | 13 ------------- .../android/ui/AddQuickPressShortcutActivity.java | 11 +++++++++-- .../wordpress/android/ui/AppLogViewerActivity.java | 10 ++++++++-- .../ui/DeepLinkingIntentReceiverActivity.java | 11 +++++++++-- .../android/ui/HelpshiftDeepLinkReceiver.java | 11 +++++++++-- .../android/ui/ShareIntentReceiverActivity.java | 11 +++++++++-- .../android/ui/VisualEditorOptionsReceiver.java | 11 +++++++++-- .../org/wordpress/android/ui/WPLaunchActivity.java | 11 +++++++++-- .../org/wordpress/android/ui/WebViewActivity.java | 11 +++++++++-- .../wordpress/android/ui/accounts/HelpActivity.java | 11 +++++++++-- .../android/ui/accounts/LoginActivity.java | 11 +++++++++-- .../android/ui/accounts/LoginEpilogueActivity.java | 11 +++++++++-- .../android/ui/accounts/NewBlogActivity.java | 11 +++++++++-- .../android/ui/accounts/SignupEpilogueActivity.java | 11 +++++++++-- .../android/ui/accounts/SiteCreationActivity.java | 11 +++++++++-- .../android/ui/comments/CommentsActivity.java | 11 +++++++++-- .../android/ui/comments/CommentsDetailActivity.java | 11 +++++++++-- .../android/ui/comments/EditCommentActivity.java | 11 +++++++++-- .../android/ui/main/SitePickerActivity.java | 10 ++++++++-- .../wordpress/android/ui/main/WPMainActivity.java | 11 +++++++++-- .../android/ui/media/MediaBrowserActivity.java | 10 ++++++++-- .../android/ui/media/MediaPreviewActivity.java | 10 ++++++++-- .../android/ui/media/MediaSettingsActivity.java | 10 ++++++++-- .../notifications/NotificationsDetailActivity.java | 11 +++++++++-- .../android/ui/people/PeopleManagementActivity.java | 11 +++++++++-- .../android/ui/photopicker/PhotoPickerActivity.java | 11 +++++++++-- .../wordpress/android/ui/plans/PlansActivity.java | 11 +++++++++-- .../android/ui/plugins/PluginBrowserActivity.java | 10 ++++++++-- .../android/ui/plugins/PluginDetailActivity.java | 11 +++++++++-- .../android/ui/posts/EditPostActivity.java | 10 ++++++++-- .../android/ui/posts/PostPreviewActivity.java | 11 +++++++++-- .../android/ui/posts/PostSettingsTagsActivity.java | 10 ++++++++-- .../android/ui/posts/PostsListActivity.java | 11 +++++++++-- .../android/ui/posts/SelectCategoriesActivity.java | 11 +++++++++-- .../wordpress/android/ui/prefs/AboutActivity.java | 11 +++++++++-- .../android/ui/prefs/AccountSettingsActivity.java | 11 +++++++++-- .../android/ui/prefs/AppSettingsActivity.java | 11 +++++++++-- .../android/ui/prefs/BlogPreferencesActivity.java | 11 +++++++++-- .../android/ui/prefs/MyProfileActivity.java | 11 +++++++++-- .../NotificationsSettingsActivity.java | 11 +++++++++-- .../android/ui/publicize/PublicizeListActivity.java | 11 +++++++++-- .../ui/reader/ReaderCommentListActivity.java | 11 +++++++++-- .../ui/reader/ReaderPhotoViewerActivity.java | 11 +++++++++-- .../android/ui/reader/ReaderPostListActivity.java | 11 +++++++++-- .../android/ui/reader/ReaderPostPagerActivity.java | 11 +++++++++-- .../android/ui/reader/ReaderSubsActivity.java | 11 +++++++++-- .../android/ui/reader/ReaderUserListActivity.java | 11 +++++++++-- .../ui/reader/ReaderVideoViewerActivity.java | 11 +++++++++-- .../wordpress/android/ui/stats/StatsActivity.java | 9 +++++++-- .../ui/stats/StatsConnectJetpackActivity.java | 11 +++++++++-- .../ui/stats/StatsSingleItemDetailsActivity.java | 9 +++++++-- .../android/ui/stats/StatsViewAllActivity.java | 11 +++++++++-- .../ui/stats/StatsWidgetConfigureActivity.java | 12 +++++++++--- .../android/ui/themes/ThemeBrowserActivity.java | 11 +++++++++-- 56 files changed, 465 insertions(+), 137 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/BaseActivity.java delete mode 100644 WordPress/src/main/java/org/wordpress/android/BaseListActivity.java diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 364c39738916..79a79ac0dc0e 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -507,10 +507,6 @@
- - - - * Redirects users to the reader activity along with IDs passed in the intent */ -public class DeepLinkingIntentReceiverActivity extends BaseActivity { +public class DeepLinkingIntentReceiverActivity extends AppCompatActivity { private String mInterceptedUri; private String mBlogId; private String mPostId; @Inject AccountStore mAccountStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/HelpshiftDeepLinkReceiver.java b/WordPress/src/main/java/org/wordpress/android/ui/HelpshiftDeepLinkReceiver.java index aa1e0be2ddc3..dde7cd567a2a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/HelpshiftDeepLinkReceiver.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/HelpshiftDeepLinkReceiver.java @@ -1,14 +1,21 @@ package org.wordpress.android.ui; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import com.helpshift.support.Support; -import org.wordpress.android.BaseActivity; +import org.wordpress.android.util.LocaleManager; + +public class HelpshiftDeepLinkReceiver extends AppCompatActivity { + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } -public class HelpshiftDeepLinkReceiver extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java index 29c738c4154c..f280df5d0edd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java @@ -1,5 +1,6 @@ package org.wordpress.android.ui; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -8,9 +9,9 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v4.app.TaskStackBuilder; +import android.support.v7.app.AppCompatActivity; import android.widget.Toast; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -24,6 +25,7 @@ import org.wordpress.android.ui.media.MediaBrowserType; import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.FluxCUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.PermissionUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.WPPermissionUtils; @@ -42,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 BaseActivity 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"; @@ -60,6 +62,11 @@ protected void onNewIntent(Intent intent) { refreshContent(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/VisualEditorOptionsReceiver.java b/WordPress/src/main/java/org/wordpress/android/ui/VisualEditorOptionsReceiver.java index dc9a660ac538..22fadabf5063 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/VisualEditorOptionsReceiver.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/VisualEditorOptionsReceiver.java @@ -1,17 +1,24 @@ package org.wordpress.android.ui; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.ui.prefs.AppPrefs; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; -public class VisualEditorOptionsReceiver extends BaseActivity { +public class VisualEditorOptionsReceiver extends AppCompatActivity { + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WPLaunchActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WPLaunchActivity.java index aad694dcbe73..127114818140 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WPLaunchActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WPLaunchActivity.java @@ -1,22 +1,29 @@ package org.wordpress.android.ui; +import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.ui.main.WPMainActivity; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ProfilingUtils; import org.wordpress.android.util.ToastUtils; -public class WPLaunchActivity extends BaseActivity { +public class WPLaunchActivity extends 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 * manifest to have no UI */ + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java index 8ff237e9c5a4..255fc4bfee42 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java @@ -1,22 +1,24 @@ package org.wordpress.android.ui; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.webkit.WebView; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; +import org.wordpress.android.util.LocaleManager; import java.util.Map; /** * Basic activity for displaying a WebView. */ -public abstract class WebViewActivity extends BaseActivity { +public abstract class WebViewActivity extends AppCompatActivity { /** * Primary webview used to display content. */ @@ -25,6 +27,11 @@ public abstract class WebViewActivity extends BaseActivity { protected WebView mWebView; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { supportRequestWindowFeature(Window.FEATURE_PROGRESS); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.java index 7d7cb04da561..48b00ffb7df3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.java @@ -1,13 +1,14 @@ package org.wordpress.android.ui.accounts; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.store.AccountStore; @@ -17,14 +18,20 @@ import org.wordpress.android.util.HelpshiftHelper; import org.wordpress.android.util.HelpshiftHelper.MetadataKey; import org.wordpress.android.util.HelpshiftHelper.Tag; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.widgets.WPTextView; import javax.inject.Inject; -public class HelpActivity extends BaseActivity { +public class HelpActivity extends AppCompatActivity { @Inject AccountStore mAccountStore; @Inject SiteStore mSiteStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java index 4d6cfd4a429e..3d9f26079266 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java @@ -1,6 +1,7 @@ package org.wordpress.android.ui.accounts; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -10,6 +11,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import com.google.android.gms.auth.api.credentials.Credential; @@ -17,7 +19,6 @@ import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -50,6 +51,7 @@ import org.wordpress.android.util.CrashlyticsUtils; import org.wordpress.android.util.HelpshiftHelper; import org.wordpress.android.util.HelpshiftHelper.Tag; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.SelfSignedSSLUtils; import org.wordpress.android.util.StringUtils; @@ -65,7 +67,7 @@ import dagger.android.DispatchingAndroidInjector; import dagger.android.support.HasSupportFragmentInjector; -public class LoginActivity extends BaseActivity implements ConnectionCallbacks, OnConnectionFailedListener, +public class LoginActivity extends AppCompatActivity implements ConnectionCallbacks, OnConnectionFailedListener, Callback, LoginListener, GoogleListener, LoginPrologueListener, SignupSheetListener, HasSupportFragmentInjector { public static final String MAGIC_LOGIN = "magic-login"; @@ -91,6 +93,11 @@ private enum SmartLockHelperState { @Inject DispatchingAndroidInjector mFragmentInjector; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { ((WordPress) getApplication()).component().inject(this); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java index 342358302138..0c9d721e77c9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java @@ -1,27 +1,34 @@ package org.wordpress.android.ui.accounts; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.ui.ActivityLauncher; import org.wordpress.android.ui.accounts.login.LoginEpilogueFragment; import org.wordpress.android.ui.accounts.login.LoginEpilogueListener; +import org.wordpress.android.util.LocaleManager; import java.util.ArrayList; import javax.inject.Inject; -public class LoginEpilogueActivity extends BaseActivity implements LoginEpilogueListener { +public class LoginEpilogueActivity extends AppCompatActivity implements LoginEpilogueListener { public static final String EXTRA_DO_LOGIN_UPDATE = "EXTRA_DO_LOGIN_UPDATE"; public static final String EXTRA_SHOW_AND_RETURN = "EXTRA_SHOW_AND_RETURN"; public static final String ARG_OLD_SITES_IDS = "ARG_OLD_SITES_IDS"; @Inject AccountStore mAccountStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/NewBlogActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/NewBlogActivity.java index 4b8ae7d14401..4249433112ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/NewBlogActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/NewBlogActivity.java @@ -1,13 +1,20 @@ package org.wordpress.android.ui.accounts; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.ui.accounts.signup.SiteCreationCreatingFragment; +import org.wordpress.android.util.LocaleManager; + +public class NewBlogActivity extends AppCompatActivity { + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } -public class NewBlogActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/SignupEpilogueActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/SignupEpilogueActivity.java index bab07de4af21..faade651b630 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/SignupEpilogueActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/SignupEpilogueActivity.java @@ -1,14 +1,16 @@ package org.wordpress.android.ui.accounts; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.ui.accounts.signup.SignupEpilogueFragment; import org.wordpress.android.ui.accounts.signup.SignupEpilogueListener; +import org.wordpress.android.util.LocaleManager; -public class SignupEpilogueActivity extends BaseActivity implements SignupEpilogueListener { +public class SignupEpilogueActivity extends AppCompatActivity implements SignupEpilogueListener { public static final String EXTRA_SIGNUP_DISPLAY_NAME = "EXTRA_SIGNUP_DISPLAY_NAME"; public static final String EXTRA_SIGNUP_EMAIL_ADDRESS = "EXTRA_SIGNUP_EMAIL_ADDRESS"; public static final String EXTRA_SIGNUP_IS_EMAIL = "EXTRA_SIGNUP_IS_EMAIL"; @@ -17,6 +19,11 @@ public class SignupEpilogueActivity extends BaseActivity implements SignupEpilog public static final String MAGIC_SIGNUP_PARAMETER = "new_user"; public static final String MAGIC_SIGNUP_VALUE = "1"; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/SiteCreationActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/SiteCreationActivity.java index c7490ed3c92b..53a87664dcf9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/SiteCreationActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/SiteCreationActivity.java @@ -1,12 +1,13 @@ package org.wordpress.android.ui.accounts; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -19,10 +20,11 @@ import org.wordpress.android.ui.accounts.signup.SiteCreationThemeLoaderFragment; import org.wordpress.android.ui.main.SitePickerActivity; import org.wordpress.android.util.HelpshiftHelper; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UrlUtils; -public class SiteCreationActivity extends BaseActivity implements SiteCreationListener { +public class SiteCreationActivity extends AppCompatActivity implements SiteCreationListener { public static final String ARG_USERNAME = "ARG_USERNAME"; public static final String KEY_DO_NEW_POST = "KEY_DO_NEW_POST"; @@ -40,6 +42,11 @@ public class SiteCreationActivity extends BaseActivity implements SiteCreationLi private String mSiteTagline; private String mSiteDomain; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsActivity.java index 42d3a730f800..a9913137735b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsActivity.java @@ -4,17 +4,18 @@ import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -32,11 +33,12 @@ import org.wordpress.android.ui.prefs.AppPrefs; import org.wordpress.android.ui.reader.ReaderPostDetailFragment; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import javax.inject.Inject; -public class CommentsActivity extends BaseActivity +public class CommentsActivity extends AppCompatActivity implements OnCommentSelectedListener, NotificationFragment.OnPostClickListener { static final String KEY_AUTO_REFRESHED = "has_auto_refreshed"; @@ -53,6 +55,11 @@ public class CommentsActivity extends BaseActivity @Inject Dispatcher mDispatcher; @Inject CommentStore mCommentStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java index 7e884c89b248..80bef38de6ff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java @@ -1,10 +1,12 @@ package org.wordpress.android.ui.comments; +import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; @@ -12,7 +14,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -25,6 +26,7 @@ import org.wordpress.android.fluxc.store.CommentStore.FetchCommentsPayload; import org.wordpress.android.models.CommentList; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.widgets.WPViewPager; @@ -34,7 +36,7 @@ import static org.wordpress.android.ui.comments.CommentsListFragment.COMMENTS_PER_PAGE; -public class CommentsDetailActivity extends BaseActivity +public class CommentsDetailActivity extends AppCompatActivity implements CommentAdapter.OnLoadMoreListener, CommentActions.OnCommentActionListener { public static final String COMMENT_ID_EXTRA = "commentId"; @@ -56,6 +58,11 @@ public class CommentsDetailActivity extends BaseActivity private boolean mIsUpdatingComments; private boolean mCanLoadMoreComments = true; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java index 4d68a47b5a25..7cf2d9d73a5d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java @@ -3,10 +3,12 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; import android.view.Menu; @@ -18,7 +20,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.datasets.NotificationsTable; @@ -36,12 +37,13 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; import org.wordpress.android.util.EditTextUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import javax.inject.Inject; -public class EditCommentActivity extends BaseActivity { +public class EditCommentActivity extends AppCompatActivity { static final String KEY_COMMENT = "KEY_COMMENT"; static final String KEY_NOTE_ID = "KEY_NOTE_ID"; @@ -56,6 +58,11 @@ public class EditCommentActivity extends BaseActivity { @Inject SiteStore mSiteStore; @Inject CommentStore mCommentStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 8a25aa0dbdb1..841118e040a5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -14,6 +14,7 @@ import android.support.annotation.Nullable; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.content.res.AppCompatResources; import android.support.v7.view.ActionMode; import android.support.v7.widget.DefaultItemAnimator; @@ -35,7 +36,6 @@ import org.greenrobot.eventbus.ThreadMode; import org.json.JSONException; import org.json.JSONObject; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -54,6 +54,7 @@ import org.wordpress.android.ui.stats.datasets.StatsTable; import org.wordpress.android.util.ActivityUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.helpers.Debouncer; @@ -70,7 +71,7 @@ import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; -public class SitePickerActivity extends BaseActivity +public class SitePickerActivity extends AppCompatActivity implements SitePickerAdapter.OnSiteClickListener, SitePickerAdapter.OnSelectedCountChangedListener, SearchView.OnQueryTextListener { @@ -95,6 +96,11 @@ public class SitePickerActivity extends BaseActivity @Inject SiteStore mSiteStore; @Inject Dispatcher mDispatcher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 80994160f096..e7e8ef230f5a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -2,6 +2,7 @@ import android.animation.ObjectAnimator; import android.app.Fragment; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -13,13 +14,13 @@ import android.support.design.widget.TabLayout; import android.support.v4.app.RemoteInput; import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.TextView; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -66,6 +67,7 @@ import org.wordpress.android.util.AuthenticationDialogUtils; import org.wordpress.android.util.CoreEvents.MainViewPagerScrolled; import org.wordpress.android.util.FluxCUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ProfilingUtils; import org.wordpress.android.util.ToastUtils; @@ -81,7 +83,7 @@ /** * Main activity which hosts sites, reader, me and notifications tabs */ -public class WPMainActivity extends BaseActivity { +public class WPMainActivity extends AppCompatActivity { public static final String ARG_DO_LOGIN_UPDATE = "ARG_DO_LOGIN_UPDATE"; public static final String ARG_OLD_SITES_IDS = "ARG_OLD_SITES_IDS"; public static final String ARG_OPENED_FROM_PUSH = "opened_from_push"; @@ -117,6 +119,11 @@ public interface OnActivityBackPressedListener { boolean onActivityBackPressed(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { ProfilingUtils.split("WPMainActivity.onCreate"); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java index 9484f6ac9d41..ba6f18049f50 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java @@ -25,6 +25,7 @@ import android.support.v4.view.MenuItemCompat.OnActionExpandListener; import android.support.v4.view.ViewCompat; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.view.ActionMode; import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView.OnQueryTextListener; @@ -39,7 +40,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.BuildConfig; import org.wordpress.android.R; import org.wordpress.android.WordPress; @@ -66,6 +66,7 @@ import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.FluxCUtils; import org.wordpress.android.util.ListUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.MediaUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PermissionUtils; @@ -84,7 +85,7 @@ /** * The main activity in which the user can browse their media. */ -public class MediaBrowserActivity extends BaseActivity implements MediaGridListener, +public class MediaBrowserActivity extends AppCompatActivity implements MediaGridListener, OnQueryTextListener, OnActionExpandListener, WPMediaUtils.LaunchCameraCallback { public static final String ARG_BROWSER_TYPE = "media_browser_type"; @@ -120,6 +121,11 @@ private enum AddMenuItem { ITEM_CHOOSE_VIDEO } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java index 42954aa79e04..c556a332948e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java @@ -17,6 +17,7 @@ import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.SparseArray; @@ -26,7 +27,6 @@ import android.view.animation.Animation; import org.greenrobot.eventbus.EventBus; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.MediaModel; @@ -35,6 +35,7 @@ import org.wordpress.android.fluxc.tools.FluxCImageLoader; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.widgets.WPViewPagerTransformer; import org.wordpress.android.widgets.WPViewPagerTransformer.TransformType; @@ -43,7 +44,7 @@ import javax.inject.Inject; -public class MediaPreviewActivity extends BaseActivity implements MediaPreviewFragment.OnMediaTappedListener { +public class MediaPreviewActivity extends AppCompatActivity implements MediaPreviewFragment.OnMediaTappedListener { private static final String ARG_ID_LIST = "id_list"; private int mMediaId; @@ -119,6 +120,11 @@ private static void startIntent(Context context, Intent intent) { ActivityCompat.startActivity(context, intent, options.toBundle()); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java index 3bb2d90a9571..b7bedfa3da37 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java @@ -31,6 +31,7 @@ import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.text.format.DateUtils; @@ -52,7 +53,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.editor.EditorImageMetaData; @@ -71,6 +71,7 @@ import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.EditTextUtils; import org.wordpress.android.util.ImageUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.MediaUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PermissionUtils; @@ -90,7 +91,7 @@ import static org.wordpress.android.editor.EditorImageMetaData.ARG_EDITOR_IMAGE_METADATA; -public class MediaSettingsActivity extends BaseActivity +public class MediaSettingsActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback { private static final String ARG_MEDIA_LOCAL_ID = "media_local_id"; private static final String ARG_ID_LIST = "id_list"; @@ -197,6 +198,11 @@ public static void showForResult(@NonNull Activity activity, ActivityCompat.startActivityForResult(activity, intent, RequestCodes.MEDIA_SETTINGS, options.toBundle()); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index fc94a1f613ac..59cc4f0984b0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -2,6 +2,7 @@ import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; @@ -9,13 +10,13 @@ import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.widget.ProgressBar; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -44,6 +45,7 @@ import org.wordpress.android.ui.stats.StatsViewAllActivity; import org.wordpress.android.ui.stats.StatsViewType; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.widgets.WPSwipeSnackbar; @@ -63,7 +65,7 @@ import static org.wordpress.android.models.Note.NOTE_FOLLOW_TYPE; import static org.wordpress.android.models.Note.NOTE_LIKE_TYPE; -public class NotificationsDetailActivity extends BaseActivity implements +public class NotificationsDetailActivity extends AppCompatActivity implements CommentActions.OnNoteCommentActionListener { private static final String ARG_TITLE = "activityTitle"; private static final String DOMAIN_WPCOM = "wordpress.com"; @@ -78,6 +80,11 @@ public class NotificationsDetailActivity extends BaseActivity implements private NotificationDetailFragmentAdapter mAdapter; private boolean mIsReaderSwipeToNavigateShown; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java index 50dcd2892395..16ddb9f9749c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java @@ -4,15 +4,16 @@ import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -27,6 +28,7 @@ import org.wordpress.android.ui.people.utils.PeopleUtils; import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; @@ -37,7 +39,7 @@ import de.greenrobot.event.EventBus; -public class PeopleManagementActivity extends BaseActivity +public class PeopleManagementActivity extends AppCompatActivity implements PeopleListFragment.OnPersonSelectedListener, PeopleListFragment.OnFetchPeopleListener { private static final String KEY_PEOPLE_LIST_FRAGMENT = "people-list-fragment"; private static final String KEY_PERSON_DETAIL_FRAGMENT = "person-detail-fragment"; @@ -90,6 +92,11 @@ public class PeopleManagementActivity extends BaseActivity private SiteModel mSite; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java index 794045735cdf..fd8c5bf584a6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java @@ -4,19 +4,20 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.app.ProgressDialog; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.MenuItem; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.BuildConfig; import org.wordpress.android.R; import org.wordpress.android.WordPress; @@ -33,6 +34,7 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.FluxCUtils; import org.wordpress.android.util.ListUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.WPMediaUtils; @@ -44,7 +46,7 @@ import javax.inject.Inject; -public class PhotoPickerActivity extends BaseActivity +public class PhotoPickerActivity extends AppCompatActivity implements PhotoPickerFragment.PhotoPickerListener { private static final String PICKER_FRAGMENT_TAG = "picker_fragment_tag"; private static final String KEY_MEDIA_CAPTURE_PATH = "media_capture_path"; @@ -83,6 +85,11 @@ public static PhotoPickerMediaSource fromString(String strSource) { } } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plans/PlansActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plans/PlansActivity.java index 5b200d2592a0..d836dc60e590 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plans/PlansActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plans/PlansActivity.java @@ -3,6 +3,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; +import android.content.Context; import android.graphics.Point; import android.os.Build; import android.os.Bundle; @@ -10,6 +11,7 @@ import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewCompat; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; @@ -20,7 +22,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.SiteModel; @@ -33,6 +34,7 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; import org.wordpress.android.util.DisplayUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UrlUtils; @@ -45,7 +47,7 @@ import de.greenrobot.event.EventBus; -public class PlansActivity extends BaseActivity { +public class PlansActivity extends AppCompatActivity { private static final String ARG_LOCAL_AVAILABLE_PLANS = "ARG_LOCAL_AVAILABLE_PLANS"; private SiteModel mSelectedSite; @@ -59,6 +61,11 @@ public class PlansActivity extends BaseActivity { @Inject AccountStore mAccountStore; @Inject AccountStore mSiteStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java index a1cd9dadeaa4..9ab780dcc6a6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java @@ -14,6 +14,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; @@ -29,7 +30,6 @@ import android.widget.RatingBar; import android.widget.TextView; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.SiteModel; @@ -40,6 +40,7 @@ import org.wordpress.android.util.ActivityUtils; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.HtmlUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.viewmodel.PluginBrowserViewModel; import org.wordpress.android.viewmodel.PluginBrowserViewModel.PluginListType; @@ -50,7 +51,7 @@ import javax.inject.Inject; -public class PluginBrowserActivity extends BaseActivity +public class PluginBrowserActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener { @Inject ViewModelProvider.Factory mViewModelFactory; @@ -63,6 +64,11 @@ public class PluginBrowserActivity extends BaseActivity private MenuItem mSearchMenuItem; private SearchView mSearchView; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java index 060ee43c423b..a3d286ac0ef4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java @@ -2,6 +2,7 @@ import android.animation.ObjectAnimator; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -11,6 +12,7 @@ import android.support.design.widget.Snackbar; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.support.v7.content.res.AppCompatResources; import android.support.v7.widget.Toolbar; import android.text.Html; @@ -30,7 +32,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -55,6 +56,7 @@ import org.wordpress.android.util.DateTimeUtils; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.FormatUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.StringUtils; @@ -79,7 +81,7 @@ import static org.wordpress.android.widgets.WPNetworkImageView.ImageType.PHOTO; import static org.wordpress.android.widgets.WPNetworkImageView.ImageType.PLUGIN_ICON; -public class PluginDetailActivity extends BaseActivity { +public class PluginDetailActivity extends AppCompatActivity { public static final String KEY_PLUGIN_SLUG = "KEY_PLUGIN_SLUG"; private static final String KEY_IS_CONFIGURING_PLUGIN = "KEY_IS_CONFIGURING_PLUGIN"; private static final String KEY_IS_UPDATING_PLUGIN = "KEY_IS_UPDATING_PLUGIN"; @@ -128,6 +130,11 @@ public class PluginDetailActivity extends BaseActivity { @Inject PluginStore mPluginStore; @Inject Dispatcher mDispatcher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index b3b6597bda7b..6dab891b8fe4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -26,6 +26,7 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -42,7 +43,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.BuildConfig; import org.wordpress.android.JavaScriptException; import org.wordpress.android.R; @@ -120,6 +120,7 @@ import org.wordpress.android.util.FluxCUtils; import org.wordpress.android.util.ImageUtils; import org.wordpress.android.util.ListUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.MediaUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.PermissionUtils; @@ -158,7 +159,7 @@ import de.greenrobot.event.EventBus; -public class EditPostActivity extends BaseActivity implements +public class EditPostActivity extends AppCompatActivity implements EditorFragmentActivity, EditorImageSettingsListener, EditorDragAndDropListener, @@ -263,6 +264,11 @@ public void run() { } }; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostPreviewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostPreviewActivity.java index e8f660165028..3e2de73b318f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostPreviewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostPreviewActivity.java @@ -3,9 +3,11 @@ import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; @@ -16,7 +18,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -36,6 +37,7 @@ import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; @@ -45,7 +47,7 @@ import static org.wordpress.android.ui.posts.EditPostActivity.EXTRA_POST_LOCAL_ID; -public class PostPreviewActivity extends BaseActivity { +public class PostPreviewActivity extends AppCompatActivity { private boolean mIsUpdatingPost; private PostModel mPost; @@ -54,6 +56,11 @@ public class PostPreviewActivity extends BaseActivity { @Inject Dispatcher mDispatcher; @Inject PostStore mPostStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java index 7ba997278035..16a80aa47663 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; @@ -23,7 +24,6 @@ import org.apache.commons.text.StringEscapeUtils; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -31,6 +31,7 @@ import org.wordpress.android.fluxc.model.TermModel; import org.wordpress.android.fluxc.store.TaxonomyStore; import org.wordpress.android.util.ActivityUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import java.util.ArrayList; @@ -38,7 +39,7 @@ import javax.inject.Inject; -public class PostSettingsTagsActivity extends BaseActivity implements TextWatcher, View.OnKeyListener { +public class PostSettingsTagsActivity extends AppCompatActivity implements TextWatcher, View.OnKeyListener { public static final String KEY_TAGS = "KEY_TAGS"; public static final String KEY_SELECTED_TAGS = "KEY_SELECTED_TAGS"; private SiteModel mSite; @@ -49,6 +50,11 @@ public class PostSettingsTagsActivity extends BaseActivity implements TextWatche @Inject Dispatcher mDispatcher; @Inject TaxonomyStore mTaxonomyStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java index 504be6306d42..dd1223f62560 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.java @@ -1,12 +1,13 @@ package org.wordpress.android.ui.posts; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.PostModel; @@ -15,11 +16,12 @@ import org.wordpress.android.fluxc.store.SiteStore; import org.wordpress.android.ui.ActivityId; import org.wordpress.android.ui.RequestCodes; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import javax.inject.Inject; -public class PostsListActivity extends BaseActivity { +public class PostsListActivity extends AppCompatActivity { public static final String EXTRA_VIEW_PAGES = "viewPages"; public static final String EXTRA_TARGET_POST_LOCAL_ID = "targetPostLocalId"; @@ -30,6 +32,11 @@ public class PostsListActivity extends BaseActivity { @Inject SiteStore mSiteStore; @Inject PostStore mPostStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java index 06fd127993e4..d911f7a11107 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java @@ -1,10 +1,12 @@ package org.wordpress.android.ui.posts; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.util.LongSparseArray; import android.util.SparseBooleanArray; import android.view.Menu; @@ -15,7 +17,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -30,6 +31,7 @@ import org.wordpress.android.fluxc.store.TaxonomyStore.OnTermUploaded; import org.wordpress.android.fluxc.store.TaxonomyStore.RemoteTermPayload; import org.wordpress.android.models.CategoryNode; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.ToastUtils.Duration; @@ -46,7 +48,7 @@ import static org.wordpress.android.ui.posts.EditPostActivity.EXTRA_POST_LOCAL_ID; import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; -public class SelectCategoriesActivity extends BaseActivity { +public class SelectCategoriesActivity extends AppCompatActivity { public static final String KEY_SELECTED_CATEGORY_IDS = "KEY_SELECTED_CATEGORY_IDS"; private ListView mListView; @@ -63,6 +65,11 @@ public class SelectCategoriesActivity extends BaseActivity { @Inject TaxonomyStore mTaxonomyStore; @Inject Dispatcher mDispatcher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AboutActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AboutActivity.java index fa38007851ea..ee16e5dac193 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AboutActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AboutActivity.java @@ -1,20 +1,27 @@ package org.wordpress.android.ui.prefs; +import android.content.Context; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import org.wordpress.android.BaseActivity; import org.wordpress.android.Constants; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.ui.ActivityLauncher; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.widgets.WPTextView; import java.util.Calendar; -public class AboutActivity extends BaseActivity implements OnClickListener { +public class AboutActivity extends AppCompatActivity implements OnClickListener { + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java index 00095a269412..fd5a85aaad57 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java @@ -1,16 +1,23 @@ package org.wordpress.android.ui.prefs; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; +import org.wordpress.android.util.LocaleManager; -public class AccountSettingsActivity extends BaseActivity { +public class AccountSettingsActivity extends AppCompatActivity { private static final String KEY_ACCOUNT_SETTINGS_FRAGMENT = "account-settings-fragment"; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java index 8242dd8b6acd..55ed42595911 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java @@ -1,25 +1,32 @@ package org.wordpress.android.ui.prefs; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.preference.Preference; import android.preference.SwitchPreference; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.push.GCMMessageService; +import org.wordpress.android.util.LocaleManager; import org.wordpress.passcodelock.AppLockManager; import org.wordpress.passcodelock.PasscodePreferenceFragment; -public class AppSettingsActivity extends BaseActivity { +public class AppSettingsActivity extends AppCompatActivity { private static final String KEY_APP_SETTINGS_FRAGMENT = "app-settings-fragment"; private static final String KEY_PASSCODE_FRAGMENT = "passcode-fragment"; private AppSettingsFragment mAppSettingsFragment; private PasscodePreferenceFragment mPasscodePreferenceFragment; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java index f45b94a1a365..69f3683123dd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/BlogPreferencesActivity.java @@ -2,14 +2,15 @@ import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import org.apache.commons.text.StringEscapeUtils; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; @@ -19,6 +20,7 @@ import org.wordpress.android.fluxc.store.SiteStore.OnSiteDeleted; import org.wordpress.android.fluxc.store.SiteStore.OnSiteRemoved; import org.wordpress.android.networking.ConnectionChangeReceiver; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.ToastUtils; @@ -29,7 +31,7 @@ /** * Activity for configuring blog specific settings. */ -public class BlogPreferencesActivity extends BaseActivity { +public class BlogPreferencesActivity extends AppCompatActivity { private static final String KEY_SETTINGS_FRAGMENT = "settings-fragment"; private SiteModel mSite; @@ -38,6 +40,11 @@ public class BlogPreferencesActivity extends BaseActivity { @Inject SiteStore mSiteStore; @Inject Dispatcher mDispatcher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java index 50078395bf83..a6e853833fb5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java @@ -1,24 +1,31 @@ package org.wordpress.android.ui.prefs; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.Dispatcher; import org.wordpress.android.fluxc.store.AccountStore; +import org.wordpress.android.util.LocaleManager; import javax.inject.Inject; -public class MyProfileActivity extends BaseActivity { +public class MyProfileActivity extends AppCompatActivity { private static final String KEY_MY_PROFILE_FRAGMENT = "my-profile-fragment"; @Inject Dispatcher mDispatcher; @Inject AccountStore mAccountStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java index ed7939072d29..dce9be5ead13 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.java @@ -1,9 +1,11 @@ package org.wordpress.android.ui.prefs.notifications; import android.app.FragmentManager; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.Toolbar; @@ -15,15 +17,15 @@ import android.widget.TextView; import android.widget.Toast; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.ui.notifications.NotificationEvents; +import org.wordpress.android.util.LocaleManager; import de.greenrobot.event.EventBus; // Simple wrapper activity for NotificationsSettingsFragment -public class NotificationsSettingsActivity extends BaseActivity { +public class NotificationsSettingsActivity extends AppCompatActivity { private TextView mMessageTextView; private View mMessageContainer; @@ -31,6 +33,11 @@ public class NotificationsSettingsActivity extends BaseActivity { protected SwitchCompat mMasterSwitch; protected Toolbar mToolbarSwitch; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index a07abd027f0f..d08de05d968f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -4,14 +4,15 @@ import android.app.FragmentManager; import android.app.FragmentTransaction; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; @@ -21,13 +22,14 @@ import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.services.PublicizeUpdateService; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.ToastUtils; import javax.inject.Inject; import de.greenrobot.event.EventBus; -public class PublicizeListActivity extends BaseActivity +public class PublicizeListActivity extends AppCompatActivity implements PublicizeActions.OnPublicizeActionListener, PublicizeServiceAdapter.OnServiceClickListener, @@ -37,6 +39,11 @@ public class PublicizeListActivity extends BaseActivity @Inject SiteStore mSiteStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index f1589fe26dfa..214b60c5c724 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -1,11 +1,13 @@ package org.wordpress.android.ui.reader; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.Toolbar; import android.text.TextUtils; @@ -16,7 +18,6 @@ import android.widget.ProgressBar; import android.widget.TextView; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -45,6 +46,7 @@ import org.wordpress.android.util.AppLog.T; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.EditTextUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.WPActivityUtils; @@ -62,7 +64,7 @@ import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; -public class ReaderCommentListActivity extends BaseActivity { +public class ReaderCommentListActivity extends AppCompatActivity { private static final String KEY_REPLY_TO_COMMENT_ID = "reply_to_comment_id"; private static final String KEY_HAS_UPDATED_COMMENTS = "has_updated_comments"; @@ -92,6 +94,11 @@ public class ReaderCommentListActivity extends BaseActivity { @Inject AccountStore mAccountStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java index 53072893e82c..b87db2d85489 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java @@ -2,22 +2,24 @@ import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.TextView; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.ui.reader.models.ReaderImageList; import org.wordpress.android.ui.reader.utils.ReaderImageScanner; import org.wordpress.android.ui.reader.views.ReaderPhotoView.PhotoViewListener; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.widgets.WPViewPager; import org.wordpress.android.widgets.WPViewPagerTransformer; import org.wordpress.android.widgets.WPViewPagerTransformer.TransformType; @@ -26,7 +28,7 @@ * Full-screen photo viewer - uses a ViewPager to enable scrolling between images in a blog * post, but also supports viewing a single image */ -public class ReaderPhotoViewerActivity extends BaseActivity +public class ReaderPhotoViewerActivity extends AppCompatActivity implements PhotoViewListener { private String mInitialImageUrl; private boolean mIsPrivate; @@ -37,6 +39,11 @@ public class ReaderPhotoViewerActivity extends BaseActivity private TextView mTxtTitle; private boolean mIsTitleVisible; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java index 70f3e651ad8b..5d6f38fa6ce6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java @@ -1,27 +1,34 @@ package org.wordpress.android.ui.reader; import android.app.Fragment; +import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.AppBarLayout; import android.support.design.widget.CoordinatorLayout; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.datasets.ReaderBlogTable; import org.wordpress.android.models.ReaderTag; import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType; +import org.wordpress.android.util.LocaleManager; /* * serves as the host for ReaderPostListFragment when showing blog preview & tag preview */ -public class ReaderPostListActivity extends BaseActivity { +public class ReaderPostListActivity extends AppCompatActivity { private ReaderPostListType mPostListType; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java index 7aa8cb89f7c9..57f8121169ec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -11,6 +12,7 @@ import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.SparseArray; @@ -19,7 +21,6 @@ import android.view.ViewGroup; import android.widget.ProgressBar; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -40,6 +41,7 @@ import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.widgets.WPSwipeSnackbar; @@ -71,7 +73,7 @@ * * Will also handle jumping to the comments section, liking a commend and liking a post directly */ -public class ReaderPostPagerActivity extends BaseActivity +public class ReaderPostPagerActivity extends AppCompatActivity implements ReaderInterfaces.AutoHideToolbarListener { /** * Type of URL intercepted @@ -117,6 +119,11 @@ public enum DirectOperation { @Inject SiteStore mSiteStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 60f2282e4780..819b13439c15 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -2,6 +2,7 @@ import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.TabLayout; @@ -10,6 +11,7 @@ import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Gravity; @@ -23,7 +25,6 @@ import android.widget.TextView; import android.widget.Toast; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.datasets.ReaderBlogTable; @@ -42,6 +43,7 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.EditTextUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UrlUtils; @@ -57,7 +59,7 @@ * activity which shows the user's subscriptions and recommended subscriptions - includes * followed tags, followed blogs, and recommended blogs */ -public class ReaderSubsActivity extends BaseActivity +public class ReaderSubsActivity extends AppCompatActivity implements ReaderTagAdapter.TagDeletedListener { private EditText mEditAdd; private ImageButton mBtnAdd; @@ -75,6 +77,11 @@ public class ReaderSubsActivity extends BaseActivity private static final int TAB_IDX_FOLLOWED_BLOGS = 1; private static final int TAB_IDX_RECOMMENDED_BLOGS = 2; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java index b1815047edb4..1b2a76ae3f45 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java @@ -1,12 +1,13 @@ package org.wordpress.android.ui.reader; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.Toolbar; import android.view.View; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.datasets.ReaderCommentTable; import org.wordpress.android.datasets.ReaderPostTable; @@ -16,16 +17,22 @@ import org.wordpress.android.ui.reader.utils.ReaderUtils; import org.wordpress.android.ui.reader.views.ReaderRecyclerView; import org.wordpress.android.util.DisplayUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.widgets.RecyclerItemDecoration; /* * displays a list of users who like a specific reader post */ -public class ReaderUserListActivity extends BaseActivity { +public class ReaderUserListActivity extends AppCompatActivity { private ReaderRecyclerView mRecyclerView; private ReaderUserAdapter mAdapter; private int mRestorePosition; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java index 05a6f8e512d8..ddff87d20a69 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderVideoViewerActivity.java @@ -1,25 +1,32 @@ package org.wordpress.android.ui.reader; +import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.ProgressBar; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.util.LocaleManager; /** * Full screen landscape video player for the reader */ -public class ReaderVideoViewerActivity extends BaseActivity { +public class ReaderVideoViewerActivity extends AppCompatActivity { private String mVideoUrl; private WebView mWebView; private ProgressBar mProgress; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java index 1935fa2ba1e9..35f07d70bdfd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDialogFragment; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; @@ -21,7 +22,6 @@ import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -39,6 +39,7 @@ import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.RateLimitedTask; import org.wordpress.android.util.SiteUtils; @@ -59,7 +60,7 @@ * By pressing a spinner on the action bar, the user can select which timeframe they wish to see. *

*/ -public class StatsActivity extends BaseActivity +public class StatsActivity extends AppCompatActivity implements NestedScrollViewExt.ScrollViewListener, StatsVisitorsAndViewsFragment.OnDateChangeListener, StatsVisitorsAndViewsFragment.OnOverviewItemChangeListener, @@ -100,6 +101,10 @@ public enum StatsLaunchedFrom { StatsVisitorsAndViewsFragment.OverviewLabel.VIEWS; private boolean mThereWasAnErrorLoadingStats = false; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } @Override public void onCreate(Bundle savedInstanceState) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java index 9a99ad72cdfb..0feb111f1048 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.java @@ -1,20 +1,22 @@ package org.wordpress.android.ui.stats; +import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.Button; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.ui.JetpackConnectionWebViewActivity; +import org.wordpress.android.util.LocaleManager; import javax.inject.Inject; @@ -25,10 +27,15 @@ * An activity that shows when user tries to open Stats without Jetpack connected. * It offers a link to the Jetpack connection flow. */ -public class StatsConnectJetpackActivity extends BaseActivity { +public class StatsConnectJetpackActivity extends AppCompatActivity { @Inject AccountStore mAccountStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java index 5e6e36a942c3..d4183530b3f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsSingleItemDetailsActivity.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.os.Handler; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.MenuItem; @@ -24,7 +25,6 @@ import org.json.JSONException; import org.json.JSONObject; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker; @@ -36,6 +36,7 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.FormatUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.helpers.SwipeToRefreshHelper; @@ -51,7 +52,7 @@ /** * Single item details activity. */ -public class StatsSingleItemDetailsActivity extends BaseActivity +public class StatsSingleItemDetailsActivity extends AppCompatActivity implements StatsBarGraph.OnGestureListener { public static final String ARG_REMOTE_BLOG_ID = "ARG_REMOTE_BLOG_ID"; public static final String ARG_REMOTE_ITEM_ID = "ARG_REMOTE_ITEM_ID"; @@ -101,6 +102,10 @@ public class StatsSingleItemDetailsActivity extends BaseActivity private static final String ARG_AVERAGES_EXPANDED_ROWS = "ARG_AVERAGES_EXPANDED_ROWS"; private static final String ARG_RECENT_EXPANDED_ROWS = "ARG_RECENT_EXPANDED_ROWS"; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } @Override public void onCreate(Bundle savedInstanceState) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java index ba72d171f9b3..bcf9afc3fd72 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsViewAllActivity.java @@ -2,19 +2,21 @@ import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; import android.widget.TextView; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.analytics.AnalyticsTracker.Stat; import org.wordpress.android.ui.ActivityId; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.helpers.SwipeToRefreshHelper; @@ -33,7 +35,7 @@ /** * Single item details activity. */ -public class StatsViewAllActivity extends BaseActivity { +public class StatsViewAllActivity extends AppCompatActivity { public static final String ARG_STATS_VIEW_ALL_TITLE = "arg_stats_view_all_title"; private static final String SAVED_STATS_SCROLL_POSITION = "SAVED_STATS_SCROLL_POSITION"; @@ -51,6 +53,11 @@ public class StatsViewAllActivity extends BaseActivity { private Serializable[] mRestResponse; private int mOuterPagerSelectedButtonIndex = 0; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java index 216d51032e6d..009f4a239758 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsWidgetConfigureActivity.java @@ -9,26 +9,27 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.MenuItem; import android.view.View; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.fluxc.store.SiteStore; +import org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.FluxCUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord; import javax.inject.Inject; -public class StatsWidgetConfigureActivity extends BaseActivity +public class StatsWidgetConfigureActivity extends AppCompatActivity implements StatsWidgetConfigureAdapter.OnSiteClickListener { private StatsWidgetConfigureAdapter mAdapter; private RecyclerView mRecycleView; @@ -37,6 +38,11 @@ public class StatsWidgetConfigureActivity extends BaseActivity @Inject AccountStore mAccountStore; @Inject SiteStore mSiteStore; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index 70a69feba472..fd6b9d967d95 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -2,18 +2,19 @@ import android.app.AlertDialog; import android.app.FragmentManager; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.MenuItem; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.wordpress.android.BaseActivity; import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.analytics.AnalyticsTracker.Stat; @@ -30,6 +31,7 @@ import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; @@ -38,7 +40,7 @@ import javax.inject.Inject; -public class ThemeBrowserActivity extends BaseActivity implements ThemeBrowserFragmentCallback { +public class ThemeBrowserActivity extends AppCompatActivity implements ThemeBrowserFragmentCallback { public static boolean isAccessible(SiteModel site) { // themes are only accessible to admin wordpress.com users return site != null && site.isUsingWpComRestApi() && site.getHasCapabilityEditThemeOptions(); @@ -58,6 +60,11 @@ public static boolean isAccessible(SiteModel site) { @Inject ThemeStore mThemeStore; @Inject Dispatcher mDispatcher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleManager.setLocale(newBase)); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); From cdea37580b9cadded9bfaeef3af68e9e6d09f0a6 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Thu, 8 Mar 2018 11:02:29 -0700 Subject: [PATCH 06/12] Fix checkstyle errors. --- .../wordpress/android/ui/ShareIntentReceiverActivity.java | 3 ++- .../org/wordpress/android/ui/accounts/LoginActivity.java | 1 + .../ui/accounts/signup/SignupEpilogueFragment.java | 8 ++++---- .../android/ui/accounts/signup/SiteCreationService.java | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java index 50f45188938b..849a10ed78ac 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java @@ -257,7 +257,8 @@ private void trackMediaAddedToMediaLibrary(SiteModel selectedSite) { boolean isVideo = mimeType != null && mimeType.startsWith("video"); Map properties = AnalyticsUtils.getMediaProperties(this, isVideo, uri, null); - AnalyticsTracker.Stat mediaTypeTrack = isVideo ? AnalyticsTracker.Stat.MEDIA_LIBRARY_ADDED_VIDEO : AnalyticsTracker.Stat.MEDIA_LIBRARY_ADDED_PHOTO; + AnalyticsTracker.Stat mediaTypeTrack = isVideo ? AnalyticsTracker.Stat.MEDIA_LIBRARY_ADDED_VIDEO + : AnalyticsTracker.Stat.MEDIA_LIBRARY_ADDED_PHOTO; AnalyticsUtils.trackWithSiteDetails(mediaTypeTrack, selectedSite, properties); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java index 869d2abe8150..c821eb74d4d7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java @@ -51,6 +51,7 @@ import org.wordpress.android.util.CrashlyticsUtils; import org.wordpress.android.util.HelpshiftHelper; import org.wordpress.android.util.HelpshiftHelper.Tag; +import org.wordpress.android.util.LanguageUtils; import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.SelfSignedSSLUtils; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java index 276b43cee739..1a58659c6509 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java @@ -567,8 +567,8 @@ protected void loadAvatar(String avatarUrl, String injectFilePath) { // trusted to update the image quick enough. injectCache(new File(injectFilePath), avatarUrl); } catch (IOException exception) { - AppLog.e(T.NUX, "Gravatar image could not be injected into request cache - " + - exception.toString() + " - " + exception.getMessage()); + AppLog.e(T.NUX, "Gravatar image could not be injected into request cache - " + + exception.toString() + " - " + exception.getMessage()); showErrorDialogAvatar(getString(R.string.signup_epilogue_error_avatar)); } @@ -760,8 +760,8 @@ public void onError() { } }); } catch (NullPointerException | URISyntaxException exception) { - AppLog.e(T.NUX, "Google avatar download and Gravatar upload failed - " + - exception.toString() + " - " + exception.getMessage()); + AppLog.e(T.NUX, "Google avatar download and Gravatar upload failed - " + + exception.toString() + " - " + exception.getMessage()); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SiteCreationService.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SiteCreationService.java index dfd549bc0c28..e67bfa539018 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SiteCreationService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SiteCreationService.java @@ -281,8 +281,8 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) { mIsRetry = intent.hasExtra(ARG_RESUME_PHASE); - final SiteCreationStep continueFromPhase = mIsRetry ? - SiteCreationStep.valueOf(intent.getStringExtra(ARG_RESUME_PHASE)) : SiteCreationStep.IDLE; + final SiteCreationStep continueFromPhase = mIsRetry + ? SiteCreationStep.valueOf(intent.getStringExtra(ARG_RESUME_PHASE)) : SiteCreationStep.IDLE; if (continueFromPhase == SiteCreationStep.IDLE && mNewSite != null) { // site already exists but we're not in a retry attempt _after_ having issued the new-site creation call. @@ -307,7 +307,7 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) { private SiteModel getWpcomSiteBySlug(String siteSlug) { final String url = siteSlug + ".wordpress.com"; - for(SiteModel site : mSiteStore.getSites()) { + for (SiteModel site : mSiteStore.getSites()) { if (Uri.parse(site.getUrl()).getHost().equals(url)) { return site; } From 954a0dea14841b28931f3d6b1169a13e0028b840 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 02:31:36 -0700 Subject: [PATCH 07/12] Fix checkstyle errors. --- .../org/wordpress/android/ui/plugins/PluginBrowserActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java index 3c20394f2258..77b64fa0f8aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java @@ -38,7 +38,6 @@ import org.wordpress.android.util.ActivityUtils; import org.wordpress.android.util.AnalyticsUtils; import org.wordpress.android.util.AniUtils; -import org.wordpress.android.util.HtmlUtils; import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; From 1f3a05bef7a1e01f35dab6b52c9fa633bde14754 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 14:29:47 -0700 Subject: [PATCH 08/12] Clean up method language and consolidate locale-related methods to LocaleManager * Move all language related helper methods from WPPrefUtils to LocaleManager * Remove unnecessary try/catch --- .../android/ui/prefs/AppSettingsFragment.java | 15 +- .../ui/prefs/SiteSettingsFragment.java | 9 +- .../ui/prefs/SiteSettingsInterface.java | 4 +- .../ui/reader/views/ReaderSiteHeaderView.java | 15 +- .../wordpress/android/util/LocaleManager.java | 138 +++++++++++++++++- .../wordpress/android/util/WPPrefUtils.java | 126 ---------------- 6 files changed, 149 insertions(+), 158 deletions(-) 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 82f0e06c4c12..91f343d8795a 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 @@ -3,7 +3,6 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.preference.ListPreference; @@ -11,7 +10,6 @@ import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.text.TextUtils; import android.util.Pair; @@ -44,7 +42,6 @@ public class AppSettingsFragment extends PreferenceFragment private static final int IDX_AZTEC_EDITOR = 2; private DetailListPreference mLanguagePreference; - private SharedPreferences mSettings; // This Device settings private WPSwitchPreference mOptimizedImage; @@ -133,8 +130,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { R.string.pref_key_site_video_encoder_bitrate); } - mSettings = PreferenceManager.getDefaultSharedPreferences(getActivity()); - updateEditorSettings(); } @@ -277,7 +272,7 @@ private void changeLanguage(String languageCode) { return; } - if (!LocaleManager.isDifferentLanguage(languageCode)) { + if (LocaleManager.isSameLanguage(languageCode)) { return; } @@ -305,11 +300,11 @@ private void updateLanguagePreference(String languageCode) { return; } - Locale languageLocale = WPPrefUtils.languageLocale(languageCode); + Locale languageLocale = LocaleManager.languageLocale(languageCode); String[] availableLocales = getResources().getStringArray(R.array.available_languages); Pair pair = - WPPrefUtils.createSortedLanguageDisplayStrings(availableLocales, languageLocale); + LocaleManager.createSortedLanguageDisplayStrings(availableLocales, languageLocale); // check for a possible NPE if (pair == null) { return; @@ -320,10 +315,10 @@ private void updateLanguagePreference(String languageCode) { mLanguagePreference.setEntries(sortedEntries); mLanguagePreference.setEntryValues(sortedValues); - mLanguagePreference.setDetails(WPPrefUtils.createLanguageDetailDisplayStrings(sortedValues)); + mLanguagePreference.setDetails(LocaleManager.createLanguageDetailDisplayStrings(sortedValues)); mLanguagePreference.setValue(languageCode); - mLanguagePreference.setSummary(WPPrefUtils.getLanguageString(languageCode, languageLocale)); + mLanguagePreference.setSummary(LocaleManager.getLanguageString(languageCode, languageLocale)); mLanguagePreference.refreshAdapter(); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java index 006bab6c0b9a..d85189b92788 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java @@ -66,6 +66,7 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.HelpshiftHelper; import org.wordpress.android.util.HtmlUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.StringUtils; @@ -1371,7 +1372,7 @@ private void changeLanguageValue(String newValue) { if (TextUtils.isEmpty(mLanguagePref.getSummary()) || !newValue.equals(mLanguagePref.getValue())) { mLanguagePref.setValue(newValue); - String summary = WPPrefUtils.getLanguageString(newValue, WPPrefUtils.languageLocale(newValue)); + String summary = LocaleManager.getLanguageString(newValue, LocaleManager.languageLocale(newValue)); mLanguagePref.setSummary(summary); mLanguagePref.refreshAdapter(); } @@ -1382,15 +1383,15 @@ private void sortLanguages() { return; } - Pair pair = WPPrefUtils - .createSortedLanguageDisplayStrings(mLanguagePref.getEntryValues(), WPPrefUtils.languageLocale(null)); + Pair pair = LocaleManager + .createSortedLanguageDisplayStrings(mLanguagePref.getEntryValues(), LocaleManager.languageLocale(null)); if (pair != null) { String[] sortedEntries = pair.first; String[] sortedValues = pair.second; mLanguagePref.setEntries(sortedEntries); mLanguagePref.setEntryValues(sortedValues); - mLanguagePref.setDetails(WPPrefUtils.createLanguageDetailDisplayStrings(sortedValues)); + mLanguagePref.setDetails(LocaleManager.createLanguageDetailDisplayStrings(sortedValues)); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsInterface.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsInterface.java index 6887e51b6f16..8a22062469b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsInterface.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsInterface.java @@ -24,9 +24,9 @@ import org.wordpress.android.models.JetpackSettingsModel; import org.wordpress.android.models.SiteSettingsModel; import org.wordpress.android.util.LanguageUtils; +import org.wordpress.android.util.LocaleManager; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.StringUtils; -import org.wordpress.android.util.WPPrefUtils; import java.util.ArrayList; import java.util.HashMap; @@ -218,7 +218,7 @@ protected SiteSettingsInterface(Context host, SiteModel site, SiteSettingsListen mRemoteSettings = new SiteSettingsModel(); mJpSettings = new JetpackSettingsModel(); mRemoteJpSettings = new JetpackSettingsModel(); - mLanguageCodes = WPPrefUtils.generateLanguageMap(host); + mLanguageCodes = LocaleManager.generateLanguageMap(host); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java index 74c7268e5019..98d1bf0678df 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java @@ -129,17 +129,10 @@ private void showBlogInfo(ReaderBlog blogInfo) { txtDescription.setVisibility(View.GONE); } - try { - txtFollowCount.setText(String.format( - LocaleManager.getSafeLocale(getContext()), - getContext().getString(R.string.reader_label_follow_count), - blogInfo.numSubscribers)); - } catch (ArithmeticException exception) { - txtFollowCount.setText(String.format( - LocaleManager.getSafeLocale(getContext()), - getContext().getString(R.string.reader_label_follow_count), - blogInfo.numSubscribers)); - } + txtFollowCount.setText(String.format( + LocaleManager.getSafeLocale(getContext()), + getContext().getString(R.string.reader_label_follow_count), + blogInfo.numSubscribers)); if (!mAccountStore.hasAccessToken()) { mFollowButton.setVisibility(View.GONE); diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index 025dfabc8ceb..a5efa6a48576 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -7,8 +7,16 @@ import android.content.res.Resources; import android.os.Build; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import android.util.Pair; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import javax.annotation.Nullable; @@ -18,6 +26,24 @@ * android version. */ public abstract class LocaleManager { + /** + * Length of a {@link String} (representing a language code) when there is no region included. + * For example: "en" contains no region, "en_US" contains a region (US) + *

+ * Used to parse a language code {@link String} when creating a {@link Locale}. + */ + private static final int NO_REGION_LANG_CODE_LEN = 2; + + /** + * Index of a language code {@link String} where the region code begins. The language code + * format is cc_rr, where cc is the country code (e.g. en, es, az) and rr is the region code + * (e.g. us, au, gb). + */ + private static final int REGION_SUBSTRING_INDEX = 3; + + /** + * Key used for saving the language selection to shared preferences. + */ private static final String LANGUAGE_KEY = "language-pref"; /** @@ -35,7 +61,7 @@ public static Context setLocale(Context context) { * @param language The 2-letter language code (example "en") to switch to */ public static Context setNewLocale(Context context, String language) { - Locale newLocale = WPPrefUtils.languageLocale(language); + Locale newLocale = languageLocale(language); if (Locale.getDefault().toString().equals(newLocale.toString())) { removePersistedLanguage(context); @@ -50,9 +76,9 @@ public static Context setNewLocale(Context context, String language) { * @param language The language to compare * @return True if the languages are the same, else false */ - public static boolean isDifferentLanguage(String language) { - Locale newLocale = WPPrefUtils.languageLocale(language); - return !Locale.getDefault().getLanguage().equals(newLocale.getLanguage()); + public static boolean isSameLanguage(@NonNull String language) { + Locale newLocale = languageLocale(language); + return Locale.getDefault().getLanguage().equals(newLocale.getLanguage()); } /** @@ -143,9 +169,111 @@ public static Locale getSafeLocale(@Nullable Context context) { } if (Build.VERSION.SDK_INT >= 24) { - return WPPrefUtils.languageLocale(baseLocale.getLanguage()); + return languageLocale(baseLocale.getLanguage()); } else { return baseLocale; } } + + /** + * Gets a locale for the given language code. + * @param languageCode The 2-letter language code (example "en"). If null or empty will return + * the current default locale. + */ + public static Locale languageLocale(@Nullable String languageCode) { + if (TextUtils.isEmpty(languageCode)) { + return Locale.getDefault(); + } + + if (languageCode.length() > NO_REGION_LANG_CODE_LEN) { + return new Locale(languageCode.substring(0, NO_REGION_LANG_CODE_LEN), + languageCode.substring(REGION_SUBSTRING_INDEX)); + } + + return new Locale(languageCode); + } + + /** + * Creates a map from language codes to WordPress language IDs. + */ + public static Map generateLanguageMap(Context context) { + String[] languageIds = context.getResources().getStringArray(org.wordpress.android.R.array.lang_ids); + String[] languageCodes = context.getResources().getStringArray(org.wordpress.android.R.array.language_codes); + + Map languageMap = new HashMap<>(); + for (int i = 0; i < languageIds.length && i < languageCodes.length; ++i) { + languageMap.put(languageCodes[i], languageIds[i]); + } + + return languageMap; + } + + /** + * Generates display strings for given language codes. Used as entries in language preference. + */ + @android.support.annotation.Nullable + public static Pair createSortedLanguageDisplayStrings(CharSequence[] languageCodes, + Locale locale) { + if (languageCodes == null || languageCodes.length < 1) { + return null; + } + + ArrayList entryStrings = new ArrayList<>(languageCodes.length); + for (int i = 0; i < languageCodes.length; ++i) { + // "__" is used to sort the language code with the display string so both arrays are sorted at the same time + entryStrings.add(i, StringUtils.capitalize( + getLanguageString(languageCodes[i].toString(), locale)) + "__" + languageCodes[i]); + } + + Collections.sort(entryStrings, Collator.getInstance(locale)); + + String[] sortedEntries = new String[languageCodes.length]; + String[] sortedValues = new String[languageCodes.length]; + + for (int i = 0; i < entryStrings.size(); ++i) { + // now, we can split the sorted array to extract the display string and the language code + String[] split = entryStrings.get(i).split("__"); + sortedEntries[i] = split[0]; + sortedValues[i] = split[1]; + } + + return new Pair<>(sortedEntries, sortedValues); + } + + /** + * Generates detail display strings in the currently selected locale. Used as detail text + * in language preference dialog. + */ + @android.support.annotation.Nullable + public static String[] createLanguageDetailDisplayStrings(CharSequence[] languageCodes) { + if (languageCodes == null || languageCodes.length < 1) { + return null; + } + + String[] detailStrings = new String[languageCodes.length]; + for (int i = 0; i < languageCodes.length; ++i) { + detailStrings[i] = StringUtils.capitalize(getLanguageString( + languageCodes[i].toString(), languageLocale(languageCodes[i].toString()))); + } + + return detailStrings; + } + + /** + * Return a non-null display string for a given language code. + */ + public static String getLanguageString(String languageCode, Locale displayLocale) { + if (languageCode == null || languageCode.length() < 2 || languageCode.length() > 6) { + return ""; + } + + Locale languageLocale = languageLocale(languageCode); + String displayLanguage = StringUtils.capitalize(languageLocale.getDisplayLanguage(displayLocale)); + String displayCountry = languageLocale.getDisplayCountry(displayLocale); + + if (!TextUtils.isEmpty(displayCountry)) { + return displayLanguage + " (" + displayCountry + ")"; + } + return displayLanguage; + } } diff --git a/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java b/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java index ab26e0244764..29c8496785f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/util/WPPrefUtils.java @@ -1,46 +1,20 @@ package org.wordpress.android.util; -import android.content.Context; import android.preference.Preference; import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; -import android.support.annotation.Nullable; -import android.text.TextUtils; -import android.util.Pair; import android.util.TypedValue; import android.widget.EditText; import android.widget.TextView; import org.wordpress.android.R; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - /** * Design guidelines for Calypso-styled Site Settings (and likely other screens) */ public class WPPrefUtils { - /** - * Length of a {@link String} (representing a language code) when there is no region included. - * For example: "en" contains no region, "en_US" contains a region (US) - *

- * Used to parse a language code {@link String} when creating a {@link Locale}. - */ - private static final int NO_REGION_LANG_CODE_LEN = 2; - - /** - * Index of a language code {@link String} where the region code begins. The language code - * format is cc_rr, where cc is the country code (e.g. en, es, az) and rr is the region code - * (e.g. us, au, gb). - */ - private static final int REGION_SUBSTRING_INDEX = 3; - /** * Gets a preference and sets the {@link android.preference.Preference.OnPreferenceChangeListener}. */ @@ -186,104 +160,4 @@ public static void setTextViewAttributes(TextView textView, int size, int colorR textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); textView.setTextColor(textView.getResources().getColor(colorRes)); } - - /** - * Gets a locale for the given language code. - */ - public static Locale languageLocale(String languageCode) { - if (TextUtils.isEmpty(languageCode)) { - return Locale.getDefault(); - } - - if (languageCode.length() > NO_REGION_LANG_CODE_LEN) { - return new Locale(languageCode.substring(0, NO_REGION_LANG_CODE_LEN), - languageCode.substring(REGION_SUBSTRING_INDEX)); - } - - return new Locale(languageCode); - } - - /** - * Creates a map from language codes to WordPress language IDs. - */ - public static Map generateLanguageMap(Context context) { - String[] languageIds = context.getResources().getStringArray(R.array.lang_ids); - String[] languageCodes = context.getResources().getStringArray(R.array.language_codes); - - Map languageMap = new HashMap<>(); - for (int i = 0; i < languageIds.length && i < languageCodes.length; ++i) { - languageMap.put(languageCodes[i], languageIds[i]); - } - - return languageMap; - } - - /** - * Generates display strings for given language codes. Used as entries in language preference. - */ - @Nullable - public static Pair createSortedLanguageDisplayStrings(CharSequence[] languageCodes, - Locale locale) { - if (languageCodes == null || languageCodes.length < 1) { - return null; - } - - ArrayList entryStrings = new ArrayList<>(languageCodes.length); - for (int i = 0; i < languageCodes.length; ++i) { - // "__" is used to sort the language code with the display string so both arrays are sorted at the same time - entryStrings.add(i, StringUtils.capitalize( - getLanguageString(languageCodes[i].toString(), locale)) + "__" + languageCodes[i]); - } - - Collections.sort(entryStrings, Collator.getInstance(locale)); - - String[] sortedEntries = new String[languageCodes.length]; - String[] sortedValues = new String[languageCodes.length]; - - for (int i = 0; i < entryStrings.size(); ++i) { - // now, we can split the sorted array to extract the display string and the language code - String[] split = entryStrings.get(i).split("__"); - sortedEntries[i] = split[0]; - sortedValues[i] = split[1]; - } - - return new Pair<>(sortedEntries, sortedValues); - } - - /** - * Generates detail display strings in the currently selected locale. Used as detail text - * in language preference dialog. - */ - @Nullable - public static String[] createLanguageDetailDisplayStrings(CharSequence[] languageCodes) { - if (languageCodes == null || languageCodes.length < 1) { - return null; - } - - String[] detailStrings = new String[languageCodes.length]; - for (int i = 0; i < languageCodes.length; ++i) { - detailStrings[i] = StringUtils.capitalize(getLanguageString( - languageCodes[i].toString(), WPPrefUtils.languageLocale(languageCodes[i].toString()))); - } - - return detailStrings; - } - - /** - * Return a non-null display string for a given language code. - */ - public static String getLanguageString(String languageCode, Locale displayLocale) { - if (languageCode == null || languageCode.length() < 2 || languageCode.length() > 6) { - return ""; - } - - Locale languageLocale = WPPrefUtils.languageLocale(languageCode); - String displayLanguage = StringUtils.capitalize(languageLocale.getDisplayLanguage(displayLocale)); - String displayCountry = languageLocale.getDisplayCountry(displayLocale); - - if (!TextUtils.isEmpty(displayCountry)) { - return displayLanguage + " (" + displayCountry + ")"; - } - return displayLanguage; - } } From abd0dcc297fc036f0d298e3d04383cd5821d4b0f Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 14:39:07 -0700 Subject: [PATCH 09/12] Fix broken methods getCurrentDeviceLanguage(context), getCurrentDeviceLanguageCode(context) and deprecate method signatures Methods stopped working as expected as of API 25. Context argument is no longer needed, but may still be used by other libraries so deprecated those method signatures and added new updated method signatures. --- .../wordpress/android/util/LanguageUtils.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/LanguageUtils.java b/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/LanguageUtils.java index c043b2f0d97c..586c1e18b553 100644 --- a/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/LanguageUtils.java +++ b/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/LanguageUtils.java @@ -1,6 +1,7 @@ package org.wordpress.android.util; import android.content.Context; +import android.support.annotation.Nullable; import java.util.Locale; @@ -8,17 +9,35 @@ * Methods for dealing with i18n messages */ public class LanguageUtils { - public static Locale getCurrentDeviceLanguage(Context context) { - // better use getConfiguration as it has the latest locale configuration change. - // Otherwise Locale.getDefault().getLanguage() gets - // the config upon application launch. - Locale deviceLocale = context != null ? context.getResources().getConfiguration().locale : Locale.getDefault(); - return deviceLocale; + /** + * @deprecated Use {@link #getCurrentDeviceLanguage()}. As of API 25, setting the locale by updating the + * configuration on the resources object was deprecated, so this method stopped working for newer versions + * of Android. The current active locale should always be set in {@link Locale#getDefault()}. When manually + * setting the active locale, the developer should set it in {@link Locale#setDefault(Locale)}. + */ + @SuppressWarnings("DeprecatedIsStillUsed") + @Deprecated + public static Locale getCurrentDeviceLanguage(@Nullable Context context) { + return getCurrentDeviceLanguage(); + } + + @SuppressWarnings("WeakerAccess") + public static Locale getCurrentDeviceLanguage() { + return Locale.getDefault(); + } + + /** + * @deprecated Use {@link #getCurrentDeviceLanguageCode()}. + */ + @SuppressWarnings("WeakerAccess,DeprecatedIsStillUsed") + @Deprecated + public static String getCurrentDeviceLanguageCode(@Nullable Context context) { + return getCurrentDeviceLanguageCode(); } - public static String getCurrentDeviceLanguageCode(Context context) { - String deviceLanguageCode = getCurrentDeviceLanguage(context).toString(); - return deviceLanguageCode; + @SuppressWarnings("WeakerAccess") + public static String getCurrentDeviceLanguageCode() { + return getCurrentDeviceLanguage().toString(); } public static String getPatchedCurrentDeviceLanguage(Context context) { @@ -28,6 +47,7 @@ public static String getPatchedCurrentDeviceLanguage(Context context) { /** * Patches a deviceLanguageCode if any of deprecated values iw, id, or yi */ + @SuppressWarnings("WeakerAccess") public static String patchDeviceLanguageCode(String deviceLanguageCode) { String patchedCode = deviceLanguageCode; /* From 123e50e89f36ed40e6ddea8282999fe6567f6bc3 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 14:59:59 -0700 Subject: [PATCH 10/12] Remove abstract keyword --- .../src/main/java/org/wordpress/android/util/LocaleManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index a5efa6a48576..07d4e0adb8c7 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -25,7 +25,7 @@ * selected language is properly saved and resources appropriately updated for the * android version. */ -public abstract class LocaleManager { +public class LocaleManager { /** * Length of a {@link String} (representing a language code) when there is no region included. * For example: "en" contains no region, "en_US" contains a region (US) From 5217f882943e70b5c56144935ec1fcda9d76d116 Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 15:26:19 -0700 Subject: [PATCH 11/12] No need to return the context from LocaleManager.setNewLocale(...). Updated login in method to just exit it the new language is the same as the current language. --- .../android/ui/prefs/AppSettingsFragment.java | 5 ++--- .../org/wordpress/android/util/LocaleManager.java | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) 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 91f343d8795a..3f9f2462bbf2 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 @@ -1,7 +1,6 @@ package org.wordpress.android.ui.prefs; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -276,13 +275,13 @@ private void changeLanguage(String languageCode) { return; } - Context newContext = LocaleManager.setNewLocale(WordPress.getContext(), languageCode); + LocaleManager.setNewLocale(WordPress.getContext(), languageCode); updateLanguagePreference(languageCode); // 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", newContext.getResources().getConfiguration().locale.toString()); + 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 diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index 07d4e0adb8c7..dac6b52df335 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -60,15 +60,12 @@ public static Context setLocale(Context context) { * @param context The current context * @param language The 2-letter language code (example "en") to switch to */ - public static Context setNewLocale(Context context, String language) { - Locale newLocale = languageLocale(language); - - if (Locale.getDefault().toString().equals(newLocale.toString())) { - removePersistedLanguage(context); - } else { - saveLanguageToPref(context, language); + public static void setNewLocale(Context context, String language) { + if (isSameLanguage(language)) { + return; } - return updateResources(context, language); + saveLanguageToPref(context, language); + updateResources(context, language); } /** From cf64885d56271abed6d1fd19845083630193006c Mon Sep 17 00:00:00 2001 From: Amanda Riu Date: Fri, 9 Mar 2018 15:43:31 -0700 Subject: [PATCH 12/12] Remove unused method and add proper @Nullable import. --- .../wordpress/android/util/LocaleManager.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java index dac6b52df335..20dac9b93581 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java +++ b/WordPress/src/main/java/org/wordpress/android/util/LocaleManager.java @@ -8,6 +8,7 @@ import android.os.Build; import android.preference.PreferenceManager; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Pair; @@ -18,8 +19,6 @@ import java.util.Locale; import java.util.Map; -import javax.annotation.Nullable; - /** * Helper class for working with localized strings. Ensures updates to the users * selected language is properly saved and resources appropriately updated for the @@ -104,18 +103,6 @@ private static void saveLanguageToPref(Context context, String language) { prefs.edit().putString(LANGUAGE_KEY, language).commit(); } - /** - * Remove any saved custom language selection from SharedPreferences. - * Use commit() instead of apply() to ensure the language preference is saved instantly - * as the app may be restarted immediately. - * @param context The current context - */ - @SuppressLint("ApplySharedPref") - private static void removePersistedLanguage(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().remove(LANGUAGE_KEY).commit(); - } - /** * Update resources for the current session. * @@ -208,7 +195,7 @@ public static Map generateLanguageMap(Context context) { /** * Generates display strings for given language codes. Used as entries in language preference. */ - @android.support.annotation.Nullable + @Nullable public static Pair createSortedLanguageDisplayStrings(CharSequence[] languageCodes, Locale locale) { if (languageCodes == null || languageCodes.length < 1) { @@ -241,7 +228,7 @@ public static Pair createSortedLanguageDisplayStrings(CharSe * Generates detail display strings in the currently selected locale. Used as detail text * in language preference dialog. */ - @android.support.annotation.Nullable + @Nullable public static String[] createLanguageDetailDisplayStrings(CharSequence[] languageCodes) { if (languageCodes == null || languageCodes.length < 1) { return null;