Consolidate shared prefs to a single store (#2613)

* Consolidate shared prefs to a single store
* Fix achievements activity
* Fix store usage
This commit is contained in:
Vivek Maskara 2019-03-16 19:26:56 +05:30 committed by Adam Jones
parent 51f58b7118
commit 7cb87f3cab
41 changed files with 207 additions and 279 deletions

View file

@ -43,7 +43,7 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AccountUtil;
import fr.free.nrw.commons.category.CategoryImageUtils;
import fr.free.nrw.commons.category.QueryContinue;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationUtils;
import fr.free.nrw.commons.utils.ConfigUtils;
@ -65,8 +65,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
private CustomMwApi api;
private CustomMwApi wikidataApi;
private Context context;
private BasicKvStore defaultKvStore;
private BasicKvStore categoryKvStore;
private JsonKvStore defaultKvStore;
private Gson gson;
private final String ERROR_CODE_BAD_TOKEN = "badtoken";
@ -74,8 +73,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
public ApacheHttpClientMediaWikiApi(Context context,
String apiURL,
String wikidatApiURL,
BasicKvStore defaultKvStore,
BasicKvStore categoryKvStore,
JsonKvStore defaultKvStore,
Gson gson) {
this.context = context;
BasicHttpParams params = new BasicHttpParams();
@ -92,7 +90,6 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
api = new CustomMwApi(apiURL, httpClient);
wikidataApi = new CustomMwApi(wikidatApiURL, httpClient);
this.defaultKvStore = defaultKvStore;
this.categoryKvStore = categoryKvStore;
this.gson = gson;
}
@ -796,7 +793,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
* @param queryContinue
*/
private void setQueryContinueValues(String keyword, QueryContinue queryContinue) {
categoryKvStore.putString(keyword, gson.toJson(queryContinue));
defaultKvStore.putString(keyword, gson.toJson(queryContinue));
}
/**
@ -806,7 +803,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
*/
@Nullable
private QueryContinue getQueryContinueValues(String keyword) {
String queryContinueString = categoryKvStore.getString(keyword, null);
String queryContinueString = defaultKvStore.getString(keyword, null);
return gson.fromJson(queryContinueString, QueryContinue.class);
}

View file

@ -4,7 +4,7 @@ import android.content.Context;
import android.os.Build;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
public class EventLog {
static final String DEVICE;
@ -17,11 +17,11 @@ public class EventLog {
}
}
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
private static LogBuilder schema(String schema, long revision, MediaWikiApi mwApi, JsonKvStore prefs, Context context) {
return new LogBuilder(schema, revision, mwApi, prefs, context);
}
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, BasicKvStore prefs, Context context) {
public static LogBuilder schema(Object[] scid, MediaWikiApi mwApi, JsonKvStore prefs, Context context) {
if (scid.length != 2) {
throw new IllegalArgumentException("Needs an object array with schema as first param and revision as second");
}

View file

@ -12,7 +12,7 @@ import java.net.URL;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.utils.ConfigUtils;
@ -22,7 +22,7 @@ public class LogBuilder {
private final JSONObject data;
private final long rev;
private final String schema;
private final BasicKvStore prefs;
private final JsonKvStore prefs;
private final Context context;
/**
@ -36,7 +36,7 @@ public class LogBuilder {
LogBuilder(String schema,
long revision,
MediaWikiApi mwApi,
BasicKvStore prefs,
JsonKvStore prefs,
Context context) {
this.prefs = prefs;
this.data = new JSONObject();