购物车列表及确认订单页面 - 相关代码(三)

前言

购物车系列文章:
购物车列表及确认订单页面 - 技术分析(一)
购物车列表及确认订单页面 - 相关代码(二)
购物车列表及确认订单页面 - 相关代码(三)
购物车列表及确认订单页面 - 部分知识点思路解析(四)

3>:用Gson解析之后的 ShopCartListBean
public class ShopCartListBean implements Serializable{
    /**
     * msg : 查看成功
     * code : 0
     * data : [{"merchantCode":"3","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试1","id":22,"userId":32,"productList":[{"cartSum":1,"couponOriginalCost":"50","couponName":"哇哇哇哇哇","addTime":1536633418000,"productImg":"5131.png,5132.png,5133.png","currentPrice":"3880","title":"海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口"},{"cartSum":1,"couponOriginalCost":"200","couponName":"小小苏","addTime":1536633440000,"productImg":"6111.png,6112.png,6113.png","currentPrice":"6900","title":"灭蚊灯家用室内插电式一扫光驱蚊器防蚊灭蚊神器婴儿捕蚊子全自动"},{"cartSum":1,"addTime":1536633428000,"productImg":"5161.png,5162.png,5163.png","currentPrice":"23800","title":"得力9939碎纸机办公迷你家用颗粒电动小型大功率纸张文件粉碎机"},{"cartSum":1,"addTime":1536633434000,"productImg":"6121.png,6122.png,6123.png","currentPrice":"8900","title":"德国灭蚊灯室内一扫光插电式驱蚊器防蚊神器无辐射静音婴儿全自动"}]},{"merchantCode":"4","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试2","id":23,"userId":32,"productList":[{"cartSum":1,"addTime":1536633423000,"productImg":"5141.png,5142.png,5143.png","currentPrice":"3980","title":"HP/惠普S1000无线鼠标静音无声男女生电脑办公笔记本台式无限游戏"}]},{"merchantCode":"5","isLatest":0,"isDeleted":0,"isEnabled":0,"businessName":"北京测试3","id":24,"userId":32,"productList":[{"cartSum":1,"couponOriginalCost":"100","couponName":"嘤嘤嘤","addTime":1536633514000,"productImg":"5151.png,5152.png,5153.png","currentPrice":"79900","title":"康亿B类点钞机新版人民币验钞机银行专用小型便携式办公家用商用"}]}]
     * totalCount : 3
     */

    private String msg;
    private String code;
//    private int totalCount;
    private List data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

   /*public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }*/

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public static class DataBean {
        /**
         * merchantCode : 3
         * isLatest : 0
         * isDeleted : 0
         * isEnabled : 0
         * businessName : 北京测试1
         * id : 22
         * userId : 32
         * productList : [{"cartSum":1,"couponOriginalCost":"50","couponName":"哇哇哇哇哇","addTime":1536633418000,"productImg":"5131.png,5132.png,5133.png","currentPrice":"3880","title":"海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口"},{"cartSum":1,"couponOriginalCost":"200","couponName":"小小苏","addTime":1536633440000,"productImg":"6111.png,6112.png,6113.png","currentPrice":"6900","title":"灭蚊灯家用室内插电式一扫光驱蚊器防蚊灭蚊神器婴儿捕蚊子全自动"},{"cartSum":1,"addTime":1536633428000,"productImg":"5161.png,5162.png,5163.png","currentPrice":"23800","title":"得力9939碎纸机办公迷你家用颗粒电动小型大功率纸张文件粉碎机"},{"cartSum":1,"addTime":1536633434000,"productImg":"6121.png,6122.png,6123.png","currentPrice":"8900","title":"德国灭蚊灯室内一扫光插电式驱蚊器防蚊神器无辐射静音婴儿全自动"}]
         */

        private String merchantCode;
        private int isLatest;
        private int isDeleted;
        private int isEnabled;
        private String businessName;
        private int id;
        private int userId;
        private List productList;

        public String getMerchantCode() {
            return merchantCode;
        }

        public void setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
        }

        public int getIsLatest() {
            return isLatest;
        }

        public void setIsLatest(int isLatest) {
            this.isLatest = isLatest;
        }

        public int getIsDeleted() {
            return isDeleted;
        }

        public void setIsDeleted(int isDeleted) {
            this.isDeleted = isDeleted;
        }

        public int getIsEnabled() {
            return isEnabled;
        }

        public void setIsEnabled(int isEnabled) {
            this.isEnabled = isEnabled;
        }

        public String getBusinessName() {
            return businessName;
        }

        public void setBusinessName(String businessName) {
            this.businessName = businessName;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getUserId() {
            return userId;
        }

        public void setUserId(int userId) {
            this.userId = userId;
        }

        public List getProductList() {
            return productList;
        }

        public void setProductList(List productList) {
            this.productList = productList;
        }

        public static class ProductListBean {
            /**
             * cartSum : 1
             * couponOriginalCost : 50
             * couponName : 哇哇哇哇哇
             * addTime : 1536633418000
             * productImg : 5131.png,5132.png,5133.png
             * currentPrice : 3880
             * title : 海志Q1复古圆键帽有线键盘无线静音巧克力办公家用笔记本USB接口
             */

            private int cartSum;
            private String couponOriginalCost;
            private String couponName;
            private long addTime;
            private String productImg;
            private String currentPrice;
            private String title;

            public int getMerchantId() {
                return merchantId;
            }

            public void setMerchantId(int merchantId) {
                this.merchantId = merchantId;
            }

            private int merchantId ;

            public int getCartSum() {
                return cartSum;
            }

            public void setCartSum(int cartSum) {
                this.cartSum = cartSum;
            }

            public String getCouponOriginalCost() {
                return couponOriginalCost;
            }

            public void setCouponOriginalCost(String couponOriginalCost) {
                this.couponOriginalCost = couponOriginalCost;
            }

            public String getCouponName() {
                return couponName;
            }

            public void setCouponName(String couponName) {
                this.couponName = couponName;
            }

            public long getAddTime() {
                return addTime;
            }

            public void setAddTime(long addTime) {
                this.addTime = addTime;
            }

            public String getProductImg() {
                return productImg;
            }

            public void setProductImg(String productImg) {
                this.productImg = productImg;
            }

            public String getCurrentPrice() {
                return currentPrice;
            }

            public void setCurrentPrice(String currentPrice) {
                this.currentPrice = currentPrice;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}
4>:组装数据的MiddleBean
public class MiddleBean implements Serializable{
    private String msg;
    private String code;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    private List data ;

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    // 店鋪
    public static class StoreInfo implements Serializable{

        // 商家id
        private String id;
        private String name;
        private boolean isChoosed;
        private boolean isEditor; //自己对该组的编辑状态
        private boolean ActionBarEditor;// 全局对该组的编辑状态
        private List goodses ;

        // 商家编码
        private String merchantCode;

        public StoreInfo(){

        }
        public StoreInfo(String id, String merchantCode,String name) {
            this.id = id;
            this.merchantCode = merchantCode ;
            this.name = name;
        }



        public String getMerchantCode() {
            return merchantCode;
        }

        public void setMerchantCode(String merchantCode) {
            this.merchantCode = merchantCode;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isChoosed() {
            return isChoosed;
        }

        public void setChoosed(boolean choosed) {
            isChoosed = choosed;
        }

        public boolean isEditor() {
            return isEditor;
        }

        public void setEditor(boolean editor) {
            isEditor = editor;
        }

        public boolean isActionBarEditor() {
            return ActionBarEditor;
        }

        public void setActionBarEditor(boolean actionBarEditor) {
            ActionBarEditor = actionBarEditor;
        }

        public List getGoodses() {
            return goodses;
        }

        public void setGoodses(List goodses) {
            this.goodses = goodses;
        }


        // 商品
        public static class GoodsInfo implements Serializable{

        // 店铺id
        private String stroeId ;

            public String getStroeId() {
                return stroeId;
            }

            public void setStroeId(String stroeId) {
                this.stroeId = stroeId;
            }

            // 商品id
        private String id;
        private String name;
        private boolean isChoosed;
        private String imageUrl;
        private String desc;
        private double price;
        private double prime_price;
        private int postion;
        private int count;
        private String color;
        private String size;
        private int goodsImg;

            private StoreInfo storeInfo ;

            public StoreInfo getStoreInfo() {
                return storeInfo;
            }

            public void setStoreInfo(StoreInfo storeInfo) {
                this.storeInfo = storeInfo;
            }

            public GoodsInfo(){

            }
        public GoodsInfo( String stroeId , String id, String name, String desc,double price, double prime_price,
                         String color, String size, int goodsImg,int count) {
            this.stroeId = stroeId ;
            this.id = id;
            this.name = name;
            this.desc = desc;
            this.price = price;
            this.prime_price = prime_price;
            this.color = color;
            this.size = size;
            this.goodsImg = goodsImg;
            this.count = count;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isChoosed() {
            return isChoosed;
        }

        public void setChoosed(boolean choosed) {
            isChoosed = choosed;
        }

        public String getImageUrl() {
            return imageUrl;
        }

        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public double getPrime_price() {
            return prime_price;
        }

        public void setPrime_price(double prime_price) {
            this.prime_price = prime_price;
        }

        public int getPostion() {
            return postion;
        }

        public void setPostion(int postion) {
            this.postion = postion;
        }

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }

        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 getGoodsImg() {
            return goodsImg;
        }

        public void setGoodsImg(int goodsImg) {
            this.goodsImg = goodsImg;
        }
    }

    }
}
5>:确认订单页面:GoPayCartActivity:
public class GoPayCartActivity extends AppCompatActivity {

    private ListView listView;
    private RelativeLayout layout_title_left;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_pay_cart);

        initView() ;
    }

    private void initView() {
        layout_title_left = (RelativeLayout) findViewById(R.id.layout_title_left);


        // 传递过来选中的商品和店铺的集合数据
        List listConfirm = (List) getIntent().getSerializableExtra("listConfirm");
        listView = (ListView) findViewById(R.id.listView);
        ParentShopCartAdapter shopCartAdapter= new ParentShopCartAdapter(GoPayCartActivity.this, listConfirm);
        listView.setAdapter(shopCartAdapter);


        layout_title_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
6>:店铺的 ParentShopCartAdapter
public class ParentShopCartAdapter  extends BaseAdapter {


    private Context context ;
    private List listConfirm ;

    double mtempTotalPrice = 0.00;
    int mtempTotalCount = 0 ;


    public ParentShopCartAdapter(Context context , List listConfirm){
        this.context = context ;
        this.listConfirm = listConfirm ;
        Log.e("TAG" , "ParentShopCartAdapter: "+listConfirm.size()) ;
    }

    @Override
    public int getCount() {
        return listConfirm.size();
    }

    @Override
    public Object getItem(int position) {
        return listConfirm.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = View.inflate(context, R.layout.item_parent_shopcat, null);  //  module_listview_item

            holder.tv_shop_name = (TextView) convertView.findViewById(R.id.tv_shop_name);
            holder.child_shopcat_lv = (MyListView) convertView.findViewById(R.id.child_shopcat_lv);
            holder.tv_total_shop = (TextView) convertView.findViewById(R.id.tv_total_shop);
            holder.tv_price_2 = (TextView) convertView.findViewById(R.id.tv_price_2);
            convertView.setTag(holder);

        } else {
            holder = (Holder) convertView.getTag();
        }

        mtempTotalPrice = 0.00;
        mtempTotalCount = 0;

//        Log.e("TAG" , "getView: "+listConfirm.get(position).getName()) ;

        holder.tv_shop_name.setText(listConfirm.get(position).getName());
        List goodses = listConfirm.get(position).getGoodses();
        for (int i = 0; i < goodses.size(); i++) {
            int count = goodses.get(i).getCount();
            double price = goodses.get(i).getPrice();
            mtempTotalCount++;
            mtempTotalPrice += price*count ;
        }
        Log.e("TAG" , "填充数据:mtempTotalCount:"+mtempTotalCount+", mtempTotalPrice:"+mtempTotalPrice) ;
        if (goodses != null && goodses.size() > 0) {
            holder.child_shopcat_lv.setAdapter(new ChildShopCartAdapter(context, listConfirm,goodses));
        }

        holder.tv_total_shop.setText("共"+mtempTotalCount+"件商品");
        holder.tv_price_2.setText(mtempTotalPrice+"");
        return convertView;
    }

    class Holder {
        TextView tv_shop_name,tv_total_shop,tv_price_2 ;
        MyListView child_shopcat_lv ;
    }
}

你可能感兴趣的:(购物车列表及确认订单页面 - 相关代码(三))