Mvp复杂 二级购物车加删除


//---------------------------------------MainActivity布局
<?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="match_parent"
    android:orientation="vertical">
    <ExpandableListView
        android:id="@+id/elv"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:childIndicator="@null"
        android:groupIndicator="@null" >
    </ExpandableListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <CheckBox
            android:id="@+id/all_chekbox"
            android:layout_marginLeft="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="全选"/>
        <LinearLayout
            android:id="@+id/ll_info"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginRight="20dp"
                android:layout_weight="1"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="right"
                    >
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="合计:"
                        android:textSize="18sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/total_price"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="¥0.00"
                        android:textColor="#f23232"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>

            </LinearLayout>
            <TextView
                android:id="@+id/tv_go_to_pay"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:background="#fd7a05"
                android:clickable="true"
                android:gravity="center"
                android:text="结算"
                android:textColor="#FAFAFA"
                />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
 
 
 
//------------------------------------------父级别的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:background="#cccc"
    android:layout_height="match_parent">
    <CheckBox
        android:id="@+id/group_checkbox"
        android:layout_marginLeft="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"/>

    <TextView
        android:id="@+id/shop_name"
        android:layout_marginLeft="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="23dp" />
</LinearLayout>


 
//----------------------------------------------子级别的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="match_parent">

    <CheckBox
        android:id="@+id/child_checkbox"
        android:layout_width="0dp"
        android:layout_marginLeft="45dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="9">

        <TextView
            android:id="@+id/shop_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="17dp"
            android:layout_marginStart="17dp"
            android:textSize="20dp"
            android:text="TextView" />

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/shop_img"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_marginTop="10dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/shop_price"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:textSize="25dp"
                    android:text="¥20"
                    android:textColor="#f23232" />
                <Button
                    android:id="@+id/delete_btn"
                    android:text="删除"
                    android:background="#fd7a05"
                    android:layout_marginLeft="200dp"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp" />

                <com.example.shopping.AddDeleteView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/adddeleteview"
                    android:gravity="center">
                </com.example.shopping.AddDeleteView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

//自定义View的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="减"
        android:gravity="center"
        android:textSize="20dp"
        android:id="@+id/txt_delete"
        />
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/et_number"
        android:layout_weight="2"
        android:gravity="center"
        android:textSize="20dp"
        android:text="1"
        />
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="加"
        android:gravity="center"
        android:id="@+id/txt_add"
        android:textSize="20dp"
        />
</LinearLayout>

 
//------------------------------Iview
Iview
package com.example.shopping.view;

/**
 * Created by on 2017/12/13.
 */

public interface Iview {
    void OnSuccess(Object o);
    void OnFailed(Exception e);
}
//---------------------------------BasePersenter
package com.example.shopping.presenters;

import java.util.Map;

/**
 * Created by  on 2017/12/13.
 */

public interface BasePersenter {
    void getData(Map<String,String> map);
}
//----------------------------------Imodel
package com.example.shopping.model;
import java.util.Map;

/**
 * Created by on 2017/12/13.
 */

public interface Imodel {
    void getData(Map<String,String> map);
}

//----------------------------------ModelView
package com.example.shopping.model;
import com.example.shopping.bean.Child;
import java.util.List;

/**
 * Created by on 2017/12/14.
 */

public interface MoneyView {
    void isCheck(List<List<Child>> list);
}
//-------------------------------------ApiService
package com.example.shopping.http;
import com.example.shopping.bean.DaBean;
import com.example.shopping.bean.MessageBean;
import java.util.Map;
import io.reactivex.Flowable;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;

/**
 * Created by  on 2017/12/13.
 */

public interface ApiService {
     @POST("product/getCarts")
     Flowable<DaBean> getNews(@QueryMap Map<String,String> map);

    @POST("product/deleteCart")
    Flowable<MessageBean> deleteData(@Query("uid") String uid, @Query("pid") String pid);
}

//---------------------------------------Imodel
package com.example.shopping.model;
import com.example.shopping.bean.DaBean;
import com.example.shopping.http.RetrofitUtils;
import com.example.shopping.presenters.NewsPersenter;
import java.util.Map;
import io.reactivex.Flowable;

/**
 * Created by  on 2017/12/13.
 */

public class NewsModel implements Imodel{
    private NewsPersenter presenter;
    public NewsModel(NewsPersenter presenter){
        this.presenter=presenter;
    }

    @Override
    public void getData(Map<String, String> map) {
        Flowable<DaBean> news = RetrofitUtils.getInstance().getApiService().getNews(map);
        presenter.getNews(news);
    }
}

//------------------------------------------------------BasePersenter
package com.example.shopping.presenters;
import com.example.shopping.bean.DaBean;
import com.example.shopping.model.Imodel;
import com.example.shopping.model.NewsModel;
import com.example.shopping.view.Iview;
import java.util.Map;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;

/**
 * Created by  on 2017/12/13.
 */

public class NewsPersenter implements  BasePersenter{
    private Iview iv;
    private DisposableSubscriber subscriber;
    public  void attacView(Iview iv){
        this.iv=iv;
    }

    public void detachView() {
        if (iv != null) {
            iv = null;
        }
        if (subscriber != null) {//rxjava的防止内存泄漏
            if (!subscriber.isDisposed()) {
                subscriber.isDisposed();
            }
        }
    }

    public void getNews(Flowable<DaBean> news){
         news.subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribeWith(new DisposableSubscriber<DaBean>() {
                     @Override
                     public void onNext(DaBean daBean) {
                         iv.OnSuccess(daBean);
                     }

                     @Override
                     public void onError(Throwable t) {

                     }

                     @Override
                     public void onComplete() {

                     }
                 });
    }
    @Override
    public void getData(Map<String, String> map) {
        Imodel model=new NewsModel(this);//多态  this是当前的p层、
        model.getData(map);
    }
}

//-----------------------------------RetrofitUtils
package com.example.shopping.http;
import com.example.shopping.Logger;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by on 2017/12/13.
 */

public class RetrofitUtils {
    private  static  volatile RetrofitUtils instance;
    private final ApiService apiService;

    private RetrofitUtils() {
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl("http://120.27.23.105/")
                .client(new OkHttpClient.Builder().addInterceptor(new Logger()).build())
                .build();
        apiService = retrofit.create(ApiService.class);
    }

        public static  RetrofitUtils getInstance(){
            if (instance==null){
                synchronized (RetrofitUtils.class){
                    if (null==instance){
                        instance=new RetrofitUtils();
                    }
                }
            }
            return  instance;
        }


    public ApiService getApiService(){
        return  apiService;
    }
}

//-------------------------------------------------------适配器
package com.example.shopping.adapter;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.shopping.AddDeleteView;
import com.example.shopping.MainActivity;
import com.example.shopping.R;
import com.example.shopping.bean.Child;
import com.example.shopping.bean.Group;
import com.example.shopping.model.MoneyView;
import org.greenrobot.eventbus.EventBus;
import java.util.List;

/**
 * Created by on 2017/12/14.
 */

public class ExpandableAdapter extends BaseExpandableListAdapter {

    private Context context;
    private List<Group> group;
    private List<List<Child>> child;
    //实现该接口
    private MoneyView moneyview;
    private TextView shop_title;
    private ImageView shop_img;
    private TextView shop_price;
    private View delete_btn;

    public ExpandableAdapter(Context context, List<Group> group, List<List<Child>> child, MoneyView moneyview) {
        this.context = context;
        this.group = group;
        this.child = child;
        this.moneyview = moneyview;
    }


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

    @Override
    public int getChildrenCount(int i) {
        return child.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return group.get(i).getSellerName();
    }

    @Override
    public Object getChild(int i, int i1) {
        return child.get(i).get(i1).getTitle();
    }

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

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

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

    @Override
    public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
        final View view9 = View.inflate(context, R.layout.group, null);
        final CheckBox groupCb = view9.findViewById(R.id.group_checkbox);
        TextView shopName = view9.findViewById(R.id.shop_name);

        shopName.setText(group.get(i).getSellerName());
        groupCb.setChecked(group.get(i).isGropuCb());

        //一级的复选框
        groupCb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //checked 一级的check
                if (groupCb.isChecked() == true) {
                    //遍历子集合 让子集合中的Boolean值改为true
                    List<Child> childBeen1 = child.get(i);
                    for (int x = 0; x < childBeen1.size(); x++) {
                        childBeen1.get(x).setChildCb(true);
                    }
                    //改父级别的check的值
                    group.get(i).setGropuCb(true);
                    //刷新  重新加载
                    notifyDataSetChanged();

                    moneyview.isCheck(child);
                } else {
                    List<Child> childBeen1 = child.get(i);
                    for (int x = 0; x < childBeen1.size(); x++) {
                        childBeen1.get(x).setChildCb(false);
                    }
                    group.get(i).setGropuCb(false);
                    notifyDataSetChanged();
                }

                //3全选设置
                //得到Activity的全选按钮
                MainActivity tag = (MainActivity) context;
                CheckBox checkAll = (CheckBox) tag.findViewById(R.id.all_chekbox);
                //设置一个初始的boolean值 用来判断
                Boolean A = true;
                //遍历父集合
                for (int i = 0; i < group.size(); i++) {
                    boolean gropuCb = group.get(i).isGropuCb();
                    if (gropuCb != true) {
                        A = false;
                        break;
                    }
                }
                //设置全选按钮
                checkAll.setChecked(A);

                moneyview.isCheck(child);
            }
        });
        return view9;

    }

    @Override
    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
        View viewa = View.inflate(context, R.layout.child, null);
        final CheckBox childCheck=  viewa.findViewById(R.id.child_checkbox);
        shop_title =viewa.findViewById(R.id.shop_title);
        shop_img =viewa.findViewById(R.id.shop_img);
        shop_price =viewa.findViewById(R.id.shop_price);
        delete_btn =viewa.findViewById(R.id.delete_btn);

        //找到自定义的View主键
        final AddDeleteView adv=  viewa.findViewById(R.id.adddeleteview);
        adv.setNumber(child.get(i).get(i1).getNum());

        //删除   发送pid
        delete_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(child.get(i).get(i1).getPid());
            }
        });


        adv.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {
            @Override
            public void onAddClick(View v) {
                int origin=adv.getNumber();
                origin++;
                adv.setNumber(origin);

                //设置子check为true
                child.get(i).get(i1).setChildCb(true);
                child.get(i).get(i1).setNum(origin);

                Log.e("TAG",origin+"");

                notifyDataSetChanged();

                moneyview.isCheck(child);

            }

            @Override
            public void onDelClick(View v) {
                int origin=adv.getNumber();
                origin--;
                adv.setNumber(origin);

                //设置子check为true
                child.get(i).get(i1).setChildCb(true);
                child.get(i).get(i1).setNum(origin);
                notifyDataSetChanged();

                moneyview.isCheck(child);
            }
        });


        shop_title.setText(child.get(i).get(i1).getTitle());
        String images = child.get(i).get(i1).getImages();
        Glide.with(context).load(images).into(shop_img);
        shop_price.setText(child.get(i).get(i1).getPrice()+"");
        childCheck.setChecked(child.get(i).get(i1).isChildCb());

        //子级别的点击事件都点完之后  父级别根着动
        childCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //得到子类里状态值
                boolean childCb = child.get(i).get(i1).isChildCb();
                if(childCb){
                    child.get(i).get(i1).setChildCb(false);
                }else{
                    child.get(i).get(i1).setChildCb(true);
                }
                //写一个变量值用来判断
                Boolean A=true;
                //遍历子集合
                List<Child> childBeen1 = child.get(i);
                for (int i=0;i<childBeen1.size();i++){
                    //判断子级别中有没有false
                    if(childBeen1.get(i).isChildCb()==false){
                        A=false;
                    }
                }
                //如果为true 子级别全选
                if(A){
                    //设置父级别的选择框
                    group.get(i).setGropuCb(true);
                }else{
                    group.get(i).setGropuCb(false);
                }
                notifyDataSetChanged();



                //子级别的全选按钮的判断设置
                MainActivity tag= (MainActivity) context;
                CheckBox checkAll= (CheckBox) tag.findViewById(R.id.all_chekbox);
                //设置一个初始的boolean值 用来判断
                Boolean B=true;
                //遍历父集合
                for(int x=0;x<child.size();x++){
                    List<Child> childBeen = ExpandableAdapter.this.child.get(x);
                    for(int j=0;j<childBeen.size();j++){
                        boolean childCb1 = childBeen.get(j).isChildCb();
                        if(childCb1!=true){
                            B=false;
                            break;
                        }
                    }
                }
                //设置全选按钮
                checkAll.setChecked(B);

                moneyview.isCheck(child);
            }
        });
        return viewa;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}

//---------------------------------------------自定义View
package com.example.shopping;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by  on 2017/12/14.
 */

public class AddDeleteView extends LinearLayout {
    //设置接口回调
    private OnAddDelClickListener Listener;
    private TextView etNumber;

    public interface OnAddDelClickListener{
        void onAddClick(View v);
        void onDelClick(View v);
    }
    //接口对象
    public void setOnAddDelClickListener(OnAddDelClickListener Listener){
        if (Listener!=null){
            this.Listener=Listener;
        }
    }


    public AddDeleteView(Context context) {
        this(context,null);
    }

    public AddDeleteView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AddDeleteView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        //加载布局
        View view = View.inflate(context, R.layout.zidingyiview, this);

        //获得主键
        TextView txtDelete = (TextView) findViewById(R.id.txt_delete);
        TextView txtAdd = (TextView) findViewById(R.id.txt_add);
        etNumber = (TextView) findViewById(R.id.et_number);

        //点击事件
        txtAdd.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Listener.onAddClick(AddDeleteView.this);
            }
        });

        txtDelete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Listener.onDelClick(AddDeleteView.this);
            }
        });
    }

    //对外提供设置EditText值得方法
    public void setNumber(int number){
        if (number>0){
            etNumber.setText(number+"");
        }
    }

    public int getNumber(){
        int number=0;
        try {
            String trim = etNumber.getText().toString().trim();
            number = Integer.valueOf(trim);
        }catch (Exception e){
            number=0;
        }
        return number;
    }
}

//--------------------------------------------------拦截器
package com.example.shopping;
import java.io.IOException;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by  on 2017/12/14.
 */

public class Logger 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);
    }
}

//----------------------------------------------------MianActivity
package com.example.shopping;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.shopping.adapter.ExpandableAdapter;
import com.example.shopping.bean.Child;
import com.example.shopping.bean.DaBean;
import com.example.shopping.bean.Group;
import com.example.shopping.bean.MessageBean;
import com.example.shopping.http.RetrofitUtils;
import com.example.shopping.model.MoneyView;
import com.example.shopping.presenters.NewsPersenter;
import com.example.shopping.view.Iview;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;
import static com.example.shopping.R.id.elv;

public class MainActivity extends AppCompatActivity implements Iview,MoneyView{

    private ExpandableListView exlv;
    List<Group> groupBeen=new ArrayList<>();
    List<List<Child>> data2=new ArrayList<>();
    private TextView total_price;
    private CheckBox all_chekbox;
    private NewsPersenter presenter;
    private ExpandableAdapter expandableAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        exlv =(ExpandableListView)findViewById(elv);
        total_price =(TextView)findViewById(R.id.total_price);//价钱
        all_chekbox =(CheckBox)findViewById(R.id.all_chekbox);

        EventBus.getDefault().register(this);

        HashMap<String, String> map = new HashMap<>();
        map.put("uid","1234");
        presenter = new NewsPersenter();
        presenter.attacView(this);
        presenter.getData(map);

        //全选的点击事件
        all_chekbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //初始值
                double money = 0;
                //判断全选的check是否为选择状态
                if(all_chekbox.isChecked()){
                    //更改父子check状态
                    for (int i=0;i<groupBeen.size();i++){
                        groupBeen.get(i).setGropuCb(true);
                        List<Child> childBeen = MainActivity.this.data2.get(i);
                        for(int x=0;x<childBeen.size();x++){
                            childBeen.get(x).setChildCb(true);
                            //计算全选的价格
                            int num = childBeen.get(x).getNum();
                            double price = childBeen.get(x).getPrice();
                            money=money+num*price;
                        }
                    }
                    //设置底部的价格money的显示
                    total_price.setText(money+"");
                }else{
                    for (int i=0;i<groupBeen.size();i++){
                        groupBeen.get(i).setGropuCb(false);
                        List<Child> childBeen = MainActivity.this.data2.get(i);
                        for(int x=0;x<childBeen.size();x++){
                            childBeen.get(x).setChildCb(false);
                        }
                    }
                    total_price.setText(0+"");
                }
                expandableAdapter.notifyDataSetChanged();
            }
        });

    }

    @Override
    public void OnSuccess(Object o) {
        DaBean bean=(DaBean)o;
        List<DaBean.DataBean> data = bean.getData();
        for (DaBean.DataBean i:data){
            Group groupBean = new Group(i.getSellerName(), false);
            this.groupBeen.add(groupBean);

            //二级
            List<DaBean.DataBean.ListBean> list = i.getList();
            List<Child> ls=new ArrayList<>();
            for (DaBean.DataBean.ListBean w:list){
                String[] split = w.getImages().toString().split("\\|");
                Child childBean = new Child(w.getTitle(),split[0], w.getPrice(), 1, false, false,w.getPid()+"");
                ls.add(childBean);
            }
            this.data2.add(ls);
        }
        expandableAdapter = new ExpandableAdapter(MainActivity.this, groupBeen, data2,this);
        exlv.setAdapter(expandableAdapter);
        //默认展开
        for (int i = 0; i< expandableAdapter.getGroupCount(); i++){
            exlv.expandGroup(i);
        }
    }

    @Override
    public void OnFailed(Exception e) {

    }

    @Override
    public void isCheck(List<List<Child>> list) {
        double money=0;
        for (int i=0;i<data2.size();i++){
            List<Child> childBeen = MainActivity.this.data2.get(i);
            for(int x=0;x<childBeen.size();x++){
                //计算全选的价格
                if(childBeen.get(x).isChildCb()){
                    int num = childBeen.get(x).getNum();
                    double price = childBeen.get(x).getPrice();
                    money=money+num*price;
                }
            }
        }
        //设置底部的价格money的显示
        total_price.setText(money+"");
    }

    @Subscribe
    public void onEventMainThread(final String event) {
        Flowable<MessageBean> messageBeanFlowable = RetrofitUtils.getInstance().getApiService().deleteData("1234", event);
        messageBeanFlowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<MessageBean>() {
                    @Override
                    public void onNext(MessageBean messageBean) {
                        String code = messageBean.getCode();
                        if(code.equals("0")){

                            Toast.makeText(MainActivity.this,"删除成功",Toast.LENGTH_SHORT).show();

                            //data2.remove(event);

                            data2.clear();
                            groupBeen.clear();

                            HashMap<String, String> map = new HashMap<>();
                            map.put("uid","1234");
                            presenter.getData(map);
                            expandableAdapter.notifyDataSetChanged();
                        }else{
                            Toast.makeText(MainActivity.this,"删除失败",Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }

}

//---------------------------------------------------------------------------总的Bean
package com.example.shopping.bean;
import java.util.List;

/**
 * Created by on 2017/12/13.
 */

public class DaBean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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":2,"pid":9,"price":78.99,"pscid":1,"selected":0,"sellerid":2,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","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":3,"pid":10,"price":555.55,"pscid":1,"selected":0,"sellerid":3,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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":11,"price":8989,"pscid":1,"selected":0,"sellerid":4,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家4","sellerid":"4"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":69,"price":16999,"pscid":40,"selected":0,"sellerid":13,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家13","sellerid":"13"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","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":11,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","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":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","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":5,"price":88.99,"pscid":1,"selected":0,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家21","sellerid":"21"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","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":7,"price":120.01,"pscid":1,"selected":0,"sellerid":23,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家23","sellerid":"23"}]
     */

    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":111.99,"createtime":"2017-10-14T21:48:08","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":2,"pid":9,"price":78.99,"pscid":1,"selected":0,"sellerid":2,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}]
         * sellerName : 商家2
         * sellerid : 2
         */

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

        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 : 111.99
             * createtime : 2017-10-14T21:48:08
             * 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 : 2
             * pid : 9
             * price : 78.99
             * pscid : 1
             * selected : 0
             * sellerid : 2
             * subhead : 每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下
             * title : 北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g
             */

            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 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;
            }
        }
    }
}

//------------------------------------------------------------父级别的Bean
package com.example.shopping.bean;

/**
 * Created by n 2017/12/13.
 */

public class Group {
    private String sellerName;///
    private boolean gropuCb;

    public Group(String sellerName, boolean gropuCb) {
        this.sellerName = sellerName;
        this.gropuCb = gropuCb;
    }

    public String getSellerName() {
        return sellerName;
    }

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

    public boolean isGropuCb() {
        return gropuCb;
    }

    public void setGropuCb(boolean gropuCb) {
        this.gropuCb = gropuCb;
    }
}
//-----------------------------------------------------------------子级别的Bean
package com.example.shopping.bean;

/**
 * Created by  on 2017/12/13.
 */

public class Child {
    private String title;
    private String images;
    private double price;
    private int num;
    private boolean childCb;
    private boolean btn;
    private String pid;


    public Child(String title, String images, double price, int num, boolean childCb, boolean btn, String pid) {
        this.title = title;
        this.images = images;
        this.price = price;
        this.num = num;
        this.childCb = childCb;
        this.btn = btn;
        this.pid = pid;
    }

    public String getTitle() {
        return title;
    }

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

    public String getImages() {
        return images;
    }

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

    public double getPrice() {
        return price;
    }

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

    public int getNum() {
        return num;
    }

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

    public boolean isChildCb() {
        return childCb;
    }

    public void setChildCb(boolean childCb) {
        this.childCb = childCb;
    }

    public boolean isBtn() {
        return btn;
    }

    public void setBtn(boolean btn) {
        this.btn = btn;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }
}
//===-------------------------------------------------------删除成功和失败的Bean
package com.example.shopping.bean;

/**
 * Created by on 2017/12/14.
 */

public class MessageBean {

    /**
     * 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;
    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值