MVP框架做的登陆注册,商品列表,商品详情,购物车功能 RxJava+Retrofit ijkplayer EventBus ButterKnife


答:总是如此

话不多说

首先先贴上权限

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

<!-- 网络状态 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
依赖

compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.facebook.fresco:fresco:0.12.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:+'
compile 'io.reactivex.rxjava2:rxjava:+'
compile 'io.reactivex.rxjava2:rxandroid:+'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
compile 'com.xhb:xbanner:1.3.0'
compile 'com.squareup.retrofit2:retrofit:+'
compile 'com.squareup.retrofit2:converter-gson:+'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'jp.wasabeef:glide-transformations:1.0.6'
compile 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
testCompile 'junit:junit:4.12'
compile 'org.greenrobot:eventbus:3.1.1'
网络请求接口类
public class RxJavaUtils {
    private final Retrofit mRetrofit;

    public RxJavaUtils(String baseUrl) {
        Log.e("TAG","RxJavaUtils===");
        mRetrofit = new Retrofit.Builder()
                .client(new OkHttpClient.Builder()
                        .connectTimeout(10000, TimeUnit.MILLISECONDS)
                        .build())
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }

    public <T> T creat(Class<T> clazz){
        return mRetrofit.create(clazz);
    }
}

先将MVP的基类贴上
public interface IModel {
}
public interface IView {
}
贴上API
public interface MyLoginApi {
    @GET("user/login")
    Observable<LoginBean> getLogin(@Query("source") String source,@Query("mobile") String mobile ,@Query("password") String password );

    @GET("user/reg")
    Observable<RegBean> getReg(@Query("source") String source, @Query("mobile") String mobile , @Query("password") String password );
}
登陆注册页面p逻辑操作
public abstract class IPresenter<T extends LoginView> {
    T view;

    public IPresenter(T view) {
        this.view = view;
        init();
    }

    protected abstract void init();
}
public class LoginPresenter extends IPresenter<LoginView> {

    private LoginModel loginModel;

    public LoginPresenter(LoginView view) {
        super(view);
    }

    @Override
    protected void init() {
        loginModel = new LoginModel();
    }

    public void getLoginAction(String phone,String password){
        Observable<LoginBean> login = loginModel.Login(phone, password);
        login.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<LoginBean>() {
                               @Override
                               public void accept(LoginBean bean) throws Exception {
                                    view.getLoginSucceed(bean);
                               }
                           });

    }

    public void getRegAction(String phone,String password){
        Observable<RegBean> login = loginModel.Reg(phone, password);
        login.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<RegBean>() {
                    @Override
                    public void accept(RegBean bean) throws Exception {
                        view.getRegSucceed(bean);
                    }
                });

    }
}
登录模块 V层接口
public interface LoginView extends IView {
    void getLoginSucceed(LoginBean bean);
    void getRegSucceed(RegBean bean);
}
登录视图
public class MainActivity extends AppCompatActivity implements LoginView{

    @InjectView(R.id.name)
    EditText name;
    @InjectView(R.id.pwd)
    EditText pwd;
    @InjectView(R.id.newUser)
    TextView newUser;
    @InjectView(R.id.login)
    ImageView login;
    @InjectView(R.id.qq)
    ImageView qq;
    private String phone;
    private String password;
    private LoginPresenter loginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        loginPresenter = new LoginPresenter(this);

    }


    @OnClick({R.id.newUser, R.id.login, R.id.qq})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.newUser:
                Intent intent = new Intent(MainActivity.this,RegActivity.class);
                startActivity(intent);
                break;
            case R.id.login:
                phone = name.getText().toString();
                password = pwd.getText().toString();
                if(phone!=null&&password!=null){
                    loginPresenter.getLoginAction(phone,password);
                }else{
                    Toast.makeText(this, "请正确填写,不能为空", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.qq:
                break;
        }
    }

    @Override
    public void getLoginSucceed(LoginBean bean) {
//        Log.e("TAG",bean.getCode()+""+bean.getMsg());
        if(bean.getCode().equals("0")){
            Intent intent1 = new Intent(MainActivity.this,GoodsListActivity.class);
            startActivity(intent1);
        }

    }

    @Override
    public void getRegSucceed(RegBean bean) {

    }
}
注册视图
public class RegActivity extends AppCompatActivity implements LoginView{

    @InjectView(R.id.nname)
    EditText nname;
    @InjectView(R.id.npwd1)
    EditText npwd1;
    @InjectView(R.id.npwd2)
    EditText npwd2;
    @InjectView(R.id.email)
    EditText email;
    @InjectView(R.id.regImg)
    ImageView regImg;
    private LoginPresenter loginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        ButterKnife.inject(this);
        loginPresenter = new LoginPresenter(this);
    }

    @OnClick(R.id.regImg)
    public void onViewClicked() {
        String phone = nname.getText().toString();
        String password = npwd1.getText().toString();
        loginPresenter.getRegAction(phone,password);
    }

    @Override
    public void getLoginSucceed(LoginBean bean) {

    }

    @Override
    public void getRegSucceed(RegBean bean) {
//        Log.e("TAG",bean.getMsg());
        if(bean.getCode().equals("0")){
            finish();
        }
    }
}
登陆注册M层
public class LoginModel implements IModel {
    String baseUri = "http://120.27.23.105/";
    public Observable<LoginBean> Login(String phone,String password){
        MyLoginApi creat = new RxJavaUtils(baseUri).creat(MyLoginApi.class);
        Observable<LoginBean> android = creat.getLogin("android", phone, password);
        return android;
    }

    public Observable<RegBean> Reg(String phone, String password){
        MyLoginApi creat = new RxJavaUtils(baseUri).creat(MyLoginApi.class);
        Observable<RegBean> androi = creat.getReg("androi", phone, password);
        return androi;
    }
}
ok到了现在登陆注册就完成了
这里开始商品列表And详情
首先还是API
public interface MyCartApi {
    @GET("product/getProducts")
    Observable<GoodListBean> getGoodList(@Query("source") String source, @Query("pscid") String pscid);

    @GET("product/getProductDetail")
    Observable<XiangQingBean> getXiqngQing(@Query("source") String source, @Query("pid") String pid);


}
M层请求数据
public class CartModel implements IModel{
    String baseUri = "http://120.27.23.105/";
    public Observable<GoodListBean> getGoodList( String pscid){
        MyCartApi creat = new RxJavaUtils(baseUri).creat(MyCartApi.class);
        Observable<GoodListBean> android = creat.getGoodList("android", pscid);
        return android;
    }
    public Observable<XiangQingBean> getXiangQing(String pid){
        MyCartApi creat = new RxJavaUtils(baseUri).creat(MyCartApi.class);
        Observable<XiangQingBean> android = creat.getXiqngQing("android", pid);
        return android;
    }

}
P逻辑操作
public abstract class IPresenter<T extends CartView> {
    T view;

    public IPresenter(T view) {
        this.view = view;
        init();
    }

    protected abstract void init();
}
public class CartPresenter extends IPresenter<CartView> {


    private CartModel cartModel;

    public CartPresenter(CartView view) {
        super(view);
    }


    @Override
    protected void init() {
        cartModel = new CartModel();
    }

    public void getLoginAction(String pscid) {
        Observable<GoodListBean> goodList = cartModel.getGoodList(pscid);
        goodList.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<GoodListBean>() {
                    @Override
                    public void accept(GoodListBean goodListBean) throws Exception {
                        view.getGoodListSucceed(goodListBean);
                    }
                });
    }

    public void getXiangQingAction(String pid){
        Observable<XiangQingBean> xiangQing = cartModel.getXiangQing(pid);
        xiangQing.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<XiangQingBean>() {
                    @Override
                    public void accept(XiangQingBean xiangQingBean) throws Exception {
                        view.getXiangQingSucceed(xiangQingBean);
//                        Log.e("TAG",xiangQingBean.getCode()+xiangQingBean.getMsg());
                    }
                });
    }
}
V层接口
public interface CartView extends IView{
    void getGoodListSucceed(GoodListBean bean);
    void getXiangQingSucceed(XiangQingBean bean);
}
列表视图Activity
public class GoodsListActivity extends AppCompatActivity implements CartView {


    @InjectView(R.id.xrecycler)
    XRecyclerView xrecycler;
    private CartPresenter cartPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_list);
        ButterKnife.inject(this);
        cartPresenter = new CartPresenter(this);
        cartPresenter.getLoginAction(39 + "");
        xrecycler.setLayoutManager(new LinearLayoutManager(this));

    }

    @Override
    public void getGoodListSucceed(GoodListBean bean) {
        Log.e("TAG", bean.getMsg());
        if(bean.getCode().equals("0")){
            List<GoodListBean.DataBean> data = bean.getData();
            MyGoodListAdapter myGoodListAdapter = new MyGoodListAdapter(data, GoodsListActivity.this);
            xrecycler.setAdapter(myGoodListAdapter);
        }
    }

    @Override
    public void getXiangQingSucceed(XiangQingBean bean) {

    }
}
到详情了
public class XiangQingActivity extends AppCompatActivity implements CartView {

    @InjectView(R.id.img)
    ImageView img;
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.js)
    TextView js;
    @InjectView(R.id.price)
    TextView price;
    @InjectView(R.id.newprice)
    TextView newprice;
    @InjectView(R.id.add)
    Button add;
    @InjectView(R.id.by)
    Button by;

    private CartPresenter cartPresenter;
    private PlayerView playerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiang_qing);
        ButterKnife.inject(this);
        cartPresenter = new CartPresenter(this);
        Intent intent = getIntent();
        String pid = intent.getStringExtra("pid");
        cartPresenter.getXiangQingAction(pid);
        playerView = new PlayerView(this);
        playerView.setTitle("我是标题");
        playerView.setScaleType(fitparent);
        playerView.hideMenu(true);
        playerView.forbidTouch(false);
        playerView.setPlaySource("http://ips.ifeng.com/video19.ifeng.com/video09/2014/06/16/1989823-102-086-0009.mp4 ");

        playerView.startPlay();
    }

    @Override
    public void onStop() {
        super.onStop();
        playerView.stopPlay();
    }


    @Override
    public void getGoodListSucceed(GoodListBean bean) {
//        Log.e("TAG",bean.getMsg());
    }

    @Override
    public void getXiangQingSucceed(XiangQingBean bean) {
//        Log.e("TAG",bean.getMsg()+"================================");
        title.setText(bean.getData().getTitle());
        price.setText(bean.getData().getPrice() + "");
        Glide.with(XiangQingActivity.this).load(bean.getData().getImages().split("!")[0]).into(img);
    }

    @OnClick({R.id.add, R.id.by})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.add:
                startActivity(new Intent(this, GwcActivity.class));
                break;
            case R.id.by:
                startActivity(new Intent(this, GwcActivity.class));
                break;
        }
    }
}
这里贴上Adapter适配器 适配商品列表
public class MyGoodListAdapter extends XRecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<GoodListBean.DataBean> data;
    Context context;

    public MyGoodListAdapter(List<GoodListBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

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

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyViewHolder myViewHolder = (MyGoodListAdapter.MyViewHolder) holder;
        myViewHolder.js.setText(data.get(position).getSubhead());
        myViewHolder.title.setText(data.get(position).getTitle());
        myViewHolder.newprice.setText(data.get(position).getPrice()+"");
        myViewHolder.price.setText(data.get(position).getPrice()+"");
        Glide.with(context).load(data.get(position).getImages().split("!")[0]).into(myViewHolder.img);
        myViewHolder.linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, XiangQingActivity.class);
//                Intent intent = new Intent(context, GwcActivity.class);
                intent.putExtra("pid",data.get(position).getPid()+"");
                context.startActivity(intent);
            }
        });
    }

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

    class MyViewHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView title,js,price,newprice;
        private final LinearLayout linear;

        public MyViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            title = itemView.findViewById(R.id.title);
            js = itemView.findViewById(R.id.js);
            price = itemView.findViewById(R.id.price);
            newprice = itemView.findViewById(R.id.newprice);
            linear = itemView.findViewById(R.id.linear);
        }
    }


}
购物车Api
public interface MyGwcApi  {
    @GET("product/getCarts")
    Observable<GwcBean> getGwc(@Query("source") String source,@Query("uid") String uid);
}
M请求数据购物车模块
public class GwcModel implements IModel {
    public Observable<GwcBean> gwc(){
        MyGwcApi creat = new RxJavaUtils("http://120.27.23.105/").creat(MyGwcApi.class);
        Observable<GwcBean> android = creat.getGwc("android", "2902");
        return android;
    }
}
开始购物车模块的Pceng
public class GwcPersent extends IPersent<GwcView> {

    private GwcModel gwcModel;

    public GwcPersent(GwcView view) {
        super(view);
    }

    @Override
    protected void init() {
        gwcModel = new GwcModel();
    }

    public void getGwcAction(){
        final Observable<GwcBean> gwc = gwcModel.gwc();
        gwc.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<GwcBean>() {
                    @Override
                    public void accept(GwcBean gwcBean) throws Exception {

                            view.getGwcSucceed(gwcBean);

                    }
                });
    }
}
public abstract class IPersent <T extends GwcView> {
    T view;

    public IPersent(T view){
        this.view = view;
        init();
    }

    protected abstract void init();
}
public interface GwcView extends IView{
    void getGwcSucceed(GwcBean bean);
}
V层接口
public interface GwcView extends IView{
    void getGwcSucceed(GwcBean bean);
}
Activity
public class GwcActivity extends AppCompatActivity implements GwcView {

    @InjectView(R.id.elv)
    ExpandableListView elv;
    @InjectView(R.id.checkbox2)
    CheckBox checkbox2;
    @InjectView(tv_price)
    TextView tvPrice;
    @InjectView(R.id.tv_num)
    TextView tvNum;
    private GwcPersent gwcPersent;
    private List<List<GwcBean.DataBean.ListBean>> list;
    private MyGwcAdapter myGwcAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gwc);
        ButterKnife.inject(this);
        gwcPersent = new GwcPersent(this);
        gwcPersent.getGwcAction();


    }

    @Override
    public void getGwcSucceed(GwcBean bean) {
        Toast.makeText(this, "000" + bean.getCode(), Toast.LENGTH_SHORT).show();
        Log.e("TAG", "123456" + bean.getMsg());
        List<GwcBean.DataBean> data = bean.getData();
        list = new ArrayList<>();
        for (int i = 0; i < data.size(); i++) {
            GwcBean.DataBean dataBean = data.get(i);
            list.add(dataBean.getList());
        }
        myGwcAdapter = new MyGwcAdapter(this, data, list);
        elv.setAdapter(myGwcAdapter);
        elv.setGroupIndicator(null);
        for (int i = 0; i < data.size(); i++) {
            elv.expandGroup(i);
        }
    }

    @OnClick({R.id.checkbox2, R.id.tv_num})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.checkbox2:
                if(checkbox2.isChecked()){
                    myGwcAdapter.AllCheck(true);
                }else{
                    myGwcAdapter.AllCheck(false);
                }
                break;
            case R.id.tv_num:
                break;
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(EventBean event) {/*  */
        checkbox2.setChecked(event.getFalg());
        Log.e("TAG","======"+event.getFalg()+event.getNum()+event.getPrice());
        tvNum.setText(event.getNum());
        tvPrice.setText(event.getPrice());
    }

    ;
}
适配器
public class MyGwcAdapter extends BaseExpandableListAdapter {
    Context context;
    List<GwcBean.DataBean> groupList;
    List<List<GwcBean.DataBean.ListBean>> childrenlist;
    private int price;
    private int count;


    public MyGwcAdapter(Context context, List<GwcBean.DataBean> groupList, List<List<GwcBean.DataBean.ListBean>> childrenlist) {
        this.context = context;
        this.groupList = groupList;
        this.childrenlist = childrenlist;
        AllCheck(true);
        AllPrice();
    }

    @Override
    public int getGroupCount() {
        return groupList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return childrenlist.get(groupPosition).size();
    }

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

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return childrenlist.get(groupPosition).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 true;
    }

    @Override
    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.group_item_layout, parent, false);
        final gViewHolder gHolder = new gViewHolder(inflate);
        final GwcBean.DataBean dataBean = groupList.get(groupPosition);
        gHolder.checkGroup.setChecked(dataBean.isGroupChecked());
        gHolder.textGroup.setText(dataBean.getSellerName());
        gHolder.checkGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gHolder.checkGroup.isChecked()) {
                    groupList.get(groupPosition).setGroupChecked(true);
                    for (int i = 0; i < childrenlist.get(groupPosition).size(); i++) {
                        childrenlist.get(groupPosition).get(i).setChildrenChecked(true);
                    }
//                    if (isGroupdAllCheek()) {
//                        EventBus.getDefault().post(new EventBean(true, "", ""));
//                    }
                    AllPrice();
                    notifyDataSetChanged();
                } else {
                    groupList.get(groupPosition).setGroupChecked(false);
                    for (int i = 0; i < childrenlist.get(groupPosition).size(); i++) {
                        childrenlist.get(groupPosition).get(i).setChildrenChecked(false);
                    }
                    EventBus.getDefault().post(new EventBean(false, "", ""));
                }
                AllPrice();
                notifyDataSetChanged();
            }
        });
        return inflate;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.child_item_layout, parent, false);
        final cViewHolder cHolder = new cViewHolder(inflate);
        final GwcBean.DataBean.ListBean listBean = childrenlist.get(groupPosition).get(childPosition);
        cHolder.checkChild.setChecked(listBean.isChildrenChecked());
        cHolder.textPrice.setText(listBean.getPrice() + "");
        Glide.with(context).load(listBean.getImages().split("!")[0]).into(cHolder.imageGood);
        cHolder.textNum.setText(listBean.getNum() + "");
        cHolder.textTitle.setText(listBean.getTitle());
        cHolder.textAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = childrenlist.get(groupPosition).get(childPosition).getNum();
                num+=1;
                childrenlist.get(groupPosition).get(childPosition).setNum(num);
                AllPrice();
            }
        });
        cHolder.textJian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = childrenlist.get(groupPosition).get(childPosition).getNum();
                if(!(num<2)){
                    num-=1;
                    childrenlist.get(groupPosition).get(childPosition).setNum(num);
                    AllPrice();
                }

            }
        });
        cHolder.checkChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cHolder.checkChild.isChecked()) {
                    listBean.setChildrenChecked(true);
                    if (isChildAllCheek(groupPosition)) {
                        groupList.get(groupPosition).setGroupChecked(true);
//                        if (isGroupdAllCheek()) {
//                            EventBus.getDefault().post(new EventBean(true, "", ""));
//                        }
                    }
                    AllPrice();
                    notifyDataSetChanged();
                } else {
                    listBean.setChildrenChecked(false);
                    groupList.get(groupPosition).setGroupChecked(false);
                    EventBus.getDefault().post(new EventBean(false, "", ""));
                }
                AllPrice();
                notifyDataSetChanged();
            }
        });
        return inflate;
    }

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

    public boolean isChildAllCheek(int groupPosition) {
        for (int i = 0; i < childrenlist.get(groupPosition).size(); i++) {
            GwcBean.DataBean.ListBean listBean1 = childrenlist.get(groupPosition).get(i);
            if (!listBean1.isChildrenChecked()) {
                return false;
            }
        }
        return true;
    }

    public boolean isGroupdAllCheek() {
        for (int i = 0; i < groupList.size(); i++) {
            if (!groupList.get(i).isGroupChecked()) {
                return false;
            }
        }

        return true;
    }

    public void AllCheck(Boolean falg) {
        for (int i = 0; i < groupList.size(); i++) {
            GwcBean.DataBean dataBean = groupList.get(i);
            dataBean.setGroupChecked(falg);
            for (int j = 0; j < dataBean.getList().size(); j++) {
                GwcBean.DataBean.ListBean listBean = dataBean.getList().get(j);
                listBean.setChildrenChecked(falg);
            }
        }
        AllPrice();
        notifyDataSetChanged();
    }

    public void AllPrice() {
        price = 0;
        count = 0;
        for (int i = 0; i < groupList.size(); i++) {
            int size = childrenlist.get(i).size();
            for (int j = 0; j < size; j++) {
                GwcBean.DataBean.ListBean listBean = childrenlist.get(i).get(j);
                if (listBean.isChildrenChecked()) {
                    count += listBean.getNum();
                    price += listBean.getBargainPrice() * listBean.getNum();
                }
            }
        }
        notifyDataSetChanged();
        EventBus.getDefault().post(new EventBean(isGroupdAllCheek(), price+"", count+""));
    }

    static class gViewHolder {
        @InjectView(R.id.check_group)
        CheckBox checkGroup;
        @InjectView(R.id.text_group)
        TextView textGroup;

        gViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    static class cViewHolder {
        @InjectView(R.id.check_child)
        CheckBox checkChild;
        @InjectView(R.id.image_good)
        ImageView imageGood;
        @InjectView(R.id.text_title)
        TextView textTitle;
        @InjectView(R.id.text_price)
        TextView textPrice;
        @InjectView(R.id.text_jian)
        TextView textJian;
        @InjectView(R.id.text_num)
        TextView textNum;
        @InjectView(R.id.text_add)
        TextView textAdd;

        cViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
EventBean
public class EventBean {
    private Boolean falg;
    private String num;
    private String price;

    public EventBean(Boolean falg, String num, String price) {
        this.falg = falg;
        this.num = num;
        this.price = price;
    }

    public Boolean getFalg() {
        return falg;
    }

    public void setFalg(Boolean falg) {
        this.falg = falg;
    }

    public String getNum() {
        return num;
    }

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

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }
}
购物车Bean
public class GwcBean {
 

    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 {
   
        private boolean groupChecked;
        private String sellerName;
        private String sellerid;
        private List<ListBean> list;

        public boolean isGroupChecked() {
            return groupChecked;
        }

        public void setGroupChecked(boolean groupChecked) {
            this.groupChecked = groupChecked;
        }

        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 {


            private boolean childrenChecked;
            private double bargainPrice;
            private String createtime;
            private String detailUrl;
            private String images;
            private int num;
            private int pid;
            private double price;
            private int pscid;
            private int selected;
            private int sellerid;
            private String subhead;
            private String title;

            public boolean isChildrenChecked() {
                return childrenChecked;
            }

            public void setChildrenChecked(boolean childrenChecked) {
                this.childrenChecked = childrenChecked;
            }

            public double getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(double 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 double getPrice() {
                return price;
            }

            public void setPrice(double 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;
            }
        }
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值