Panagiotis Triantafyllou

optimizations part1

......@@ -140,7 +140,7 @@ public class ActiveCouponsActivity extends Activity implements View.OnClickListe
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Coupon").concat(":").concat(coupon.getName()));
Intent intent = new Intent(ActiveCouponsActivity.this, CouponInfoActivity.class);
intent.putExtra("coupon", coupon.getCoupon());
intent.putExtra("isFromWallet", false);
intent.putExtra("isFromWallet", true);
startActivity(intent);
}
})
......
......@@ -320,7 +320,9 @@ public class ContextualActivity extends Activity implements View.OnClickListener
// runOnUiThread(() -> {
if (status == 1) {
successActivatingDialog();
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
/* New Addition start */
WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver);
/* New Addition end */
WarplyManager.getCampaigns(mCampaignsCallback);
} else
errorActivatingDialog();
......
......@@ -32,7 +32,6 @@ import ly.warp.sdk.R;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
import ly.warp.sdk.io.request.CosmoteCouponSharingRequest;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
......@@ -66,6 +65,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
private AlertDialog mAlertDialogSuccessSharing, mAlertDialogErrorSharing,
mAlertDialogCouponAskSharing, mAlertDialogWrongNumberSharing, mAlertDialogNoAssets;
private boolean mIsFromWallet = false, mIsActiveUnified = false;
private RelativeLayout mPbLoading;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -106,6 +106,8 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
mFontHeader = findViewById(R.id.textView3);
mFontDescription = findViewById(R.id.textView14);
mFontButtonShare = findViewById(R.id.button_share);
mPbLoading = findViewById(R.id.pb_loading);
mPbLoading.setOnTouchListener((v, event) -> true);
WarpUtils.renderCustomFont(this, R.font.bt_cosmo_bold, mFontHeader, mTvCouponTitle);
WarpUtils.renderCustomFont(this, R.font.peridot_regular, mFontDescription, mTvPhoneHeader, mEdtReceiver);
WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, mFontButtonShare);
......@@ -310,6 +312,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("ShareCoupon")
.concat(":")
.concat(mCoupon.getCouponsetDetails().getName()));
mPbLoading.setVisibility(View.VISIBLE);
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
......@@ -346,12 +349,22 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
String message = result.optString("msg", "");
if (status == 1)
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
if (status == 1) {
/* New Addition start */
// WarplyManager.getUserCouponsWithCouponsetsInternal(mUserCouponsReceiver);
WarplyManagerHelper.removeCouponItem(mCoupon);
/* New Addition end */
}
runOnUiThread(() -> {
if (status == 1)
mPbLoading.setVisibility(View.GONE);
if (status == 1) {
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
couponsChanged.setChanged(true);
EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
acceptSharingDialog();
else if (status == 4)
} else if (status == 4)
wrongNumberDialog(message);
else
errorSharingDialog();
......@@ -361,23 +374,26 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
@Override
public void onFailure(int errorCode) {
Log.v("COUPON_SHARE", String.valueOf(errorCode));
runOnUiThread(() -> errorSharingDialog());
runOnUiThread(() -> {
mPbLoading.setVisibility(View.GONE);
errorSharingDialog();
});
}
};
private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList result) {
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
couponsChanged.setChanged(true);
EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
}
@Override
public void onFailure(int errorCode) {
}
};
// private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
// @Override
// public void onSuccess(CouponList result) {
// WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
// couponsChanged.setChanged(true);
// EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// };
// ===========================================================
// Inner and Anonymous Classes
......
......@@ -8,7 +8,7 @@ import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
......@@ -28,10 +28,10 @@ import ly.warp.sdk.R;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
import ly.warp.sdk.io.models.Merchant;
import ly.warp.sdk.io.models.WarplyCCMSEnabledModel;
import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
import ly.warp.sdk.io.request.WarplyRedeemCouponRequest;
......@@ -58,7 +58,7 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
mFontHeader, mFontButtonGetIt;
private Couponset mCouponset;
private LinearLayout mLlRedeem, mLlTerms;
private ProgressBar mPbLoading;
private RelativeLayout mPbLoading;
private Coupon mCoupon;
private boolean mIsTermsPressed = false, mIsGiftPressed = false;
private AlertDialog mAlertDialogCouponset;
......@@ -100,6 +100,7 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
mIvCouponsetPhoto = findViewById(R.id.imageView6);
mLlRedeem = findViewById(R.id.ll_get_gift);
mPbLoading = findViewById(R.id.pb_loading);
mPbLoading.setOnTouchListener((v, event) -> true);
mLlTerms = findViewById(R.id.ll_terms_inner);
mTvTermsValue = findViewById(R.id.tv_terms_value);
mIvTermsArrow = findViewById(R.id.iv_terms_arrow);
......@@ -238,13 +239,40 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
mCoupon = new Coupon(result.optJSONObject("result"));
if (mCouponset != null) {
/* New Addition start */
Merchant merchant = new Merchant();
for (Merchant mer : WarplyManagerHelper.getMerchantList()) {
if (mer.getUuid().equals(mCouponset.getMerchantUuid())) {
merchant = mer;
break;
}
}
/* New Addition end */
mCoupon.setDescription(mCouponset.getShortDescription());
mCoupon.setImage(mCouponset.getImgPreview());
mCoupon.setName(mCouponset.getName());
/* New Addition start */
mCoupon.setDiscount(mCouponset.getDiscount());
mCoupon.setCouponsetUuid(mCouponset.getUuid());
mCoupon.setMerchantUuid(mCouponset.getMerchantUuid());
mCoupon.setStatus(1);
mCoupon.setCouponsetDetails(mCouponset);
mCoupon.setMerchantDetails(merchant);
/* New Addition end */
}
showDialog(true, 1);
WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
/* New Addition start */
// WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
/* New Addition end */
WarplyManagerHelper.addCouponItem(mCoupon);
WarplyManager.getCampaigns(mCampaignsCallback);
/* New Addition start */
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
couponsChanged.setChanged(true);
EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
/* New Addition end */
} else {
showDialog(false, status);
}
......@@ -363,19 +391,19 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
// Inner and Anonymous Classes
// ===========================================================
private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList result) {
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
couponsChanged.setChanged(true);
EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
}
@Override
public void onFailure(int errorCode) {
}
};
// private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
// @Override
// public void onSuccess(CouponList result) {
// WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
// couponsChanged.setChanged(true);
// EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
// }
//
// @Override
// public void onFailure(int errorCode) {
//
// }
// };
private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
@Override
......
......@@ -45,6 +45,8 @@ import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -301,7 +303,7 @@ public class WarplyManagerHelper {
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1) {
WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() {
WarplyManager.getUserCouponsWithCouponsetsInternal(new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList result) {
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
......@@ -445,7 +447,7 @@ public class WarplyManagerHelper {
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1) {
WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() {
WarplyManager.getUserCouponsWithCouponsetsInternal(new CallbackReceiver<CouponList>() {
@Override
public void onSuccess(CouponList result) {
WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
......@@ -1253,6 +1255,18 @@ public class WarplyManagerHelper {
return mCouponList;
}
public static void addCouponItem(Coupon cpn) {
if (mCouponList != null) {
mCouponList.add(cpn);
}
}
public static void removeCouponItem(Coupon cpn) {
if (mCouponList != null && !mCouponList.isEmpty()) {
mCouponList.remove(cpn);
}
}
public static CouponList getCouponExpiredList() {
if (mCouponListExpired != null && mCouponListExpired.size() > 0) {
WarpUtils.log("GET_COUPON_EXPIRED_LIST size: " + String.valueOf(mCouponListExpired.size()));
......
......@@ -27,8 +27,6 @@ package ly.warp.sdk.utils.managers;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
......@@ -112,7 +110,6 @@ import ly.warp.sdk.io.models.TransactionsList;
import ly.warp.sdk.io.models.TripMetrics;
import ly.warp.sdk.io.models.UnifiedCampaignModel;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.models.WarplyPacingEventModel;
import ly.warp.sdk.io.request.CosmoteCouponSharingRequest;
import ly.warp.sdk.io.request.CosmotePostEventRequest;
import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
......@@ -127,7 +124,6 @@ import ly.warp.sdk.io.request.WarplyChangePasswordRequest;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyContactRequest;
import ly.warp.sdk.io.request.WarplyContentRequest;
import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
import ly.warp.sdk.io.request.WarplyDeleteAddressRequest;
import ly.warp.sdk.io.request.WarplyDeleteCardRequest;
import ly.warp.sdk.io.request.WarplyEditAddressRequest;
......@@ -162,10 +158,8 @@ import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
import ly.warp.sdk.io.volley.ApiClient;
import ly.warp.sdk.io.volley.ApiService;
import ly.warp.sdk.services.EventCampaignService;
import ly.warp.sdk.services.EventCouponsService;
import ly.warp.sdk.services.EventRewardsCouponsService;
import ly.warp.sdk.services.EventUnifiedCouponsService;
import ly.warp.sdk.services.WarplyHealthService;
import ly.warp.sdk.utils.WarpJSONParser;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyDeviceInfoCollector;
......@@ -1908,6 +1902,42 @@ public class WarplyManager {
}, executorService);
}
public static void getUserCouponsWithCouponsetsInternal(final CallbackReceiver<CouponList> receiver) {
WarpUtils.log("************* WARPLY User Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
SettableFuture<CouponList> futureUniversal = SettableFuture.create();
ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0, futureUniversal);
ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCoupons);
ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync(
allResultsFuture,
results -> {
CouponList resultCoupons = (CouponList) results.get(0);
return executorService.submit(() -> resultCoupons);
},
executorService
);
Futures.addCallback(mergedResultFuture, new FutureCallback<CouponList>() {
@Override
public void onSuccess(CouponList mergedResult) {
executorService.shutdownNow();
new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(mergedResult));
}
@Override
public void onFailure(Throwable throwable) {
executorService.shutdownNow();
new Handler(Looper.getMainLooper()).post(() -> receiver.onFailure(2));
}
}, executorService);
}
public static void getCampaigns(final CallbackReceiver<ArrayList<Campaign>> receiver) {
WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
......
......@@ -192,4 +192,22 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/pb_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@android:color/transparent"
android:visibility="gone"
tools:visibility="visible">
<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>
......
......@@ -150,14 +150,21 @@
</LinearLayout>
</ScrollView>
<ProgressBar
<RelativeLayout
android:id="@+id/pb_loading"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/cos_green5"
android:indeterminateTintMode="src_atop"
android:background="@android:color/transparent"
android:visibility="gone"
tools:visibility="visible" />
tools:visibility="visible">
<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>
......