From 55db358fdf1f5cd576ffbd13e839f20d9448541a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?mustafa=20ic=CC=A7men?= Date: Sun, 9 Aug 2020 19:17:51 +0300 Subject: [PATCH] Voucher Servis Entegrasyonu --- .../CampaignProductDetailsActivity.java | 4 +- .../android/activity/LoginActivity.java | 4 +- .../activity/ProductDetailsActivity.java | 4 +- .../android/activity/SplashActivity.java | 6 +- .../pizzacucina/android/api/ApiEndPoints.java | 3 +- .../pizzacucina/android/api/ApiInterface.java | 12 +- .../android/fragment/CartFragment.java | 8 +- .../CreateOrderSummaryFragment.java | 16 +- .../createOrder/PaymentMethodFragment.java | 92 ++++-- .../android/helper/SessionHelper.java | 51 +++- .../android/helper/SharedPrefsHelper.java | 42 ++- .../android/model/CouponModel.java | 54 ++++ .../pizzacucina/android/model/CouponType.java | 7 + ...uponModel.java => GeneralCouponModel.java} | 278 ++++++------------ .../android/model/PersonalCouponModel.java | 116 ++++++++ 15 files changed, 431 insertions(+), 266 deletions(-) create mode 100644 app/src/main/java/ch/pizzacucina/android/model/CouponModel.java create mode 100644 app/src/main/java/ch/pizzacucina/android/model/CouponType.java rename app/src/main/java/ch/pizzacucina/android/model/{CheckCouponModel.java => GeneralCouponModel.java} (63%) create mode 100644 app/src/main/java/ch/pizzacucina/android/model/PersonalCouponModel.java diff --git a/app/src/main/java/ch/pizzacucina/android/activity/CampaignProductDetailsActivity.java b/app/src/main/java/ch/pizzacucina/android/activity/CampaignProductDetailsActivity.java index ed33952..9614e33 100644 --- a/app/src/main/java/ch/pizzacucina/android/activity/CampaignProductDetailsActivity.java +++ b/app/src/main/java/ch/pizzacucina/android/activity/CampaignProductDetailsActivity.java @@ -391,9 +391,7 @@ public class CampaignProductDetailsActivity extends BaseActivity { HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/activity/LoginActivity.java b/app/src/main/java/ch/pizzacucina/android/activity/LoginActivity.java index 00ff048..88bbbe4 100644 --- a/app/src/main/java/ch/pizzacucina/android/activity/LoginActivity.java +++ b/app/src/main/java/ch/pizzacucina/android/activity/LoginActivity.java @@ -141,9 +141,7 @@ public class LoginActivity extends BaseActivity { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/activity/ProductDetailsActivity.java b/app/src/main/java/ch/pizzacucina/android/activity/ProductDetailsActivity.java index 1476900..5f3af7f 100644 --- a/app/src/main/java/ch/pizzacucina/android/activity/ProductDetailsActivity.java +++ b/app/src/main/java/ch/pizzacucina/android/activity/ProductDetailsActivity.java @@ -389,9 +389,7 @@ public class ProductDetailsActivity extends BaseActivity { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/activity/SplashActivity.java b/app/src/main/java/ch/pizzacucina/android/activity/SplashActivity.java index 7414ebf..2d60dd2 100644 --- a/app/src/main/java/ch/pizzacucina/android/activity/SplashActivity.java +++ b/app/src/main/java/ch/pizzacucina/android/activity/SplashActivity.java @@ -1,8 +1,6 @@ package ch.pizzacucina.android.activity; import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -460,9 +458,7 @@ public class SplashActivity extends BaseActivity { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/api/ApiEndPoints.java b/app/src/main/java/ch/pizzacucina/android/api/ApiEndPoints.java index f516d84..755699b 100644 --- a/app/src/main/java/ch/pizzacucina/android/api/ApiEndPoints.java +++ b/app/src/main/java/ch/pizzacucina/android/api/ApiEndPoints.java @@ -46,7 +46,8 @@ public class ApiEndPoints { public static final String API_UPDATE_PROFILE = PREFIX + "updateCustomerInfo" + SUFFIX + "&token="; public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token="; public static final String API_GET_ORDER_PRODUCT_LIST = PREFIX + "getOrderProducts" + SUFFIX + "&token="; - public static final String API_CHECK_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token="; + public static final String API_CHECK_GENERAL_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token="; + public static final String API_CHECK_PERSONAL_COUPON = PREFIX + "checkVoucher" + SUFFIX + "&token="; public static final String API_CREATE_BRAINTREE_PAYMENT = PREFIX + "checkBrainTreePayment" + SUFFIX + "&token="; public static final String API_REPEAT_ORDER = PREFIX + "reOrder" + SUFFIX + "&token="; public static final String API_CHECK_ORDER_PRICE = PREFIX + "checkOrderPrice" + SUFFIX + "&token="; diff --git a/app/src/main/java/ch/pizzacucina/android/api/ApiInterface.java b/app/src/main/java/ch/pizzacucina/android/api/ApiInterface.java index e8d2cfc..614335a 100644 --- a/app/src/main/java/ch/pizzacucina/android/api/ApiInterface.java +++ b/app/src/main/java/ch/pizzacucina/android/api/ApiInterface.java @@ -8,7 +8,8 @@ import ch.pizzacucina.android.model.AddressModel; import ch.pizzacucina.android.model.AppVersionModel; import ch.pizzacucina.android.model.CampaignBannerModel; import ch.pizzacucina.android.model.CampaignModel; -import ch.pizzacucina.android.model.CheckCouponModel; +import ch.pizzacucina.android.model.GeneralCouponModel; +import ch.pizzacucina.android.model.PersonalCouponModel; import ch.pizzacucina.android.model.CountryModel; import ch.pizzacucina.android.model.DeleteAddressResponseModel; import ch.pizzacucina.android.model.PaymentMethodsResponseModel; @@ -195,8 +196,13 @@ public interface ApiInterface { @Field("order_id") String orderId); @FormUrlEncoded @POST - Call> checkCoupon(@Url String url, - @Field("coupon") String couponCode); + Call> checkGeneralCoupon(@Url String url, + @Field("coupon") String couponCode); + + @FormUrlEncoded + @POST + Call> checkPersonalCoupon(@Url String url, + @Field("voucher") String couponCode); @GET("{storeName}" + ApiEndPoints.API_CHECK_CAMPAIGN_PIZZAPASS) Call> checkPizzapassCampaign(@Path("storeName") String storeName, diff --git a/app/src/main/java/ch/pizzacucina/android/fragment/CartFragment.java b/app/src/main/java/ch/pizzacucina/android/fragment/CartFragment.java index 3f94993..71ab75e 100644 --- a/app/src/main/java/ch/pizzacucina/android/fragment/CartFragment.java +++ b/app/src/main/java/ch/pizzacucina/android/fragment/CartFragment.java @@ -210,9 +210,7 @@ public class CartFragment extends BaseFragment { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), @@ -392,9 +390,7 @@ public class CartFragment extends BaseFragment { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/CreateOrderSummaryFragment.java b/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/CreateOrderSummaryFragment.java index adcf164..0ee4a89 100644 --- a/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/CreateOrderSummaryFragment.java +++ b/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/CreateOrderSummaryFragment.java @@ -219,9 +219,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment { params.put("is_pizza_pass_campaign", createOrderActivity.getCartInfo().isPizzapassCampaignUsed()); params.put("is_kebap_pass_campaign", createOrderActivity.getCartInfo().isKebappassCampaignUsed()); params.put("application_id", ApiConstants.APP_TYPE_ID_ANDROID); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); if(dateOfOrderString != null && !dateOfOrderString.isEmpty() && timeOfOrder != null && !timeOfOrder.isEmpty()){ params.put("delivery_date", dateOfOrderString + " " + timeOfOrder); @@ -721,9 +719,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment { if(paymentMethodNonce != null){ params.put("payment_method_nonce", paymentMethodNonce); } - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); if(dateOfOrderString != null && !dateOfOrderString.isEmpty() && timeOfOrder != null && !timeOfOrder.isEmpty()){ params.put("delivery_date", dateOfOrderString + " " + timeOfOrder); @@ -803,9 +799,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment { "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken()); */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), @@ -843,13 +837,11 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment { */ HashMap params = new HashMap<>(); - if(SessionHelper.getSelectedCoupon() != null){ - params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); - } params.put("payment_method", createOrderActivity.getSelectedPaymentMethod().getCode()); params.put("payment_method_code", createOrderActivity.getSelectedPaymentMethod().getCode()); params.put("shipping_method",createOrderActivity.getSelectedShippingMethod().getCode()); params.put("shipping_method_code",createOrderActivity.getSelectedShippingMethod().getCode()); + SessionHelper.addCouponCodeToRequestParamsIfNeeded(params); Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), diff --git a/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/PaymentMethodFragment.java b/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/PaymentMethodFragment.java index fd28cc9..0404b6e 100644 --- a/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/PaymentMethodFragment.java +++ b/app/src/main/java/ch/pizzacucina/android/fragment/createOrder/PaymentMethodFragment.java @@ -26,7 +26,10 @@ import ch.pizzacucina.android.api.ResponseObject; import ch.pizzacucina.android.helper.DialogHelper; import ch.pizzacucina.android.helper.SessionHelper; import ch.pizzacucina.android.interfaces.RecyclerItemClickListener; -import ch.pizzacucina.android.model.CheckCouponModel; +import ch.pizzacucina.android.model.CouponModel; +import ch.pizzacucina.android.model.CouponType; +import ch.pizzacucina.android.model.GeneralCouponModel; +import ch.pizzacucina.android.model.PersonalCouponModel; import ch.pizzacucina.android.model.PaymentMethodModel; import ch.pizzacucina.android.model.PaymentMethodsResponseModel; import ch.pizzacucina.android.model.cart.CartInfoModel; @@ -52,7 +55,7 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment { private ArrayList paymentMethodList = new ArrayList<>(); private PaymentMethodsRecyclerAdapter paymentMethodsRecyclerAdapter; - private CheckCouponModel couponModel; + private CouponModel couponModel; private PaymentMethodModel selectedPaymentMethod; @@ -99,11 +102,8 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment { } else { createOrderActivity.setCouponCode(couponCodeEditText.getText().toString()); - checkCoupon(); + checkPersonalCoupon(); } - - - break; } } @@ -228,27 +228,77 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment { paymentMethodsRecyclerView.setAdapter(paymentMethodsRecyclerAdapter); } - private void checkCoupon(){ - DialogHelper.showLoadingDialog(); - Call> call = - ApiService.apiInterface.checkCoupon( - "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_COUPON + SessionHelper.getCustomerToken().getToken(), + private void checkPersonalCoupon(){ + Call> call = + ApiService.apiInterface.checkPersonalCoupon( + "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_PERSONAL_COUPON + SessionHelper.getCustomerToken().getToken(), couponCodeEditText.getText().toString()); - call.enqueue(new Callback>() { + call.enqueue(new Callback>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call> call, Response> response) { if(response.isSuccessful() && response.body().getData() != null && response.body().isSuccess()){ couponModel = response.body().getData(); couponModel.setStoreName(SessionHelper.getSelectedStore().getStoreName()); - couponModel.checkNull(); + if(couponModel.isActive()){ + + String couponName = ""; + if(couponModel instanceof PersonalCouponModel){ + couponName = ((PersonalCouponModel) couponModel).getTheme(); + } + + SessionHelper.saveSelectedCoupon(couponModel); + DialogHelper.showDialogWithPositiveButton( + couponUsedDialogTitle, + BaseActivity.currentActivity, + couponUsedDialogContentPart1 + " " + couponName + " " + couponUsedDialogContentPart2); + getCartProducts(); + } + else { + checkGeneralCoupon(); + } + } + else { + DialogHelper.hideLoadingDialog(); + ApiErrorUtils.parseError(response); + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + DialogHelper.hideLoadingDialog(); + DialogHelper.showFailedDialog(); + } + }); + } + + private void checkGeneralCoupon(){ + DialogHelper.showLoadingDialog(); + Call> call = + ApiService.apiInterface.checkGeneralCoupon( + "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_CHECK_GENERAL_COUPON + SessionHelper.getCustomerToken().getToken(), + couponCodeEditText.getText().toString()); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if(response.isSuccessful() && + response.body().getData() != null && + response.body().isSuccess()){ + couponModel = response.body().getData(); + couponModel.setStoreName(SessionHelper.getSelectedStore().getStoreName()); + + String couponName = ""; + if(couponModel instanceof GeneralCouponModel){ + couponName = ((GeneralCouponModel) couponModel).getName(); + } + if(couponModel.isActive()){ SessionHelper.saveSelectedCoupon(couponModel); DialogHelper.showDialogWithPositiveButton( couponUsedDialogTitle, BaseActivity.currentActivity, - couponUsedDialogContentPart1 + " " + couponModel.getName() + " " + couponUsedDialogContentPart2); + couponUsedDialogContentPart1 + " " + couponName + " " + couponUsedDialogContentPart2); getCartProducts(); } else { @@ -263,7 +313,7 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment { } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call> call, Throwable t) { DialogHelper.hideLoadingDialog(); DialogHelper.showFailedDialog(); } @@ -278,7 +328,15 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment { */ HashMap params = new HashMap<>(); - params.put("coupon", couponModel.getCode()); + if(couponModel != null){ + if(couponModel.getCouponType() == CouponType.PERSONAL){ + params.put("voucher", couponModel.getCode()); + } + else if(couponModel.getCouponType() == CouponType.GENERAL){ + params.put("coupon", couponModel.getCode()); + } + } + Call> call = ApiService.apiInterface.getCartProducts( "/" + SessionHelper.getSelectedStore().getStoreName() + ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken(), params); diff --git a/app/src/main/java/ch/pizzacucina/android/helper/SessionHelper.java b/app/src/main/java/ch/pizzacucina/android/helper/SessionHelper.java index 18badac..0df8b70 100644 --- a/app/src/main/java/ch/pizzacucina/android/helper/SessionHelper.java +++ b/app/src/main/java/ch/pizzacucina/android/helper/SessionHelper.java @@ -4,9 +4,13 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; -import ch.pizzacucina.android.model.CheckCouponModel; +import ch.pizzacucina.android.model.CouponModel; +import ch.pizzacucina.android.model.CouponType; +import ch.pizzacucina.android.model.GeneralCouponModel; import ch.pizzacucina.android.model.CustomerTokenModel; +import ch.pizzacucina.android.model.PersonalCouponModel; import ch.pizzacucina.android.model.StoreModel; import ch.pizzacucina.android.model.UserModel; @@ -74,8 +78,41 @@ public class SessionHelper { clearCustomerInfo(); } - public static void saveSelectedCoupon(CheckCouponModel couponModel){ - SharedPrefsHelper.saveSelectedCoupon(couponModel); + public static void saveSelectedCoupon(CouponModel couponModel){ + if(couponModel instanceof PersonalCouponModel){ + PersonalCouponModel personalCouponModel = (PersonalCouponModel) couponModel; + SharedPrefsHelper.saveSelectedPersonalCoupon(personalCouponModel); + } + else if(couponModel instanceof GeneralCouponModel){ + GeneralCouponModel generalCouponModel = (GeneralCouponModel) couponModel; + SharedPrefsHelper.saveSelectedGeneralCoupon(generalCouponModel); + } + } + + public static CouponModel getSelectedCoupon(){ + if(SharedPrefsHelper.getSelectedPersonalCoupon() != null){ + return SharedPrefsHelper.getSelectedPersonalCoupon(); + } + else { + return SharedPrefsHelper.getSelectedGeneralCoupon(); + } + } + + public static void clearSelectedCoupon(){ + SharedPrefsHelper.clearSelectedGeneralCoupon(); + SharedPrefsHelper.clearSelectedPersonalCoupon(); + } + + public static void addCouponCodeToRequestParamsIfNeeded(HashMap params){ + CouponModel selectedCoupon = SessionHelper.getSelectedCoupon(); + if(SessionHelper.getSelectedCoupon() != null){ + if(selectedCoupon.getCouponType() == CouponType.PERSONAL){ + params.put("voucher", SessionHelper.getSelectedCoupon().getCode()); + } + else if(selectedCoupon.getCouponType() == CouponType.GENERAL){ + params.put("coupon", SessionHelper.getSelectedCoupon().getCode()); + } + } } public static String getSessionId(){ @@ -86,14 +123,6 @@ public class SessionHelper { SharedPrefsHelper.saveSessionId(sessionId); } - public static CheckCouponModel getSelectedCoupon(){ - return SharedPrefsHelper.getSelectedCoupon(); - } - - public static void clearSelectedCoupon(){ - SharedPrefsHelper.clearSelectedCoupon(); - } - public static Calendar getTokenDeathDate(String tokenDeathTime){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/app/src/main/java/ch/pizzacucina/android/helper/SharedPrefsHelper.java b/app/src/main/java/ch/pizzacucina/android/helper/SharedPrefsHelper.java index 526f3ad..fd5ee3a 100644 --- a/app/src/main/java/ch/pizzacucina/android/helper/SharedPrefsHelper.java +++ b/app/src/main/java/ch/pizzacucina/android/helper/SharedPrefsHelper.java @@ -11,7 +11,8 @@ import java.util.ArrayList; import ch.pizzacucina.android.activity.BaseActivity; import ch.pizzacucina.android.model.CategoryModel; -import ch.pizzacucina.android.model.CheckCouponModel; +import ch.pizzacucina.android.model.GeneralCouponModel; +import ch.pizzacucina.android.model.PersonalCouponModel; import ch.pizzacucina.android.model.CustomerTokenModel; import ch.pizzacucina.android.model.StoreModel; import ch.pizzacucina.android.model.UserModel; @@ -36,7 +37,8 @@ public class SharedPrefsHelper { private static final String PREF_KEY_CART_TOTAL_PRICE = SHARED_PREFS_NAME + "cartTotalPrice"; private static final String PREF_KEY_USER_SELECTED_STORE = SHARED_PREFS_NAME + "selectedStore"; private static final String PREF_KEY_IS_FIRST_TIME = SHARED_PREFS_NAME + "isFirstTime"; - private static final String PREF_KEY_SELECTED_COUPON = SHARED_PREFS_NAME + "selectedCoupon"; + private static final String PREF_KEY_SELECTED_GENERAL_COUPON = SHARED_PREFS_NAME + "selectedGeneralCoupon"; + private static final String PREF_KEY_SELECTED_PERSONAL_COUPON = SHARED_PREFS_NAME + "selectedPersonalCoupon"; private static final String PREF_KEY_SESSION_ID = SHARED_PREFS_NAME + "sessionId"; private static SharedPreferences sharedPreferences = @@ -93,7 +95,8 @@ public class SharedPrefsHelper { editor.remove(PREF_KEY_CUSTOMER_TOKEN); editor.remove(PREF_KEY_CART_ITEM_COUNT); editor.remove(PREF_KEY_CART_TOTAL_PRICE); - editor.remove(PREF_KEY_SELECTED_COUPON); + editor.remove(PREF_KEY_SELECTED_GENERAL_COUPON); + editor.remove(PREF_KEY_SELECTED_PERSONAL_COUPON); editor.remove(PREF_KEY_SESSION_ID); editor.apply(); } @@ -167,13 +170,13 @@ public class SharedPrefsHelper { return sharedPreferences.getBoolean(PREF_KEY_IS_FIRST_TIME, true); } - public static void saveSelectedCoupon(CheckCouponModel couponModel){ - editor.putString(PREF_KEY_SELECTED_COUPON, gson.toJson(couponModel)); + public static void saveSelectedGeneralCoupon(GeneralCouponModel couponModel){ + editor.putString(PREF_KEY_SELECTED_GENERAL_COUPON, gson.toJson(couponModel)); editor.apply(); } - public static CheckCouponModel getSelectedCoupon(){ - CheckCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_COUPON, ""), CheckCouponModel.class); + public static GeneralCouponModel getSelectedGeneralCoupon(){ + GeneralCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_GENERAL_COUPON, ""), GeneralCouponModel.class); if(selectedCouponModel != null && selectedCouponModel.getStoreName().toLowerCase().equals(SessionHelper.getSelectedStore().getStoreName().toLowerCase())){ return selectedCouponModel; @@ -183,8 +186,29 @@ public class SharedPrefsHelper { } } - public static void clearSelectedCoupon(){ - editor.remove(PREF_KEY_SELECTED_COUPON); + public static void clearSelectedGeneralCoupon(){ + editor.remove(PREF_KEY_SELECTED_GENERAL_COUPON); + editor.apply(); + } + + public static void saveSelectedPersonalCoupon(PersonalCouponModel couponModel){ + editor.putString(PREF_KEY_SELECTED_PERSONAL_COUPON, gson.toJson(couponModel)); + editor.apply(); + } + + public static PersonalCouponModel getSelectedPersonalCoupon(){ + PersonalCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_PERSONAL_COUPON, ""), PersonalCouponModel.class); + if(selectedCouponModel != null && + selectedCouponModel.getStoreName().toLowerCase().equals(SessionHelper.getSelectedStore().getStoreName().toLowerCase())){ + return selectedCouponModel; + } + else { + return null; + } + } + + public static void clearSelectedPersonalCoupon(){ + editor.remove(PREF_KEY_SELECTED_PERSONAL_COUPON); editor.apply(); } diff --git a/app/src/main/java/ch/pizzacucina/android/model/CouponModel.java b/app/src/main/java/ch/pizzacucina/android/model/CouponModel.java new file mode 100644 index 0000000..86a702c --- /dev/null +++ b/app/src/main/java/ch/pizzacucina/android/model/CouponModel.java @@ -0,0 +1,54 @@ +package ch.pizzacucina.android.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class CouponModel { + + @Expose + @SerializedName("date_added") + private String addedDate; + + private String code; + private String storeName; + private String status; + + public CouponType getCouponType(){ + return CouponType.UNKNOWN; + } + public boolean isActive(){ + return false; + } + + public String getAddedDate() { + if(addedDate == null){ + addedDate = "1970-01-01"; + } + return addedDate; + } + + public String getCode() { + if(code == null){ + code = ""; + } + return code; + } + + public String getStoreName() { + if(storeName == null){ + storeName = ""; + } + return storeName; + } + + public String getStatus() { + if(status == null){ + status = ""; + } + return status; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } +} diff --git a/app/src/main/java/ch/pizzacucina/android/model/CouponType.java b/app/src/main/java/ch/pizzacucina/android/model/CouponType.java new file mode 100644 index 0000000..83c06e8 --- /dev/null +++ b/app/src/main/java/ch/pizzacucina/android/model/CouponType.java @@ -0,0 +1,7 @@ +package ch.pizzacucina.android.model; + +public enum CouponType { + PERSONAL, + GENERAL, + UNKNOWN +} diff --git a/app/src/main/java/ch/pizzacucina/android/model/CheckCouponModel.java b/app/src/main/java/ch/pizzacucina/android/model/GeneralCouponModel.java similarity index 63% rename from app/src/main/java/ch/pizzacucina/android/model/CheckCouponModel.java rename to app/src/main/java/ch/pizzacucina/android/model/GeneralCouponModel.java index 600e1ba..88d38fb 100644 --- a/app/src/main/java/ch/pizzacucina/android/model/CheckCouponModel.java +++ b/app/src/main/java/ch/pizzacucina/android/model/GeneralCouponModel.java @@ -14,7 +14,7 @@ import java.util.Date; * Created by cimenmus on 6.02.2018. */ -public class CheckCouponModel { +public class GeneralCouponModel extends CouponModel { @Expose @SerializedName("coupon_id") @@ -40,89 +40,99 @@ public class CheckCouponModel { @SerializedName("uses_customer") private String userUsageCount; - @Expose - @SerializedName("date_added") - private String addedDate; - - private String code; private String name; private String type; private String discount; private String shipping; private String total; - private String status; - - - private String storeName; - - public void checkNull(){ - - if(couponId == null){ - couponId = ""; - } - - if(startDate == null){ - startDate = "1970-01-01"; - } - - if(endDate == null){ - endDate = "1970-01-01"; - } - - if(totalUsageCount == null){ - totalUsageCount = ""; - } - - if(userUsageCount == null){ - userUsageCount = ""; - } - - if(addedDate == null){ - addedDate = ""; - } - - if(code == null){ - code = ""; - } - - if(name == null){ - name = ""; - } - - if(type == null){ - type = ""; - } - - if(discount == null){ - discount = ""; - } - - if(shipping == null){ - shipping = ""; - } - - if(total == null){ - total = ""; - } - - if(status == null){ - status = ""; - } - - if(productIdList == null){ - productIdList = new ArrayList<>(); - } - - if(storeName == null){ - storeName = ""; - } - } public enum CouponDiscountType { FIXED, PERCENT } + @Override + public CouponType getCouponType() { + return CouponType.GENERAL; + } + + public String getCouponId() { + if(couponId == null){ + couponId = ""; + } + return couponId; + } + + public ArrayList getProductIdList() { + if(productIdList == null){ + productIdList = new ArrayList<>(); + } + return productIdList; + } + + public String getStartDate() { + if(startDate == null){ + startDate = "1970-01-01"; + } + return startDate; + } + + public String getEndDate() { + if(endDate == null){ + endDate = "1970-01-01"; + } + return endDate; + } + + public String getTotalUsageCount() { + if(totalUsageCount == null){ + totalUsageCount = ""; + } + return totalUsageCount; + } + + public String getUserUsageCount() { + if(userUsageCount == null){ + userUsageCount = ""; + } + return userUsageCount; + } + + public String getName() { + if(name == null){ + name = ""; + } + return name; + } + + public String getType() { + if(type == null){ + type = ""; + } + return type; + } + + public String getDiscount() { + if(discount == null){ + discount = ""; + } + return discount; + } + + public String getShipping() { + if(shipping == null){ + shipping = ""; + } + return shipping; + } + + public String getTotal() { + if(total == null){ + total = ""; + } + return total; + } + public CouponDiscountType getCouponDiscountType(){ if(type.toLowerCase().equals("f")){ return CouponDiscountType.FIXED; @@ -132,8 +142,9 @@ public class CheckCouponModel { } } + @Override public boolean isActive(){ - return status.equals("1") && isCouponUsable(); + return getStatus().equals("1") && isCouponUsable(); } private boolean isCouponUsable(){ @@ -167,123 +178,4 @@ public class CheckCouponModel { } } - public String getCouponId() { - return couponId; - } - - public void setCouponId(String couponId) { - this.couponId = couponId; - } - - public ArrayList getProductIdList() { - return productIdList; - } - - public void setProductIdList(ArrayList productIdList) { - this.productIdList = productIdList; - } - - public String getStartDate() { - return startDate; - } - - public void setStartDate(String startDate) { - this.startDate = startDate; - } - - public String getEndDate() { - return endDate; - } - - public void setEndDate(String endDate) { - this.endDate = endDate; - } - - public String getTotalUsageCount() { - return totalUsageCount; - } - - public void setTotalUsageCount(String totalUsageCount) { - this.totalUsageCount = totalUsageCount; - } - - public String getUserUsageCount() { - return userUsageCount; - } - - public void setUserUsageCount(String userUsageCount) { - this.userUsageCount = userUsageCount; - } - - public String getAddedDate() { - return addedDate; - } - - public void setAddedDate(String addedDate) { - this.addedDate = addedDate; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDiscount() { - return discount; - } - - public void setDiscount(String discount) { - this.discount = discount; - } - - public String getShipping() { - return shipping; - } - - public void setShipping(String shipping) { - this.shipping = shipping; - } - - public String getTotal() { - return total; - } - - public void setTotal(String total) { - this.total = total; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getStoreName() { - return storeName; - } - - public void setStoreName(String storeName) { - this.storeName = storeName; - } } diff --git a/app/src/main/java/ch/pizzacucina/android/model/PersonalCouponModel.java b/app/src/main/java/ch/pizzacucina/android/model/PersonalCouponModel.java new file mode 100644 index 0000000..0a3cbeb --- /dev/null +++ b/app/src/main/java/ch/pizzacucina/android/model/PersonalCouponModel.java @@ -0,0 +1,116 @@ +package ch.pizzacucina.android.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class PersonalCouponModel extends CouponModel { + + @Expose + @SerializedName("voucher_id") + private String voucherId; + + @Expose + @SerializedName("from_name") + private String fromName; + + @Expose + @SerializedName("from_email") + private String fromEmail; + + @Expose + @SerializedName("to_name") + private String toName; + + @Expose + @SerializedName("to_email") + private String toEmail; + + @Expose + @SerializedName("voucher_theme_id") + private String voucherThemeId; + + private String theme; + private String message; + private String image; + private String amount; + + @Override + public CouponType getCouponType() { + return CouponType.PERSONAL; + } + + @Override + public boolean isActive() { + return getStatus().equals("1"); + } + + public String getVoucherId() { + if(voucherId == null){ + voucherId = ""; + } + return voucherId; + } + + public String getFromName() { + if(fromName == null){ + fromName = ""; + } + return fromName; + } + + public String getFromEmail() { + if(fromEmail == null){ + fromEmail = ""; + } + return fromEmail; + } + + public String getToName() { + if(toName == null){ + toName = ""; + } + return toName; + } + + public String getToEmail() { + if(toEmail == null){ + toEmail = ""; + } + return toEmail; + } + + public String getVoucherThemeId() { + if(voucherThemeId == null){ + voucherThemeId = ""; + } + return voucherThemeId; + } + + public String getTheme() { + if(theme == null){ + theme = ""; + } + return theme; + } + + public String getMessage() { + if(message == null){ + message = ""; + } + return message; + } + + public String getImage() { + if(image == null){ + image = ""; + } + return image; + } + + public String getAmount() { + if(amount == null){ + amount = ""; + } + return amount; + } +}