diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml new file mode 100644 index 0000000..86e0ca1 --- /dev/null +++ b/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/java/com/llw/cart/MainActivity.java b/main/java/com/llw/cart/MainActivity.java new file mode 100644 index 0000000..d47bafc --- /dev/null +++ b/main/java/com/llw/cart/MainActivity.java @@ -0,0 +1,389 @@ +package com.llw.cart; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.annotation.SuppressLint; +import android.content.DialogInterface; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.google.gson.Gson; +import com.llw.cart.adapter.StoreAdapter; +import com.llw.cart.bean.CarResponse; +import com.llw.cart.util.Constant; +import com.llw.cart.util.GoodsCallback; +import com.scwang.smartrefresh.layout.SmartRefreshLayout; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 购物车 + * + * @author llw + */ +public class MainActivity extends AppCompatActivity implements GoodsCallback, View.OnClickListener { + + public static final String TAG = "MainActivity"; + + private RecyclerView rvStore; + private StoreAdapter storeAdapter; + private List mList = new ArrayList<>(); + private TextView tvEdit;//编辑 + private ImageView ivCheckedAll;//全选 + private TextView tvTotal;//合计价格 + private TextView tvSettlement;//结算 + private LinearLayout layEdit;//编辑底部布局 + private TextView tvShareGoods;//分享商品 + private TextView tvCollectGoods;//收藏商品 + private TextView tvDeleteGoods;//删除商品 + + private boolean isEdit = false;//是否编辑 + private boolean isAllChecked = false;//是否全选 + + private List shopIdList = new ArrayList<>();//店铺列表 + + private double totalPrice = 0.00;//商品总价 + private int totalCount = 0;//商品总数量 + + private AlertDialog dialog;//弹窗 + + private boolean isHaveGoods = false;//购物车是否有商品 + + private SmartRefreshLayout refresh;//刷新布局 + private LinearLayout layEmpty;//空布局 + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + initView(); + } + + /** + * 初始化 + */ + private void initView() { + //设置亮色状态栏模式 systemUiVisibility在Android11中弃用了,可以尝试一下。 + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + + rvStore = findViewById(R.id.rv_store); + tvEdit = findViewById(R.id.tv_edit); + ivCheckedAll = findViewById(R.id.iv_checked_all); + tvTotal = findViewById(R.id.tv_total); + tvSettlement = findViewById(R.id.tv_settlement); + layEdit = findViewById(R.id.lay_edit); + tvShareGoods = findViewById(R.id.tv_share_goods); + tvCollectGoods = findViewById(R.id.tv_collect_goods); + tvDeleteGoods = findViewById(R.id.tv_delete_goods); + refresh = findViewById(R.id.refresh); + layEmpty = findViewById(R.id.lay_empty); + //禁用下拉刷新和上拉加载更多 + refresh.setEnableRefresh(false); + refresh.setEnableLoadMore(false); + //下拉刷新监听 + refresh.setOnRefreshListener(refreshLayout -> initView()); + + tvEdit.setOnClickListener(this); + ivCheckedAll.setOnClickListener(this); + tvSettlement.setOnClickListener(this); + tvShareGoods.setOnClickListener(this); + tvCollectGoods.setOnClickListener(this); + tvDeleteGoods.setOnClickListener(this); + + CarResponse carResponse = new Gson().fromJson(Constant.CAR_JSON, CarResponse.class); + + mList.addAll(carResponse.getOrderData()); + storeAdapter = new StoreAdapter(R.layout.item_store, mList, this); + rvStore.setLayoutManager(new LinearLayoutManager(this)); + rvStore.setAdapter(storeAdapter); + //店铺点击 + storeAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() { + @Override + public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { + CarResponse.OrderDataBean storeBean = mList.get(position); + if (view.getId() == R.id.iv_checked_store) { + storeBean.setChecked(!storeBean.isChecked()); + storeAdapter.notifyDataSetChanged(); + //传递选中店铺的id + if (storeBean.isChecked()) { + //全选商品 + storeAdapter.controlGoods(storeBean.getShopId(), true); + + //添加到列表中 + if (!shopIdList.contains(storeBean.getShopId())) { + //如果列表中没有这个店铺Id且当前店铺为选中状态 + shopIdList.add(storeBean.getShopId()); + } + } else { + //清除全选商品 + storeAdapter.controlGoods(storeBean.getShopId(), false); + + //从列表中清除 + if (shopIdList.contains(storeBean.getShopId())) { + shopIdList.remove((Integer) storeBean.getShopId()); + } + } + //控制页面全选 + controlAllChecked(); + } + } + }); + //有商品 + isHaveGoods = true; + //下拉加载数据完成后,关闭下拉刷新动画 + refresh.finishRefresh(); + //隐藏布局 + layEmpty.setVisibility(View.GONE); + } + + /** + * 控制页面全选 与页面全选进行交互 + */ + private void controlAllChecked() { + if (shopIdList.size() == mList.size() && mList.size() != 0) { + //全选 + ivCheckedAll.setImageDrawable(getDrawable(R.drawable.ic_checked)); + isAllChecked = true; + } else { + //不全选 + ivCheckedAll.setImageDrawable(getDrawable(R.drawable.ic_check)); + isAllChecked = false; + } + //计算价格 + calculationPrice(); + } + + /** + * 选中店铺 + * + * @param shopId 店铺id + */ + @Override + public void checkedStore(int shopId, boolean state) { + for (CarResponse.OrderDataBean bean : mList) { + //遍历 + if (shopId == bean.getShopId()) { + bean.setChecked(state); + storeAdapter.notifyDataSetChanged(); + //记录选中店铺的shopid,添加到一个列表中。 + if (!shopIdList.contains(bean.getShopId()) && state) { + //如果列表中没有这个店铺Id且当前店铺为选中状态 + shopIdList.add(bean.getShopId()); + } else { + if (shopIdList.contains(bean.getShopId())) { + //通过list.indexOf获取属性的在列表中的下标,不过强转Integer更简洁 + shopIdList.remove((Integer) bean.getShopId()); + } + } + } + } + //控制页面全选 + controlAllChecked(); + } + + + /** + * 商品价格 + */ + @Override + public void calculationPrice() { + //每次计算之前先置零 + totalPrice = 0.00; + totalCount = 0; + //循环购物车中的店铺列表 + for (int i = 0; i < mList.size(); i++) { + CarResponse.OrderDataBean orderDataBean = mList.get(i); + //循环店铺中的商品列表 + for (int j = 0; j < orderDataBean.getCartlist().size(); j++) { + CarResponse.OrderDataBean.CartlistBean cartlistBean = orderDataBean.getCartlist().get(j); + //当有选中商品时计算数量和价格 + if (cartlistBean.isChecked()) { + totalCount++; + totalPrice += cartlistBean.getPrice() * cartlistBean.getCount(); + } + } + } + tvTotal.setText("¥" + totalPrice); + tvSettlement.setText(totalCount == 0 ? "结算" : "结算(" + totalCount + ")"); + } + + /** + * 页面控件点击事件 + * + * @param v + */ + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.tv_edit://编辑 + if (!isHaveGoods) { + showMsg("当前购物车空空如也~"); + return; + } + if (isEdit) { + tvEdit.setText("编辑"); + layEdit.setVisibility(View.GONE); + isEdit = false; + } else { + tvEdit.setText("完成"); + layEdit.setVisibility(View.VISIBLE); + isEdit = true; + } + break; + case R.id.iv_checked_all://全选 + if (!isHaveGoods) { + showMsg("当前购物车空空如也~"); + return; + } + if (isAllChecked) { + //取消全选 + isSelectAllStore(false); + } else { + //全选 + isSelectAllStore(true); + } + break; + case R.id.tv_settlement://结算 + if (!isHaveGoods) { + showMsg("当前购物车空空如也~"); + return; + } + if (totalCount == 0) { + showMsg("请选择要结算的商品"); + return; + } + //弹窗 + dialog = new AlertDialog.Builder(this) + .setMessage("总计:" + totalCount + "种商品," + totalPrice + "元") + .setPositiveButton("确定", (dialog, which) -> deleteGoods()) + .setNegativeButton("取消", (dialog, which) -> dialog.dismiss()) + .create(); + dialog.show(); + break; + case R.id.tv_delete_goods://删除 + if (totalCount == 0) { + showMsg("请选择要删除的商品"); + return; + } + //弹窗 + dialog = new AlertDialog.Builder(this) + .setMessage("确定要删除所选商品吗?") + .setPositiveButton("确定", (dialog, which) -> deleteGoods()) + .setNegativeButton("取消", (dialog, which) -> dialog.dismiss()) + .create(); + dialog.show(); + break; + case R.id.tv_collect_goods://收藏 + if (totalCount == 0) { + showMsg("请选择要收藏的商品"); + return; + } + showMsg("收藏成功!"); + break; + case R.id.tv_share_goods://分享 + if (totalCount == 0) { + showMsg("请选择要分享的商品"); + return; + } + showMsg("分享成功!"); + break; + default: + break; + } + } + + /** + * 删除商品 + */ + private void deleteGoods() { + //店铺列表 + List storeList = new ArrayList<>(); + + for (int i = 0; i < mList.size(); i++) { + CarResponse.OrderDataBean store = mList.get(i); + if (store.isChecked()) { + //店铺如果选择则添加到此列表中 + storeList.add(store); + } + //商品列表 + List goodsList = new ArrayList<>(); + + List goods = store.getCartlist(); + //循环店铺中的商品列表 + for (int j = 0; j < goods.size(); j++) { + CarResponse.OrderDataBean.CartlistBean cartlistBean = goods.get(j); + //当有选中商品时添加到此列表中 + if (cartlistBean.isChecked()) { + goodsList.add(cartlistBean); + } + } + //删除商品 + goods.removeAll(goodsList); + } + //删除店铺 + mList.removeAll(storeList); + + shopIdList.clear();//删除了选中商品,清空已选择的标识 + controlAllChecked();//控制去全选 + //改变界面UI + tvEdit.setText("编辑"); + layEdit.setVisibility(View.GONE); + isEdit = false; + //刷新数据 + storeAdapter.notifyDataSetChanged(); + if (mList.size() <= 0) { + //无商品 + isHaveGoods = false; + //启用下拉刷新 + refresh.setEnableRefresh(true); + //显示空布局 + layEmpty.setVisibility(View.VISIBLE); + } + } + + /** + * 是否全选 + * + * @param state 状态 + */ + private void isSelectAllStore(boolean state) { + //修改背景 + ivCheckedAll.setImageDrawable(getDrawable(state ? R.drawable.ic_checked : R.drawable.ic_check)); + + for (CarResponse.OrderDataBean orderDataBean : mList) { + //商品是否选中 + storeAdapter.controlGoods(orderDataBean.getShopId(), state); + //店铺是否选中 + checkedStore(orderDataBean.getShopId(), state); + } + isAllChecked = state; + } + + /** + * Toast提示 + * + * @param msg + */ + private void showMsg(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + +} diff --git a/main/java/com/llw/cart/adapter/GoodsAdapter.java b/main/java/com/llw/cart/adapter/GoodsAdapter.java new file mode 100644 index 0000000..a0986d4 --- /dev/null +++ b/main/java/com/llw/cart/adapter/GoodsAdapter.java @@ -0,0 +1,49 @@ +package com.llw.cart.adapter; + +import android.view.View; +import android.widget.ImageView; + +import androidx.annotation.Nullable; + +import com.bumptech.glide.Glide; +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.llw.cart.bean.CarResponse; +import com.llw.cart.R; + +import java.util.List; + +/** + * 商品适配器 + * + * @author llw + */ +public class GoodsAdapter extends BaseQuickAdapter { + + public GoodsAdapter(int layoutResId, @Nullable List data) { + super(layoutResId, data); + } + + @Override + protected void convert(BaseViewHolder helper, CarResponse.OrderDataBean.CartlistBean item) { + helper.setText(R.id.tv_good_name, item.getProductName()) + .setText(R.id.tv_good_color, item.getColor()) + .setText(R.id.tv_good_size, item.getSize()) + .setText(R.id.tv_goods_price, item.getPrice() + "") + .setText(R.id.tv_goods_num, item.getCount() + ""); + ImageView goodImg = helper.getView(R.id.iv_goods); + + + ImageView checkedGoods = helper.getView(R.id.iv_checked_goods); + //判断商品是否选中 + if (item.isChecked()) { + checkedGoods.setImageDrawable(mContext.getDrawable(R.drawable.ic_checked)); + } else { + checkedGoods.setImageDrawable(mContext.getDrawable(R.drawable.ic_check)); + } + //添加点击事件 + helper.addOnClickListener(R.id.iv_checked_goods)//选中商品 + .addOnClickListener(R.id.tv_increase_goods_num)//增加商品 + .addOnClickListener(R.id.tv_reduce_goods_num);//减少商品 + } +} diff --git a/main/java/com/llw/cart/adapter/StoreAdapter.java b/main/java/com/llw/cart/adapter/StoreAdapter.java new file mode 100644 index 0000000..bf4d4c6 --- /dev/null +++ b/main/java/com/llw/cart/adapter/StoreAdapter.java @@ -0,0 +1,155 @@ +package com.llw.cart.adapter; + +import android.view.View; +import android.widget.ImageView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.llw.cart.MainActivity; +import com.llw.cart.bean.CarResponse; +import com.llw.cart.R; +import com.llw.cart.util.GoodsCallback; + +import java.util.List; + +/** + * 店铺适配器 + * + * @author llw + */ +public class StoreAdapter extends BaseQuickAdapter { + + private RecyclerView rvGood; + //商品回调 + private GoodsCallback goodsCallback; + //店铺对象 + private List storeBean; + + public StoreAdapter(int layoutResId, @Nullable List data, GoodsCallback goodsCallback) { + super(layoutResId, data); + this.goodsCallback = goodsCallback; + storeBean = data;//赋值 + } + + @Override + protected void convert(BaseViewHolder helper, final CarResponse.OrderDataBean item) { + + rvGood = helper.getView(R.id.rv_goods); + helper.setText(R.id.tv_store_name, item.getShopName()); + + ImageView checkedStore = helper.getView(R.id.iv_checked_store); + if (item.isChecked()) { + checkedStore.setImageDrawable(mContext.getDrawable(R.drawable.ic_checked)); + } else { + checkedStore.setImageDrawable(mContext.getDrawable(R.drawable.ic_check)); + } + //点击事件 + helper.addOnClickListener(R.id.iv_checked_store);//选中店铺 + + + final GoodsAdapter goodsAdapter = new GoodsAdapter(R.layout.item_good, item.getCartlist()); + rvGood.setLayoutManager(new LinearLayoutManager(mContext)); + rvGood.setAdapter(goodsAdapter); + + //商品item中的点击事件 + goodsAdapter.setOnItemChildClickListener(new OnItemChildClickListener() { + @Override + public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { + CarResponse.OrderDataBean.CartlistBean goodsBean = item.getCartlist().get(position); + + switch (view.getId()) { + case R.id.iv_checked_goods://选中商品 + //如果已选中则取消选中,未选中则选中 + goodsBean.setChecked(!goodsBean.isChecked()); + //刷新适配器 + goodsAdapter.notifyDataSetChanged(); + //控制店铺是否选中 + controlStore(item); + //商品控制价格 + goodsCallback.calculationPrice(); + break; + case R.id.tv_increase_goods_num://增加商品数量 + updateGoodsNum(goodsBean, goodsAdapter,true); + break; + case R.id.tv_reduce_goods_num://减少商品数量 + updateGoodsNum(goodsBean, goodsAdapter,false); + break; + default: + break; + } + } + }); + + } + + /** + * 修改商品数量 增加或者减少 + * @param goodsBean + * @param goodsAdapter + * @param state true增加 false减少 + */ + private void updateGoodsNum(CarResponse.OrderDataBean.CartlistBean goodsBean, GoodsAdapter goodsAdapter,boolean state) { + //其实商品应该还有一个库存值或者其他的限定值,我这里写一个假的库存值为10 + int inventory = 10; + int count = goodsBean.getCount(); + + if(state){ + if (count >= inventory){ + Toast.makeText(mContext,"商品数量不可超过库存值~",Toast.LENGTH_SHORT).show(); + return; + } + count++; + }else { + if (count <= 1){ + Toast.makeText(mContext,"已是最低商品数量~",Toast.LENGTH_SHORT).show(); + return; + } + count--; + } + goodsBean.setCount(count);//设置商品数量 + //刷新适配器 + goodsAdapter.notifyDataSetChanged(); + //计算商品价格 + goodsCallback.calculationPrice(); + } + + /** + * 控制店铺是否选中 + */ + private void controlStore(CarResponse.OrderDataBean item) { + int num = 0; + for (CarResponse.OrderDataBean.CartlistBean bean : item.getCartlist()) { + if (bean.isChecked()) { + ++num; + } + } + if (num == item.getCartlist().size()) { + //全选中 传递需要选中的店铺的id过去 + goodsCallback.checkedStore(item.getShopId(), true); + } else { + goodsCallback.checkedStore(item.getShopId(), false); + } + } + + /** + * 控制商品是否选中 + */ + public void controlGoods(int shopId, boolean state) { + //根据店铺id选中该店铺下所有商品 + for (CarResponse.OrderDataBean orderDataBean : storeBean) { + //店铺id等于传递过来的店铺id 则选中该店铺下所有商品 + if (orderDataBean.getShopId() == shopId) { + for (CarResponse.OrderDataBean.CartlistBean cartlistBean : orderDataBean.getCartlist()) { + cartlistBean.setChecked(state); + //刷新 + notifyDataSetChanged(); + } + } + } + } +} diff --git a/main/java/com/llw/cart/bean/CarResponse.java b/main/java/com/llw/cart/bean/CarResponse.java new file mode 100644 index 0000000..236bb79 --- /dev/null +++ b/main/java/com/llw/cart/bean/CarResponse.java @@ -0,0 +1,196 @@ +package com.llw.cart.bean; + +import java.util.List; + +/** + * 购物车返回数据 + * @author llw + */ +public class CarResponse { + + + /** + * code : 200 + * orderData : [{"shopId":1,"shopName":"京东自营","cartlist":[{"id":1,"shopId":1,"shopName":"京东自营","defaultPic":"https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg","productId":1,"productName":"三只松鼠_零食大礼包","color":"黑色","size":"18L","price":20,"count":1},{"id":2,"shopId":1,"shopName":"京东自营","defaultPic":"https://img14.360buyimg.com/n0/jfs/t2971/15/167732091/93002/204c1016/574d9d9aNe4e6fa7a.jpg","productId":2,"productName":"小米心跳手环","color":"白色","size":"20XXL","price":148,"count":1}]},{"shopId":2,"shopName":"海澜之家","cartlist":[{"id":1,"shopId":2,"shopName":"海澜之家","defaultPic":"https://img30.360buyimg.com/popWaterMark/jfs/t4075/83/1343091204/132469/9034cb9c/5873496bN68020ba8.jpg","productId":1,"productName":"短袖T恤男 2017夏季新品","color":"蓝色","size":"30X","price":181,"count":1}]},{"shopId":3,"shopName":"OPPO官方旗舰店","cartlist":[{"id":1,"shopId":3,"shopName":"OPPO官方旗舰店","defaultPic":"https://img10.360buyimg.com/cms/jfs/t6064/272/2163314583/157700/442d6477/593c1c49N7c63a7d9.jpg","productId":1,"productName":"OPPO R11 全网通","color":"蓝色","size":"30X","price":1999,"count":1},{"id":2,"shopId":3,"shopName":"OPPO官方旗舰店","defaultPic":"https://img14.360buyimg.com/n0/jfs/t3142/194/4953241722/254855/1651c2b1/585b9021Nf653e48a.jpg","productId":1,"productName":"OPPO R9 全网通","color":"蓝色","size":"30X","price":999,"count":1}]}] + */ + + + private int code; + private List orderData; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getOrderData() { + return orderData; + } + + public void setOrderData(List orderData) { + this.orderData = orderData; + } + + public static class OrderDataBean { + /** + * shopId : 1 + * shopName : 京东自营 + * cartlist : [{"id":1,"shopId":1,"shopName":"京东自营","defaultPic":"https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg","productId":1,"productName":"三只松鼠_零食大礼包","color":"黑色","size":"18L","price":20,"count":1},{"id":2,"shopId":1,"shopName":"京东自营","defaultPic":"https://img14.360buyimg.com/n0/jfs/t2971/15/167732091/93002/204c1016/574d9d9aNe4e6fa7a.jpg","productId":2,"productName":"小米心跳手环","color":"白色","size":"20XXL","price":148,"count":1}] + */ + + private int shopId; + private String shopName; + private List cartlist; + private boolean isChecked;//店铺是否选中 + + public int getShopId() { + return shopId; + } + + public void setShopId(int shopId) { + this.shopId = shopId; + } + + public String getShopName() { + return shopName; + } + + public void setShopName(String shopName) { + this.shopName = shopName; + } + + public List getCartlist() { + return cartlist; + } + + public void setCartlist(List cartlist) { + this.cartlist = cartlist; + } + + public boolean isChecked() { + return isChecked; + } + + public void setChecked(boolean checked) { + isChecked = checked; + } + + public static class CartlistBean { + /** + * id : 1 + * shopId : 1 + * shopName : 京东自营 + * defaultPic : https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg + * productId : 1 + * productName : 三只松鼠_零食大礼包 + * color : 黑色 + * size : 18L + * price : 20 + * count : 1 + */ + + private int id; + private int shopId; + private String shopName; + private String defaultPic; + private int productId; + private String productName; + private String color; + private String size; + private int price; + private int count; + private boolean isChecked;//商品是否选中 + + public boolean isChecked() { + return isChecked; + } + + public void setChecked(boolean checked) { + isChecked = checked; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getShopId() { + return shopId; + } + + public void setShopId(int shopId) { + this.shopId = shopId; + } + + public String getShopName() { + return shopName; + } + + public void setShopName(String shopName) { + this.shopName = shopName; + } + + public String getDefaultPic() { + return defaultPic; + } + + public void setDefaultPic(String defaultPic) { + this.defaultPic = defaultPic; + } + + public int getProductId() { + return productId; + } + + public void setProductId(int productId) { + this.productId = productId; + } + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + } + } +} diff --git a/main/java/com/llw/cart/util/Constant.java b/main/java/com/llw/cart/util/Constant.java new file mode 100644 index 0000000..92125cc --- /dev/null +++ b/main/java/com/llw/cart/util/Constant.java @@ -0,0 +1,101 @@ +package com.llw.cart.util; + +/** + * 常量 + * @author llw + */ +public class Constant { + + public static final String CAR_JSON = "{ \"code\" : 200 ,\n" + + " \"orderData\" : [\n" + + " {\n" + + "\n" + + " \"shopId\": 1,\n" + + " \"shopName\":\"小黄の店铺\",\n" + + " \"cartlist\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"shopId\": 1,\n" + + " \"shopName\": \"小黄の店铺\",\n" + + " \"productId\": 1,\n" + + " \"productName\": \"QQㄋㄟㄋㄟ好喝到咩噗茶\",\n" + + " \"color\": \"无\",\n" + + " \"size\": \"600ml\",\n" + + " \"price\": 20,\n" + + " \"count\":1\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"shopId\": 1,\n" + + " \"shopName\": \"小黄の店铺\",\n" + + " \"productId\": 1,\n" + + " \"productName\": \"银耀石手串\",\n" + + " \"color\": \"无\",\n" + + " \"size\": \"8mm\",\n" + + " \"price\": 20,\n" + + " \"count\":1\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"shopId\": 1,\n" + + " \"shopName\": \"小黄の店铺\",\n" + + " \"productId\": 2,\n" + + " \"productName\": \"菩提手串\",\n" + + " \"color\": \"白色\",\n" + + " \"size\": \"9mm\",\n" + + " \"price\": 50,\n" + + " \"count\": 1\n" + + " }\n" + + " ]\n" + + " }\n" + + " ,\n" + + " {\n" + + " \"shopId\": 2,\n" + + " \"shopName\":\"手办之家\",\n" + + " \"cartlist\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"shopId\": 2,\n" + + " \"shopName\": \"手办之家\",\n" + + " \"productId\": 1,\n" + + " \"productName\": \"坂田银时 2023夏季新品\",\n" + + " \"color\": \"无\",\n" + + " \"size\": \"1/8\",\n" + + " \"price\": 999,\n" + + " \"count\":1\n" + + " }\n" + + " ]\n" + + " }\n" + + " ,\n" + + " {\n" + + " \"shopId\": 3,\n" + + " \"shopName\":\"小孙杂货铺\",\n" + + " \"cartlist\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"shopId\": 3,\n" + + " \"shopName\": \"小孙杂货铺\",\n" + + " \"productId\": 1,\n" + + " \"productName\": \"《广陵夜阙》\",\n" + + " \"color\": \"装订本\",\n" + + " \"size\": \"珍藏版\",\n" + + " \"price\": 188,\n" + + " \"count\":1\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"shopId\": 3,\n" + + " \"shopName\": \"小孙杂货铺\",\n" + + " \"productId\": 1,\n" + + " \"productName\": \"《春风夜夜周郎便》\",\n" + + " \"color\": \"合订本\",\n" + + " \"size\": \"珍藏签名版\",\n" + + " \"price\": 216,\n" + + " \"count\":1\n" + + " }\n" + + " ]\n" + + " }\n" + + "\n" + + " ]\n" + + "}"; +} diff --git a/main/java/com/llw/cart/util/GoodsCallback.java b/main/java/com/llw/cart/util/GoodsCallback.java new file mode 100644 index 0000000..7e52b75 --- /dev/null +++ b/main/java/com/llw/cart/util/GoodsCallback.java @@ -0,0 +1,21 @@ +package com.llw.cart.util; + + +/** + * 商品回调接口 + * @author llw + */ +public interface GoodsCallback { + + /** + * 选中店铺 + * @param shopId 店铺id + * @param state 是否选中 + */ + void checkedStore(int shopId,boolean state); + + /** + * 计算价格 + */ + void calculationPrice(); +} diff --git a/main/res/drawable-v24/ic_launcher_foreground.xml b/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/main/res/drawable/beijing.jpg b/main/res/drawable/beijing.jpg new file mode 100644 index 0000000..215fd3e Binary files /dev/null and b/main/res/drawable/beijing.jpg differ diff --git a/main/res/drawable/bg.png b/main/res/drawable/bg.png new file mode 100644 index 0000000..06340c2 Binary files /dev/null and b/main/res/drawable/bg.png differ diff --git a/main/res/drawable/bg1.png b/main/res/drawable/bg1.png new file mode 100644 index 0000000..de33b20 Binary files /dev/null and b/main/res/drawable/bg1.png differ diff --git a/main/res/drawable/bg_goods_num.xml b/main/res/drawable/bg_goods_num.xml new file mode 100644 index 0000000..7ef60a2 --- /dev/null +++ b/main/res/drawable/bg_goods_num.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/main/res/drawable/bg_increase_goods_num.xml b/main/res/drawable/bg_increase_goods_num.xml new file mode 100644 index 0000000..d049da2 --- /dev/null +++ b/main/res/drawable/bg_increase_goods_num.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/main/res/drawable/bg_reduce_goods_num.xml b/main/res/drawable/bg_reduce_goods_num.xml new file mode 100644 index 0000000..f071253 --- /dev/null +++ b/main/res/drawable/bg_reduce_goods_num.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/main/res/drawable/bg_settlement.xml b/main/res/drawable/bg_settlement.xml new file mode 100644 index 0000000..be029bd --- /dev/null +++ b/main/res/drawable/bg_settlement.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/main/res/drawable/bg_white_8.xml b/main/res/drawable/bg_white_8.xml new file mode 100644 index 0000000..5adf7f0 --- /dev/null +++ b/main/res/drawable/bg_white_8.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/res/drawable/ic_check.xml b/main/res/drawable/ic_check.xml new file mode 100644 index 0000000..c3f13f5 --- /dev/null +++ b/main/res/drawable/ic_check.xml @@ -0,0 +1,10 @@ + + + + diff --git a/main/res/drawable/ic_checked.xml b/main/res/drawable/ic_checked.xml new file mode 100644 index 0000000..9d7471b --- /dev/null +++ b/main/res/drawable/ic_checked.xml @@ -0,0 +1,10 @@ + + + + diff --git a/main/res/drawable/ic_launcher_background.xml b/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/res/drawable/ic_shopping_cart.xml b/main/res/drawable/ic_shopping_cart.xml new file mode 100644 index 0000000..6c489be --- /dev/null +++ b/main/res/drawable/ic_shopping_cart.xml @@ -0,0 +1,11 @@ + + + + diff --git a/main/res/drawable/tu.jpg b/main/res/drawable/tu.jpg new file mode 100644 index 0000000..fd0d5f7 Binary files /dev/null and b/main/res/drawable/tu.jpg differ diff --git a/main/res/layout/activity_main.xml b/main/res/layout/activity_main.xml new file mode 100644 index 0000000..26ee348 --- /dev/null +++ b/main/res/layout/activity_main.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/item_good.xml b/main/res/layout/item_good.xml new file mode 100644 index 0000000..3b72cf4 --- /dev/null +++ b/main/res/layout/item_good.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/item_store.xml b/main/res/layout/item_store.xml new file mode 100644 index 0000000..9c86de0 --- /dev/null +++ b/main/res/layout/item_store.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/mipmap-anydpi-v26/ic_launcher.xml b/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/res/mipmap-hdpi/ic_launcher.png b/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..898f3ed Binary files /dev/null and b/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/main/res/mipmap-hdpi/ic_launcher_round.png b/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..dffca36 Binary files /dev/null and b/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-mdpi/ic_launcher.png b/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..64ba76f Binary files /dev/null and b/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/main/res/mipmap-mdpi/ic_launcher_round.png b/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..dae5e08 Binary files /dev/null and b/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xhdpi/ic_launcher.png b/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..e5ed465 Binary files /dev/null and b/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xhdpi/ic_launcher_round.png b/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..14ed0af Binary files /dev/null and b/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xxhdpi/ic_launcher.png b/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b0907ca Binary files /dev/null and b/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxhdpi/ic_launcher_round.png b/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..d8ae031 Binary files /dev/null and b/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xxxhdpi/ic_launcher.png b/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..2c18de9 Binary files /dev/null and b/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..beed3cd Binary files /dev/null and b/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml new file mode 100644 index 0000000..60c7b79 --- /dev/null +++ b/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #FFF + #FFF + #D81B60 + diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml new file mode 100644 index 0000000..5e7c5c6 --- /dev/null +++ b/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + ShoppingCart + diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml new file mode 100644 index 0000000..0eb88fe --- /dev/null +++ b/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/main/res/xml/network_config.xml b/main/res/xml/network_config.xml new file mode 100644 index 0000000..dca93c0 --- /dev/null +++ b/main/res/xml/network_config.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file