package com.example.administrator.erzhoumoni.shopcar; import com.example.administrator.erzhoumoni.base.BaseContract; import com.example.administrator.erzhoumoni.bean.GetCartsBean; import com.example.administrator.erzhoumoni.bean.SellerBean; import java.util.List; /** * Created by Administrator on 2018/5/19 0019. */ public interface ShopCarContract { interface View extends BaseContract.BaseView{ void getCartsSuccess( List<SellerBean> groupList, List<List<GetCartsBean.DataBean.ListBean>> childList); void updateCartsSuccess(String msg); void deleteCartSuccess(String msg); } interface presenter extends BaseContract.BasePresenter<View>{ void getCarts(String uid, String token); void updateCarts(String uid, String sellerid, String pid, String num, String selected, String token); void deleteCart(String uid, String pid, String token); }
}
package com.example.administrator.erzhoumoni.shopcar; import com.example.administrator.erzhoumoni.base.BasePresenter; import com.example.administrator.erzhoumoni.bean.BaseBean; import com.example.administrator.erzhoumoni.bean.GetCartsBean; import com.example.administrator.erzhoumoni.bean.SellerBean; import com.example.administrator.erzhoumoni.net.ProjectApi; import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; /** * Created by Administrator on 2018/5/19 0019. */ public class ShopCarPresenter extends BasePresenter<ShopCarContract.View> implements ShopCarContract.presenter { private ProjectApi projectApi; @Inject public ShopCarPresenter(ProjectApi projectApi) { this.projectApi = projectApi; } @Override public void getCarts(String uid, String token) { projectApi.getCarts(uid,token) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<GetCartsBean>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(GetCartsBean getCartsBean) { List<SellerBean> groupList = new ArrayList<>(); List<List<GetCartsBean.DataBean.ListBean>> childList = new ArrayList<>(); List<GetCartsBean.DataBean> data = getCartsBean.getData(); for (int i = 0; i < data.size(); i++) { GetCartsBean.DataBean dataBean = data.get(i); SellerBean sellerBean = new SellerBean(); sellerBean.setSellerid(dataBean.getSellerid()); sellerBean.setSellerName(dataBean.getSellerName()); sellerBean.setSelected(isSellerProductAllSelect(dataBean)); groupList.add(sellerBean); List<GetCartsBean.DataBean.ListBean> list = dataBean.getList(); childList.add(list); } if (mView != null) { mView.getCartsSuccess(groupList,childList); } } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } @Override public void updateCarts(String uid, String sellerid, String pid, String num, String selected, String token) { projectApi.updateCarts(uid, sellerid, pid, num, selected, token) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map(new Function<BaseBean, String>() { @Override public String apply(BaseBean baseBean) throws Exception { return baseBean.getMsg(); } }).subscribe(new Observer<String>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(String s) { if (mView != null) { mView.updateCartsSuccess(s); } } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } @Override public void deleteCart(String uid, String pid, String token) { projectApi.deleteCart(uid, pid, token) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map(new Function<BaseBean, String>() { @Override public String apply(BaseBean baseBean) throws Exception { return baseBean.getMsg(); } }).subscribe(new Observer<String>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(String s) { if (mView != null) { mView.deleteCartSuccess(s); } } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); } public boolean isSellerProductAllSelect(GetCartsBean.DataBean dataBean){ List<GetCartsBean.DataBean.ListBean> list = dataBean.getList(); for (int i = 0; i <list.size() ; i++) { GetCartsBean.DataBean.ListBean listBean = list.get(i); if (listBean.getSelected()==0){ return false; } } return true; } }
AddSubLayout
package com.example.administrator.erzhoumoni; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; /** * Created by Administrator on 2018/4/29 0029. */ public class AddSubLayout extends LinearLayout { private TextView add; private TextView sub; private EditText num; public AddSubLayout(Context context) { this(context,null); } public AddSubLayout(Context context, @Nullable AttributeSet attrs) { this(context, attrs,0); } public AddSubLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); View view = LayoutInflater.from(context).inflate(R.layout.add_sub_item, this); add = view.findViewById(R.id.add); sub = view.findViewById(R.id.sub); num = view.findViewById(R.id.num); } //设置数量 public void setNum(String str){ num.setText(str); } //获取数量 public String getNum(){ return num.getText().toString(); } // 给加号设置点击事件 public void setAddClickListeren(OnClickListener onClickListener){ add.setOnClickListener(onClickListener); } // 给减号设置点击事件 public void setSubClickListeren(OnClickListener onClickListener){ sub.setOnClickListener(onClickListener); } }
MainActivity
package com.example.administrator.erzhoumoni; 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 com.example.administrator.erzhoumoni.adapter.ElvShopcartAdapter; import com.example.administrator.erzhoumoni.base.BaseActivity; import com.example.administrator.erzhoumoni.bean.GetCartsBean; import com.example.administrator.erzhoumoni.bean.SellerBean; import com.example.administrator.erzhoumoni.component.DaggerHttpComponent; import com.example.administrator.erzhoumoni.shopcar.ShopCarContract; import com.example.administrator.erzhoumoni.shopcar.ShopCarPresenter; import com.example.administrator.erzhoumoni.uitls.SharedPreferencesUtils; import java.util.List; public class MainActivity extends BaseActivity<ShopCarPresenter> implements ShopCarContract.View { private ExpandableListView mElv; /** * 全选 */ private CheckBox mCbAll; /** * 合计: */ private TextView mTvMoney; /** * 去结算: */ private TextView mTvTotal; private ElvShopcartAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); SharedPreferencesUtils.setParam(this, "uid", "13681"); SharedPreferencesUtils.setParam(this, "token", "0D070EAEDE56DD9C682F519F06A7661A"); String token = (String) SharedPreferencesUtils.getParam(MainActivity.this, "token", ""); String uid = (String) SharedPreferencesUtils.getParam(MainActivity.this, "uid", ""); mPresenter.getCarts(uid,token); } private void initView() { mElv = (ExpandableListView) findViewById(R.id.elv); mCbAll = (CheckBox) findViewById(R.id.cbAll); mTvMoney = (TextView) findViewById(R.id.tvMoney); mTvTotal = (TextView) findViewById(R.id.tvTotal); mCbAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (adapter !=null){ adapter.changeAllState(mCbAll.isChecked()); } } }); } @Override public int getContentLayout() { return R.layout.activity_main; } @Override public void inject() { DaggerHttpComponent.builder().build().inject(this); } @Override public void getCartsSuccess(List<SellerBean> groupList, List<List<GetCartsBean.DataBean.ListBean>> childList) { //判断所有商家是否全部选中 mCbAll.setChecked(isSellerAddSelected(groupList)); adapter = new ElvShopcartAdapter(this,groupList,childList,mPresenter); mElv.setAdapter(adapter); String[] strings = adapter.computeMoneyAndNum(); mTvMoney.setText("总计:"+strings[0]+"元"); mTvTotal.setText("去结算("+strings[1]+"个)"); for (int i = 0; i <groupList.size() ; i++) { mElv.expandGroup(i); } } //* 判断所有商家是否全部选中 public boolean isSellerAddSelected(List<SellerBean> groupList){ for (int i = 0; i <groupList.size() ; i++) { SellerBean sellerBean = groupList.get(i); if (!sellerBean.getSelected()){ return false; } } return true; } @Override public void updateCartsSuccess(String msg) { if (adapter!=null){ adapter.updataSuccess(); } } @Override public void deleteCartSuccess(String msg) { if (adapter!=null){ adapter.delSuccess(); } } }
package com.example.administrator.erzhoumoni.adapter; import android.content.Context; import android.view.LayoutInflater; 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 android.widget.Toast; import com.example.administrator.erzhoumoni.AddSubLayout; import com.example.administrator.erzhoumoni.R; import com.example.administrator.erzhoumoni.bean.GetCartsBean; import com.example.administrator.erzhoumoni.bean.SellerBean; import com.example.administrator.erzhoumoni.shopcar.ShopCarPresenter; import com.example.administrator.erzhoumoni.uitls.SharedPreferencesUtils; import com.facebook.drawee.view.SimpleDraweeView; import java.util.List; /** * Created by Administrator on 2018/5/19 0019. */ public class ElvShopcartAdapter extends BaseExpandableListAdapter { private Context context; private List<SellerBean> groupList; private List<List<GetCartsBean.DataBean.ListBean>> childList; private ShopCarPresenter shopCarPresenter; private final LayoutInflater inflater; private final String uid; private final String token; private int productIndex; private boolean addSelect; private static final int GETCARTS = 0;//查询购物车 private static final int UPDATE_PRODUCT = 1; //更新商品 private static final int UPDATE_SELLER = 2; //更新卖家 private static int state = GETCARTS; private int groupPosition; private boolean checked; public ElvShopcartAdapter(Context context, List<SellerBean> groupList, List<List<GetCartsBean.DataBean.ListBean>> childList, ShopCarPresenter shopCarPresenter) { this.context = context; this.groupList = groupList; this.childList = childList; this.shopCarPresenter = shopCarPresenter; inflater = LayoutInflater.from(context); uid = (String) SharedPreferencesUtils.getParam(context, "uid", ""); token = (String) SharedPreferencesUtils.getParam(context, "token", ""); } @Override public int getGroupCount() { return groupList.size(); } @Override public int getChildrenCount(int groupPosition) { return childList.get(groupPosition).size(); } @Override public Object getGroup(int groupPosition) { return groupList.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return childList.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) { final GroupViewHolder groupViewHolder; if (convertView == null) { groupViewHolder = new GroupViewHolder(); convertView = inflater.inflate(R.layout.shopcart_seller_item, null); groupViewHolder.cbSeller = convertView.findViewById(R.id.cbSeller); groupViewHolder.tvSeller = convertView.findViewById(R.id.tvSeller); convertView.setTag(groupViewHolder); } else { groupViewHolder = (GroupViewHolder) convertView.getTag(); } //设置值 final SellerBean sellerBean = groupList.get(groupPosition); groupViewHolder.tvSeller.setText(sellerBean.getSellerName()); groupViewHolder.cbSeller.setChecked(sellerBean.getSelected()); groupViewHolder.cbSeller.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //设置当前的更新状态 state = UPDATE_PRODUCT; checked = groupViewHolder.cbSeller.isChecked(); //默认从第一个商品开始更新购物车状态 productIndex = 0; ElvShopcartAdapter.this.groupPosition=groupPosition; updateProductInSeller(); } }); return convertView; } //删除成功回调接口 public void delSuccess() { shopCarPresenter.getCarts(uid, token); } private void updateProductInSeller() { SellerBean sellerBean = groupList.get(groupPosition); String sellerid = sellerBean.getSellerid(); //获取pid GetCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(productIndex); int num = listBean.getNum(); int pid = listBean.getPid(); shopCarPresenter.updateCarts(uid, sellerid, pid + "", num + "", checked ? "1" : "0", token); } private void updateProductInSeller(boolean bool) { SellerBean sellerBean = groupList.get(groupPosition); String sellerid = sellerBean.getSellerid(); //获取pid GetCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(productIndex); int num = listBean.getNum(); int pid = listBean.getPid(); shopCarPresenter.updateCarts(uid, sellerid, pid + "", num + "", bool ? "1" : "0", token); } @Override public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final ChildViewHolder childViewHolder; if (convertView == null) { childViewHolder = new ChildViewHolder(); convertView = inflater.inflate(R.layout.shopcart_seller_product_item, null); childViewHolder.cbProduct = convertView.findViewById(R.id.cbProduct); childViewHolder.iv = convertView.findViewById(R.id.iv); childViewHolder.tvTitle = convertView.findViewById(R.id.tvTitle); childViewHolder.tvPrice = convertView.findViewById(R.id.tvPrice); childViewHolder.tvDel = convertView.findViewById(R.id.tvDel); childViewHolder.addSubLayout = convertView.findViewById(R.id.add_sub); convertView.setTag(childViewHolder); } else { childViewHolder = (ChildViewHolder) convertView.getTag(); } //设置值 final GetCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(childPosition); childViewHolder.tvTitle.setText(listBean.getTitle()); childViewHolder.tvPrice.setText(listBean.getPrice()+""); childViewHolder.iv.setImageURI(listBean.getImages().split("\\|")[0]); childViewHolder.cbProduct.setChecked(listBean.getSelected()==1?true:false); childViewHolder.addSubLayout.setNum(listBean.getNum()+""); childViewHolder.cbProduct.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { state = GETCARTS; ElvShopcartAdapter.this.groupPosition = groupPosition; //获取卖家id String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid String pid = listBean.getPid() + ""; //是否选中 boolean childchecked = childViewHolder.cbProduct.isChecked(); shopCarPresenter.updateCarts(uid,sellerid,pid,"1",childchecked?"1":"0",token); } }); //给删除设置点击事件 childViewHolder.tvDel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context,"点击了删除",Toast.LENGTH_LONG).show(); state = GETCARTS; //获取pid int pid = listBean.getPid(); //删除购物车里的选项 shopCarPresenter.deleteCart(uid, pid + "", token); } }); //加号 childViewHolder.addSubLayout.setAddClickListeren(new View.OnClickListener() { @Override public void onClick(View view) { state = GETCARTS; ElvShopcartAdapter.this.groupPosition = groupPosition; //获取卖家id String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid String pid = listBean.getPid() + ""; int num = listBean.getNum() ; num+=1; //是否选中 boolean childchecked = childViewHolder.cbProduct.isChecked(); shopCarPresenter.updateCarts(uid,sellerid,pid,num+"",childchecked?"1":"0",token); } }); //减号 childViewHolder.addSubLayout.setSubClickListeren(new View.OnClickListener() { @Override public void onClick(View view) { state = GETCARTS; ElvShopcartAdapter.this.groupPosition = groupPosition; //获取卖家id String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid String pid = listBean.getPid() + ""; int num = listBean.getNum(); if (num<=1){ Toast.makeText(context, "数量不能小于1", Toast.LENGTH_SHORT).show(); return; } num=num-1; // num=num-1; //是否选中 boolean childchecked = childViewHolder.cbProduct.isChecked(); shopCarPresenter.updateCarts(uid,sellerid,pid,num+"",childchecked?"1":"0",token); } }); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } public void updataSuccess(){ switch (state){ case GETCARTS: //更新成功以后调用查询购物车接口 productIndex = 0; groupPosition = 0; shopCarPresenter.getCarts(uid,token); break; case UPDATE_PRODUCT: //更新成功一个商品以后,再接着更新该商家下面的其它商品,直到没有商品为止 productIndex++; //下标是否越界 if (productIndex < childList.get(groupPosition).size()) { //可以继续跟新商品 updateProductInSeller(); } else { //商品已经全部更新完成,请查询购物车 state = GETCARTS; updataSuccess(); } break; case UPDATE_SELLER: //遍历所有商家下的商品,并更新状态 productIndex++; //下标是否越界 if (productIndex < childList.get(groupPosition).size()) { //可以继续跟新商品 updateProductInSeller(addSelect); } else { //商品已经全部更新完成,请查询购物车 productIndex = 0; groupPosition++; if (groupPosition < groupList.size()) { //可以继续跟新商品 updateProductInSeller(addSelect); } else { //商品已经全部更新完成,请查询购物车 state = GETCARTS; updataSuccess(); } } break; } } //全选 public void changeAllState(boolean bool){ this.addSelect=bool; state=UPDATE_SELLER; updateProductInSeller(bool); } // 计算数量和价钱 public String[] computeMoneyAndNum(){ double zongji=0; int shuliang=0; for (int i = 0; i <groupList.size() ; i++) { for (int j=0;j<childList.get(i).size();j++){ //判断商品是否选中 GetCartsBean.DataBean.ListBean listBean = childList.get(i).get(j); if (listBean.getSelected()==1){ //该商品为选中状态 zongji+=listBean.getPrice()*listBean.getNum(); shuliang+=listBean.getNum(); } } } return new String[]{zongji+"",shuliang+""}; } class GroupViewHolder { CheckBox cbSeller; TextView tvSeller; } class ChildViewHolder { CheckBox cbProduct; SimpleDraweeView iv; TextView tvTitle; TextView tvPrice; TextView tvDel; AddSubLayout addSubLayout; } }
bean包
package com.example.administrator.erzhoumoni.bean; /** * Created by Administrator on 2018/5/19 0019. */ public class BaseBean { /** * msg : success * 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; }
}
package com.example.administrator.erzhoumoni.bean; import java.util.List; /** * Created by Administrator on 2018/5/19 0019. */ public class GetCartsBean { /** * msg : 请求成功 * code : 0 * data : [{"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":8,"price":324,"pscid":1,"selected":0,"sellerid":1,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":25,"price":399,"pscid":2,"selected":1,"sellerid":2,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":5599,"createtime":"2017-10-10T17:30:32","detailUrl":"https://item.m.jd.com/product/4824715.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n12/jfs/t7768/184/1153704394/148460/f42e1432/599a930fN8a85626b.jpg!q70.jpg","num":1,"pid":59,"price":5599,"pscid":40,"selected":0,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"}],"sellerName":"商家3","sellerid":"3"},{"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":20,"price":599,"pscid":1,"selected":0,"sellerid":13,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"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":1,"pid":1,"price":118,"pscid":1,"selected":1,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"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":2,"pid":3,"price":198,"pscid":1,"selected":0,"sellerid":19,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家19","sellerid":"19"},{"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":1,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家21","sellerid":"21"},{"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":6,"price":7.99,"pscid":1,"selected":0,"sellerid":22,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家22","sellerid":"22"}] */ 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-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":8,"price":324,"pscid":1,"selected":0,"sellerid":1,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}] * sellerName : 商家1 * sellerid : 1 */ 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-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 : 8 * price : 324.0 * pscid : 1 * selected : 0 * sellerid : 1 * 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; } } } }
package com.example.administrator.erzhoumoni.bean; /** * Created by Administrator on 2018/5/19 0019. */ public class SellerBean { private String sellerName; private String sellerid; private Boolean selected; 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 Boolean getSelected() { return selected; } public void setSelected(Boolean selected) { this.selected = selected; } }module包
package com.example.administrator.erzhoumoni.module; import com.example.administrator.erzhoumoni.net.API; import com.example.administrator.erzhoumoni.net.MyInterceptor; import com.example.administrator.erzhoumoni.net.ProjectApi; import com.example.administrator.erzhoumoni.net.ProjectApiService; import java.util.concurrent.TimeUnit; import dagger.Module; import dagger.Provides; import okhttp3.OkHttpClient; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by Administrator on 2018/5/19 0019. */ @Module public class HttpModule { @Provides OkHttpClient.Builder provideOkHttpClientBuilder() { return new OkHttpClient.Builder() .writeTimeout(20, TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .connectTimeout(10, TimeUnit.SECONDS); } @Provides ProjectApi provideProjectApi(OkHttpClient.Builder builder){ builder.addInterceptor(new MyInterceptor()); Retrofit retrofit = new Retrofit.Builder().baseUrl(API.BASEURL) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .client(builder.build()) .build(); ProjectApiService projectApiService = retrofit.create(ProjectApiService.class); return ProjectApi.getProjectApi(projectApiService); } }
add_sub_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/sub" android:padding="10dp" android:text="-" android:background="#fff"/> <TextView android:id="@+id/num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="7dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:background="#fff" android:paddingTop="7dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/add" android:padding="10dp" android:background="#fff" android:text="+"/> </LinearLayout>
activity_shop_car.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.administrator.yuekaomoni.shopcar.ShopCarActivity"> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="购物车"/> <ExpandableListView android:id="@+id/elv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"></ExpandableListView> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <CheckBox android:id="@+id/cbAll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="全选"/> <TextView android:id="@+id/tvMoney" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/cbAll" android:text="合计:"/> <TextView android:id="@+id/tvTotal" android:layout_width="wrap_content" android:layout_height="match_parent" android:paddingLeft="10dp" android:paddingRight="10dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:textColor="#ffffff" android:background="#ff0000" android:gravity="center" android:layout_marginLeft="10dp" android:text="去结算:"/> </RelativeLayout> </LinearLayout>
shopcart_seller_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="30dp" android:gravity="center_vertical" android:orientation="horizontal"> <CheckBox android:id="@+id/cbSeller" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp"/> <TextView android:id="@+id/tvSeller" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp"/> </LinearLayout>
shopcart_seller_product_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:padding="10dp" android:layout_height="150dp" android:orientation="horizontal"> <CheckBox android:layout_marginLeft="20dp" android:id="@+id/cbProduct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> <ImageView android:id="@+id/iv" android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center_vertical"/> <LinearLayout android:layout_width="200dp" android:layout_height="150dp" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:orientation="vertical"> <TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="70dp" android:orientation="horizontal"> <TextView android:id="@+id/tvPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="12312" android:textColor="#ff0000"/> <com.example.administrator.yuekaomoni.shopcar.AddSubLayout android:layout_width="wrap_content" android:layout_marginLeft="30dp" android:layout_marginTop="20dp" android:layout_height="wrap_content" android:id="@+id/add_sub"></com.example.administrator.yuekaomoni.shopcar.AddSubLayout> </LinearLayout> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" android:id="@+id/tvDel" android:textSize="25dp" android:layout_gravity="center_vertical" android:textColor="#f12"/> </LinearLayout>