Panagiotis Triantafyllou

sdk optimizations

......@@ -2,25 +2,15 @@ package warp.ly.android_sdk.activities;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import org.json.JSONObject;
import java.util.Timer;
import java.util.TimerTask;
import ly.warp.sdk.Warply;
import ly.warp.sdk.activities.BaseFragmentActivity;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
import ly.warp.sdk.io.request.WarplyLoginRequest;
import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
import ly.warp.sdk.utils.WarplyInitializer;
import ly.warp.sdk.utils.managers.WarplyManager;
import warp.ly.android_sdk.R;
public class SplashActivity extends BaseActivity {
......@@ -35,14 +25,7 @@ public class SplashActivity extends BaseActivity {
mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() {
@Override
public void onWarplyReady() {
if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179
WarplyManager.getCosmoteUser("7000001053", mLoginReceiver);
// WarplyManager.verifyTicket("", "7000023699", mLoginReceiver);
} else {
startNextActivity();
}
startNextActivity();
}
@Override
......@@ -93,19 +76,4 @@ public class SplashActivity extends BaseActivity {
}, MIN_SPLASH_TIME);
}
}
private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
if (result != null && result.optInt("status") == 1) {
startNextActivity();
}
}
@Override
public void onFailure(int errorCode) {
// startNextActivity();
Toast.makeText(SplashActivity.this, "LOGIN ERROR", Toast.LENGTH_SHORT).show();
}
};
}
......
......@@ -19,6 +19,7 @@ import com.google.android.material.navigation.NavigationBarView;
import java.util.ArrayList;
import ly.warp.sdk.R;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.fragments.HomeFragment;
import ly.warp.sdk.fragments.LoyaltyFragment;
import ly.warp.sdk.fragments.MyRewardsFragment;
......@@ -53,9 +54,11 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
mBottomNavigationView = findViewById(R.id.bt_tabs);
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback);
if (WarplyDBHelper.getInstance(this).isTableNotEmpty("auth")) {
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (!hasNotificationPermission()) {
......
......@@ -40,7 +40,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
private static final String DB_NAME = "warply.db";
private static final int DB_VERSION = 10;
private static final int DB_VERSION = 12;
private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W";
//------------------------------ Fields -----------------------------//
......@@ -154,6 +154,19 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
return mDb;
}
private SQLiteDatabase getReadableDb() {
if (mDb == null)
mDb = getReadableDatabase(KEY_CIPHER);
return mDb;
}
private void closeDb() {
if (mDb != null && mDb.isOpen()) {
mDb.close();
mDb = null;
}
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_REQUESTS);
......@@ -215,27 +228,36 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
public synchronized void clearTable(String tableName) {
SQLiteDatabase db = getDb();
db.delete(tableName, null, null);
closeDb();
}
public synchronized void insert(String tableName, ContentValues values) {
SQLiteDatabase db = getDb();
db.insert(tableName, null, values);
closeDb();
}
public synchronized void update(String tableName, ContentValues values) {
SQLiteDatabase db = getDb();
db.update(tableName, values, null, null);
closeDb();
}
public synchronized boolean isTableNotEmpty(String tableName) {
Cursor cursor = getDb().rawQuery("SELECT COUNT(*) FROM " + tableName,
Cursor cursor = getReadableDb().rawQuery("SELECT COUNT(*) FROM " + tableName,
null);
if (cursor != null && cursor.moveToFirst()) {
boolean isNotEmpty = cursor.getInt(0) > 0;
cursor.close();
closeDb();
return isNotEmpty;
} else
} else {
closeDb();
return false;
}
}
//------------------------------ Auth -----------------------------//
......@@ -266,24 +288,30 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
@Nullable
public synchronized String getAuthValue(String columnName) {
String columnValue = "";
Cursor cursor = getDb().query(TABLE_AUTH, new String[]{columnName}, null, null, null, null, null);
Cursor cursor = getReadableDb().query(TABLE_AUTH, new String[]{columnName}, null, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.moveToFirst();
columnValue = cursor.getString(cursor.getColumnIndex(columnName));
cursor.close();
}
closeDb();
return columnValue;
}
@Nullable
public synchronized String getClientValue(String columnName) {
String columnValue = "";
Cursor cursor = getDb().query(TABLE_CLIENT, new String[]{columnName}, null, null, null, null, null);
Cursor cursor = getReadableDb().query(TABLE_CLIENT, new String[]{columnName}, null, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.moveToFirst();
columnValue = cursor.getString(cursor.getColumnIndex(columnName));
cursor.close();
}
closeDb();
return columnValue;
}
......@@ -297,24 +325,21 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
//------------------------------ Api requests -----------------------------//
public synchronized Cursor getAllRequests() {
return getDb().query(TABLE_REQUESTS,
return getReadableDb().query(TABLE_REQUESTS,
new String[]{KEY_REQUESTS_ID,
KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null,
KEY_REQUESTS_DATE_ADDED + " asc", "20");
}
public synchronized Cursor getAllPushRequests() {
return getDb().query(TABLE_PUSH_REQUESTS,
return getReadableDb().query(TABLE_PUSH_REQUESTS,
new String[]{KEY_REQUESTS_ID,
KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null,
KEY_REQUESTS_DATE_ADDED + " asc", "20");
}
public synchronized Cursor getAllPushAckRequests() {
return getDb().query(TABLE_PUSH_ACK_REQUESTS,
return getReadableDb().query(TABLE_PUSH_ACK_REQUESTS,
new String[]{KEY_REQUESTS_ID,
KEY_REQUESTS_MICROAPP, KEY_REQUESTS_ENTITY}, null, null, null, null,
KEY_REQUESTS_DATE_ADDED + " asc", "20");
......@@ -375,7 +400,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public synchronized void deleteRequests(Long... ids) {
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
......@@ -386,10 +410,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append(ids[i]);
}
getDb().delete(TABLE_REQUESTS, strFilter.toString(), null);
closeDb();
}
public synchronized void deletePushRequests(Long... ids) {
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
......@@ -400,10 +425,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append(ids[i]);
}
getDb().delete(TABLE_PUSH_REQUESTS, strFilter.toString(), null);
closeDb();
}
public synchronized void deletePushAckRequests(Long... ids) {
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
if (i > 0) {
......@@ -414,45 +440,55 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append(ids[i]);
}
getDb().delete(TABLE_PUSH_ACK_REQUESTS, strFilter.toString(), null);
closeDb();
}
public synchronized boolean isForceRequestsExist() {
Cursor cursor = getDb().query(TABLE_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
Cursor cursor = getReadableDb().query(TABLE_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
null, null, null, null);
boolean result = false;
if (cursor != null) {
result = cursor.getCount() > 0;
cursor.close();
}
closeDb();
return result;
}
public synchronized boolean isForcePushRequestsExist() {
Cursor cursor = getDb().query(TABLE_PUSH_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
Cursor cursor = getReadableDb().query(TABLE_PUSH_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
null, null, null, null);
boolean result = false;
if (cursor != null) {
result = cursor.getCount() > 0;
cursor.close();
}
closeDb();
return result;
}
public synchronized boolean isForcePushAckRequestsExist() {
Cursor cursor = getDb().query(TABLE_PUSH_ACK_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
Cursor cursor = getReadableDb().query(TABLE_PUSH_ACK_REQUESTS, null, KEY_REQUESTS_FORCE + "=1",
null, null, null, null);
boolean result = false;
if (cursor != null) {
result = cursor.getCount() > 0;
cursor.close();
}
closeDb();
return result;
}
//------------------------------ Tags -----------------------------//
public synchronized void saveTags(String[] tags) {
if (tags != null && tags.length > 0) {
try {
getDb().beginTransaction();
ContentValues values = new ContentValues();
......@@ -464,11 +500,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
getDb().setTransactionSuccessful();
} catch (SQLException e) {
closeDb();
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
} finally {
getDb().endTransaction();
closeDb();
}
}
}
......@@ -505,6 +544,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter.append("'");
}
getDb().delete(TABLE_TAGS, strFilter.toString(), null);
closeDb();
}
public synchronized void removeAllTags() {
......@@ -515,7 +555,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
public synchronized String[] getTags() {
List<String> tags = null;
Cursor cursor = getDb().query(TABLE_TAGS, null, null, null, null, null, null);
Cursor cursor = getReadableDb().query(TABLE_TAGS, null, null, null, null, null, null);
if (cursor != null) {
tags = new ArrayList<>(cursor.getCount());
......@@ -525,6 +565,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
cursor.close();
}
closeDb();
return tags != null ? tags.toArray(new String[tags.size()]) : null;
}
......
......@@ -5,6 +5,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
......@@ -12,10 +13,7 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.json.JSONObject;
......@@ -23,28 +21,24 @@ import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.R;
import ly.warp.sdk.activities.ActiveCouponsActivity;
import ly.warp.sdk.activities.BaseFragmentActivity;
import ly.warp.sdk.activities.TelematicsActivity;
import ly.warp.sdk.activities.TelematicsHistoryActivity;
import ly.warp.sdk.activities.WarpViewActivity;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.request.WarplyGetCampaignsRequest;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyManager;
import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
public class HomeFragment extends Fragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
private RelativeLayout mOptionOne, mOptionTwo, mOptionThree, mRlDriving, mRlDrivingHistory;
private LinearLayout mLlBillPayment;
private TextView mTvUsername, mTvActiveCoupons;
private ConstraintLayout mClActiveCoupons;
private ImageView mIvStepsActivity;
private RelativeLayout mOptionOne, mOptionTwo, mOptionThree, mRlDriving,
mRlDrivingHistory, mPbLoading;
private TextView mTvUsername;
private SwipeRefreshLayout mSwipeRefresh;
private EditText mEtGuid;
private LinearLayout mLlAuthLogin, mLlAuthLogout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
......@@ -74,17 +68,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
mOptionThreeText.setText("1");
mOptionThreeImage.setImageResource(R.drawable.tv_option);
mClActiveCoupons = view.findViewById(R.id.cl_coupon);
mTvActiveCoupons = mClActiveCoupons.findViewById(R.id.tv_active_coupons);
mTvActiveCoupons.setText(String.format(getResources().getString(R.string.cos_active_coupons), String.valueOf(WarplyManagerHelper.getCouponList().size())));
mClActiveCoupons.setOnClickListener(this);
mLlBillPayment = view.findViewById(R.id.ll_bill_payment);
mLlBillPayment.setOnClickListener(this);
mIvStepsActivity = view.findViewById(R.id.iv_settings);
mIvStepsActivity.setOnClickListener(this);
mTvUsername = view.findViewById(R.id.welcome_user_txt);
if (WarplyManagerHelper.getConsumer() != null)
mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user),
......@@ -94,6 +77,25 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
mRlDriving.setOnClickListener(this);
mRlDrivingHistory = view.findViewById(R.id.rl_driving_history);
mRlDrivingHistory.setOnClickListener(this);
mPbLoading = view.findViewById(R.id.pb_loading);
mPbLoading.setOnTouchListener((v, event) -> true);
mEtGuid = view.findViewById(R.id.et_login);
mLlAuthLogin = view.findViewById(R.id.ll_auth_login);
mLlAuthLogin.setOnClickListener(this);
mLlAuthLogout = view.findViewById(R.id.ll_auth_logout);
mLlAuthLogout.setOnClickListener(this);
if (!WarplyDBHelper.getInstance(getActivity()).isTableNotEmpty("auth")) {
mLlAuthLogout.setVisibility(View.GONE);
mLlAuthLogin.setVisibility(View.VISIBLE);
mEtGuid.setVisibility(View.VISIBLE);
} else {
mEtGuid.setVisibility(View.GONE);
mLlAuthLogin.setVisibility(View.GONE);
mLlAuthLogout.setVisibility(View.VISIBLE);
}
}
@Override
......@@ -111,12 +113,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
@Override
public void onClick(View view) {
if (view.getId() == R.id.cl_coupon) {
Intent intent = new Intent(getContext(), ActiveCouponsActivity.class);
intent.putExtra("couponlist", WarplyManagerHelper.getCouponList());
startActivity(intent);
return;
}
if (view.getId() == R.id.rl_driving) {
Intent intent = new Intent(getContext(), TelematicsActivity.class);
startActivity(intent);
......@@ -127,7 +123,15 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
startActivity(intent);
return;
}
if (view.getId() == R.id.iv_settings) {
if (view.getId() == R.id.ll_auth_login) {
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179
mPbLoading.setVisibility(View.VISIBLE);
WarplyManager.getCosmoteUser(mEtGuid.getText().toString(), mLoginReceiver);
return;
}
if (view.getId() == R.id.ll_auth_logout) {
mPbLoading.setVisibility(View.VISIBLE);
WarplyManager.logout(mLogoutReceiver);
}
}
......@@ -177,12 +181,38 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
private final CallbackReceiver<JSONObject> mLogoutReceiver = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
mPbLoading.setVisibility(View.GONE);
mLlAuthLogout.setVisibility(View.GONE);
mLlAuthLogin.setVisibility(View.VISIBLE);
mEtGuid.setVisibility(View.VISIBLE);
Toast.makeText(getActivity(), "LOGOUT SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int errorCode) {
mPbLoading.setVisibility(View.GONE);
Toast.makeText(getActivity(), "LOGOUT ERROR", Toast.LENGTH_SHORT).show();
}
};
private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
mPbLoading.setVisibility(View.GONE);
mLlAuthLogin.setVisibility(View.GONE);
mEtGuid.setVisibility(View.GONE);
mLlAuthLogout.setVisibility(View.VISIBLE);
if (result != null && result.optInt("status") == 1) {
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
WarplyManager.getCampaigns(mCampaignsCallback);
WarplyManager.getUnifiedCouponsDeals(mUnifiedCallback);
}
}
@Override
public void onFailure(int errorCode) {
mPbLoading.setVisibility(View.GONE);
Toast.makeText(getActivity(), "LOGIN ERROR", Toast.LENGTH_SHORT).show();
}
};
}
\ No newline at end of file
......
......@@ -25,7 +25,6 @@
package ly.warp.sdk.io.callbacks;
import org.json.JSONException;
import org.json.JSONObject;
import ly.warp.sdk.Warply;
......@@ -42,6 +41,8 @@ import ly.warp.sdk.utils.WarpUtils;
import static ly.warp.sdk.Warply.getWarplyContext;
import android.text.TextUtils;
public class VolleyTransformer implements Listener<JSONObject>, ErrorListener {
public VolleyTransformer(CallbackReceiver<JSONObject> listener) {
......@@ -81,30 +82,42 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener {
@Override
public void onResponse(JSONObject response) {
if (response != null) {
if (response.optJSONObject("context") != null) {
if (response.optJSONObject("context").optJSONObject("device_status") != null) {
WarpUtils.setIsWarped(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("warped"));
// WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token"));
// WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved"));
WarpUtils.setDeviceId(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_id"));
WarpUtils.setIsDeviceIdSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_id_saved"));
// WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved"));
if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info") != null) {
WarpUtils.setAppDataObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info"));
WarpUtils.setSDKVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("sdk_version"));
WarpUtils.setAppVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("app_version"));
JSONObject contextObj = response.optJSONObject("context");
if (contextObj != null) {
JSONObject deviceStatusObj = contextObj.optJSONObject("device_status");
if (deviceStatusObj != null) {
WarpUtils.setIsWarped(getWarplyContext(), deviceStatusObj.optBoolean("warped"));
WarpUtils.setDeviceId(getWarplyContext(), deviceStatusObj.optString("device_id"));
WarpUtils.setIsDeviceIdSaved(getWarplyContext(), deviceStatusObj.optBoolean("device_id_saved"));
JSONObject applicationInfoObj = deviceStatusObj.optJSONObject("application_info");
if (applicationInfoObj != null) {
WarpUtils.setAppDataObject(getWarplyContext(), applicationInfoObj);
WarpUtils.setSDKVersion(getWarplyContext(), applicationInfoObj.optString("sdk_version"));
WarpUtils.setAppVersion(getWarplyContext(), applicationInfoObj.optString("app_version"));
}
if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info") != null) {
WarpUtils.setDeviceInfoObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info"));
WarpUtils.setOSVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("os_version"));
WarpUtils.setDeviceBrand(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("manufacturer"));
WarpUtils.setCarrierName(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("device_info").optString("carrier_name"));
JSONObject deviceInfoObj = deviceStatusObj.optJSONObject("device_info");
if (deviceInfoObj != null) {
WarpUtils.setDeviceInfoObject(getWarplyContext(), deviceInfoObj);
WarpUtils.setOSVersion(getWarplyContext(), deviceInfoObj.optString("os_version"));
WarpUtils.setDeviceBrand(getWarplyContext(), deviceInfoObj.optString("manufacturer"));
WarpUtils.setCarrierName(getWarplyContext(), deviceInfoObj.optString("carrier_name"));
}
}
if (response.optJSONObject("context").optJSONObject("application_data") != null) {
WarpUtils.setIsAPPDATAENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("APPLICATION_DATA_ENABLED"));
WarpUtils.setIsDEVICEINFOENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("DEVICE_INFO_ENABLED"));
WarpUtils.setIsLIFECYCLEANALYTICSENABLED(getWarplyContext(), response.optJSONObject("context").optJSONObject("application_data").optBoolean("LIFECYCLE_ANALYTICS_ENABLED", true));
JSONObject applicationDataObj = contextObj.optJSONObject("application_data");
if (applicationDataObj != null) {
WarpUtils.setIsAPPDATAENABLED(getWarplyContext(), applicationDataObj.optBoolean("APPLICATION_DATA_ENABLED"));
WarpUtils.setIsDEVICEINFOENABLED(getWarplyContext(), applicationDataObj.optBoolean("DEVICE_INFO_ENABLED"));
WarpUtils.setIsLIFECYCLEANALYTICSENABLED(getWarplyContext(), applicationDataObj.optBoolean("LIFECYCLE_ANALYTICS_ENABLED", true));
if (applicationDataObj.has("AUTHENTICATION")) {
String jwtAuth = applicationDataObj.optString("AUTHENTICATION", "");
WarpUtils.setIsJWTEnabled(getWarplyContext(), !TextUtils.isEmpty(jwtAuth) && jwtAuth.equals("JWT"));
} else {
WarpUtils.setIsJWTEnabled(getWarplyContext(), false);
}
}
}
}
......
......@@ -77,6 +77,17 @@ public interface ApiService {
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@Headers("Content-Type: application/json")
@POST("/user/v5/{appUuid}/logout")
Call<ResponseBody> logoutUserJwt(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
@Body RequestBody request,
......
......@@ -159,6 +159,8 @@ public class WarpUtils {
+ "steps";
private static final String PREFERENCES_KEY_STEPS_MANUALLY_STOPPED = PREFERENCES_PREFIX
+ "steps_manually_stopped";
private static final String PREFERENCES_KEY_JWT_ENABLED = PREFERENCES_PREFIX
+ "jwt_enabled";
private static SharedPreferences _prefs;
......@@ -639,6 +641,17 @@ public class WarpUtils {
editor.apply();
}
public static boolean isJWTEnabled(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(PREFERENCES_KEY_JWT_ENABLED, true);
}
public static void setIsJWTEnabled(Context context, boolean jwtEnabled) {
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putBoolean(PREFERENCES_KEY_JWT_ENABLED, jwtEnabled);
editor.apply();
}
public static JSONObject getAppDataObject(Context context) {
SharedPreferences prefs = getPreferences(context);
try {
......
......@@ -595,21 +595,39 @@ public class WarplyManager {
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
jsonParams.put("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token"));
if (WarpUtils.isJWTEnabled(Warply.getWarplyContext())) {
jsonParams.put("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
jsonParams.put("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token"));
} else {
jsonParams.put("token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
jsonParams.put("client_id", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id"));
jsonParams.put("client_secret", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret"));
}
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> logoutCall = 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
......
......@@ -5,16 +5,17 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sw_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/cos_skyblue2">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
android:background="@color/cos_skyblue2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rl_header"
......@@ -22,7 +23,7 @@
android:layout_height="wrap_content"
android:background="@android:color/white"
android:paddingHorizontal="16dp"
android:paddingTop="16dp">
android:paddingTop="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_img"
......@@ -100,14 +101,86 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_header"
android:background="@drawable/home_bg">
android:background="@color/cos_skyblue2"
android:paddingBottom="48dp">
<RelativeLayout
android:id="@+id/rl_auth_view"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginHorizontal="8dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"
android:background="@drawable/shape_cos_white">
<EditText
android:id="@+id/et_login"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:hint="@string/cos_hint"
android:inputType="number"
android:textColor="@color/blue_dark"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone"
tools:visibility="visible"/>
<LinearLayout
android:id="@+id/ll_auth_login"
android:layout_width="140dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:background="@drawable/selector_button_green"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/cos_login_text"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_auth_logout"
android:layout_width="140dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:background="@drawable/selector_button_green"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/cos_logout_text"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_driving"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/rl_auth_view"
android:layout_marginHorizontal="8dp"
android:layout_marginTop="50dp"
android:layout_marginBottom="16dp"
android:background="@drawable/shape_cos_white">
......@@ -138,8 +211,8 @@
android:layout_below="@+id/rl_driving"
android:layout_marginHorizontal="8dp"
android:layout_marginBottom="16dp"
android:visibility="gone"
android:background="@drawable/shape_cos_white">
android:background="@drawable/shape_cos_white"
android:visibility="visible">
<TextView
android:layout_width="wrap_content"
......@@ -160,171 +233,32 @@
android:src="@drawable/cosmote_one" />
</RelativeLayout>
<LinearLayout
android:id="@+id/rl_home_coupons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_driving_history"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_home_coupons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp" />
</LinearLayout>
<include
android:id="@+id/rl_home_info_widget"
layout="@layout/info_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl_home_coupons"
android:layout_below="@id/rl_driving_history"
android:layout_marginHorizontal="8dp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_coupon"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_below="@+id/rl_home_info_widget"
android:layout_marginTop="24dp"
android:background="@drawable/ic_coupon_background">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tv_active_coupons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="#3A5266"
android:textFontWeight="600"
android:textSize="16sp"
tools:text="@string/cos_active_coupons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Δες τα όλα ->"
android:textColor="#3A5266" />
</LinearLayout>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginEnd="32dp"
android:src="@drawable/ic_gifts_for_you"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/hsv_title"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@+id/cl_coupon"
android:layout_marginTop="24dp"
android:background="@android:color/white"
android:paddingHorizontal="25dp"
android:paddingTop="10dp"
android:text="Βρες γρήγορα"
android:textColor="#3C464F" />
<HorizontalScrollView
android:id="@+id/ll_add"
<RelativeLayout
android:id="@+id/pb_loading"
android:layout_width="match_parent"
android:layout_height="110dp"
android:layout_below="@id/hsv_title"
android:background="@android:color/white"
android:paddingBottom="15dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/divider"
android:showDividers="middle">
<LinearLayout
android:id="@+id/ll_bill_payment"
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/doc" />
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:scrollHorizontally="true"
android:text="Πληρωμή λογαριασμού"
android:textAlignment="center"
android:textColor="#3C464F" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/message" />
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:scrollHorizontally="true"
android:text="Υποστήριξη"
android:textAlignment="center"
android:textColor="#3C464F" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/doc" />
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:scrollHorizontally="true"
android:text="Πληρωμή λογαριασμού"
android:textAlignment="center"
android:textColor="#3C464F" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@android:color/transparent"
android:visibility="gone"
tools:visibility="visible"
android:translationZ="100dp">
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/cos_green5"
android:indeterminateTintMode="src_atop" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
......
......@@ -213,6 +213,7 @@
<string name="lbl_take_photo_decline">Άκυρο</string>
<string name="lbl_gps_enabled">Θέλετε να ενεργοποιήσετε το GPS;</string>
<string name="cos_telematics">Safe Driving</string>
<string name="cos_hint">GUID</string>
<string name="cos_telematics_metrics">Ανάλυση</string>
<string name="cos_dlg_start_trip">Έναρξη</string>
<string name="cos_dlg_stop_trip">Παύση</string>
......@@ -244,6 +245,8 @@
<string name="cos_vouchers_info_title_disabled">Διαθέσιμο υπόλοιπο</string>
<string name="cos_vouchers_info_title_disabled_en">Available balance</string>
<string name="cos_coupons_header">Κουπόνια</string>
<string name="cos_login_text">Σύνδεση</string>
<string name="cos_logout_text">Αποσύνδεση</string>
<string-array name="coupons_array">
<item>Κουπόνια</item>
......