购物车

2017-12-20  本文已影响0人  ForCrazyLove

详情页面

packagecom.example.shoppingcar;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.support.v7.app.AppCompatActivity;

importandroid.support.v7.widget.LinearLayoutManager;

importandroid.support.v7.widget.RecyclerView;

importandroid.widget.TextView;

importcom.example.shoppingcar.bean.CartBean;

importcom.example.shoppingcar.presenter.cartPresenter;

importcom.example.shoppingcar.view.ViewCallBack;

importjava.util.List;

importbutterknife.Bind;

importbutterknife.ButterKnife;

importbutterknife.OnClick;

public classXQActivityextendsAppCompatActivityimplementsViewCallBack {

@Bind(R.id.GWC)

TextViewGWC;

@Bind(R.id.XQ_Recy)

RecyclerViewXQRecy;

privatecom.example.shoppingcar.presenter.cartPresentercartPresenter;

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_xq);

ButterKnife.bind(this);

cartPresenter=newcartPresenter(this);

cartPresenter.cartFF();

}

@OnClick(R.id.GWC)

public voidonViewClicked() {

startActivity(newIntent(XQActivity.this, MainActivity.class));

finish();

}

@Override

public voidsuccess(CartBean cartBean) {

List data = cartBean.data;

XQRecy.setLayoutManager(newLinearLayoutManager(this));

XQRecy.setAdapter(newXQAdapter(this, data));

}

@Override

public voidfailure(Exception e) {

}

@Override

protected voidonDestroy() {

super.onDestroy();

cartPresenter.detach();

}

}

详情页面Adapter

packagecom.example.shoppingcar;

importandroid.content.Context;

importandroid.net.Uri;

importandroid.support.v7.widget.RecyclerView;

importandroid.view.View;

importandroid.view.ViewGroup;

importandroid.widget.Button;

importandroid.widget.TextView;

importandroid.widget.Toast;

importcom.example.shoppingcar.bean.CartBean;

importcom.example.shoppingcar.bean.addBean;

importcom.example.shoppingcar.utils.APIFactory;

importcom.facebook.drawee.backends.pipeline.Fresco;

importcom.facebook.drawee.view.SimpleDraweeView;

importjava.util.HashMap;

importjava.util.List;

importjava.util.Map;

importrx.Observer;

public classXQAdapterextendsRecyclerView.Adapter {

Contextcontext;

Listdata;

publicXQAdapter(XQActivity xqActivity, List data) {

this.context= xqActivity;

this.data= data;

Fresco.initialize(context);

}

@Override

publicRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,intviewType) {

View view = View.inflate(context, R.layout.xqitem,null);

return newXQViewHolder(view);

}

@Override

public voidonBindViewHolder(RecyclerView.ViewHolder holder,final intposition) {

//拆分images字段

String[] split =data.get(position).images.split("\\|");

//设置商品的图片

((XQViewHolder) holder).img.setImageURI(Uri.parse(split[0]));

((XQViewHolder) holder).name.setText(data.get(position).title);

((XQViewHolder) holder).price.setText(data.get(position).price+"");

((XQViewHolder) holder).btn.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

intpid =data.get(position).pid;

Map map =newHashMap();

map.put("uid","4421");

map.put("pid", pid +"");

APIFactory.getInstance().add(map,newObserver() {

@Override

public voidonCompleted() {

}

@Override

public voidonError(Throwable e) {

}

@Override

public voidonNext(addBean addBean) {

String code = addBean.code;

if(code.equals("0")) {

Toast.makeText(context,"加购成功", Toast.LENGTH_SHORT).show();

}else if(code.equals("1")) {

Toast.makeText(context,"天呢!用户未登录或用户id不能为空", Toast.LENGTH_SHORT).show();

}

}

});

}

});

}

@Override

public intgetItemCount() {

returndata.size();

}

classXQViewHolderextendsRecyclerView.ViewHolder {

private finalSimpleDraweeViewimg;

private finalTextViewname;

private finalTextViewprice;

private finalButtonbtn;

publicXQViewHolder(View itemView) {

super(itemView);

img= itemView.findViewById(R.id.xq_fresco);

name= itemView.findViewById(R.id.xq_name);

price= itemView.findViewById(R.id.xq_price);

btn= itemView.findViewById(R.id.xq_btn);

}

}

}

购物车Activity


packagecom.example.shoppingcar;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.support.v7.app.AppCompatActivity;

importandroid.support.v7.widget.LinearLayoutManager;

importandroid.support.v7.widget.RecyclerView;

importandroid.view.View;

importandroid.widget.CheckBox;

importandroid.widget.LinearLayout;

importandroid.widget.TextView;

importandroid.widget.Toast;

importcom.example.shoppingcar.bean.queryBean;

importcom.example.shoppingcar.presenter.queryPresenter;

importcom.example.shoppingcar.view.queryView;

importbutterknife.Bind;

importbutterknife.ButterKnife;

public classMainActivityextendsAppCompatActivityimplementsqueryView {

@Bind(R.id.bianji)

TextViewbianji;

@Bind(R.id.recycler_View)

RecyclerViewrecyclerView;

@Bind(R.id.quanxuan)

CheckBoxquanxuan;

@Bind(R.id.total_price)

TextViewtotalPrice;

@Bind(R.id.total_num)

TextViewtotalNum;

@Bind(R.id.quzhifu)

TextViewquzhifu;

@Bind(R.id.shanchu)

TextViewshanchu;

@Bind(R.id.linear_shanchu)

LinearLayoutlinearShanchu;

@Bind(R.id.activity_main)

LinearLayoutactivityMain;

@Bind(R.id.back)

TextViewback;

privateRecyAdapterrecyAdapter;

privatecom.example.shoppingcar.presenter.queryPresenterqueryPresenter;

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ButterKnife.bind(this);

bianji.setTag(1);//编辑设置TAG=1

quanxuan.setTag(1);//全选设置TAG=1  为未选中

queryPresenter=newqueryPresenter(this);

recyclerView.setLayoutManager(newLinearLayoutManager(this));

recyAdapter=newRecyAdapter(this);

queryPresenter.queryFF();

recyclerView.setAdapter(recyAdapter);

back.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

startActivity(newIntent(MainActivity.this, XQActivity.class));

finish();

}

});

//调用RecyAdapter里面的接口,设置全选按钮  总价  总数量

recyAdapter.setUpdateListener(newRecyAdapter.UpdateListener() {

@Override

public voidsetTotal(String total, String num,booleanallCheck) {

//设置ui的改变

totalNum.setText("共"+ num +"件商品");//总数量

totalPrice.setText("总价 :¥"+ total +"元");//总价

if(allCheck) {

quanxuan.setTag(2);

quanxuan.setBackgroundResource(R.drawable.shopcart_selected);

}else{

quanxuan.setTag(1);

quanxuan.setBackgroundResource(R.drawable.shopcart_unselected);

}

quanxuan.setChecked(allCheck);

}

});

//这里只做ui更改, 点击全选按钮,,调到adapter里面操作

quanxuan.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View v) {

//调用adapter里面的方法 ,,把当前quanxuan状态传递过去

inttag = (int)quanxuan.getTag();

if(tag ==1) {

quanxuan.setTag(2);

quanxuan.setBackgroundResource(R.drawable.shopcart_selected);

}else{

quanxuan.setTag(1);

quanxuan.setBackgroundResource(R.drawable.shopcart_unselected);

}

recyAdapter.quanXuan(quanxuan.isChecked());

}

});

//点击批量删除的按钮

shanchu.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

recyAdapter.shanChu();

}

});

//点击编辑按钮,

bianji.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

inttag = (int)bianji.getTag();

if(tag ==1) {

bianji.setText("完成");

bianji.setTag(2);

quzhifu.setVisibility(View.GONE);

shanchu.setVisibility(View.VISIBLE);

}else{

bianji.setText("编辑");

bianji.setTag(1);

quzhifu.setVisibility(View.VISIBLE);

shanchu.setVisibility(View.GONE);

}

}

});

}

@Override

public voidsuccess(queryBean queryBean) {

if(queryBean !=null) {

//将返回的数据添加到适配器中

recyAdapter.add(queryBean);

}

}

@Override

public voidfailure() {

System.out.println("网不好");

runOnUiThread(newRunnable() {

@Override

public voidrun() {

Toast.makeText(MainActivity.this,"网有点慢", Toast.LENGTH_SHORT).show();

}

});

}

@Override

protected voidonDestroy() {

super.onDestroy();

//解除绑定

queryPresenter.detach();

}

}

购物车Adapter

packagecom.example.shoppingcar;

importandroid.content.Context;

importandroid.content.DialogInterface;

importandroid.net.Uri;

importandroid.support.v7.app.AlertDialog;

importandroid.support.v7.widget.RecyclerView;

importandroid.view.View;

importandroid.view.ViewGroup;

importandroid.widget.CheckBox;

importandroid.widget.ImageView;

importandroid.widget.TextView;

importandroid.widget.Toast;

importcom.example.shoppingcar.bean.deleteBean;

importcom.example.shoppingcar.bean.queryBean;

importcom.example.shoppingcar.presenter.deletePresenter;

importcom.example.shoppingcar.presenter.queryPresenter;

importcom.example.shoppingcar.utils.APIFactory;

importcom.example.shoppingcar.view.deleteView;

importcom.example.shoppingcar.view.queryView;

importcom.facebook.drawee.backends.pipeline.Fresco;

importjava.util.ArrayList;

importjava.util.HashMap;

importjava.util.List;

importjava.util.Map;

importrx.Observer;

public classRecyAdapterextendsRecyclerView.AdapterimplementsqueryView, deleteView {

queryPresenterqueryPresenter;

deletePresenterdeletePresenter;

Contextcontext;

//创建大的集合

privateListlist;

//存放商家的id和商家的名称的map集合

privateMapmap=newHashMap<>();

publicRecyAdapter(MainActivity mainActivity) {

this.context= mainActivity;

queryPresenter=newqueryPresenter(this);

deletePresenter=newdeletePresenter(this);

//初始化Fresco

Fresco.initialize(context);

}

@Override

publicRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,intviewType) {

View view = View.inflate(context, R.layout.recy_cart_item,null);

return newMyViewHolder(view);

}

@Override

public voidonBindViewHolder(finalRecyclerView.ViewHolder holder,final intposition) {

/**

* 设置商铺的 shop_checkbox和商铺的名字 显示或隐藏

* */

if(list.get(position).getIsFirst() ==1) {

//显示商家

((MyViewHolder) holder).shop_checkbox.setVisibility(View.VISIBLE);

((MyViewHolder) holder).shop_name.setVisibility(View.VISIBLE);

//设置shop_checkbox的选中状态

((MyViewHolder) holder).shop_checkbox.setChecked(list.get(position).isShop_check());

((MyViewHolder) holder).shop_name.setText(map.get(String.valueOf(list.get(position).getSellerid())) +" >");

}else{//2

//隐藏商家

((MyViewHolder) holder).shop_name.setVisibility(View.GONE);

((MyViewHolder) holder).shop_checkbox.setVisibility(View.GONE);

}

//拆分images字段

String[] split =list.get(position).getImages().split("\\|");

//设置商品的图片

((MyViewHolder) holder).item_face.setImageURI(Uri.parse(split[0]));

// ImageLoader.getInstance().displayImage(split[0],holder.item_face);

//控制商品的item_checkbox,,根据字段改变

((MyViewHolder) holder).item_checkbox.setChecked(list.get(position).isItem_check());

((MyViewHolder) holder).item_name.setText(list.get(position).getTitle());

((MyViewHolder) holder).item_price.setText(list.get(position).getPrice() +"");

//调用customjiajian里面的方法设置 加减号中间的数字

((MyViewHolder) holder).customJiaJian.setEditText(list.get(position).getNum());

((MyViewHolder) holder).item_bianji.setTag(1);

//点击item编辑才显示 自定义加减框

((MyViewHolder) holder).item_bianji.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

inttag = (int) ((MyViewHolder)holder).item_bianji.getTag();

if(tag ==1) {

//加减号显示

((MyViewHolder)holder).item_bianji.setText("完成");

((MyViewHolder)holder).customJiaJian.setVisibility(View.VISIBLE);

//商品的名称隐藏

((MyViewHolder)holder).item_name.setVisibility(View.GONE);

((MyViewHolder)holder).item_yansechima.setVisibility(View.VISIBLE);

((MyViewHolder)holder).item_price.setVisibility(View.GONE);

((MyViewHolder)holder).item_delete.setVisibility(View.VISIBLE);

((MyViewHolder)holder).item_bianji.setTag(2);

}else{

//相反的 隐藏的显示,显示的隐藏

//加减号显示

((MyViewHolder)holder).item_bianji.setText("编辑");

((MyViewHolder)holder).customJiaJian.setVisibility(View.GONE);

//商品的名称隐藏

((MyViewHolder)holder).item_name.setVisibility(View.VISIBLE);

((MyViewHolder)holder).item_yansechima.setVisibility(View.GONE);

((MyViewHolder)holder).item_price.setVisibility(View.VISIBLE);

((MyViewHolder)holder).item_delete.setVisibility(View.GONE);

((MyViewHolder)holder).item_bianji.setTag(1);

}

}

});

//设置点击多选框

//商铺的shop_checkbox点击事件 ,控制商品的item_checkbox

((MyViewHolder) holder).shop_checkbox.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View v) {

//先改变数据源中的shop_check

list.get(position).setShop_check(((MyViewHolder)holder).shop_checkbox.isChecked());

for(inti =0; i

//如果是同一家商铺的 都给成相同状态

if(list.get(position).getSellerid() ==list.get(i).getSellerid()) {

//当前条目的选中状态 设置成 当前商铺的选中状态

list.get(i).setItem_check(((MyViewHolder)holder).shop_checkbox.isChecked());

}

}

//刷新适配器

notifyDataSetChanged();

//调用求和的方法

sum(list);

}

});

//商品的item_checkbox点击事件,控制商铺的shop_checkbox

((MyViewHolder) holder).item_checkbox.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View v) {

//先改变数据源中的item_checkbox

list.get(position).setItem_check(((MyViewHolder)holder).item_checkbox.isChecked());

//反向控制商铺的shop_checkbox

for(inti =0; i

for(intj =0; j

//如果两个商品是同一家店铺的 并且 这两个商品的item_checkbox选中状态不一样

if(list.get(i).getSellerid() ==list.get(j).getSellerid() && !list.get(j).isItem_check()) {

//就把商铺的shop_checkbox改成false

list.get(i).setShop_check(false);

break;

}else{

//同一家商铺的商品 选中状态都一样,就把商铺shop_checkbox状态改成true

list.get(i).setShop_check(true);

}

}

}

//更新适配器

notifyDataSetChanged();

//调用求和的方法

sum(list);

}

});

//删除条目的点击事件

((MyViewHolder) holder).item_delete.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View v) {

//                list.remove(position);//移除集合中的当前数据

//删除完当前的条目 重新判断商铺的显示隐藏

intpid =list.get(position).getPid();

Map mapDel =newHashMap();

mapDel.put("uid","4421");

mapDel.put("pid", pid +"");

APIFactory.getInstance().delete(mapDel,newObserver() {

@Override

public voidonCompleted() {

}

@Override

public voidonError(Throwable e) {

}

@Override

public voidonNext(deleteBean deleteBean) {

String code = deleteBean.code;

if(code.equals("0")) {

Toast.makeText(context,"删除购物车成功", Toast.LENGTH_SHORT).show();

list.remove(position);

setFirst(list);

//调用重新求和

sum(list);

notifyDataSetChanged();

}else if(code.equals("1")) {

Toast.makeText(context,"天呢!商品id不能为空", Toast.LENGTH_SHORT).show();

}

}

});

}

});

//加减号的监听,

((MyViewHolder) holder).customJiaJian.setCustomListener(newCustomJiaJian.CustomListener() {

@Override

public voidjiajian(intcount) {

//改变数据源中的数量

list.get(position).setNum(count);

notifyDataSetChanged();

sum(list);

}

@Override

//输入值 求总价

public voidshuRuZhi(intcount) {

list.get(position).setNum(count);

notifyDataSetChanged();

sum(list);

}

});

}

@Override

public intgetItemCount() {

returnlist==null?0:list.size();

}

classMyViewHolderextendsRecyclerView.ViewHolder {

private finalCheckBoxshop_checkbox;

private finalTextViewshop_name;

private finalCheckBoxitem_checkbox;

private finalTextViewitem_name;

private finalTextViewitem_price;

private finalCustomJiaJiancustomJiaJian;

//private final ImageView item_delete;

private finalTextViewitem_delete;

private finalImageViewitem_face;

private finalTextViewitem_bianji;

private finalTextViewitem_yansechima;

publicMyViewHolder(View itemView) {

super(itemView);

//拿到控件

shop_checkbox= (CheckBox) itemView.findViewById(R.id.shop_checkbox);

shop_name= (TextView) itemView.findViewById(R.id.shop_name);

item_checkbox= (CheckBox) itemView.findViewById(R.id.item_checkbox);

item_name= (TextView) itemView.findViewById(R.id.item_name);

item_price= (TextView) itemView.findViewById(R.id.item_price);

customJiaJian= (CustomJiaJian) itemView.findViewById(R.id.custom_jiajian);

//item_delete = (ImageView) itemView.findViewById(R.id.item_delete);

item_delete= (TextView) itemView.findViewById(R.id.item_delete);

item_face= (ImageView) itemView.findViewById(R.id.item_face);

item_bianji= itemView.findViewById(R.id.item_bianji);

item_yansechima= itemView.findViewById(R.id.item_yansechima);

}

}

UpdateListenerupdateListener;

public voidsetUpdateListener(UpdateListener updateListener) {

this.updateListener= updateListener;

}

//view层调用这个方法, 点击quanxuan按钮的操作

public voidquanXuan(booleanchecked) {

for(inti =0; i

list.get(i).setShop_check(checked);

list.get(i).setItem_check(checked);

}

notifyDataSetChanged();

sum(list);

}

private voidsum(List list) {

inttotalNum =0;

floattotalMoney =0.0f;

booleanallCheck =true;

for(inti =0; i < list.size(); i++) {

if(list.get(i).isItem_check()) {

totalNum += list.get(i).getNum();

totalMoney += list.get(i).getNum() * list.get(i).getPrice();

}else{

//如果有个未选中,就标记为false

allCheck =false;

}

}

//接口回调出去 把总价 总数量 和allcheck 传给view层

updateListener.setTotal(totalMoney +"", totalNum +"", allCheck);

}

//批量删除的按钮

public voidshanChu() {

//存储删除的id

finalList delete_listid =newArrayList<>();

for(inti =0; i

if(list.get(i).isItem_check()) {

//将要删除的pid添加到这个集合里

delete_listid.add(list.get(i).getPid());

}

}

if(delete_listid.size() ==0) {

//如果没有要删除的,就吐司提示

Toast.makeText(context,"请选中至少一个商品后再删除", Toast.LENGTH_SHORT).show();

return;

}

//弹框

finalAlertDialog.Builder dialog =newAlertDialog.Builder(context);

dialog.setTitle("操作提示");

dialog.setMessage("你确定要删除这"+ delete_listid.size() +"个商品?");

dialog.setPositiveButton("确定",newDialogInterface.OnClickListener() {

@Override

public voidonClick(DialogInterface dialogInterface,inti) {

//使用接口删除

String a ="";

for(intj =0; j

// a+=delete_listid.get(j)+"";

Integer integer =delete_listid.get(j);

String pid = String.valueOf(integer);

deletePresenter.deleteFF(pid);

// list.remove(j);

}

//  Toast.makeText(context, a,Toast.LENGTH_SHORT).show();

}

}).setNegativeButton("取消",newDialogInterface.OnClickListener() {

@Override

public voidonClick(DialogInterface dialogInterface,inti) {

dialogInterface.cancel();

}

}).create().show();

}

public voidadd(queryBean queryBean) {

if(list==null) {

list=newArrayList<>();

}

if(queryBean !=null) {

for(queryBean.DataBean shop : queryBean.getData()) {

map.put(shop.getSellerid(), shop.getSellerName());

//第二层遍历里面的商品

for(inti =0; i < shop.getList().size(); i++) {

//添加到list集合里

list.add(shop.getList().get(i));

}

}

//调用方法 设置显示或隐藏 商铺名

setFirst(list);

}

notifyDataSetChanged();

}

/**

* 设置数据源,控制是否显示商家

*/

private voidsetFirst(List list) {

if(list.size() >0) {

list.get(0).setIsFirst(1);

//从第二条开始遍历

for(inti =1; i < list.size(); i++) {

//如果和前一个商品是同一家商店的

if(list.get(i).getSellerid() == list.get(i -1).getSellerid()) {

//设置成2不显示商铺

list.get(i).setIsFirst(2);

}else{//设置成1显示商铺

list.get(i).setIsFirst(1);

//如果当前条目选中,把当前的商铺也选中

if(list.get(i).isItem_check() ==true) {

list.get(i).setShop_check(list.get(i).isItem_check());

}

}

}

}

}

@Override

public voidsuccess(queryBean queryBean) {

list.clear();

add(queryBean);

}

@Override

public voidsuccess(deleteBean deleteBean) {

queryPresenter.queryFF();

}

@Override

public voidfailure() {

System.out.println("网不好");

Toast.makeText(context,"adapter网有点慢", Toast.LENGTH_SHORT).show();

}

//接口

public interfaceUpdateListener {

public voidsetTotal(String total, String num,booleanallCheck);

}

}

自定义控件:加减器


packagecom.example.shoppingcar;

importandroid.content.Context;

importandroid.support.annotation.Nullable;

importandroid.util.AttributeSet;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.EditText;

importandroid.widget.LinearLayout;

importandroid.widget.Toast;

/**

* Created by Menglucywhh on 2017/12/19.

*/

public classCustomJiaJianextendsLinearLayout{

privateButtonreverse;

privateButtonadd;

privateEditTextcountEdit;

private intmCount=1;

publicCustomJiaJian(Context context) {

super(context);

}

publicCustomJiaJian(finalContext context,@NullableAttributeSet attrs) {

super(context, attrs);

View view = View.inflate(context, R.layout.custom_jiajian,this);

reverse= (Button) view.findViewById(R.id.reverse);

add= (Button) view.findViewById(R.id.add);

countEdit= (EditText) view.findViewById(R.id.count);

reverse.setOnClickListener(newOnClickListener() {

@Override

public voidonClick(View v) {

String content =countEdit.getText().toString().trim();

intcount = Integer.valueOf(content);

if(count>1){

mCount= count-1;

countEdit.setText(mCount+"");

//回调给adapter里面

if(customListener!=null){

customListener.jiajian(mCount);

}

}else{

Toast.makeText(context,"最小数量为1", Toast.LENGTH_SHORT).show();

}

}

});

add.setOnClickListener(newOnClickListener() {

@Override

public voidonClick(View v) {

String content =countEdit.getText().toString().trim();

intcount = Integer.valueOf(content)+1;

mCount= count;

countEdit.setText(mCount+"");

//接口回调给adapter

if(customListener!=null){

customListener.jiajian(mCount);

}

}

});

}

publicCustomJiaJian(Context context,@NullableAttributeSet attrs,intdefStyleAttr) {

super(context, attrs, defStyleAttr);

}

CustomListenercustomListener;

public voidsetCustomListener(CustomListener customListener){

this.customListener= customListener;

}

//加减的接口

public interfaceCustomListener{

public voidjiajian(intcount);

public voidshuRuZhi(intcount);

}

public voidsetEditText(intnum) {

if(countEdit!=null){

countEdit.setText(num+"");

}

}

}

Retrofit的URL


packagecom.example.shoppingcar;

importcom.example.shoppingcar.bean.CartBean;

importcom.example.shoppingcar.bean.addBean;

importcom.example.shoppingcar.bean.deleteBean;

importcom.example.shoppingcar.bean.queryBean;

importjava.util.Map;

importretrofit2.http.GET;

importretrofit2.http.QueryMap;

importrx.Observable;

public interfaceIGetHttpUrl {

@GET("searchProducts?page=1&source=android")

Observable cartUrl(@QueryMapMap map);

//    http://120.27.23.105/product/searchProducts?keywords=手机&page=1&source=android

@GET("addCart?token=0DA2B4A9F80689086B333CADEB7F306B&source=android")

Observable addUrl(@QueryMapMap map);

//    Observable addUrl(@Query("uid") String uid, @Query("pid") String pid);

@GET("getCarts?token=0DA2B4A9F80689086B333CADEB7F306B&source=android")

Observable queryUrl(@QueryMapMap map);

//    Observable queryUrl(@Query("uid") String uid);

@GET("deleteCart?token=0DA2B4A9F80689086B333CADEB7F306B&source=android")

Observable deleteUrl(@QueryMapMap map);

//    Observable deleteUrl(@Query("uid") String uid, @Query("pid") String pid);

}

APIFactory工具类

packagecom.example.shoppingcar.utils;

importcom.example.shoppingcar.bean.CartBean;

importcom.example.shoppingcar.bean.addBean;

importcom.example.shoppingcar.bean.deleteBean;

importcom.example.shoppingcar.bean.queryBean;

importjava.util.Map;

importrx.Observer;

importrx.android.schedulers.AndroidSchedulers;

importrx.schedulers.Schedulers;

public classAPIFactory {

private staticAPIFactoryfactory=null;

public staticAPIFactory getInstance() {

if(factory==null) {

synchronized(APIFactory.class) {

if(factory==null) {

factory=newAPIFactory();

}

}

}

returnfactory;

}

public voidquery(Map map, Observer observer) {

RetrofitUtils.getInstance().queryUrl(map)

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(observer);

}

public voiddelete(Map map, Observer observer) {

RetrofitUtils.getInstance().deleteUrl(map)

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(observer);

}

public voidcart(Map map, Observer observer) {

RetrofitUtils.getInstance().cartUrl(map)

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(observer);

}

public voidadd(Map map, Observer observer) {

RetrofitUtils.getInstance().addUrl(map)

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(observer);

}

}

OKhttp封装

packagecom.example.shoppingcar.utils;

importjava.util.concurrent.TimeUnit;

importokhttp3.OkHttpClient;

public classOkhttpUtils {

private staticOkHttpClientclient=null;

public staticOkHttpClient getInstance() {

if(client==null) {

synchronized(OkhttpUtils.class) {

if(client==null) {

client=newOkHttpClient.Builder()

.writeTimeout(20000, TimeUnit.SECONDS)

.readTimeout(20000, TimeUnit.SECONDS)

.connectTimeout(20000, TimeUnit.SECONDS)

.build();

}

}

}

returnclient;

}

}

Retrofit封装


packagecom.example.shoppingcar.utils;

importcom.example.shoppingcar.IGetHttpUrl;

importretrofit2.Retrofit;

importretrofit2.adapter.rxjava.RxJavaCallAdapterFactory;

importretrofit2.converter.gson.GsonConverterFactory;

public classRetrofitUtils {

private staticIGetHttpUrlservice=null;

public staticIGetHttpUrl getInstance() {

if(service==null) {

synchronized(RetrofitUtils.class) {

if(service==null){

Retrofit retrofit =newRetrofit.Builder()

.baseUrl("http://120.27.23.105/product/")

.addConverterFactory(GsonConverterFactory.create())

.addCallAdapterFactory(RxJavaCallAdapterFactory.create())

.client(OkhttpUtils.getInstance())

.build();

service= retrofit.create(IGetHttpUrl.class);

}

}

}

returnservice;

}

}

addBean


public classaddBean {

/**

* msg : 加购成功

* code : 0

*/

publicStringmsg;

publicStringcode;

}

cartBean

public classCartBean {

/**

* msg : 查询成功

* code : 0

* data : [{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","itemtype":1,"pid":45,"price":2999,"pscid":39,"salenum":4666,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"},{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","itemtype":0,"pid":46,"price":234,"pscid":39,"salenum":868,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"},{"bargainPrice":1599,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg","itemtype":2,"pid":47,"price":111,"pscid":39,"salenum":757,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配  1件","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"},{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","itemtype":1,"pid":48,"price":222,"pscid":39,"salenum":656,"sellerid":4,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":1999,"createtime":"2017-10-10T16:09:02","detailUrl":"https://item.m.jd.com/product/5025971.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t7210/232/3738666823/232298/9004583e/59c3a9a7N8de42e15.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8356/82/2107423621/109733/c019b8c6/59c3a9a6Ne9a4bdd7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t10219/74/25356012/171379/7d55e296/59c3a9a8N82fa6e02.jpg!q70.jpg","itemtype":0,"pid":49,"price":333,"pscid":39,"salenum":123,"sellerid":5,"subhead":"vivo X20 带你开启全面屏时代!逆光也清晰,照亮你的美!","title":"vivo X20 全面屏手机 全网通 4GB+64GB 金色 移动联通电信4G手机 双卡双待"},{"bargainPrice":3455,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","itemtype":2,"pid":50,"price":444,"pscid":39,"salenum":54,"sellerid":6,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","itemtype":1,"pid":51,"price":555,"pscid":39,"salenum":424,"sellerid":7,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":3455,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","itemtype":0,"pid":52,"price":666,"pscid":39,"salenum":212,"sellerid":8,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":2999,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2385655.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t2068/298/2448145915/157953/7be197df/56d51a42Nd86f1c8e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2437/128/1687178395/117431/bcc190c1/56d3fcbaNb2963d21.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2467/222/2263160610/95597/927b8a2f/56d3eafeNdecebeb6.jpg!q70.jpg","itemtype":2,"pid":53,"price":777,"pscid":39,"salenum":0,"sellerid":9,"subhead":"Super AMOLED三星双曲面2K 屏,支持无线充电!","title":"三星 Galaxy S7 edge(G9350)4GB+32GB 铂光金 移动联通电信4G手机 双卡双待"},{"bargainPrice":3455,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","itemtype":0,"pid":54,"price":888,"pscid":39,"salenum":7575,"sellerid":10,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}]

* page : 1

*/

publicStringmsg;

publicStringcode;

publicStringpage;

publicListdata;

public static classDataBean {

/**

* bargainPrice : 99.0

* createtime : 2017-10-14T21:38:26

* detailUrl : https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends

* images : https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg

* itemtype : 1

* pid : 45

* price : 2999.0

* pscid : 39

* salenum : 4666

* sellerid : 1

* subhead : 高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!

* title : 一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机

*/

public doublebargainPrice;

publicStringcreatetime;

publicStringdetailUrl;

publicStringimages;

public intitemtype;

public intpid;

public doubleprice;

public intpscid;

public intsalenum;

public intsellerid;

publicStringsubhead;

publicStringtitle;

}

}

deleteBean

public classdeleteBean {

/**

* msg : 删除购物车成功

* code : 0

*/

publicStringmsg;

publicStringcode;

}

queryBean

public classqueryBean {

privateStringmsg;

privateStringcode;

privateListdata;

publicString getMsg() {

returnmsg;

}

public voidsetMsg(String msg) {

this.msg= msg;

}

publicString getCode() {

returncode;

}

public voidsetCode(String code) {

this.code= code;

}

publicList getData() {

returndata;

}

public voidsetData(List data) {

this.data= data;

}

public static classDataBean {

privateStringsellerName;

privateStringsellerid;

privateListlist;

publicString getSellerName() {

returnsellerName;

}

public voidsetSellerName(String sellerName) {

this.sellerName= sellerName;

}

publicString getSellerid() {

returnsellerid;

}

public voidsetSellerid(String sellerid) {

this.sellerid= sellerid;

}

publicList getList() {

returnlist;

}

public voidsetList(List list) {

this.list= list;

}

public static classListBean {

private doublebargainPrice;

privateStringcreatetime;

privateStringdetailUrl;

privateStringimages;

private intnum;

private intpid;

private doubleprice;

private intpscid;

private intselected;

private intsellerid;

privateStringsubhead;

privateStringtitle;

private intisFirst=1;//1为显示商铺, 2为隐藏商铺

private booleanitem_check;//每个商品的选中状态

private booleanshop_check;//商店的选中状态

public intgetIsFirst() {

returnisFirst;

}

public voidsetIsFirst(intisFirst) {

this.isFirst= isFirst;

}

public booleanisItem_check() {

returnitem_check;

}

public voidsetItem_check(booleanitem_check) {

this.item_check= item_check;

}

public booleanisShop_check() {

returnshop_check;

}

public voidsetShop_check(booleanshop_check) {

this.shop_check= shop_check;

}

public doublegetBargainPrice() {

returnbargainPrice;

}

public voidsetBargainPrice(doublebargainPrice) {

this.bargainPrice= bargainPrice;

}

publicString getCreatetime() {

returncreatetime;

}

public voidsetCreatetime(String createtime) {

this.createtime= createtime;

}

publicString getDetailUrl() {

returndetailUrl;

}

public voidsetDetailUrl(String detailUrl) {

this.detailUrl= detailUrl;

}

publicString getImages() {

returnimages;

}

public voidsetImages(String images) {

this.images= images;

}

public intgetNum() {

returnnum;

}

public voidsetNum(intnum) {

this.num= num;

}

public intgetPid() {

returnpid;

}

public voidsetPid(intpid) {

this.pid= pid;

}

public doublegetPrice() {

returnprice;

}

public voidsetPrice(doubleprice) {

this.price= price;

}

public intgetPscid() {

returnpscid;

}

public voidsetPscid(intpscid) {

this.pscid= pscid;

}

public intgetSelected() {

returnselected;

}

public voidsetSelected(intselected) {

this.selected= selected;

}

public intgetSellerid() {

returnsellerid;

}

public voidsetSellerid(intsellerid) {

this.sellerid= sellerid;

}

publicString getSubhead() {

returnsubhead;

}

public voidsetSubhead(String subhead) {

this.subhead= subhead;

}

publicString getTitle() {

returntitle;

}

public voidsetTitle(String title) {

this.title= title;

}

}

}

}

deleteModel

packagecom.example.shoppingcar.model;

importcom.example.shoppingcar.bean.deleteBean;

importcom.example.shoppingcar.utils.APIFactory;

importjava.util.HashMap;

importjava.util.Map;

importrx.Observer;

/**

* date:2017/12/20

* author:张伟(Administrator)

* desc:

*/

public classdeleteModel {

public voiddelete(String pid,finaldeleteModelCallBack deleteBack) {

Map map =newHashMap<>();

map.put("uid","uid");

map.put("pid", pid);

APIFactory.getInstance().delete(map,newObserver() {

@Override

public voidonCompleted() {

}

@Override

public voidonError(Throwable e) {

}

@Override

public voidonNext(deleteBean deleteBean) {

deleteBack.success(deleteBean);

}

});

}

}

deleteModelCallBack

public interfacedeleteModelCallBack {

voidsuccess(deleteBean deleteBean);

voidfailure();

}

ModelCallBack

public interfaceModelCallBack {

voidsuccess(CartBean cartBean);

voidfailure(Exception e);

}

MyModel

public classMyModel {

public voidcart(finalModelCallBack modelCallBack) {

Map map =newHashMap<>();

map.put("keywords","手机");

APIFactory.getInstance().cart(map,newObserver() {

@Override

public voidonCompleted() {

}

@Override

public voidonError(Throwable e) {

}

@Override

public voidonNext(CartBean cartBean) {

modelCallBack.success(cartBean);

}

});

}

}

queryModel

public classqueryModel {

public voidquery(finalqueryModelCallBack queryBack) {

Map map =newHashMap<>();

map.put("uid","4421");

APIFactory.getInstance().query(map,newObserver() {

@Override

public voidonCompleted() {

}

@Override

public voidonError(Throwable e) {

}

@Override

public voidonNext(queryBean queryBean) {

queryBack.success(queryBean);

}

});

}

}

queryModelCallBack

public interfacequeryModelCallBack {

voidsuccess(queryBean queryBean);

voidfailure();

}

cartPresenter


public classcartPresenter {

ViewCallBackviewCallBack;

MyModelmyModel;

publiccartPresenter(ViewCallBack viewCallBack) {

this.viewCallBack= viewCallBack;

this.myModel=newMyModel();

}

public voidcartFF() {

myModel.cart(newModelCallBack() {

@Override

public voidsuccess(CartBean cartBean) {

viewCallBack.success(cartBean);

}

@Override

public voidfailure(Exception e) {

}

});

}

public voiddetach() {

this.viewCallBack=null;

}

}

deletePresenter

public classdeletePresenter {

deleteModeldeleteModel;

deleteViewdeleteView;

publicdeletePresenter(com.example.shoppingcar.view.deleteView deleteView) {

this.deleteView= deleteView;

this.deleteModel=newdeleteModel();

}

public voiddeleteFF(String pid) {

deleteModel.delete(pid,newdeleteModelCallBack() {

@Override

public voidsuccess(deleteBean deleteBean) {

deleteView.success(deleteBean);

}

@Override

public voidfailure() {

}

});

}

}

queryPresenter

public classqueryPresenter {

queryViewqueryView;

queryModelqueryModel;

publicqueryPresenter(queryView queryView) {

this.queryView= queryView;

this.queryModel=newqueryModel();

}

public voidqueryFF() {

queryModel.query(newqueryModelCallBack() {

@Override

public voidsuccess(queryBean queryBean) {

queryView.success(queryBean);

}

@Override

public voidfailure() {

}

});

}

public voiddetach() {

this.queryView=null;

}

}

deleteView

public interfacedeleteView {

voidsuccess(deleteBean deleteBean);

voidfailure();

}

queryView

public interfacequeryView{

voidsuccess(queryBean queryBean);

voidfailure();

}

ViewCallBack


public interfaceViewCallBack {

voidsuccess(CartBean cartBean);

voidfailure(Exception e);

}


购物车XML

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="20dp">

android:id="@+id/back"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:text="<"

android:textSize="23sp"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:text="购物车"

android:textSize="23sp"

android:textStyle="bold"/>

android:id="@+id/bianji"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:text="编辑"

android:textSize="20sp"/>

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginTop="5dp"

android:background="#D4D4D4"/>

android:id="@+id/recycler_View"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:gravity="center_vertical"

android:orientation="horizontal">

android:id="@+id/quanxuan"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="10dp"

android:background="@drawable/shopcart_unselected"

android:button="@null"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="40dp"

android:text="全选"

android:textSize="23sp"

android:textStyle="bold"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:layout_centerVertical="true"

android:layout_marginLeft="10dp"

android:layout_marginRight="70dp"

android:orientation="vertical">

android:id="@+id/total_price"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="总价 : ¥0元"

android:textColor="#e53e42"

android:textSize="20sp"/>

android:id="@+id/total_num"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/total_price"

android:text="共0件商品"

android:textSize="20sp"/>

android:id="@+id/quzhifu"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:background="#FC7903"

android:gravity="center"

android:padding="30dp"

android:text="去支付"

android:textColor="#fff"

android:textSize="22sp"/>

android:id="@+id/linear_shanchu"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_marginLeft="30dp"

android:orientation="horizontal"

android:visibility="gone">

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:background="#FC7903"

android:gravity="center"

android:padding="20dp"

android:paddingLeft="30dp"

android:paddingRight="30dp"

android:text="分享宝贝"

android:textColor="#fff"

android:textSize="20sp"/>

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:background="#FC7903"

android:gravity="center"

android:padding="20dp"

android:paddingLeft="30dp"

android:paddingRight="30dp"

android:text="移到收藏夹"

android:textColor="#fff"

android:textSize="20sp"/>

android:id="@+id/shanchu"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:background="#DC143C"

android:gravity="center"

android:padding="30dp"

android:paddingLeft="30dp"

android:paddingRight="30dp"

android:text="删除"

android:textColor="#fff"

android:textSize="20sp"/>

详情XML

android:id="@+id/GWC"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:text="点击进入"

android:textSize="20sp"

android:textStyle="bold"/>

android:id="@+id/XQ_Recy"

android:layout_width="match_parent"

android:layout_height="match_parent">

加减器XML

android:background="#F2F1F1"

android:textSize="20sp"

android:id="@+id/reverse"

android:text="一"

android:layout_width="40dp"

android:layout_height="40dp"/>

android:gravity="center"

android:background="#FAFAFA"

android:textStyle="bold"

android:textSize="23sp"

android:layout_width="40dp"

android:layout_height="40dp"

android:text="1"

android:id="@+id/count"

/>

android:id="@+id/add"

android:background="#F2F1F1"

android:textSize="25sp"

android:text="+"

android:layout_width="40dp"

android:layout_height="40dp"/>

购物车Item

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#FFFFFF"

android:padding="5dp">

android:id="@+id/shop_checkbox"

android:layout_width="50dp"

android:layout_height="50dp"

android:layout_centerVertical="true"/>

android:id="@+id/shop_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="35dp"

android:text="良品铺子"

android:textSize="23sp"

android:textStyle="bold"/>

android:id="@+id/item_bianji"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:text="编辑"

android:textSize="20sp"/>

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="#D4D4D4"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#F2F2F2"

android:gravity="center_vertical"

android:orientation="horizontal">

android:id="@+id/item_checkbox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:id="@+id/item_face"

android:layout_width="140dp"

android:layout_height="140dp"

android:src="@mipmap/ic_launcher"

fresco:failureImage="@mipmap/ic_launcher"

fresco:placeholderImage="@mipmap/ic_launcher"/>

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:layout_weight="1"

android:orientation="vertical">

android:id="@+id/item_name"

android:layout_width="wrap_content"

android:layout_height="0dp"

android:layout_weight="1"

android:text="三只松鼠"

android:textSize="20sp"/>

android:id="@+id/item_price"

android:layout_width="wrap_content"

android:layout_height="0dp"

android:layout_weight="1"

android:text="299"

android:textColor="#f00"

android:textSize="23sp"/>

android:id="@+id/custom_jiajian"

android:layout_width="wrap_content"

android:layout_height="0dp"

android:layout_weight="1"

android:visibility="gone"/>

android:id="@+id/item_yansechima"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="颜色 : 黑色 ; 尺码: 29"

android:textSize="20sp"

android:visibility="gone"/>

android:visibility="gone"

android:id="@+id/item_delete"

android:layout_marginRight="10dp"

android:src="@drawable/shopcart_delete"

android:layout_width="30dp"

android:layout_height="30dp" />-->

android:id="@+id/item_delete"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:background="#FC7903"

android:gravity="center"

android:padding="20dp"

android:text="删除"

android:textColor="#fff"

android:textSize="23sp"

android:visibility="gone"/>

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="#D4D4D4"/>

详情XML

android:layout_width="match_parent"

android:layout_height="160dp"

android:orientation="horizontal">

android:id="@+id/xq_fresco"

android:layout_width="200dp"

android:layout_height="160dp"

android:src="@mipmap/ic_launcher"

fresco:failureImage="@mipmap/ic_launcher"

fresco:placeholderImage="@mipmap/ic_launcher"/>

android:layout_width="match_parent"

android:layout_height="160dp"

android:orientation="vertical">

android:id="@+id/xq_name"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:gravity="center"/>

android:id="@+id/xq_price"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:gravity="center"/>

android:id="@+id/xq_btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:text="加入购物车"/>

上一篇下一篇

猜你喜欢

热点阅读