Panagiotis Triantafyllou

new version, locale and dark mode prefs

......@@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.4m1'
PUBLISH_VERSION = '4.5.5.4m2'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -43,6 +43,7 @@ import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
......@@ -161,11 +162,39 @@ public class WarpUtils {
+ "steps_manually_stopped";
private static final String PREFERENCES_KEY_JWT_ENABLED = PREFERENCES_PREFIX
+ "jwt_enabled";
private static final String PREFERENCES_KEY_APP_LOCALE = PREFERENCES_PREFIX
+ "app_locale";
private static final String PREFERENCES_KEY_DARK_MODE_ENABLED = PREFERENCES_PREFIX
+ "dark_mode_enabled";
private static SharedPreferences _prefs;
/* Public methods */
public static String getApplicationLocale(Context context) {
return getPreferences(context).getString(PREFERENCES_KEY_APP_LOCALE, "el");
}
public static void setApplicationLocale(Context context, String localeParam) {
String tempLocale = localeParam.toLowerCase();
if ("gr".equals(tempLocale)) {
tempLocale = "el";
}
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putString(PREFERENCES_KEY_APP_LOCALE, TextUtils.isEmpty(tempLocale) ? "el" : tempLocale);
editor.apply();
}
public static boolean getIsDarkModeEnabled(Context context) {
return getPreferences(context).getBoolean(PREFERENCES_KEY_DARK_MODE_ENABLED, false);
}
public static void setIsDarkModeEnabled(Context context, boolean isDarkModeEnabled) {
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putBoolean(PREFERENCES_KEY_DARK_MODE_ENABLED, isDarkModeEnabled);
editor.apply();
}
public static boolean getIsSteps(Context context) {
return getPreferences(context).getBoolean(PREFERENCES_KEY_STEPS, false);
}
......
......@@ -107,6 +107,8 @@ public class WarplyManagerHelper {
params.putOpt("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token"));
params.putOpt("client_id", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id"));
params.putOpt("client_secret", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret"));
params.putOpt("lan", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
params.putOpt("dark", String.valueOf(WarpUtils.getIsDarkModeEnabled(Warply.getWarplyContext())));
} catch (JSONException e) {
e.printStackTrace();
}
......@@ -131,6 +133,8 @@ public class WarplyManagerHelper {
params.putOpt("refresh_token", WarplyDBHelper.getInstance(context).getAuthValue("refresh_token"));
params.putOpt("client_id", WarplyDBHelper.getInstance(context).getClientValue("client_id"));
params.putOpt("client_secret", WarplyDBHelper.getInstance(context).getClientValue("client_secret"));
params.putOpt("lan", WarpUtils.getApplicationLocale(context));
params.putOpt("dark", String.valueOf(WarpUtils.getIsDarkModeEnabled(context)));
} catch (JSONException e) {
e.printStackTrace();
}
......@@ -152,6 +156,8 @@ public class WarplyManagerHelper {
params.putOpt("client_id", WarplyDBHelper.getInstance(context).getClientValue("client_id"));
params.putOpt("client_secret", WarplyDBHelper.getInstance(context).getClientValue("client_secret"));
params.putOpt("map", "true");
params.putOpt("lan", WarpUtils.getApplicationLocale(context));
params.putOpt("dark", String.valueOf(WarpUtils.getIsDarkModeEnabled(context)));
} catch (JSONException e) {
e.printStackTrace();
}
......
......@@ -163,7 +163,26 @@ public class WarplyManager {
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> logoutCall = WarpUtils.isJWTEnabled(Warply.getWarplyContext()) ? service.logoutUserJwt(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp)) : service.logoutUser(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp));
Call<ResponseBody> logoutCall = WarpUtils.isJWTEnabled(Warply.getWarplyContext())
? service.logoutUserJwt(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
)
: service.logoutUser(WarplyProperty.getAppUuid(Warply.getWarplyContext()),
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
);
logoutCall.enqueue(new Callback<ResponseBody>() {
@Override
......@@ -237,7 +256,17 @@ public class WarplyManager {
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> loginCall = service.cosmoteUser(WarplyProperty.getAppUuid(Warply.getWarplyContext()), loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Basic MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU=");
Call<ResponseBody> loginCall = service.cosmoteUser(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Basic MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU="
);
loginCall.enqueue(new Callback<ResponseBody>() {
@Override
......@@ -323,7 +352,15 @@ public class WarplyManager {
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> loginCall = service.verifyUser(loginRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp));
Call<ResponseBody> loginCall = service.verifyUser(
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
);
loginCall.enqueue(new Callback<ResponseBody>() {
@Override
......@@ -516,7 +553,7 @@ public class WarplyManager {
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "retrieve");
jsonParams.put("filters", new JSONObject());
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("language", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
jsonParamsCampaigns.put("campaigns", jsonParams);
RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString());
......@@ -655,7 +692,7 @@ public class WarplyManager {
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "retrieve");
jsonParams.put("filters", new JSONObject());
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("language", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
jsonParamsCampaigns.put("campaigns", jsonParams);
RequestBody campaignsPersonalizedRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString());
......@@ -987,7 +1024,7 @@ public class WarplyManager {
jArr.put("merchant");
jArr.put("redemption");
jsonParams.put("details", jArr);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("language", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
jsonParams.put("couponset_types", new JSONArray().put("supermarket"));
jsonParamsCoupons.put("coupon", jsonParams);
......@@ -1113,7 +1150,7 @@ public class WarplyManager {
jArr.put("merchant");
jArr.put("redemption");
jsonParams.put("details", jArr);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("language", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
// JSONObject jPagination= new JSONObject();
// try {
// jPagination.putOpt("page",1);
......@@ -1316,7 +1353,7 @@ public class WarplyManager {
}
jsonParams.put("action", "retrieve");
jsonParams.put("filters", jFilters);
jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
jsonParams.put("language", WarpUtils.getApplicationLocale(Warply.getWarplyContext()));
jsonParamsCampaigns.put("campaigns", jsonParams);
RequestBody campaignsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCampaigns)).toString());
......