//依赖
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
//App
package com.example.a123.liangqiqi1221yk.adapter;
import android.app.Application;
/**
* Created by 123 on 2017/12/21.
*/
public class App extends Application{
}
//ElvAdapter
package com.example.a123.liangqiqi1221yk.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.a123.liangqiqi1221yk.R;
import com.example.a123.liangqiqi1221yk.SecondActivity;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import com.example.a123.liangqiqi1221yk.bean.PriceAndCount;
import java.util.List;
/**
* Created by 123 on 2017/12/21.
*/
public class ElvAdapter extends BaseExpandableListAdapter {
private Context context;
private List<GetCart.DataBean> group;
private List<List<GetCart.DataBean.ListBean>> child;
private final LayoutInflater inflater;
public ElvAdapter(Context context, List<GetCart.DataBean> group, List<List<GetCart.DataBean.ListBean>> child) {
this.context = context;
this.group = group;
this.child = child;
inflater = LayoutInflater.from(context);
}
@Override
public int getGroupCount() {
return group.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return child.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return group.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return child.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 false;
}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View view;
final GroupViewHolder holder;
if (convertView == null) {
view = inflater.inflate(R.layout.elv_group, null);
holder = new GroupViewHolder();
holder.tv = view.findViewById(R.id.tvGroup);
holder.cbGroup = view.findViewById(R.id.cbGroup);
view.setTag(holder);
} else {
view = convertView;
holder = (GroupViewHolder) view.getTag();
}
final GetCart.DataBean dataBean = group.get(groupPosition);
holder.tv.setText(dataBean.getSellerName());
holder.cbGroup.setChecked(dataBean.isChecked());
holder.cbGroup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//需要改变三个checkbox的状态值
//1.一级列表的checkbox状态值
dataBean.setChecked(holder.cbGroup.isChecked());
//2.二级列表的checkbox状态值
setChildrenCb(groupPosition, holder.cbGroup.isChecked());
//3.全选的checkbox状态值
((SecondActivity) context).setAllChecked(isAllGroupCbChecked());
//计算钱和数量并显示
setPriceAndCount();
//刷新界面
notifyDataSetChanged();
}
});
return view;
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, final View convertView, ViewGroup parent) {
View view;
final ChildViewHolder holder;
if (convertView == null) {
view = inflater.inflate(R.layout.elv_child, null);
holder = new ChildViewHolder();
holder.iv = view.findViewById(R.id.iv);
holder.tvTitle = view.findViewById(R.id.tvTitle);
holder.tvSubhead = view.findViewById(R.id.tvSubhead);
holder.tvPrice = view.findViewById(R.id.tvPrice);
holder.cbChild = view.findViewById(R.id.cbChild);
holder.btDel = view.findViewById(R.id.btDel);
holder.tvNum = view.findViewById(R.id.tvNum);
holder.ivDel = view.findViewById(R.id.ivDel);
holder.ivAdd = view.findViewById(R.id.ivAdd);
view.setTag(holder);
} else {
view = convertView;
holder = (ChildViewHolder) view.getTag();
}
final GetCart.DataBean.ListBean listBean = child.get(groupPosition).get(childPosition);
String images = listBean.getImages();
Glide.with(context).load(images.split("\\|")[0]).into(holder.iv);
holder.tvTitle.setText(listBean.getTitle());
holder.cbChild.setChecked(child.get(groupPosition).get(childPosition).isChecked());
holder.tvSubhead.setText(listBean.getSubhead());
holder.tvPrice.setText(listBean.getPrice() + "元");
holder.tvNum.setText(listBean.getCount() + "");
//给checkbox设置点击事件
holder.cbChild.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//需要改变三个checkbox的状态值
//1.二级列表的checkbox状态值
listBean.setChecked(holder.cbChild.isChecked());
//2.一级列表的checkbox状态值
group.get(groupPosition).setChecked(isAllChildCbChecked(groupPosition));
//3.全选的checkbox状态值
((SecondActivity) context).setAllChecked(isAllGroupCbChecked());
//计算钱和数量并显示
setPriceAndCount();
//刷新界面
notifyDataSetChanged();
}
});
holder.ivAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取目前显示的值
int count = listBean.getCount();
count++;
//改变JavaBean里的状态值
listBean.setCount(count);
//计算钱和数量并显示
setPriceAndCount();
//刷新列表
notifyDataSetChanged();
}
});
holder.ivDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取目前显示的值
int count = listBean.getCount();
if (count <= 1) {
count = 1;
} else {
count--;
}
//改变JavaBean里的状态值
listBean.setCount(count);
//计算钱和数量并显示
setPriceAndCount();
//刷新列表
notifyDataSetChanged();
}
});
holder.btDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//其实就是删除集合
List<GetCart.DataBean.ListBean> listBeans = child.get(groupPosition);
if (listBeans.size() > 0) {
listBeans.remove(childPosition);
}
if (listBeans.size() == 0) {
child.remove(groupPosition);
group.remove(groupPosition);
}
//计算钱和数量并显示
setPriceAndCount();
//改变全选状态
((SecondActivity) context).setAllChecked(isAllGroupCbChecked());
//刷新列表
notifyDataSetChanged();
}
});
return view;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
class GroupViewHolder {
TextView tv;
CheckBox cbGroup;
}
class ChildViewHolder {
ImageView iv;
TextView tvTitle;
TextView tvSubhead;
TextView tvPrice;
CheckBox cbChild;
Button btDel;
TextView tvNum;
ImageView ivDel;
ImageView ivAdd;
}
/**
* 设置一级列表对应的二级列表checkbox状态
*
* @param groupPosition
* @param bool
*/
private void setChildrenCb(int groupPosition, boolean bool) {
List<GetCart.DataBean.ListBean> listBeans = child.get(groupPosition);
for (int i = 0; i < listBeans.size(); i++) {
listBeans.get(i).setChecked(bool);
}
}
/**
* 判断一级列表checkbox状态
*
* @return
*/
private boolean isAllGroupCbChecked() {
if (group.size() == 0) {
return false;
}
for (int i = 0; i < group.size(); i++) {
if (!group.get(i).isChecked()) {
return false;
}
}
return true;
}
/**
* 判断二级列表checkbox状态
*
* @return
*/
private boolean isAllChildCbChecked(int groupPosition) {
List<GetCart.DataBean.ListBean> listBeans = child.get(groupPosition);
for (int i = 0; i < listBeans.size(); i++) {
if (!listBeans.get(i).isChecked()) {
return false;
}
}
return true;
}
/**
* 设置钱和数量
*/
private void setPriceAndCount() {
((SecondActivity) context).setPriceAndCount(compute());
}
/**
* 计算钱和数量
*/
private PriceAndCount compute() {
double price = 0;
int count = 0;
for (int i = 0; i < group.size(); i++) {
List<GetCart.DataBean.ListBean> listBeans = child.get(i);
for (int j = 0; j < listBeans.size(); j++) {
if (listBeans.get(j).isChecked()) {
price += listBeans.get(j).getPrice() * listBeans.get(j).getCount();
count += listBeans.get(j).getCount();
}
}
}
return new PriceAndCount(price, count);
}
/**
* 全选或者全不选
*
* @param bool
*/
public void AllOrNone(boolean bool) {
for (int i = 0; i < group.size(); i++) {
group.get(i).setChecked(bool);
setChildrenCb(i, bool);
}
setPriceAndCount();
notifyDataSetChanged();
}
}
//RvAllAdapter
package com.example.a123.liangqiqi1221yk.adapter;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.a123.liangqiqi1221yk.R;
import com.example.a123.liangqiqi1221yk.bean.OrderBean;
import java.util.List;
/**
* Created by 123 on 2017/12/21.
*/
public class RvAllAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<OrderBean.DataBean> list;
public RvAllAdapter(Context context, List<OrderBean.DataBean> list) {
this.context = context;
this.list = list;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.order_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
MyViewHolder myViewHolder = (MyViewHolder) holder;
OrderBean.DataBean dataBean = list.get(position);
myViewHolder.tvTitle.setText(dataBean.getTitle());
int status = dataBean.getStatus();
myViewHolder.tvBt.setText("查看订单");
myViewHolder.tvStatus.setTextColor(Color.parseColor("#000000"));
if (status == 0) {
myViewHolder.tvStatus.setText("待支付");
myViewHolder.tvBt.setText("取消订单");
myViewHolder.tvStatus.setTextColor(Color.parseColor("#ff0000"));
} else if (status == 1) {
myViewHolder.tvStatus.setText("已取消");
} else if (status == 2) {
myViewHolder.tvStatus.setText("已支付");
}
myViewHolder.tvPrice.setText("价格:" + dataBean.getPrice());
myViewHolder.tvPrice.setTextColor(Color.parseColor("#ff0000"));
myViewHolder.tvTime.setText(dataBean.getCreatetime());
}
@Override
public int getItemCount() {
return list.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
private final TextView tvTitle;
private final TextView tvStatus;
private final TextView tvPrice;
private final TextView tvTime;
private final TextView tvBt;
public MyViewHolder(View itemView) {
super(itemView);
tvTitle = itemView.findViewById(R.id.textView);
tvStatus = itemView.findViewById(R.id.textView2);
tvPrice = itemView.findViewById(R.id.textView3);
tvTime = itemView.findViewById(R.id.textView4);
tvBt = itemView.findViewById(R.id.textView5);
}
}
}
//AddCartBean
package com.example.a123.liangqiqi1221yk.bean;
/**
* Created by 123 on 2017/12/21.
*/
public class AddCartBean {
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;
}
}
//GetCart
package com.example.a123.liangqiqi1221yk.bean;
import java.util.List;
/**
* Created by 123 on 2017/12/21.
*/
public class GetCart {
/**
* msg : 请求成功
* code : 0
* data : [{"list":[{"bargainPrice":399,"createtime":"2017-10-02T15:20:02","detailUrl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg","num":1,"pid":81,"price":699,"pscid":85,"selected":0,"sellerid":2,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":97,"price":1899,"pscid":112,"selected":0,"sellerid":8,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家8","sellerid":"8"},{"list":[{"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","num":1,"pid":54,"price":888,"pscid":39,"selected":0,"sellerid":10,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家10","sellerid":"10"},{"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":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":2,"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"}]
*/
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":399,"createtime":"2017-10-02T15:20:02","detailUrl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg","num":1,"pid":81,"price":699,"pscid":85,"selected":0,"sellerid":2,"subhead":"满2件,总价打6.50折","title":"Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"}]
* sellerName : 商家2
* sellerid : 2
*/
private boolean checked;
private String sellerName;
private String sellerid;
private List<ListBean> list;
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
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 : 399.0
* createtime : 2017-10-02T15:20:02
* detailUrl : https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends
* images : https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24Ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24N3324d5f4.jpg!q70.jpg
* num : 1
* pid : 81
* price : 699.0
* pscid : 85
* selected : 0
* sellerid : 2
* subhead : 满2件,总价打6.50折
* title : Gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84A)
*/
private boolean checked;
private int count=1;
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 int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
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;
}
}
}
}
//OrderBean
package com.example.a123.liangqiqi1221yk.bean;
import java.util.List;
/**
* Created by 123 on 2017/12/21.
*/
public class OrderBean {
/**
* msg : 请求成功
* code : 0
* data : [{"createtime":"2017-10-19T20:28:43","orderid":20,"price":100,"status":2,"title":"订单标题测试3","uid":71},{"createtime":"2017-10-19T20:44:40","orderid":31,"price":11800,"status":2,"title":"订单标题测试14","uid":71},{"createtime":"2017-10-19T20:44:51","orderid":32,"price":11800,"status":1,"title":"订单标题测试15","uid":71},{"createtime":"2017-10-20T08:02:07","orderid":43,"price":11800,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-10-20T08:02:16","orderid":44,"price":11800,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-10-22T15:14:39","orderid":890,"price":11800,"status":2,"title":"","uid":71},{"createtime":"2017-11-09T09:17:20","orderid":1446,"price":99.99,"status":1,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1447,"price":567,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1448,"price":256.99,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1449,"price":399,"status":2,"title":"订单标题测试","uid":71}]
* page : 1
*/
private String msg;
private String code;
private String page;
private List<DataBean> data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* createtime : 2017-10-19T20:28:43
* orderid : 20
* price : 100.0
* status : 2
* title : 订单标题测试3
* uid : 71
*/
private String createtime;
private int orderid;
private double price;
private int status;
private String title;
private int uid;
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public int getOrderid() {
return orderid;
}
public void setOrderid(int orderid) {
this.orderid = orderid;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
}
}
//PriceAndCount
package com.example.a123.liangqiqi1221yk.bean;
/**
* Created by 123 on 2017/12/21.
*/
public class PriceAndCount {
private double price;
private int count;
public PriceAndCount(double price, int count) {
this.price = price;
this.count = count;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
//ShangpinBean
package com.example.a123.liangqiqi1221yk.bean;
/**
* Created by 123 on 2017/12/21.
*/
public class ShangpinBean {
/**
* msg :
* seller : {"description":"我是商家15","icon":"http://120.27.23.105/images/icon.png","name":"商家15","productNums":999,"score":5,"sellerid":15}
* code : 0
* data : {"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","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","itemtype":0,"pid":71,"price":32999,"pscid":40,"salenum":4242,"sellerid":15,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}
*/
private String msg;
private SellerBean seller;
private String code;
private DataBean data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public SellerBean getSeller() {
return seller;
}
public void setSeller(SellerBean seller) {
this.seller = seller;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public DataBean getData() {
return data;
}
public void setData(DataBean data) {
this.data = data;
}
public static class SellerBean {
/**
* description : 我是商家15
* icon : http://120.27.23.105/images/icon.png
* name : 商家15
* productNums : 999
* score : 5.0
* sellerid : 15
*/
private String description;
private String icon;
private String name;
private int productNums;
private double score;
private int sellerid;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getProductNums() {
return productNums;
}
public void setProductNums(int productNums) {
this.productNums = productNums;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public int getSellerid() {
return sellerid;
}
public void setSellerid(int sellerid) {
this.sellerid = sellerid;
}
}
public static class DataBean {
/**
* bargainPrice : 11800.0
* createtime : 2017-10-03T23:53:28
* 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
* itemtype : 0
* pid : 71
* price : 32999.0
* pscid : 40
* salenum : 4242
* sellerid : 15
* subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)
* title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G
*/
private double bargainPrice;
private String createtime;
private String detailUrl;
private String images;
private int itemtype;
private int pid;
private double price;
private int pscid;
private int salenum;
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 getItemtype() {
return itemtype;
}
public void setItemtype(int itemtype) {
this.itemtype = itemtype;
}
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 getSalenum() {
return salenum;
}
public void setSalenum(int salenum) {
this.salenum = salenum;
}
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;
}
}
}
//AllFragment
package com.example.a123.liangqiqi1221yk.fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.a123.liangqiqi1221yk.R;
import com.example.a123.liangqiqi1221yk.adapter.RvAllAdapter;
import com.example.a123.liangqiqi1221yk.bean.OrderBean;
import com.example.a123.liangqiqi1221yk.net.HttpUtils;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by 123 on 2017/12/21.
*/
public class AllFragment extends Fragment{
private RecyclerView rv;
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_all, null);
rv = view.findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(getActivity()));
String url = "https://www.zhaoapi.cn/product/getOrders?uid=71";
HttpUtils.getHttpUtils().doGet(url, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string = response.body().string();
final OrderBean orderBean = new Gson().fromJson(string, OrderBean.class);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
RvAllAdapter adapter = new RvAllAdapter(getContext(), orderBean.getData());
rv.setAdapter(adapter);
}
});
}
});
return view;
}
}
//WaitFragment
package com.example.a123.liangqiqi1221yk.fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by 123 on 2017/12/21.
*/
public class WaitFragment extends Fragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
}
//IShangpinModel
package com.example.a123.liangqiqi1221yk.model;
import com.example.a123.liangqiqi1221yk.bean.AddCartBean;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import com.example.a123.liangqiqi1221yk.bean.ShangpinBean;
import com.example.a123.liangqiqi1221yk.net.OnNetListener;
import java.util.Map;
/**
* Created by 123 on 2017/12/21.
*/
public interface IShangpinModel {
public void doPost(Map<String,String> params, OnNetListener<ShangpinBean> onNetListener);
public void doAdd(Map<String,String> params, OnNetListener<AddCartBean> onNetListener);
public void GetCart(Map<String,String> params, OnNetListener<GetCart> onNetListener);
}
//ShangpinModel
package com.example.a123.liangqiqi1221yk.model;
import android.os.Handler;
import android.os.Looper;
import com.example.a123.liangqiqi1221yk.bean.AddCartBean;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import com.example.a123.liangqiqi1221yk.bean.ShangpinBean;
import com.example.a123.liangqiqi1221yk.net.Api;
import com.example.a123.liangqiqi1221yk.net.HttpUtils;
import com.example.a123.liangqiqi1221yk.net.OnNetListener;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by 123 on 2017/12/21.
*/
public class ShangpinModel implements IShangpinModel {
private Handler handler=new Handler(Looper.getMainLooper());
//查看商品
@Override
public void doPost(Map<String, String> params, final OnNetListener<ShangpinBean> onNetListener) {
HttpUtils.getHttpUtils().doPost(Api.str1, params, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final ShangpinBean shangpinBean = new Gson().fromJson(response.body().string(), ShangpinBean.class);
handler.post(new Runnable() {
@Override
public void run() {
onNetListener.onSuccess(shangpinBean);
}
});
}
});
}
//加入购物车
@Override
public void doAdd(Map<String, String> params, final OnNetListener<AddCartBean> onNetListener) {
; HttpUtils.getHttpUtils().doPost(Api.str1, params, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final AddCartBean addCartBean = new Gson().fromJson(response.body().string(), AddCartBean.class);
handler.post(new Runnable() {
@Override
public void run() {
onNetListener.onSuccess(addCartBean);
}
});
}
});
}
//查询购物车
@Override
public void GetCart(Map<String, String> params, final OnNetListener<GetCart> onNetListener) {
HttpUtils.getHttpUtils().doPost(Api.str2, params, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final GetCart getCart = new Gson().fromJson(response.body().string(), GetCart.class);
handler.post(new Runnable() {
@Override
public void run() {
onNetListener.onSuccess(getCart);
}
});
}
});
}
}
//Api
package com.example.a123.liangqiqi1221yk.net;
/**
* 张梦乔创建于 2017/12/18.
* 9:06
*/
public interface Api {
boolean ISONLINE = true;
String DEV = "http://169.27.23.105";
public static String ONLINE = "http://120.27.23.105";
public static String HOST = ISONLINE ? ONLINE : DEV;
public static String Login = HOST + "/user/login";
public static String REGISTER = HOST + "/user/reg";
public static String CATAGORY = HOST + "/product/getCatagory";
public static String PRODUCT_CATAGORY = HOST + "/product/getProductCatagory?cid=%s";
public static String PRODUCT_CATAGORY_LIST = HOST + "/product/getProducts";
public static String PRODUCT_DETAIL = HOST + "/product/getProductDetail?pid=%s&source=android";
public static String ADD_CARD = HOST + "/product/addCart";
public static String SELECT_CARD = HOST + "/product/getCarts";
public static String DEL_CARD = HOST + "/product/deleteCart";
public static String str1 = "https://www.zhaoapi.cn/product/getProductDetail";
public static String str2 = "https://www.zhaoapi.cn/product/getCarts";
}
//HttpUtils
package com.example.a123.liangqiqi1221yk.net;
import android.util.Log;
import java.util.Map;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
/**
* 张梦乔创建于 2017/12/18.
* 8:52
*/
public class HttpUtils {
private static HttpUtils httpUtils;
private final OkHttpClient client;
private HttpUtils(){
HttpLoggingInterceptor logging=new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
client=new OkHttpClient.Builder().addInterceptor(new MyInterceptor()).build();
}
public static HttpUtils getHttpUtils(){
if(httpUtils==null){
synchronized (HttpUtils.class){
if(httpUtils==null){
httpUtils=new HttpUtils();
}
}
}
return httpUtils;
}
/*
* GET请求*/
public void doGet(String url, Callback callback){
Request request=new Request.Builder().url(url).build();
client.newCall(request).enqueue(callback);
}
/**
* POST请求
*
* @param url
* @param params
* @param callback
*/
public void doPost(String url, Map<String, String> params, Callback callback) {
if (params == null) {
throw new RuntimeException("参数为空了");
}
FormBody.Builder builder = new FormBody.Builder();
for (Map.Entry<String, String> entry : params.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
Log.e("OkHttpUtils", "请求地址:" + url + " 请求的参数:");
FormBody formBody = builder.build();
Request request = new Request.Builder().url(url).post(formBody).build();
client.newCall(request).enqueue(callback);
}
}
//MyInterceptor
package com.example.a123.liangqiqi1221yk.net;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
* 张梦乔创建于 2017/12/18.
* 8:54
*/
public class MyInterceptor implements Interceptor{
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (request.method().equals("GET")) {
String url = request.url().url().toString();
url += "&source=android";
Request newRequset = request.newBuilder().url(url).build();
return chain.proceed(newRequset);
} else {
FormBody formBody = (FormBody) request.body();
FormBody.Builder builder = new FormBody.Builder();
for (int i = 0; i < formBody.size(); i++) {
builder.add(formBody.name(i), formBody.value(i));
}
builder.add("source", "android");
FormBody newFormBody = builder.build();
Request newRequest = request.newBuilder().url(request.url().url().toString()).post(newFormBody).build();
return chain.proceed(newRequest);
}
}
}
//OnNetListener
package com.example.a123.liangqiqi1221yk.net;
/**
* 张梦乔创建于 2017/12/18.
* 8:51
*/
public interface OnNetListener<T> {
public void onSuccess(T t);
public void onFaliure(Exception e);
}
//ShangpinPrestener
package com.example.a123.liangqiqi1221yk.prestener;
import com.example.a123.liangqiqi1221yk.bean.AddCartBean;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import com.example.a123.liangqiqi1221yk.bean.ShangpinBean;
import com.example.a123.liangqiqi1221yk.model.IShangpinModel;
import com.example.a123.liangqiqi1221yk.model.ShangpinModel;
import com.example.a123.liangqiqi1221yk.net.OnNetListener;
import com.example.a123.liangqiqi1221yk.view.ISecondListener;
import com.example.a123.liangqiqi1221yk.view.IShangpinView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by 123 on 2017/12/21.
*/
public class ShangpinPrestener {
private IShangpinModel iShangpinModel;
private IShangpinView iShangpinView;
private ISecondListener iSecondListener;
public ShangpinPrestener(IShangpinView iShangpinView) {
this.iShangpinView = iShangpinView;
iShangpinModel=new ShangpinModel();
}
public ShangpinPrestener(ISecondListener iSecondListener) {
this.iSecondListener = iSecondListener;
iShangpinModel=new ShangpinModel();
}
//查看商品
public void doPost(){
Map<String,String> params=new HashMap<>();
params.put("pid","71");
iShangpinModel.doPost(params, new OnNetListener<ShangpinBean>() {
@Override
public void onSuccess(ShangpinBean shangpinBean) {
if (iShangpinView != null) {
iShangpinView.show(shangpinBean);
}
}
@Override
public void onFaliure(Exception e) {
}
});
}
//添加购物车
public void addCart(){
Map<String,String> params=new HashMap<>();
params.put("pid", "71");
params.put("uid", "70");
iShangpinModel.doAdd(params, new OnNetListener<AddCartBean>() {
@Override
public void onSuccess(AddCartBean addCartBean) {
if(iShangpinView!=null){
iShangpinView.addShwo(addCartBean.getCode().equals("0")?"添加成功":"添加失败了");
}
}
@Override
public void onFaliure(Exception e) {
}
});
}
//查看购物车
public void getCart(){
Map<String, String> params = new HashMap<>();
params.put("uid", "1234");
params.put("pid", "71");
iShangpinModel.GetCart(params, new OnNetListener<GetCart>() {
@Override
public void onSuccess(GetCart getCart) {
if (iSecondListener != null) {
List<GetCart.DataBean> group = getCart.getData();
List<List<GetCart.DataBean.ListBean>> child = new ArrayList<>();
for (int i = 0; i < group.size(); i++) {
child.add(group.get(i).getList());
}
iSecondListener.show(group, child);
}
}
@Override
public void onFaliure(Exception e) {
}
});
}
}
//ISecondListener
package com.example.a123.liangqiqi1221yk.view;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import java.util.List;
/**
* Created by 123 on 2017/12/21.
*/
public interface ISecondListener {
void show(List<GetCart.DataBean> group, List<List<GetCart.DataBean.ListBean>> child);
}
//IShangpinView
package com.example.a123.liangqiqi1221yk.view;
import com.example.a123.liangqiqi1221yk.bean.ShangpinBean;
/**
* Created by 123 on 2017/12/21.
*/
public interface IShangpinView {
void show(ShangpinBean shangpinBean);
void addShwo(String str);
}
//ConfirmActivity
package com.example.a123.liangqiqi1221yk;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ConfirmActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mTvLeft;
/**
* 立即下单
*/
private Button mBt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_confirm);
//接收传过来实付款
Intent intent = getIntent();
String money = intent.getStringExtra("money");
initView();
mTvLeft.setText("实付款:¥" + money);
}
private void initView() {
mTvLeft = (TextView) findViewById(R.id.tvLeft);
mBt = (Button) findViewById(R.id.bt);
mBt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
default:
break;
case R.id.bt:
//跳转到订单页面
Intent intent = new Intent(ConfirmActivity.this, OrderActivity.class);
startActivity(intent);
break;
}
}
}
//MainActivity
package com.example.a123.liangqiqi1221yk;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.example.a123.liangqiqi1221yk.bean.ShangpinBean;
import com.example.a123.liangqiqi1221yk.prestener.ShangpinPrestener;
import com.example.a123.liangqiqi1221yk.view.IShangpinView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener ,IShangpinView {
private ImageView mIv;
private TextView mTvBargainPrice;
private TextView mTvPrice;
/**
* 购物车
*/
private TextView mTvCart;
/**
* 加入购物车
*/
private TextView mTvAddCart;
private ShangpinPrestener shangpinPrestener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
shangpinPrestener=new ShangpinPrestener(this);
shangpinPrestener.doPost();
}
private void initView() {
mIv = (ImageView) findViewById(R.id.iv);
mIv.setOnClickListener(this);
mTvBargainPrice = (TextView) findViewById(R.id.tvBargainPrice);
mTvBargainPrice.setOnClickListener(this);
mTvPrice = (TextView) findViewById(R.id.tvPrice);
mTvPrice.setOnClickListener(this);
mTvCart = (TextView) findViewById(R.id.tvCart);
mTvCart.setOnClickListener(this);
mTvAddCart = (TextView) findViewById(R.id.tvAddCart);
mTvAddCart.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
default:
break;
case R.id.tvCart:
Intent intent=new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
break;
case R.id.tvAddCart:
shangpinPrestener.addCart();
break;
}
}
@Override
public void show(ShangpinBean shangpinBean) {
String images = shangpinBean.getData().getImages();
String[] split = images.split("\\|");
Glide.with(this).load(split[0]).into(mIv);
mTvBargainPrice.setText("原价:"+shangpinBean.getData().getPrice());
mTvPrice.setText("优惠价:"+shangpinBean.getData().getBargainPrice());
}
@Override
public void addShwo(String str) {
Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
}
}
//OrderActivity
package com.example.a123.liangqiqi1221yk;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.a123.liangqiqi1221yk.fragment.AllFragment;
import com.example.a123.liangqiqi1221yk.fragment.WaitFragment;
import java.util.ArrayList;
import java.util.List;
public class OrderActivity extends AppCompatActivity {
/**
* 全部
*/
private TextView mTvAll;
/**
* 待支付
*/
private TextView mTvWait;
private LinearLayout mLl;
private ViewPager mVp;
private List<Fragment> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
initView();
list.add(new AllFragment());
list.add(new WaitFragment());
mVp.setAdapter(new MyAdapter(getSupportFragmentManager()));
}
private void initView() {
mTvAll = (TextView) findViewById(R.id.tvAll);
mTvWait = (TextView) findViewById(R.id.tvWait);
mLl = (LinearLayout) findViewById(R.id.ll);
mVp = (ViewPager) findViewById(R.id.vp);
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return list.get(position);
}
@Override
public int getCount() {
return list.size();
}
}
}
//SecondActivity
package com.example.a123.liangqiqi1221yk;
import android.content.Intent;
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.a123.liangqiqi1221yk.adapter.ElvAdapter;
import com.example.a123.liangqiqi1221yk.bean.GetCart;
import com.example.a123.liangqiqi1221yk.bean.PriceAndCount;
import com.example.a123.liangqiqi1221yk.prestener.ShangpinPrestener;
import com.example.a123.liangqiqi1221yk.view.ISecondListener;
import java.util.List;
public class SecondActivity extends AppCompatActivity implements ISecondListener {
private ExpandableListView mElv;
/**
* 全选
*/
private CheckBox mCb;
/**
* 合计:
*/
private TextView mTvTotal;
/**
* 去结算(0)
*/
private TextView mTvCount;
private ShangpinPrestener shangpinPrestener;
private ElvAdapter elvAdapter;
private PriceAndCount priceAndCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
initView();
shangpinPrestener=new ShangpinPrestener(this);
shangpinPrestener.getCart();
mCb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
elvAdapter.AllOrNone(mCb.isChecked());
}
});
}
private void initView() {
mElv = (ExpandableListView) findViewById(R.id.elv);
mCb = (CheckBox) findViewById(R.id.cb);
mTvTotal = (TextView) findViewById(R.id.tvTotal);
mTvCount = (TextView) findViewById(R.id.tvCount);
mTvCount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(SecondActivity.this,ConfirmActivity.class);
if(priceAndCount!=null){
intent.putExtra("money",priceAndCount.getPrice()+"");
}
startActivity(intent);
}
});
}
@Override
public void show(List<GetCart.DataBean> group, List<List<GetCart.DataBean.ListBean>> child) {
elvAdapter = new ElvAdapter(SecondActivity.this,group,child);
mElv.setGroupIndicator(null);
mElv.setAdapter(elvAdapter);
for (int i = 0; i < group.size(); i++) {
mElv.expandGroup(i);
}
} public void setPriceAndCount(PriceAndCount priceAndCount) {
this.priceAndCount = priceAndCount;
mTvTotal.setText("合计:" + priceAndCount.getPrice());
mTvCount.setText("去结算(" + priceAndCount.getCount() + ")");
}
public void setAllChecked(boolean bool) {
mCb.setChecked(bool);
}
}
//activity_confirm.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:id="@+id/activity_confirm"
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"
tools:context="com.example.a123.liangqiqi1221yk.ConfirmActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#33000000">
<TextView
android:id="@+id/tvLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#ff0000"
android:text="立即下单" />
</RelativeLayout>
</LinearLayout>
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
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"
tools:context="com.example.a123.liangqiqi1221yk.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#ff3360"
android:text="商品详情"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="25sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/iv"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:id="@+id/tvBargainPrice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF1100C"
android:id="@+id/tvPrice"/>
<View
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#33000000"
android:id="@+id/tvCart"
android:text="购物车"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/tvAddCart"
android:layout_weight="1"
android:background="#33000000"
android:gravity="center"
android:text="加入购物车"
/>
</LinearLayout>
</LinearLayout>
//activity_order.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/activity_order"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.a123.liangqiqi1221yk.OrderActivity">
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tvAll"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:text="全部" />
<TextView
android:id="@+id/tvWait"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:text="待支付" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v4.view.ViewPager>
</LinearLayout>
//activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:id="@+id/activity_second"
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"
tools:context="com.example.a123.liangqiqi1221yk.SecondActivity">
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/elv"
android:layout_weight="1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cb"
android:layout_centerVertical="true"
android:text="全选"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvTotal"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/cb"
android:text="合计:"/>
<TextView
android:id="@+id/tvCount"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#ff0000"
android:gravity="center"
android:text="去结算(0)"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
//elv_child.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="120dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="50dp">
<CheckBox
android:id="@+id/cbChild"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- <TextView
android:id="@+id/tvSubhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />-->
<TextView
android:id="@+id/tvSubhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_marginLeft="10dp"
android:id="@+id/ivDel"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/iv_del" />
<TextView
android:id="@+id/tvNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:text="1"/>
<ImageView
android:id="@+id/ivAdd"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/iv_add" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/btDel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="删除" />
</LinearLayout>
//elv_group.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="match_parent"
android:orientation="vertical"
>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cbGroup"/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/tvGroup"
android:gravity="center_vertical"/>
</LinearLayout>
//fragment_all.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</LinearLayout>
//order_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginStart="19dp"
android:layout_marginTop="21dp"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="31dp"
android:layout_marginRight="31dp"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/textView"
android:layout_marginTop="27dp"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/textView3"
android:layout_alignRight="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="24dp"
android:text="TextView" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView4"
android:layout_alignEnd="@+id/textView2"
android:layout_alignRight="@+id/textView2"
android:text="TextView" />
</RelativeLayout>
//联网权限 .name