Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: localized filters (ReaderTag) #8095

Merged
merged 4 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public boolean isSameList(ReaderTagList otherList) {
return false;
} else if (!otherTag.getEndpoint().equals(this.get(i).getEndpoint())) {
return false;
} else if (!otherTag.getTagTitle().equals(this.get(i).getTagTitle())) {
return false;
}
}

Expand Down
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
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
Expand Up @@ -3,10 +3,12 @@
import android.annotation.TargetApi;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;

import org.wordpress.android.WordPress;
import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.LocaleManager;

import java.util.EnumSet;

Expand All @@ -16,6 +18,11 @@
public class ReaderUpdateJobService extends JobService implements ServiceCompletionListener {
private ReaderUpdateLogic mReaderUpdateLogic;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public boolean onStartJob(JobParameters params) {
AppLog.i(AppLog.T.READER, "reader job service > started");
Expand All @@ -40,7 +47,7 @@ public boolean onStopJob(JobParameters params) {
@Override
public void onCreate() {
super.onCreate();
mReaderUpdateLogic = new ReaderUpdateLogic((WordPress) getApplication(), this);
mReaderUpdateLogic = new ReaderUpdateLogic(this, (WordPress) getApplication(), this);
AppLog.i(AppLog.T.READER, "reader job service > created");
}

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,16 @@ public enum UpdateTask {
private EnumSet<UpdateTask> mCurrentTasks;
private ServiceCompletionListener mCompletionListener;
private Object mListenerCompanion;
private String mLanguage;
private Context mContext;

@Inject AccountStore mAccountStore;

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

public void performTasks(EnumSet<UpdateTask> tasks, Object companion) {
Expand Down Expand Up @@ -105,7 +112,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 All @@ -124,7 +133,7 @@ public void run() {

// manually insert Bookmark tag, as server doesn't support bookmarking yet
serverTopics.add(new ReaderTag("", "",
WordPress.getContext().getString(R.string.reader_save_for_later_title), "",
mContext.getString(R.string.reader_save_for_later_title), "",
ReaderTagType.BOOKMARKED));

// parse topics from the response, detect whether they're different from local
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.wordpress.android.ui.reader.services.update;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

import org.wordpress.android.WordPress;
import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.LocaleManager;

import java.util.EnumSet;

Expand All @@ -26,10 +28,15 @@ public IBinder onBind(Intent intent) {
return null;
}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public void onCreate() {
super.onCreate();
mReaderUpdateLogic = new ReaderUpdateLogic((WordPress) getApplication(), this);
mReaderUpdateLogic = new ReaderUpdateLogic(this, (WordPress) getApplication(), this);
AppLog.i(AppLog.T.READER, "reader service > created");
}

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