add to cart dialog

This commit is contained in:
2017-10-14 22:03:11 +03:00
parent da8c8dbc20
commit 98292254b4
10 changed files with 268 additions and 122 deletions

View File

@@ -5,6 +5,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
@@ -12,6 +13,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ch.pizzalink.android.R;
import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.helper.PriceHelper;
import ch.pizzalink.android.interfaces.RecyclerItemClickListener;
import ch.pizzalink.android.model.menu.MenuProductOptionValueModel;
@@ -27,6 +29,7 @@ public class ProductCheckboxOptionsRecyclerAdapter extends RecyclerView.Adapter<
public static class ViewHolder extends RecyclerView.ViewHolder{
@BindView(R.id.productOptionCheckBox) AppCompatCheckBox productOptionCheckBox;
@BindView(R.id.optionPriceDescriptionTextView) TextView optionPriceDescriptionTextView;
public ViewHolder(final View view, final RecyclerItemClickListener recyclerItemClickListener) {
super(view);
@@ -48,7 +51,7 @@ public class ProductCheckboxOptionsRecyclerAdapter extends RecyclerView.Adapter<
@Override
public ProductCheckboxOptionsRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View root = LayoutInflater.from(BaseActivity.currentActivity).inflate(R.layout.row_checkbox_option, viewGroup, false);
View root = LayoutInflater.from(BaseActivity.currentActivity).inflate(R.layout.row_option_checkbox, viewGroup, false);
return new ProductCheckboxOptionsRecyclerAdapter.ViewHolder(root, recyclerItemClickListener);
}
@@ -56,6 +59,7 @@ public class ProductCheckboxOptionsRecyclerAdapter extends RecyclerView.Adapter<
public void onBindViewHolder(ProductCheckboxOptionsRecyclerAdapter.ViewHolder holder, int position) {
holder.productOptionCheckBox.setChecked(productOptionValueList.get(position).isSelected());
holder.productOptionCheckBox.setText(productOptionValueList.get(position).getName());
holder.optionPriceDescriptionTextView.setText(PriceHelper.getProductOptionPriceText(productOptionValueList.get(position)));
}
@Override

View File

@@ -1,23 +1,20 @@
package ch.pizzalink.android.adapter.recycler;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.AppCompatRadioButton;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import butterknife.BindDrawable;
import butterknife.BindView;
import butterknife.ButterKnife;
import ch.pizzalink.android.R;
import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.helper.PriceHelper;
import ch.pizzalink.android.interfaces.RecyclerItemClickListener;
import ch.pizzalink.android.model.menu.MenuProductOptionModel;
import ch.pizzalink.android.model.menu.MenuProductOptionValueModel;
/**
@@ -32,6 +29,7 @@ public class ProductRadioOptionsRecyclerAdapter extends RecyclerView.Adapter<Pro
public static class ViewHolder extends RecyclerView.ViewHolder{
@BindView(R.id.productOptionRadioButton) AppCompatRadioButton productOptionRadioButton;
@BindView(R.id.optionPriceDescriptionTextView) TextView optionPriceDescriptionTextView;
public ViewHolder(final View view, final RecyclerItemClickListener recyclerItemClickListener) {
super(view);
@@ -53,7 +51,7 @@ public class ProductRadioOptionsRecyclerAdapter extends RecyclerView.Adapter<Pro
@Override
public ProductRadioOptionsRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View root = LayoutInflater.from(BaseActivity.currentActivity).inflate(R.layout.row_radio_option, viewGroup, false);
View root = LayoutInflater.from(BaseActivity.currentActivity).inflate(R.layout.row_option_radio, viewGroup, false);
return new ProductRadioOptionsRecyclerAdapter.ViewHolder(root, recyclerItemClickListener);
}
@@ -61,6 +59,8 @@ public class ProductRadioOptionsRecyclerAdapter extends RecyclerView.Adapter<Pro
public void onBindViewHolder(ProductRadioOptionsRecyclerAdapter.ViewHolder holder, int position) {
holder.productOptionRadioButton.setChecked(productOptionValueList.get(position).isSelected());
holder.productOptionRadioButton.setText(productOptionValueList.get(position).getName());
holder.optionPriceDescriptionTextView.setText(PriceHelper.getProductOptionPriceText(productOptionValueList.get(position)));
}
@Override

View File

@@ -1,5 +1,6 @@
package ch.pizzalink.android.api;
import java.util.ArrayList;
import java.util.HashMap;
import ch.pizzalink.android.model.AddProductToBasketResponseModel;
@@ -14,6 +15,7 @@ import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Query;
@@ -76,6 +78,28 @@ public interface ApiInterface {
*/
/*
{
"product_id": "56",
"quantity": "1",
"token": "wXTVshBk2TU4XJmb23wa320zOBRodw4K",
"options": [
{
"optionId" : "232",
"optionValue" : "34"
},
{
"optionId" : "232",
"optionValue" : "33"
},
{
"optionId" : "231",
"optionValue" : "31"
}
]
}
*/

View File

@@ -28,6 +28,7 @@ import ch.pizzalink.android.api.ApiErrorUtils;
import ch.pizzalink.android.api.ApiService;
import ch.pizzalink.android.api.ResponseObject;
import ch.pizzalink.android.helper.DialogHelper;
import ch.pizzalink.android.helper.ImageLoadHelper;
import ch.pizzalink.android.helper.PriceHelper;
import ch.pizzalink.android.helper.SessionHelper;
import ch.pizzalink.android.helper.SharedPrefsHelper;
@@ -46,8 +47,10 @@ import retrofit2.Response;
public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragment {
@BindView(R.id.productImageView) ImageView productImageView;
@BindView(R.id.productNameTextView) TextView productNameTextView;
@BindView(R.id.productPriceTextView) TextView productPriceTextView;
@BindView(R.id.addToCartButton) Button addToCartButton;
@BindView(R.id.radioRecyclerHeaderTextView) TextView radioRecyclerHeaderTextView;
@BindView(R.id.radioRecyclerView) RecyclerView radioRecyclerView;
@BindView(R.id.checkboxRecyclerHeaderTextView) TextView checkboxRecyclerHeaderTextView;
@@ -55,7 +58,6 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
@BindView(R.id.increaseProductCountImageView) ImageView increaseProductCountImageView;
@BindView(R.id.deccreaseProductCountImageView) ImageView deccreaseProductCountImageView;
@BindView(R.id.productCountTextView) TextView productCountTextView;
@BindView(R.id.addToCartButton) Button addToCartButton;
private int productCount = 1;
@@ -82,7 +84,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
@Override
public void onStart() {
super.onStart();
//mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
@OnClick({R.id.increaseProductCountImageView,
@@ -147,7 +149,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
private void initRadioRecyclerView(){
radioRecyclerView.setNestedScrollingEnabled(false);
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 3);
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
radioRecyclerView.setLayoutManager(gridLayoutManager);
productRadioOptionsRecyclerAdapter = new ProductRadioOptionsRecyclerAdapter(productRadioOptionValueList, new RecyclerItemClickListener() {
@Override
@@ -168,7 +170,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
private void initCheckboxRecyclerView(){
checkboxRecyclerView.setNestedScrollingEnabled(false);
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 3);
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
checkboxRecyclerView.setLayoutManager(gridLayoutManager);
productCheckboxOptionsRecyclerAdapter = new ProductCheckboxOptionsRecyclerAdapter(productCheckboxOptionValueList, new RecyclerItemClickListener() {
@Override
@@ -185,6 +187,7 @@ public class ProductPropertiesBottomSheetDialog extends BottomSheetDialogFragmen
}
private void setFields(){
ImageLoadHelper.loadImage(productImageView, menuProductModel.getImageURL());
productNameTextView.setText(menuProductModel.getName());
productPriceTextView.setText(PriceHelper.getPriceWithCurreny(menuProductModel.getPrice()));
productPriceTextView.setText(PriceHelper.getPriceWithCurreny(menuProductModel.getPrice()));

View File

@@ -31,7 +31,7 @@ public class PriceHelper {
}
public static String calculatePriceAfterCountChanged(String oldPriceString, int oldCount, int newCount){
Double oldPrice = Double.valueOf(removeCurrencyFromPrice(oldPriceString));
Double oldPrice = stringToDouble(removeCurrencyFromPrice(oldPriceString));
Double productOldPrice = oldPrice / oldCount;
Double productNewPrice = productOldPrice * newCount;
return getPriceWithCurreny(productNewPrice);
@@ -41,14 +41,14 @@ public class PriceHelper {
MenuProductModel menuProductModel,
MenuProductOptionValueModel menuProductOptionValueModel){
Double productPrice = Double.valueOf(menuProductModel.getPrice());
Double productPrice = stringToDouble(menuProductModel.getPrice());
switch (menuProductOptionValueModel.getPrice_prefix()){
case "+":
productPrice += Double.valueOf(menuProductOptionValueModel.getPrice());
productPrice += stringToDouble(menuProductOptionValueModel.getPrice());
break;
case "-":
productPrice -= Double.valueOf(menuProductOptionValueModel.getPrice());
productPrice -= stringToDouble(menuProductOptionValueModel.getPrice());
break;
}
@@ -60,16 +60,16 @@ public class PriceHelper {
MenuProductModel menuProductModel,
ArrayList<MenuProductOptionValueModel> menuProductOptionValueModelList){
Double productPrice = Double.valueOf(menuProductModel.getPrice());
Double productPrice = stringToDouble(menuProductModel.getPrice());
for(MenuProductOptionValueModel menuProductOptionValueModel : menuProductOptionValueModelList){
if(menuProductOptionValueModel.isSelected()){
switch (menuProductOptionValueModel.getPrice_prefix()){
case "+":
productPrice += Double.valueOf(menuProductOptionValueModel.getPrice());
productPrice += stringToDouble(menuProductOptionValueModel.getPrice());
break;
case "-":
productPrice -= Double.valueOf(menuProductOptionValueModel.getPrice());
productPrice -= stringToDouble(menuProductOptionValueModel.getPrice());
break;
}
}
@@ -79,5 +79,20 @@ public class PriceHelper {
}
public static String getProductOptionPriceText(MenuProductOptionValueModel productOptionValueModel){
return new StringBuilder()
//.append(productOptionValueModel.getPrice_prefix())
.append(" ")
.append(BaseActivity.currentActivity.getString(R.string.chf))
.append(" ")
.append(productOptionValueModel.getPrice())
.toString();
}
private static Double stringToDouble(String string){
Double dbl = Double.valueOf(string);
return Math.floor(dbl * 100) / 100;
}
}

View File

@@ -38,7 +38,7 @@ public class MenuProductOptionValueModel implements Serializable{
price = "";
if(price_prefix == null)
price_prefix = "";
price_prefix = "+";
}
public static void checkNull(ArrayList<MenuProductOptionValueModel> productOptionValueList){

View File

@@ -23,79 +23,89 @@
android:id="@+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/cartDividerSpace"
android:layout_above="@+id/cartInfoLayout"
android:visibility="gone"/>
<android.support.v4.widget.Space
android:id="@+id/cartDividerSpace"
android:layout_width="match_parent"
android:layout_height="12dp"
android:background="@color/red"
android:layout_above="@+id/cartInfoLayout"/>
<LinearLayout
android:id="@+id/cartInfoLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingRight="24dp"
android:paddingEnd="24dp"
android:visibility="gone">
<TextView
android:id="@+id/cartTotalLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="@color/black"
android:layout_gravity="center_horizontal"
android:text="TOTAL"/>
<TextView
android:id="@+id/cartProductTotalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHF 50.00"
android:textSize="18sp"
android:layout_marginTop="12dp"
android:textColor="@color/black"
android:layout_gravity="center_horizontal"
android:textStyle="bold"/>
<View
android:id="@+id/cartDividerSpace"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/shadow" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingRight="24dp"
android:paddingEnd="24dp"
android:background="@color/white">
<Button
android:id="@+id/clearCartButton"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="12dp"
android:layout_marginRight="6dp"
android:layout_marginEnd="6dp"
android:text="@string/clear_cart"
style="@style/PizzalinkButtonWithoutMargin"
android:layout_weight="1"/>
<TextView
android:id="@+id/cartTotalLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="@color/black"
android:layout_gravity="center_horizontal"
android:text="TOTAL"/>
<Button
android:id="@+id/continueCartButton"
android:layout_width="match_parent"
android:layout_height="36dp"
<TextView
android:id="@+id/cartProductTotalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHF 50.00"
android:textSize="18sp"
android:layout_marginTop="12dp"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:text="@string/continue_cart"
style="@style/PizzalinkButtonWithoutMargin"
android:layout_weight="1"/>
android:textColor="@color/black"
android:layout_gravity="center_horizontal"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/clearCartButton"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="12dp"
android:layout_marginRight="6dp"
android:layout_marginEnd="6dp"
android:text="@string/clear_cart"
style="@style/PizzalinkButtonWithoutMargin"
android:layout_weight="1"/>
<Button
android:id="@+id/continueCartButton"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="12dp"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:text="@string/continue_cart"
style="@style/PizzalinkButtonWithoutMargin"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@@ -6,31 +6,90 @@
android:orientation="vertical"
android:background="@color/white">
<TextView
android:id="@+id/productNameTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@android:color/black"
android:textSize="18sp"
android:text="Pizza Formaggio"
android:padding="16dp"
android:textStyle="bold"
android:gravity="center"/>
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="12dp"
android:src="@drawable/ic_back"
android:visibility="gone"/>
<TextView
android:id="@+id/productPriceTextView"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:text="CHF 25.00"
android:textSize="16sp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:textStyle="bold"
android:layout_gravity="center_horizontal" />
android:padding="12dp">
<ImageView
android:id="@+id/productImageView"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="144dp"
android:orientation="vertical"
android:layout_toRightOf="@+id/productImageView"
android:layout_toEndOf="@+id/productImageView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:id="@+id/productNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/navigation_drawer_background"
android:textSize="18sp"
android:text="Pizza Formaggio"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:id="@+id/productPriceTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/navigation_drawer_background"
android:text="CHF 25.00"
android:textSize="16sp"
android:paddingBottom="12dp"
android:paddingLeft="12dp"
android:paddingStart="12dp"
android:paddingRight="12dp"
android:paddingEnd="12dp"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerVertical="true"/>
</RelativeLayout>
<Button
android:id="@+id/addToCartButton"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:text="@string/add_to_cart"
style="@style/PizzalinkButtonWithoutMargin" />
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/shadow"/>
<LinearLayout
android:layout_width="match_parent"
@@ -56,7 +115,9 @@
android:paddingLeft="12dp"
android:paddingStart="12dp"
android:paddingRight="12dp"
android:paddingEnd="12dp"/>
android:paddingEnd="12dp"
android:textSize="16sp"
android:textColor="@color/navigation_drawer_background"/>
<LinearLayout
android:id="@+id/ProductCountLayout"
@@ -67,9 +128,9 @@
<ImageView
android:id="@+id/increaseProductCountImageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="8dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:padding="4dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_increase"
android:layout_marginRight="4dp"
@@ -81,15 +142,14 @@
android:layout_height="wrap_content"
android:text="1"
android:textSize="18sp"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:textColor="@color/black"/>
<ImageView
android:id="@+id/deccreaseProductCountImageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="8dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:padding="4dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_gravity="center_vertical"
@@ -97,6 +157,10 @@
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/shadow"/>
<TextView
android:id="@+id/radioRecyclerHeaderTextView"
@@ -104,7 +168,10 @@
android:layout_height="wrap_content"
android:textStyle="bold"
android:padding="12dp"
android:visibility="gone"/>
android:visibility="gone"
android:text="Size"
android:textSize="16sp"
android:textColor="@color/navigation_drawer_background"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/radioRecyclerView"
@@ -112,13 +179,20 @@
android:layout_height="wrap_content"
android:visibility="gone"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/shadow"/>
<TextView
android:id="@+id/checkboxRecyclerHeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:padding="12dp"
android:visibility="gone"/>
android:visibility="gone"
android:textSize="16sp"
android:textColor="@color/navigation_drawer_background"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/checkboxRecyclerView"
@@ -133,20 +207,6 @@
</LinearLayout>
<RelativeLayout
android:id="@+id/addToCartButtonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<Button
android:id="@+id/addToCartButton"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="@string/add_to_cart"
style="@style/PizzalinkButtonWithoutMargin" />
</RelativeLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
@@ -14,4 +14,19 @@
android:clickable="false"
android:text="Klein"/>
</LinearLayout>
<RelativeLayout
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<TextView
android:id="@+id/optionPriceDescriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHF 14.00"/>
</RelativeLayout>
</RelativeLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
@@ -14,4 +14,19 @@
android:text="Klein"
android:clickable="false"/>
</LinearLayout>
<RelativeLayout
android:layout_width="84dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<TextView
android:id="@+id/optionPriceDescriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHF 14.00"/>
</RelativeLayout>
</RelativeLayout>