天天看点

MVP购物车订单

//依赖

compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.facebook.fresco:fresco:1.5.0'
compile 'com.jcodecraeer:xrecyclerview:1.3.2'      

//权限

<uses-permission android:name="android.permission.INTERNET" />      

//购物车的M层

//接口IShopModel

package model;
import java.util.Map;
import presenter.IShopPresenter;
public interface IShopModel {
    void getCarInfo(String path, Map<String,String> map, IShopPresenter iShopPresenter);
}
      
//ShopModel      
package model;
import com.google.gson.Gson;
import java.util.Map;
import bean.ShoppCarBean;
import presenter.IShopPresenter;
import utils.OkHttpUtils;
import utils.OnFinishListener;

public class ShopModel implements IShopModel{
    private OkHttpUtils okHttpUtils;
    @Override
    public void getCarInfo(String path, Map<String, String> map, final IShopPresenter iShopPresenter) {
        //创建对象
        okHttpUtils = OkHttpUtils.getInData();
        okHttpUtils.doGet(path, map, new OnFinishListener() {
            @Override
            public void onFailed(String msg) {
                iShopPresenter.onFailed(msg);
            }

            @Override
            public void onSuccess(Object obj) {
                Gson gson=new Gson();
                ShoppCarBean shoppCarBean = gson.fromJson(obj.toString(), ShoppCarBean.class);
                iShopPresenter.onSuccess(shoppCarBean.getData());
            }
        });

    }
}      

//购物车的P层

//IShopPresenter

package presenter;
import java.util.List;
import java.util.Map;
import bean.ShoppCarBean;

public interface IShopPresenter {
    void onSuccess(List<ShoppCarBean.DataBean> data);
    void onFailed(String msg);
    void onDestory();
    void getCarInfo(String path, Map<String,String> map);
}
      

//ShopPresenter

package presenter;
import java.util.List;
import java.util.Map;
import bean.ShoppCarBean;
import model.IShopModel;
import model.ShopModel;
import view.activity.IMainView;

public class ShopPresenter implements IShopPresenter {
    private IMainView iMainView;
    private IShopModel iShopModel;
    public ShopPresenter(IMainView iMainView) {
        this.iMainView = iMainView;
        iShopModel=new ShopModel();
    }
    @Override
    public void getCarInfo(String path, Map<String, String> map) {
        iShopModel.getCarInfo(path,map,this);
    }

    @Override
    public void onSuccess(List<ShoppCarBean.DataBean> data) {
        if(iMainView!=null){
            iMainView.onSuccess(data);
        }
    }

    @Override
    public void onFailed(String msg) {
        if(iMainView!=null){
            iMainView.onFailed(msg);
        }
    }

    @Override
    public void onDestory() {
        if(iMainView!=null){
            iMainView=null;
        }
    }
}
      

//购物车的V层

//IMainView

package view.activity;
import java.util.List;
import bean.ShoppCarBean;      
public interface IMainView {
    void onSuccess(List<ShoppCarBean.DataBean> data);
    void onFailed(String msg);
}
      
//MainActivity      
package view.activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import bawei.com.gouwuche_demo2.R;
import bean.ShoppCarBean;
import presenter.IShopPresenter;
import presenter.ShopPresenter;
import view.adapter.MyExpandAdapter;
public class MainActivity extends AppCompatActivity implements IMainView, MyExpandAdapter.addJian, MyExpandAdapter.isChecked {
    private ExpandableListView expandList;
    private IShopPresenter iShopPresenter;
    private Map<String, String> map;
    private MyExpandAdapter adapter;
    private List<ShoppCarBean.DataBean> list;
    private CheckBox btnCheckAll;
    private TextView tvTotalPrice;
    private TextView btnEditor;//编辑
    //默认是false
    private boolean flag;
    private int count = 0;
    private double price = 0.00;
    private TextView btnAmount;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //隐藏标题(actionbar)
        getSupportActionBar().hide();
        //找控件的方法
        initView();
        expandList.setAdapter(adapter);
        //加减
        adapter.setAddJian(this);
        //判断商家和商品是否选中状态
        adapter.setIsChecked(this);

        //全选点击监听事件
        btnCheckAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isCheckedAll(((CheckBox) view).isChecked());
                setTvTotalPrice();
            }
        });
    }
    private void initView() {
        expandList = (ExpandableListView) findViewById(R.id.expandList);
        btnCheckAll = (CheckBox) findViewById(R.id.btnCheckAll);
        tvTotalPrice = (TextView) findViewById(R.id.tvTotalPrice);
        btnAmount = (TextView) findViewById(R.id.btnAmount);
        btnAmount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
        //编辑按钮
        btnEditor = (TextView) findViewById(R.id.btnEditor);
        //编辑
        btnEditor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!flag) {
                    flag = true;
                    btnEditor.setText("完成");
                    adapter.showDeleteButton(flag);
                } else {
                    flag = false;
                    btnEditor.setText("编辑");
                    adapter.showDeleteButton(flag);
                }
            }
        });
        //创建P层对象
        iShopPresenter = new ShopPresenter(this);
        //创建map集合
        map = new HashMap<>();
        //存放uid
        map.put("uid", "4582");
        //调用接口中的请求网络的方法
        iShopPresenter.getCarInfo("https://www.zhaoapi.cn/product/getCarts", map);
        //创建适配器
        adapter = new MyExpandAdapter(this);
    }
    //成功
    @Override
    public void onSuccess(List<ShoppCarBean.DataBean> data) {

        this.list = data;
        adapter.setList(list);

        //调用展开的方法
        zhankai();
    }

    //展开的方法(默认展开)
    private void zhankai() {
        for (int i = 0; i < adapter.getGroupCount(); i++) {
            expandList.expandGroup(i);
        }
    }
    //失败
    @Override
    public void onFailed(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
    //商品数量加的方法
    @Override
    public void add(int groupPosition, int childPosition) {
        ShoppCarBean.DataBean.ListBean listBean = list.get(groupPosition).getList().get(childPosition);
        int num = listBean.getNum();
        num++;
        listBean.setNum(num);
        //刷新适配器
        adapter.notifyDataSetChanged();
        //调用计算总价的方法
        setTvTotalPrice();
    }

    //商品数量减的方法
    @Override
    public void jian(int groupPosition, int childPosition) {
        ShoppCarBean.DataBean.ListBean listBean = list.get(groupPosition).getList().get(childPosition);
        int num = listBean.getNum();
        if (num == 1) {
            return;
        }
        num--;
        listBean.setNum(num);
        //刷新适配器
        adapter.notifyDataSetChanged();
        //调用计算总价的方法
        setTvTotalPrice();
    }

    //判断商家是否选中的方法
    @Override
    public void IsCheckedGroup(int groupPosition, boolean isChecked) {
        //商家javabean
        ShoppCarBean.DataBean dataBean = list.get(groupPosition);
        dataBean.setGroupChoosed(isChecked);
        //遍历商家里面的商品,将其置为选中状态
        for (ShoppCarBean.DataBean.ListBean bean : dataBean.getList()) {
            bean.setChildChoosed(isChecked);
        }
        //底部结算那个checkbox状态(全选)
        if (isCheckAll()) {
            btnCheckAll.setChecked(true);
        } else {
            btnCheckAll.setChecked(false);
        }
        //刷新适配器
        adapter.notifyDataSetChanged();
        //调用计算总价的方法
        setTvTotalPrice();
    }
    //商品的checkbox
    @Override
    public void IsCheckedChild(int groupPosition, int childPosition, boolean isChecked) {
        ShoppCarBean.DataBean dataBean = list.get(groupPosition);
        ShoppCarBean.DataBean.ListBean listBean = dataBean.getList().get(childPosition);
        //你点击商家的商品条目将其选中状态记录
        listBean.setChildChoosed(isChecked);
        //检测商家里面的每一个商品是否被选中,如果被选中,返回boolean
        boolean result = isGoodsCheckAll(groupPosition);
        if (result) {
            dataBean.setGroupChoosed(result);
        } else {
            dataBean.setGroupChoosed(result);
        }
        //底部结算那个checkbox状态(全选)
        if (isCheckAll()) {
            btnCheckAll.setChecked(true);
        } else {
            btnCheckAll.setChecked(false);
        }
        //刷新适配器
        adapter.notifyDataSetChanged();
        //计算总价
        setTvTotalPrice();
    }
//检测某个商家的商品是否都选中,如果都选中的话,商家CheckBox应该是选中状态
    private boolean isGoodsCheckAll(int groupPosition) {
        ShoppCarBean.DataBean dataBean = list.get(groupPosition);
        //遍历某一个商家的每个商品是否被选中
        for (ShoppCarBean.DataBean.ListBean listBean : dataBean.getList()) {
            if (!listBean.isChildChoosed()) {
                return false;
            }
        }
        return true;
    }

    //全选与反选
    private void isCheckedAll(boolean isChecked) {
        for (ShoppCarBean.DataBean dataBean : list) {
            dataBean.setGroupChoosed(isChecked);
            for (ShoppCarBean.DataBean.ListBean listBean : dataBean.getList()) {
                listBean.setChildChoosed(isChecked);
            }
        }
        //刷新适配器
        adapter.notifyDataSetChanged();
        setTvTotalPrice();
    }
    //购物车商品是否全部选中
    private boolean isCheckAll() {
        for (ShoppCarBean.DataBean dataBean : list) {
            if (!dataBean.isGroupChoosed()) {
                return false;
            }
        }
        return true;
    }

    //计算你所选中的商品总价
    private void setTvTotalPrice() {
        //初始化值
        count = 0;
        price = 0.00;

        for (ShoppCarBean.DataBean dataBean : list) {
            for (ShoppCarBean.DataBean.ListBean listBean : dataBean.getList()) {
                if (listBean.isChildChoosed()) {
                    count++;
                    price += listBean.getNum() * listBean.getPrice();
                }
            }
        }
        //设置文本信息、合计、结算的商品数量
        tvTotalPrice.setText("合计:¥" + price);
        btnAmount.setText("结算(" + count + ")");
    }
}
      
//MyExpandAdapter适配器
package view.adapter;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.List;
import bawei.com.gouwuche_demo2.R;
import bean.ShoppCarBean;
public class MyExpandAdapter extends BaseExpandableListAdapter{
      
private List<ShoppCarBean.DataBean> list;
    private Context context;
    private CheckBox ck_group_choosed;
    //商品加减的一个接口变量
    private addJian addJian;
    private isChecked isChecked;
    private Button btn_commodity_delete;
    //接收是否处于编辑状态的一个boolean值
    private boolean isEditor;

    //商家以及商品是否被选中的一个监听
    public void setIsChecked(MyExpandAdapter.isChecked isChecked) {
        this.isChecked = isChecked;
    }
    //设置商品的加减监听
    public void setAddJian(MyExpandAdapter.addJian addJian) {
        this.addJian = addJian;
    }
    public MyExpandAdapter(Context context) {
        this.context = context;
    }
    //设置数据
    public void setList(List<ShoppCarBean.DataBean> data){
        this.list=data;
    }
    //是否显示删除按钮
    public void showDeleteButton(boolean isEditor){
        this.isEditor=isEditor;
        //刷新适配器
        notifyDataSetChanged();
    }
    @Override
    public int getGroupCount() {
        return list!=null?list.size():0;
    }

    @Override
    public int getChildrenCount(int i) {
        return list!=null&&list.get(i).getList()!=null?list.get(i).getList().size():0;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return list.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return list.get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(final int groupPosition, boolean b, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.layout_group_item,parent,false);
        }
        //找控件
        ck_group_choosed = convertView.findViewById(R.id.ck_group_choosed);
        //赋值
        ck_group_choosed.setText(list.get(groupPosition).getSellerName());
        //设置商家checkbox复选框的状态
        ck_group_choosed.setChecked(list.get(groupPosition).isGroupChoosed());
        ck_group_choosed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isChecked.IsCheckedGroup(groupPosition,((CheckBox)view).isChecked());
            }
        });
        return convertView;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean b, View convertView, ViewGroup parent) {
       if(convertView==null){
           convertView=LayoutInflater.from(context).inflate(R.layout.layout_child_item,parent,false);
       }
        //商品选择
        CheckBox ck_child_choose = convertView.findViewById(R.id.ck_child_choose);
        //商品图片
        ImageView iv_show_pic = convertView.findViewById(R.id.iv_show_pic);
        //商品主标题
        TextView tv_commodity_name = convertView.findViewById(R.id.tv_commodity_name);
       //商品副标题
        TextView tv_commodity_attr = convertView.findViewById(R.id.tv_commodity_attr);
        //商品价格
        TextView tv_commodity_price = convertView.findViewById(R.id.tv_commodity_price);
        //商品数量
        TextView tv_commodity_num = convertView.findViewById(R.id.tv_commodity_num);
        //商品减
        TextView iv_sub = convertView.findViewById(R.id.iv_sub);
        //商品加减中的数量变化
        final TextView tv_commodity_show_num = convertView.findViewById(R.id.tv_commodity_show_num);
        //商品加
        TextView iv_add = convertView.findViewById(R.id.iv_add);
        //删除按钮
        btn_commodity_delete = convertView.findViewById(R.id.btn_commodity_delete);
        //设置文本信息
        tv_commodity_name.setText(list.get(groupPosition).getList().get(childPosition).getTitle());
        tv_commodity_attr.setText(list.get(groupPosition).getList().get(childPosition).getSubhead());
        tv_commodity_price.setText("¥"+list.get(groupPosition).getList().get(childPosition).getPrice());
        tv_commodity_num.setText("x"+list.get(groupPosition).getList().get(childPosition).getNum());
        tv_commodity_show_num.setText(list.get(groupPosition).getList().get(childPosition).getNum()+"");
        //处理商品的选中状态
        ck_child_choose.setChecked(list.get(groupPosition).getList().get(childPosition).isChildChoosed());
        //商品复选框是否被选中
        ck_child_choose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isChecked.IsCheckedChild(groupPosition,childPosition,((CheckBox)view).isChecked());
            }
        });
        //分割图片地址
        String images = list.get(groupPosition).getList().get(childPosition).getImages();
        String[] urls = images.split("\\|");
        //加载商品图片
        Glide.with(context)
                .load(urls[0])
                .crossFade()
                .into(iv_show_pic);
        //商品加
        iv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast.makeText(context,"加",Toast.LENGTH_SHORT).show();
                addJian.add(groupPosition,childPosition);
            }
        });
        //减
        iv_sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                addJian.jian(groupPosition,childPosition);
            }
        });
        //控制删除按钮的隐藏与显示
        if(isEditor){
            btn_commodity_delete.setVisibility(View.VISIBLE);
            btn_commodity_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    list.remove(groupPosition);
                    notifyDataSetChanged();
                }
            });
        }else{
            btn_commodity_delete.setVisibility(View.GONE);
        }
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    //加减
    public interface addJian{
        //商品添加操作
        void add(int groupPosition, int childPosition);
        //商品减少操作
        void jian(int groupPosition, int childPosition);
    }

    public interface isChecked{
        //商家的条目的复选框监听
        void IsCheckedGroup(int groupPosition,boolean isChecked);
        //商品的条目的复选框监听
        void IsCheckedChild(int groupPosition,int childPosition,boolean isChecked);
    }
}
      

//购物车数据

package bean;

import java.util.List;

public class ShoppCarBean {


    /**
     * msg : 请求成功
     * code : 0
     * data : [{"list":[{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"},{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":1,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":21,"price":699,"pscid":1,"selected":0,"sellerid":14,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家14","sellerid":"14"}]
     */

    private String msg;
    private String code;
    private List<DataBean> 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 List<DataBean> getData() {
        return data;
    }

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

    public static class DataBean {
        /**
         * list : [{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"},{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"}]
         * sellerName : 商家1
         * sellerid : 1
         */

        private String sellerName;
        private String sellerid;
        private List<ListBean> list;

        //商家是否被选中 组条目是否被选中
        private boolean isGroupChoosed;

        public boolean isGroupChoosed() {
            return isGroupChoosed;
        }

        public void setGroupChoosed(boolean groupChoosed) {
            isGroupChoosed = groupChoosed;
        }


        public String getSellerName() {
            return sellerName;
        }

        public void setSellerName(String sellerName) {
            this.sellerName = sellerName;
        }

        public String getSellerid() {
            return sellerid;
        }

        public void setSellerid(String sellerid) {
            this.sellerid = sellerid;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public static class ListBean {
            /**
             * bargainPrice : 99
             * createtime : 2017-10-14T21:38:26
             * detailUrl : https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends
             * images : https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg
             * num : 1
             * pid : 45
             * price : 2999
             * pscid : 39
             * selected : 0
             * sellerid : 1
             * subhead : 高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!
             * title : 一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机
             */

            //private int bargainPrice;
            private String createtime;
            private String detailUrl;
            private String images;
            private int num;
            private int pid;
            private int price;
            private int pscid;
            private int selected;
            private int sellerid;
            private String subhead;
            private String title;
            //子条目商品是否被选中的一个字段状态
            private boolean isChildChoosed;

            public boolean isChildChoosed() {
                return isChildChoosed;
            }

            public void setChildChoosed(boolean childChoosed) {
                isChildChoosed = childChoosed;
            }

            /*public int getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(int bargainPrice) {
                this.bargainPrice = bargainPrice;
            }*/

            public String getCreatetime() {
                return createtime;
            }

            public void setCreatetime(String createtime) {
                this.createtime = createtime;
            }

            public String getDetailUrl() {
                return detailUrl;
            }

            public void setDetailUrl(String detailUrl) {
                this.detailUrl = detailUrl;
            }

            public String getImages() {
                return images;
            }

            public void setImages(String images) {
                this.images = images;
            }

            public int getNum() {
                return num;
            }

            public void setNum(int num) {
                this.num = num;
            }

            public int getPid() {
                return pid;
            }

            public void setPid(int pid) {
                this.pid = pid;
            }

            public int getPrice() {
                return price;
            }

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

            public int getPscid() {
                return pscid;
            }

            public void setPscid(int pscid) {
                this.pscid = pscid;
            }

            public int getSelected() {
                return selected;
            }

            public void setSelected(int selected) {
                this.selected = selected;
            }

            public int getSellerid() {
                return sellerid;
            }

            public void setSellerid(int sellerid) {
                this.sellerid = sellerid;
            }

            public String getSubhead() {
                return subhead;
            }

            public void setSubhead(String subhead) {
                this.subhead = subhead;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}
      

//订单M层(创建,展示)

(IAddModel,AddModel,IOrderModel,OrderModel)

package model;
import net.OnNetListener;
import java.util.Map;
import bean.AddCarBean;
public interface IAddModel {
    public void doCar(String url, Map<String, String> map, OnNetListener<AddCarBean> onNetListener);
}
      

//AddModel

package model;
import android.os.Handler;
import android.os.Looper;
import com.google.gson.Gson;
import net.HttpUtils;
import net.OnNetListener;
import java.io.IOException;
import java.util.Map;
import bean.AddCarBean;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class AddModel implements IAddModel {
    private Handler handler = new Handler(Looper.getMainLooper());

    @Override
    public void doCar(String url, Map<String, String> map, final OnNetListener<AddCarBean> onNetListener) {
        HttpUtils.getHttpUtils().doPost(url, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                onNetListener.OnFailed(e);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final AddCarBean addCarBean = new Gson().fromJson(string, AddCarBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onNetListener.OnSuccess(addCarBean);
                    }
                });
            }
        });
    }
}
      

//IOrderModel

package model;
import net.OnNetListener;
import bean.OrderBean;
public interface IOrderModel {
    public void getOrder(String status, String page, OnNetListener<OrderBean> onNetListener);
}
      

//OrderModel

package model;
import android.os.Handler;
import android.os.Looper;
import com.google.gson.Gson;
import net.Api;
import net.HttpUtils;
import net.OnNetListener;
import java.io.IOException;
import java.util.HashMap;
import bean.OrderBean;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class OrderModel implements IOrderModel {
    private Handler handler = new Handler(Looper.getMainLooper());
    @Override
    public void getOrder(String status, String page, final OnNetListener<OrderBean> onNetListener) {
        HashMap<String, String> map = new HashMap<>();
        map.put("uid","71");
        map.put("status",status);
        map.put("page",page);
        HttpUtils.getHttpUtils().doPost(Api.getOrders, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                onNetListener.OnFailed(e);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                final OrderBean orderBean = new Gson().fromJson(string, OrderBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onNetListener.OnSuccess(orderBean);
                    }
                });
            }
        });
    }
}
      

//订单P层

(AddPresenter,OrderPresenter)

//AddP

package presenter;
import net.Api;
import net.OnNetListener;
import java.util.HashMap;
import bean.AddCarBean;
import model.AddModel;
import view.activity.IMainActivity;
public class AddPresenter {
    private IMainActivity iMainActivity;
    private final AddModel addModel;

    public AddPresenter(IMainActivity iMainActivity) {
        this.iMainActivity = iMainActivity;
        addModel = new AddModel();
    }
    public void addCar(int uid ){
        HashMap<String, String> map = new HashMap<>();
        map.put("uid","71");
        addModel.doCar(Api.createOrder, map, new OnNetListener<AddCarBean>() {
            @Override
            public void OnSuccess(AddCarBean addCarBean) {
                iMainActivity.addCar(addCarBean);
            }

            @Override
            public void OnFailed(Exception e) {

            }
        });
    }
}
      
//OrderP      
package presenter;
import net.OnNetListener;
import bean.OrderBean;
import model.OrderModel;
import view.activity.ISecondActivity;
public class OrderPresenter {
    private ISecondActivity iSecondActivity;
    private final OrderModel orderModel;

    public OrderPresenter(ISecondActivity iSecondActivity) {
        this.iSecondActivity = iSecondActivity;
        orderModel = new OrderModel();
    }
    public void getOrder(final boolean isRefresh, String status, String page){
        orderModel.getOrder(status, page, new OnNetListener<OrderBean>() {
            @Override
            public void OnSuccess(OrderBean orderBean) {
            iSecondActivity.showData(isRefresh,orderBean.getData());
            }

            @Override
            public void OnFailed(Exception e) {

            }
        });
    }
}      

//订单V层

//IMainActivity

package view.activity;
import bean.AddCarBean;
public interface IMainActivity {
    public void show(String str);
    public void addCar(AddCarBean addCarBean);
}
      

//ISecondActivity

package view.activity;
import java.util.List;
import bean.OrderBean;
public interface  ISecondActivity {
    public void showData(boolean isRefresh, List<OrderBean.DataBean> list);
}
      

//SecondActivity

package view.activity;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.ArrayList;
import java.util.List;
import bawei.com.gouwuche_demo2.R;
import bean.OrderBean;
import presenter.OrderPresenter;
import view.adapter.MyAdapter;
public class SecondActivity extends AppCompatActivity implements ISecondActivity, View.OnClickListener{
    private ImageView mIvPop;
    /**
     * 待支付
     */
    private RadioButton mRb1;
    /**
     * 已支付
     */
    private RadioButton mRb2;
    /**
     * 已取消
     */
    private RadioButton mRb3;
    private RadioGroup mRg;
    private XRecyclerView mXrv;
    private int page = 1;
    private List<OrderBean.DataBean> list = new ArrayList<>();
    private MyAdapter myAdapter;
    private OrderPresenter orderPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        mIvPop = (ImageView) findViewById(R.id.iv_pop);
        mRb1 = (RadioButton) findViewById(R.id.rb1);
        mRb2 = (RadioButton) findViewById(R.id.rb2);
        mRb3 = (RadioButton) findViewById(R.id.rb3);
        mRg = (RadioGroup) findViewById(R.id.rg);
        mXrv = (XRecyclerView) findViewById(R.id.xrv);
        initView();
        mXrv.setLayoutManager(new LinearLayoutManager(this));
        myAdapter = new MyAdapter(this, list);
        mXrv.setAdapter(myAdapter);
        orderPresenter = new OrderPresenter(this);
        orderPresenter.getOrder(true, "1", page + "");
        mXrv.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                page = 1;
                orderPresenter.getOrder(true, "1", page + "");
            }

            @Override
            public void onLoadMore() {
                //加载更多
                page++;
                orderPresenter.getOrder(false, "1", page + "");
            }
        });
    }
    private void initView() {

        mIvPop.setOnClickListener(this);
        mRb1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                orderPresenter.getOrder(true, "0", "1");
            }
        });
        mRb2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                orderPresenter.getOrder(true, "1", "1");
            }
        });
        mRb3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                orderPresenter.getOrder(true, "2", "1");
            }
        });
    }
    @Override
    public void showData(boolean isRefresh, List<OrderBean.DataBean> newlist) {
        if (isRefresh) {
            list.clear();
            list.addAll(newlist);
            mXrv.refreshComplete();
        } else {
            list.addAll(newlist);
            mXrv.setLoadingMoreEnabled(false);
        }
        myAdapter.notifyDataSetChanged();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.iv_pop:
                View view = View.inflate(SecondActivity.this, R.layout.pop_item, null);
                TextView tv1 = view.findViewById(R.id.tv1);
                TextView tv2 = view.findViewById(R.id.tv2);
                TextView tv3 = view.findViewById(R.id.tv3);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                final PopupWindow popupWindow = new PopupWindow(view, layoutParams.width, layoutParams.height);
                //popupWindow.showAsDropDown(mIvPop, 0, 30);
                popupWindow.setBackgroundDrawable(new ColorDrawable());
                popupWindow.setOutsideTouchable(true);
                popupWindow.showAsDropDown(mIvPop);
                //popupWindow.setFocusable(true);

                tv1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(SecondActivity.this, "待支付", Toast.LENGTH_SHORT).show();
                        orderPresenter.getOrder(true, "0", "1");
                        popupWindow.dismiss();
                    }
                });
                tv2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(SecondActivity.this, "已支付", Toast.LENGTH_SHORT).show();
                        orderPresenter.getOrder(true, "1", "1");
                        popupWindow.dismiss();
                    }
                });
                tv3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(SecondActivity.this, "已取消", Toast.LENGTH_SHORT).show();
                        orderPresenter.getOrder(true, "2", "1");
                        popupWindow.dismiss();
                    }
                });
                break;
        }
    }
}
      

//MyAdapter适配器(订单)

package view.adapter;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import bawei.com.gouwuche_demo2.R;
import bean.OrderBean;

public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<OrderBean.DataBean> list;

    public MyAdapter(Context context, List<OrderBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final OrderBean.DataBean dataBean = list.get(position);
        final MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.tv_title.setText(dataBean.getTitle());
        final int status = dataBean.getStatus();
        if (status == 0) {
            myViewHolder.tv_status.setText("待支付");
            myViewHolder.tv.setText("取消订单");
            myViewHolder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("提示");
                builder.setMessage("确定取消订单吗?");
                builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(context,"订单已取消",Toast.LENGTH_SHORT).show();
                    }
                });
                builder.setNegativeButton("否", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();
                }
            });

        } else if (status == 1) {
            myViewHolder.tv_status.setText("已支付");
            myViewHolder.tv.setText("查看订单");
        } else {
            myViewHolder.tv_status.setText("已取消");
            myViewHolder.tv.setText("查看订单");
        }

        myViewHolder.tv_price.setText("价格:" + dataBean.getPrice());
        myViewHolder.tv_time.setText("创建时间:" + dataBean.getCreatetime());

        myViewHolder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (status == 1){
                    Toast.makeText(context,"查看订单",Toast.LENGTH_SHORT).show();
                }else if (status == 0){
                            AlertDialog.Builder builder = new AlertDialog.Builder(context);
                            builder.setTitle("提示");
                            builder.setMessage("确定取消订单吗?");
                            builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(context,"订单已取消",Toast.LENGTH_SHORT).show();
                                }
                            });
                            builder.setNegativeButton("否", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            });
                            builder.show();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv_title;
        private final TextView tv_status;
        private final TextView tv_price;
        private final TextView tv_time;
        private final TextView tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_status = itemView.findViewById(R.id.tv_status);
            tv_price = itemView.findViewById(R.id.tv_price);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv = itemView.findViewById(R.id.tv);
        }
    }
}
      
//创建订单bean      
package bean;

public class AddCarBean {

    /**
     * msg : 订单创建成功
     * code : 0
     */

    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;
    }
}
      
//展示请求的订单数据bean      
package bean;      
import java.util.List;      
public class OrderBean {
    /**
     * msg : 请求成功
     * code : 0
     * data : [{"createtime":"2017-10-19T20:28:43","orderid":20,"price":100,"status":0,"title":"订单标题测试3","uid":71},{"createtime":"2017-10-19T20:44:40","orderid":31,"price":11800,"status":0,"title":"订单标题测试14","uid":71},{"createtime":"2017-10-19T20:44:51","orderid":32,"price":11800,"status":0,"title":"订单标题测试15","uid":71},{"createtime":"2017-10-20T08:02:07","orderid":43,"price":11800,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-10-20T08:02:16","orderid":44,"price":11800,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-10-22T15:14:39","orderid":890,"price":11800,"status":0,"title":"","uid":71},{"createtime":"2017-11-09T09:17:20","orderid":1446,"price":99.99,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1447,"price":567,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1448,"price":256.99,"status":0,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1449,"price":399,"status":0,"title":"订单标题测试","uid":71}]
     * page : 1
     */

    private String msg;
    private String code;
    private String page;
    private List<DataBean> 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 String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public List<DataBean> getData() {
        return data;
    }

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

    public static class DataBean {
        /**
         * createtime : 2017-10-19T20:28:43
         * orderid : 20
         * price : 100.0
         * status : 0
         * title : 订单标题测试3
         * uid : 71
         */

        private String createtime;
        private int orderid;
        private double price;
        private int status;
        private String title;
        private int uid;

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public int getOrderid() {
            return orderid;
        }

        public void setOrderid(int orderid) {
            this.orderid = orderid;
        }

        public double getPrice() {
            return price;
        }

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

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public int getUid() {
            return uid;
        }

        public void setUid(int uid) {
            this.uid = uid;
        }
    }
}
      

//封装的包(utils包下的)

//拦截器

package utils;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
//拦截器
public class CommonParamsInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {

        Request request = chain.request();
        String method = request.method();
        if("GET".equals(method)){
            String oldUrl = request.url().toString();
            String newUrl=oldUrl+"&source=android";
            request=new Request.Builder()
                    .url(newUrl)
                    .build();
        }else if("POST".equals(method)){
            String path = request.url().toString();
            FormBody oldBody = (FormBody) request.body();

            FormBody.Builder newBody=new FormBody.Builder();
            for(int i=0;i<oldBody.size();i++){
                String name = oldBody.name(i);
                String value = oldBody.value(i);
                newBody.add(name,value);
            }

            newBody.add("source","android");
            request=new Request.Builder()
                    .post(newBody.build())
                    .url(path)
                    .build();
        }

        return chain.proceed(request);
    }
}
      

//封装

package utils;
import android.os.Handler;
import java.io.IOException;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
//网络请求的封装
public class OkHttpUtils {
    private static OkHttpUtils OK_HTTP_UTILS=null;
    private Handler handler=new Handler();

    private OkHttpUtils() {

    }
    public static OkHttpUtils getInData(){

        if(OK_HTTP_UTILS==null){
            synchronized (OkHttpUtils.class){
                if(OK_HTTP_UTILS==null){
                    OK_HTTP_UTILS=new OkHttpUtils();
                }
            }
        }

        return OK_HTTP_UTILS;
    }

    public void doGet(String path, Map<String,String> map, final OnFinishListener onFinishListener){
        StringBuffer sb=new StringBuffer();
        sb.append(path);
        if(sb.indexOf("?")!=-1){
            if(sb.indexOf("?")!=sb.length()-1){
                sb.append("&");
            }
        }else{
            sb.append("?");
        }

        for(Map.Entry<String,String> m:map.entrySet()){
            sb.append(m.getKey())
                    .append("=")
                    .append(m.getValue())
                    .append("&");
        }
        if(sb.lastIndexOf("&")!=-1){
            sb.deleteCharAt(sb.length()-1);
        }

        OkHttpClient okHttpClient=new OkHttpClient.Builder()
                .addInterceptor(new CommonParamsInterceptor())//应用拦截器
                .build();
        Request request=new Request.Builder()
                .get()
                .url(sb.toString())
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onFinishListener.onFailed(e.getMessage());
                    }
                });
            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                if(response.isSuccessful()){
                    final String result = response.body().string();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            onFinishListener.onSuccess(result);
                        }
                    });
                }
            }
        });
    }

    public void doPost(String path, Map<String,String> map, final OnFinishListener onFinishListener){
        OkHttpClient okHttpClient=new OkHttpClient.Builder()
                .addInterceptor(new CommonParamsInterceptor())
                .build();

        FormBody.Builder body=new FormBody.Builder();
        for(String key:map.keySet()){
            body.add(key,map.get(key));
        }

       Request request=new Request.Builder()
               .post(body.build())
               .url(path)
               .build();

        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        onFinishListener.onFailed(e.getMessage());
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){
                    final String result = response.body().string();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            onFinishListener.onSuccess(result);
                        }
                    });
                }
            }
        });
    }

}
      
//接口      
package utils;

/**
 * 定义一个接口
 */
public interface OnFinishListener {
    void onFailed(String msg);

    void onSuccess(Object obj);

}
      
//net包下的封装(用订单中)      
package net;
public interface Api {
    //获取购物车列表接口
    public static final String getCarts = "https://www.zhaoapi.cn/product/getCarts";
    //创建订单接口
    public static final String createOrder = "https://www.zhaoapi.cn/product/createOrder";
    //获取订单列表接口
    public static final String getOrders = "https://www.zhaoapi.cn/product/getOrders";
    //修改订单状态
    public static final String updateOrder = "https://www.zhaoapi.cn/product/updateOrder";

}
      
//封装
package net;
import java.util.Map;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public class HttpUtils {
    private static HttpUtils httpUtils;
    private final OkHttpClient client;

    public HttpUtils() {
        client = new OkHttpClient.Builder()
                .addInterceptor(new MyInterceptor())
                .build();
    }
    public static HttpUtils getHttpUtils(){
        if (httpUtils == null){
            synchronized (HttpUtils.class){
                if (httpUtils ==null){
                    httpUtils = new HttpUtils();
                }
            }
        }
        return httpUtils;
    }
    public void doPost(String url, Map<String,String> map, Callback callback){
        if (map == null){
            throw new RuntimeException("参数为空");
        }
        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String,String> entry: map.entrySet()) {
            builder.add(entry.getKey(),entry.getValue());
        }
        FormBody formBody = builder.build();
        Request request = new Request.Builder().url(url).post(formBody).build();
        client.newCall(request).enqueue(callback);
    }
    public void doGet(String url,Callback callback){
        Request request = new Request.Builder().url(url).build();
        client.newCall(request).enqueue(callback);
    }
}
      
//MyApp
package net;
import android.app.Application;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this).build();
        ImageLoader.getInstance().init(configuration);
        Fresco.initialize(this);
    }
}
      
//拦截器
package net;
import java.io.IOException;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class MyInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        HttpUrl url=original.url().newBuilder()
                .addQueryParameter("source","android")
                .build();
        //添加请求头
        Request request = original.newBuilder()
                .url(url)
                .build();
        return chain.proceed(request);
    }

}
      
//接口      
package net;
public interface OnNetListener<T> {
    void OnSuccess(T t);
    void OnFailed(Exception e);
}
      
//购物车、订单布局      
activity_main.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/layout_title" />


    <ExpandableListView
        android:id="@+id/expandList"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </ExpandableListView>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="2dp"
        android:background="#000000"/>


    <include layout="@layout/layout_bottom" />

</LinearLayout>
      
layout_title.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_red_light"
    android:orientation="horizontal">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回"
        android:textSize="25sp"
        android:padding="10dp"
        android:textColor="@android:color/white"
        android:id="@+id/btnBack"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:padding="10dp"
        android:textColor="@android:color/white"
        android:layout_weight="1"
        android:gravity="center"
        android:text="购物车"/>


    <TextView
        android:id="@+id/btnEditor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="编辑"
        android:textColor="@android:color/white"
        android:textSize="25sp"
        android:padding="10dp"/>
    
</LinearLayout>      
layout_bottom.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">



    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="全选"
        android:textSize="25sp"
        android:padding="10dp"
        android:id="@+id/btnCheckAll"/>


    <TextView
        android:id="@+id/tvTotalPrice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:padding="10dp"
        android:textColor="@android:color/black"
        android:layout_weight="1"
        android:gravity="center"
        android:text="合计:¥0.00"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="结算(0)"
        android:textColor="@android:color/white"
        android:textSize="25sp"
        android:padding="10dp"
        android:background="@android:color/holo_red_light"
        android:id="@+id/btnAmount"/>

</LinearLayout>      
layout_group_item.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">



    <CheckBox
        android:id="@+id/ck_group_choosed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="商家1"
        android:gravity="center_vertical"
        android:textSize="25sp"
        android:focusable="false"
        android:padding="10dp"/>

</LinearLayout>      
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <CheckBox
        android:id="@+id/ck_child_choose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:scaleX="0.6"
        android:scaleY="0.6" />
    <ImageView
        android:id="@+id/iv_show_pic"
        android:layout_width="70dp"
        android:layout_height="80dp"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:src="@mipmap/ic_launcher"
        android:layout_toRightOf="@id/ck_child_choose" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@id/iv_show_pic"
        android:orientation="vertical">
        <TextView
            android:id="@+id/tv_commodity_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="酒红色纯红色纯羊毛西服套装"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" />
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/tv_commodity_attr"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:text="属性:粉蓝色"
                android:textSize="12sp"
                android:textColor="@color/colorPrimary" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/tv_commodity_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="¥390"
                android:textColor="@android:color/holo_red_dark"
                android:textSize="12sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/tv_commodity_num"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="x1"
                android:textColor="@android:color/darker_gray" />
            <LinearLayout
                android:id="@+id/rl_edit"
                android:layout_width="120dp"
                android:background="@android:color/holo_orange_light"
                android:layout_height="30dp"
                android:layout_marginLeft="20dp"
                >
                <TextView
                    android:id="@+id/iv_sub"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:textColor="@android:color/black"
                    android:background="@android:color/white"
                    android:layout_margin="1dp"
                    android:layout_height="match_parent"
                    android:text=" - " />

                <TextView
                    android:id="@+id/tv_commodity_show_num"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:background="@android:color/white"
                    android:layout_margin="1dp"
                    android:layout_height="match_parent"
                    android:text="1"
                    />

                <TextView
                    android:id="@+id/iv_add"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    android:background="@android:color/white"
                    android:layout_height="match_parent"
                    android:text=" + " />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    <Button
        android:id="@+id/btn_commodity_delete"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="-"
        android:background="@android:color/holo_red_light"
        android:textSize="20sp"
        android:textColor="@android:color/white"
        android:layout_margin="5dp"
        android:visibility="gone" />
</RelativeLayout>      
//订单布局
activity_second.xml      
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_second"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="view.activity.SecondActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="订单列表"
            android:textSize="25sp" />

        <ImageView
            android:id="@+id/iv_pop"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:background="@drawable/lv_icon" />
    </RelativeLayout>

    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rb1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="待支付" />

        <RadioButton
            android:id="@+id/rb2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="已支付" />

        <RadioButton
            android:id="@+id/rb3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="已取消" />
    </RadioGroup>

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/xrv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
      
pop_item.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="待支付"></TextView>

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="已支付"></TextView>

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="已取消"></TextView>
</LinearLayout>      
item.xml      
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true" />

        <TextView
            android:id="@+id/tv_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />
    </RelativeLayout>

    <TextView
        android:id="@+id/tv_price"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_centerVertical="true"
        android:layout_weight="1"
        android:textColor="#ff0000" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />
    </RelativeLayout>
</LinearLayout>