Skip to content

Commit

Permalink
added locale param to /read/menu endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mzorz committed Jul 20, 2018
1 parent 5fd458f commit 68c2526
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.AccountStore.OnAccountChanged;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.ui.reader.services.update.ReaderUpdateLogic;
import org.wordpress.android.ui.reader.services.update.ReaderUpdateServiceStarter;
import org.wordpress.android.util.AnalyticsUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.LocaleManager;
Expand All @@ -36,6 +38,7 @@
import org.wordpress.android.util.WPMediaUtils;
import org.wordpress.android.util.WPPrefUtils;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -368,6 +371,9 @@ private void changeLanguage(String languageCode) {
startActivity(refresh);
getActivity().setResult(LANGUAGE_CHANGED);
getActivity().finish();

// update Reader tags as they need be localized - use the app context as the Activity is being finished
ReaderUpdateServiceStarter.startService(WordPress.getContext(), EnumSet.of(ReaderUpdateLogic.UpdateTask.TAGS));
}

private void updateLanguagePreference(String languageCode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.reader.services.update;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.android.volley.VolleyError;
Expand All @@ -23,8 +24,10 @@
import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.JSONUtils;
import org.wordpress.android.util.LocaleManager;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;

import javax.inject.Inject;
Expand All @@ -48,12 +51,14 @@ public enum UpdateTask {
private EnumSet<UpdateTask> mCurrentTasks;
private ServiceCompletionListener mCompletionListener;
private Object mListenerCompanion;
private String mLanguage;

@Inject AccountStore mAccountStore;

public ReaderUpdateLogic(WordPress app, ServiceCompletionListener listener) {
mCompletionListener = listener;
app.component().inject(this);
mLanguage = LocaleManager.getLanguage(app);
}

public void performTasks(EnumSet<UpdateTask> tasks, Object companion) {
Expand Down Expand Up @@ -105,7 +110,9 @@ public void onErrorResponse(VolleyError volleyError) {
}
};
AppLog.d(AppLog.T.READER, "reader service > updating tags");
WordPress.getRestClientUtilsV1_2().get("read/menu", null, null, listener, errorListener);
HashMap<String, String> params = new HashMap<>();
params.put("locale", mLanguage);
WordPress.getRestClientUtilsV1_2().get("read/menu", params, null, listener, errorListener);
}

private void handleUpdateTagsResponse(final JSONObject jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static boolean isSameLanguage(@NonNull String language) {
* language code, else just return the device default language code.
* @return The 2-letter language code (example "en")
*/
private static String getLanguage(Context context) {
public static String getLanguage(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(LANGUAGE_KEY, LanguageUtils.getCurrentDeviceLanguageCode());
}
Expand Down

0 comments on commit 68c2526

Please sign in to comment.