coupon code

This commit is contained in:
cimenmus
2018-02-09 00:07:12 +03:00
parent 58f1597ece
commit 104c8a98c9
17 changed files with 464 additions and 27 deletions

2
.idea/misc.xml generated
View File

@@ -24,7 +24,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -33,6 +33,7 @@ public class CreateOrderActivity extends BaseActivity {
private PaymentMethodModel selectedPaymentMethod; private PaymentMethodModel selectedPaymentMethod;
private Boolean slicePizza; private Boolean slicePizza;
private String orderNote; private String orderNote;
private String discountAmount;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -153,6 +154,10 @@ public class CreateOrderActivity extends BaseActivity {
return cartInfoModel; return cartInfoModel;
} }
public void setCartInfo(CartInfoModel cartInfoModel) {
this.cartInfoModel = cartInfoModel;
}
public ShippingMethodModel getSelectedShippingMethod(){ public ShippingMethodModel getSelectedShippingMethod(){
return selectedShippingMethod; return selectedShippingMethod;
} }
@@ -194,4 +199,12 @@ public class CreateOrderActivity extends BaseActivity {
public void setSlicePizza(Boolean slicePizza) { public void setSlicePizza(Boolean slicePizza) {
this.slicePizza = slicePizza; this.slicePizza = slicePizza;
} }
public String getDiscountAmount() {
return discountAmount;
}
public void setDiscountAmount(String discountAmount) {
this.discountAmount = discountAmount;
}
} }

View File

@@ -16,6 +16,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import ch.pizzalink.android.R; import ch.pizzalink.android.R;
import ch.pizzalink.android.api.ApiEndPoints;
import ch.pizzalink.android.api.ApiErrorUtils; import ch.pizzalink.android.api.ApiErrorUtils;
import ch.pizzalink.android.api.ApiService; import ch.pizzalink.android.api.ApiService;
import ch.pizzalink.android.api.ResponseObject; import ch.pizzalink.android.api.ResponseObject;
@@ -121,7 +122,7 @@ public class LoginActivity extends BaseActivity {
private void getCartItemCount(){ private void getCartItemCount(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
@@ -130,7 +131,7 @@ public class LoginActivity extends BaseActivity {
response.body().getData() != null && response.body().getData() != null &&
response.body().isSuccess()){ response.body().isSuccess()){
SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size()); SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size());
SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getTotals().get(0).getText())); SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getCartTotalModel().getText()));
startActivity(new Intent(LoginActivity.this, MainActivity.class)); startActivity(new Intent(LoginActivity.this, MainActivity.class));
finishAffinity(); finishAffinity();

View File

@@ -344,7 +344,7 @@ public class ProductPropertiesActivity extends BaseActivity {
private void getCartItemCount(){ private void getCartItemCount(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
@@ -353,7 +353,7 @@ public class ProductPropertiesActivity extends BaseActivity {
response.body().getData() != null && response.body().getData() != null &&
response.body().isSuccess()){ response.body().isSuccess()){
SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size()); SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size());
SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getTotals().get(0).getText())); SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getCartTotalModel().getText()));
/* /*
MainActivity mainActivity = (MainActivity) getActivity(); MainActivity mainActivity = (MainActivity) getActivity();

View File

@@ -18,6 +18,7 @@ import java.util.HashMap;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ch.pizzalink.android.R; import ch.pizzalink.android.R;
import ch.pizzalink.android.api.ApiConstants; import ch.pizzalink.android.api.ApiConstants;
import ch.pizzalink.android.api.ApiEndPoints;
import ch.pizzalink.android.api.ApiErrorUtils; import ch.pizzalink.android.api.ApiErrorUtils;
import ch.pizzalink.android.api.ApiService; import ch.pizzalink.android.api.ApiService;
import ch.pizzalink.android.api.ResponseArray; import ch.pizzalink.android.api.ResponseArray;
@@ -224,7 +225,7 @@ public class SplashActivity extends BaseActivity {
private void getCartItemCount(){ private void getCartItemCount(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
@@ -232,7 +233,7 @@ public class SplashActivity extends BaseActivity {
response.body().getData() != null && response.body().getData() != null &&
response.body().isSuccess()){ response.body().isSuccess()){
SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size()); SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size());
SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getTotals().get(0).getText())); SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getCartTotalModel().getText()));
openActivity(MainActivity.class); openActivity(MainActivity.class);
} }

View File

@@ -80,7 +80,7 @@ public class PaymentMethodsRecyclerAdapter extends RecyclerView.Adapter<Recycler
break; break;
case HOLDER_SPACE: case HOLDER_SPACE:
view = inflater.inflate(R.layout.row_space, viewGroup, false); view = inflater.inflate(R.layout.row_space_4dp, viewGroup, false);
viewHolder = new SpaceViewHolder(view); viewHolder = new SpaceViewHolder(view);
break; break;

View File

@@ -12,7 +12,7 @@ public class ApiEndPoints {
public static final String API_LOGIN = PREFIX + "login" + SUFFIX; public static final String API_LOGIN = PREFIX + "login" + SUFFIX;
public static final String API_LOGOUT = PREFIX + "logout" + SUFFIX; public static final String API_LOGOUT = PREFIX + "logout" + SUFFIX;
public static final String API_GET_ORDER_HISTORY = PREFIX + "getOrders" + SUFFIX; public static final String API_GET_ORDER_HISTORY = PREFIX + "getOrders" + SUFFIX;
public static final String API_GET_CART_PRODUCTS = PREFIX + "getBasketProducts" + SUFFIX; public static final String API_GET_CART_PRODUCTS = PREFIX + "getBasketProducts" + SUFFIX + "&token=";
public static final String API_GET_CLEAR_CART = PREFIX + "clearBasket" + SUFFIX; public static final String API_GET_CLEAR_CART = PREFIX + "clearBasket" + SUFFIX;
public static final String API_GET_PRODUCTS_BY_CATEGORY = PREFIX + "getProductsByCategory" + SUFFIX; public static final String API_GET_PRODUCTS_BY_CATEGORY = PREFIX + "getProductsByCategory" + SUFFIX;
public static final String API_GET_PRODUCT = PREFIX + "getProduct" + SUFFIX; public static final String API_GET_PRODUCT = PREFIX + "getProduct" + SUFFIX;
@@ -35,4 +35,5 @@ public class ApiEndPoints {
public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token="; public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token=";
public static final String API_GET_STORE_INFO = PREFIX + "getStoreInfo" + SUFFIX; public static final String API_GET_STORE_INFO = PREFIX + "getStoreInfo" + SUFFIX;
public static final String API_GET_ORDER_PRODUCT_LIST = PREFIX + "getOrderProducts" + SUFFIX; public static final String API_GET_ORDER_PRODUCT_LIST = PREFIX + "getOrderProducts" + SUFFIX;
public static final String API_CHECK_COUPON = PREFIX + "checkCoupon" + SUFFIX + "&token=";
} }

View File

@@ -6,6 +6,7 @@ import ch.pizzalink.android.model.AddNewAddressResponseModel;
import ch.pizzalink.android.model.AddProductToBasketResponseModel; import ch.pizzalink.android.model.AddProductToBasketResponseModel;
import ch.pizzalink.android.model.AddressModel; import ch.pizzalink.android.model.AddressModel;
import ch.pizzalink.android.model.AppVersionModel; import ch.pizzalink.android.model.AppVersionModel;
import ch.pizzalink.android.model.CheckCouponModel;
import ch.pizzalink.android.model.CountryModel; import ch.pizzalink.android.model.CountryModel;
import ch.pizzalink.android.model.DeleteAddressResponseModel; import ch.pizzalink.android.model.DeleteAddressResponseModel;
import ch.pizzalink.android.model.PaymentMethodsResponseModel; import ch.pizzalink.android.model.PaymentMethodsResponseModel;
@@ -61,8 +62,8 @@ public interface ApiInterface {
@GET(ApiEndPoints.API_GET_ORDER_HISTORY) @GET(ApiEndPoints.API_GET_ORDER_HISTORY)
Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Query("token") String token); Call<ResponseArray<OrderHistoryModel>> getOrderHistory(@Query("token") String token);
@GET(ApiEndPoints.API_GET_CART_PRODUCTS) @POST
Call<ResponseObject<CartInfoModel>> getCartProducts(@Query("token") String token); Call<ResponseObject<CartInfoModel>> getCartProducts(@Url String url);
@GET(ApiEndPoints.API_GET_CLEAR_CART) @GET(ApiEndPoints.API_GET_CLEAR_CART)
Call<ResponseObject> clearCart(@Query("token") String token); Call<ResponseObject> clearCart(@Query("token") String token);
@@ -145,4 +146,8 @@ public interface ApiInterface {
Call<ResponseArray<OrderHistoryProductModel>> getOrderProductList(@Url String url, Call<ResponseArray<OrderHistoryProductModel>> getOrderProductList(@Url String url,
@Field("order_id") String orderId); @Field("order_id") String orderId);
@FormUrlEncoded
@POST
Call<ResponseObject<CheckCouponModel>> checkCoupon(@Url String url, @Field("coupon") String couponCode);
} }

View File

@@ -336,7 +336,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
private void getCartItemCount(){ private void getCartItemCount(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
@@ -344,7 +344,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
response.body().getData() != null && response.body().getData() != null &&
response.body().isSuccess()){ response.body().isSuccess()){
SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size()); SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size());
SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getTotals().get(0).getText())); SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getCartTotalModel().getText()));
MainActivity mainActivity = (MainActivity) getActivity(); MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.setCartItemCount(); mainActivity.setCartItemCount();
dismiss(); dismiss();

View File

@@ -129,7 +129,7 @@ public class CartFragment extends BaseFragment {
private void getCartProducts(){ private void getCartProducts(){
DialogHelper.showLoadingDialog(); DialogHelper.showLoadingDialog();
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
@@ -192,8 +192,8 @@ public class CartFragment extends BaseFragment {
} }
private void setCartTotalFields(){ private void setCartTotalFields(){
cartTotalLabelTextView.setText(cartInfoModel.getTotals().get(0).getTitle().toUpperCase(Locale.GERMAN)); cartTotalLabelTextView.setText(cartInfoModel.getCartTotalModel().getTitle().toUpperCase(Locale.GERMAN));
cartProductTotalTextView.setText(PriceHelper.roundFractions(cartInfoModel.getTotals().get(0).getText())); cartProductTotalTextView.setText(PriceHelper.roundFractions(cartInfoModel.getCartTotalModel().getText()));
} }
private void initRecyclerView(){ private void initRecyclerView(){
@@ -283,7 +283,7 @@ public class CartFragment extends BaseFragment {
private void getCartItemCount(){ private void getCartItemCount(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts( Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
SessionHelper.getCustomerToken().getToken()); ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() { call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override @Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, final Response<ResponseObject<CartInfoModel>> response) { public void onResponse(Call<ResponseObject<CartInfoModel>> call, final Response<ResponseObject<CartInfoModel>> response) {
@@ -296,7 +296,7 @@ public class CartFragment extends BaseFragment {
@Override @Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size()); SharedPrefsHelper.setCartItemCount(response.body().getData().getProducts().size());
SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getTotals().get(0).getText())); SharedPrefsHelper.setCartTotalPrice(PriceHelper.removeCurrencyFromPrice(response.body().getData().getCartTotalModel().getText()));
MainActivity mainActivity = (MainActivity) getActivity(); MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.setCartItemCount(); mainActivity.setCartItemCount();
mainActivity.reopenCartFragment(); mainActivity.reopenCartFragment();

View File

@@ -91,7 +91,7 @@ public class CreateOrderSummaryFragment extends CreateOrderBaseFragment {
orderShippingMethodPizzalinkInfoLayout.setText(createOrderActivity.getSelectedShippingMethod().getTitle()); orderShippingMethodPizzalinkInfoLayout.setText(createOrderActivity.getSelectedShippingMethod().getTitle());
orderShippingAddressPizzalinkInfoLayout.setText(createOrderActivity.getSelectedShippingAddress().getAddress()); orderShippingAddressPizzalinkInfoLayout.setText(createOrderActivity.getSelectedShippingAddress().getAddress());
orderPaymentMethodPizzalinkInfoLayout.setText(createOrderActivity.getSelectedPaymentMethod().getTitle()); orderPaymentMethodPizzalinkInfoLayout.setText(createOrderActivity.getSelectedPaymentMethod().getTitle());
orderTotalPizzalinkInfoLayout.setText(PriceHelper.roundFractions(createOrderActivity.getCartInfo().getTotals().get(0).getText())); orderTotalPizzalinkInfoLayout.setText(PriceHelper.roundFractions(createOrderActivity.getCartInfo().getCartTotalModel().getText()));
if(createOrderActivity.getOrderNote().isEmpty()){ if(createOrderActivity.getOrderNote().isEmpty()){
orderNotePizzalinkInfoLayout.setVisibility(View.GONE); orderNotePizzalinkInfoLayout.setVisibility(View.GONE);
} }

View File

@@ -3,6 +3,7 @@ package ch.pizzalink.android.fragment.createOrder;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -17,14 +18,18 @@ import ch.pizzalink.android.R;
import ch.pizzalink.android.activity.BaseActivity; import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.activity.CreateOrderActivity; import ch.pizzalink.android.activity.CreateOrderActivity;
import ch.pizzalink.android.adapter.recycler.PaymentMethodsRecyclerAdapter; import ch.pizzalink.android.adapter.recycler.PaymentMethodsRecyclerAdapter;
import ch.pizzalink.android.api.ApiEndPoints;
import ch.pizzalink.android.api.ApiErrorUtils; import ch.pizzalink.android.api.ApiErrorUtils;
import ch.pizzalink.android.api.ApiService; import ch.pizzalink.android.api.ApiService;
import ch.pizzalink.android.api.ResponseObject; import ch.pizzalink.android.api.ResponseObject;
import ch.pizzalink.android.helper.DialogHelper; import ch.pizzalink.android.helper.DialogHelper;
import ch.pizzalink.android.helper.SessionHelper; import ch.pizzalink.android.helper.SessionHelper;
import ch.pizzalink.android.interfaces.RecyclerItemClickListener; import ch.pizzalink.android.interfaces.RecyclerItemClickListener;
import ch.pizzalink.android.model.CheckCouponModel;
import ch.pizzalink.android.model.PaymentMethodModel; import ch.pizzalink.android.model.PaymentMethodModel;
import ch.pizzalink.android.model.PaymentMethodsResponseModel; import ch.pizzalink.android.model.PaymentMethodsResponseModel;
import ch.pizzalink.android.model.cart.CartInfoModel;
import ch.pizzalink.android.view.PizzalinkEditText;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
@@ -36,11 +41,15 @@ import retrofit2.Response;
public class PaymentMethodFragment extends CreateOrderBaseFragment { public class PaymentMethodFragment extends CreateOrderBaseFragment {
@BindView(R.id.paymentMethodsRecyclerView) RecyclerView paymentMethodsRecyclerView; @BindView(R.id.paymentMethodsRecyclerView) RecyclerView paymentMethodsRecyclerView;
@BindView(R.id.couponCodePizzalinkEditText) PizzalinkEditText couponCodePizzalinkEditText;
@BindString(R.string.app_name) String appName;
@BindString(R.string.alert_choose_payment_method) String choosePaymentMethodText; @BindString(R.string.alert_choose_payment_method) String choosePaymentMethodText;
@BindString(R.string.coupon_is_not_active) String couponIsNotActiveText;
private ArrayList<PaymentMethodModel> paymentMethodList = new ArrayList<>(); private ArrayList<PaymentMethodModel> paymentMethodList = new ArrayList<>();
private PaymentMethodsRecyclerAdapter paymentMethodsRecyclerAdapter; private PaymentMethodsRecyclerAdapter paymentMethodsRecyclerAdapter;
private CheckCouponModel couponModel;
private PaymentMethodModel selectedPaymentMethod; private PaymentMethodModel selectedPaymentMethod;
@@ -79,8 +88,17 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
DialogHelper.showAlertDialog(BaseActivity.currentActivity, choosePaymentMethodText); DialogHelper.showAlertDialog(BaseActivity.currentActivity, choosePaymentMethodText);
break; break;
} }
createOrderActivity.setSelectedPaymentMethod(selectedPaymentMethod);
createOrderActivity.onNextClicked(FRAGMENT_NAME); if(couponCodePizzalinkEditText.isEmpty()){
createOrderActivity.setSelectedPaymentMethod(selectedPaymentMethod);
createOrderActivity.onNextClicked(FRAGMENT_NAME);
}
else {
checkCoupon();
}
break; break;
} }
} }
@@ -157,4 +175,70 @@ public class PaymentMethodFragment extends CreateOrderBaseFragment {
paymentMethodsRecyclerView.setLayoutManager(layoutManager); paymentMethodsRecyclerView.setLayoutManager(layoutManager);
paymentMethodsRecyclerView.setAdapter(paymentMethodsRecyclerAdapter); paymentMethodsRecyclerView.setAdapter(paymentMethodsRecyclerAdapter);
} }
private void checkCoupon(){
DialogHelper.showLoadingDialog();
Call<ResponseObject<CheckCouponModel>> call =
ApiService.apiInterface.checkCoupon(
ApiEndPoints.API_CHECK_COUPON + SessionHelper.getCustomerToken().getToken(),
couponCodePizzalinkEditText.getText());
call.enqueue(new Callback<ResponseObject<CheckCouponModel>>() {
@Override
public void onResponse(Call<ResponseObject<CheckCouponModel>> call, Response<ResponseObject<CheckCouponModel>> response) {
if(response.isSuccessful() &&
response.body().getData() != null &&
response.body().isSuccess()){
couponModel = response.body().getData();
couponModel.checkNull();
if(couponModel.isActive()){
DialogHelper.showDialogWithPositiveButton(appName, BaseActivity.currentActivity, couponModel.getName());
getCartProducts();
}
else {
DialogHelper.hideLoadingDialog();
DialogHelper.showAlertDialog(BaseActivity.currentActivity, couponIsNotActiveText);
}
}
else {
DialogHelper.hideLoadingDialog();
ApiErrorUtils.parseError(response);
}
}
@Override
public void onFailure(Call<ResponseObject<CheckCouponModel>> call, Throwable t) {
DialogHelper.hideLoadingDialog();
DialogHelper.showFailedDialog();
}
});
}
private void getCartProducts(){
Call<ResponseObject<CartInfoModel>> call = ApiService.apiInterface.getCartProducts(
ApiEndPoints.API_GET_CART_PRODUCTS + SessionHelper.getCustomerToken().getToken());
call.enqueue(new Callback<ResponseObject<CartInfoModel>>() {
@Override
public void onResponse(Call<ResponseObject<CartInfoModel>> call, Response<ResponseObject<CartInfoModel>> response) {
DialogHelper.hideLoadingDialog();
if(response.isSuccessful() &&
response.body().getData() != null &&
response.body().isSuccess()){
CreateOrderActivity createOrderActivity = (CreateOrderActivity) getActivity();
createOrderActivity.setCartInfo(response.body().getData());
createOrderActivity.setSelectedPaymentMethod(selectedPaymentMethod);
createOrderActivity.onNextClicked(FRAGMENT_NAME);
}
else {
ApiErrorUtils.parseError(response);
}
}
@Override
public void onFailure(Call<ResponseObject<CartInfoModel>> call, Throwable t) {
DialogHelper.hideLoadingDialog();
DialogHelper.showFailedDialog();
}
});
}
} }

View File

@@ -0,0 +1,276 @@
package ch.pizzalink.android.model;
import android.util.Log;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
/**
* Created by cimenmus on 6.02.2018.
*/
public class CheckCouponModel {
@Expose
@SerializedName("coupon_id")
private String couponId;
@Expose
@SerializedName("product")
private ArrayList<String> productIdList;
@Expose
@SerializedName("date_start")
private String startDate;
@Expose
@SerializedName("date_end")
private String endDate;
@Expose
@SerializedName("uses_total")
private String totalUsageCount;
@Expose
@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;
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<>();
}
}
public enum CouponDiscountType {
FIXED,
PERCENT
}
public CouponDiscountType getCouponDiscountType(){
if(type.toLowerCase().equals("f")){
return CouponDiscountType.FIXED;
}
else {
return CouponDiscountType.PERCENT;
}
}
public boolean isActive(){
return status.equals("1") && isCouponUsable();
}
private boolean isCouponUsable(){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendarEnd = null;
Calendar calendarNow = Calendar.getInstance();
try {
Date dateEnd = formatter.parse(endDate);
calendarEnd = Calendar.getInstance();
calendarEnd.setTime(dateEnd);
if(calendarNow.get(Calendar.YEAR) > calendarEnd.get(Calendar.YEAR)){
return true;
}
if(calendarNow.get(Calendar.MONTH) + 1 > calendarEnd.get(Calendar.MONTH) + 1){
return true;
}
if(calendarNow.get(Calendar.DAY_OF_MONTH) >= calendarEnd.get(Calendar.DAY_OF_MONTH)){
return true;
}
return false;
} catch (ParseException e) {
e.printStackTrace();
return false;
}
}
public String getCouponId() {
return couponId;
}
public void setCouponId(String couponId) {
this.couponId = couponId;
}
public ArrayList<String> getProductIdList() {
return productIdList;
}
public void setProductIdList(ArrayList<String> 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;
}
}

View File

@@ -20,6 +20,7 @@ public class CartInfoModel implements Serializable {
this.products = products; this.products = products;
} }
/*
public ArrayList<CartTotalModel> getTotals() { public ArrayList<CartTotalModel> getTotals() {
return totals; return totals;
} }
@@ -27,4 +28,19 @@ public class CartInfoModel implements Serializable {
public void setTotals(ArrayList<CartTotalModel> totals) { public void setTotals(ArrayList<CartTotalModel> totals) {
this.totals = totals; this.totals = totals;
} }
*/
public CartTotalModel getCartTotalModel(){
CartTotalModel cartTotalModel = null;
for(CartTotalModel crtTtl : totals){
if(crtTtl.getTitle().toLowerCase().equals("total")){
cartTotalModel = crtTtl;
break;
}
}
if(cartTotalModel == null){
cartTotalModel = totals.get(0);
}
return cartTotalModel;
}
} }

View File

@@ -1,17 +1,49 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/white"> android:background="@color/white"
tools:ignore="MissingPrefix">
<android.support.v7.widget.RecyclerView <LinearLayout
android:id="@+id/paymentMethodsRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" android:orientation="vertical"
android:layout_above="@+id/ordersBottomLayout"/> android:layout_above="@+id/ordersBottomLayout">
<ch.pizzalink.android.view.PizzalinkEditText
android:id="@+id/couponCodePizzalinkEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:edittextTheme="navy"
app:inputType="name"
app:hint="@string/coupon_code"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontPath="fonts/Quicksand-Bold.ttf"
android:textColor="@color/navy"
android:text="@string/payment_method"
android:layout_marginTop="24dp"
android:layout_marginBottom="12dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingRight="20dp"
android:paddingEnd="20dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/paymentMethodsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
<include layout="@layout/layout_orders_bottom"/> <include layout="@layout/layout_orders_bottom"/>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.Space
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="4dp" />

View File

@@ -144,10 +144,13 @@
<!-- PaymentMethodFragment--> <!-- PaymentMethodFragment-->
<string name="alert_choose_payment_method">Bitte wählen Sie ein Bezahlverfahren aus.</string> <string name="alert_choose_payment_method">Bitte wählen Sie ein Bezahlverfahren aus.</string>
<string name="coupon_code">Gutscheincode (Wahlweise)</string>
<string name="payment_method">Bezahlverfahren</string>
<string name="coupon_is_not_active">Coupon is not active.</string>
<!-- PaymentMethodFragment--> <!-- PaymentMethodFragment-->
<!-- CreateOrderNoteFragment--> <!-- CreateOrderNoteFragment-->
<string name="order_note">Nachricht (Optional)</string> <string name="order_note">Nachricht (Wahlweise)</string>
<string name="slice_pizza">Aus Gründen der Qualität empfehlen wir nicht, die Pizza zu schneiden</string> <string name="slice_pizza">Aus Gründen der Qualität empfehlen wir nicht, die Pizza zu schneiden</string>
<string name="yes">Bitte Pizza Schneiden</string> <string name="yes">Bitte Pizza Schneiden</string>
<string name="no">Nein, danke</string> <string name="no">Nein, danke</string>