//权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
//依赖
compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okio:okio:1.11.0' //gson compile 'com.google.code.gson:gson:2.8.2' //glide compile 'com.github.bumptech.glide:glide:3.7.0' compile 'jp.wasabeef:glide-transformations:1.0.6' compile 'com.youth.banner:banner:1.4.9' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile 'cn.yipianfengye.android:zxing-library:2.1' compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'
//适配器:购物车
package com.example.dell.shopping1.adapter; import android.content.Context; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.dell.shopping1.Model.Bean.CartBean; import com.example.dell.shopping1.Model.Bean.CountPriceBean; import com.example.dell.shopping1.R; import com.example.dell.shopping1.pree.inter.MainPresenter1; import com.example.dell.shopping1.utils.ApiUtil; import com.example.dell.shopping1.utils.OkHttp3Util; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by Dash on 2018/1/3. */ public class ShoppingAdapter extends BaseExpandableListAdapter{ private MainPresenter1 mainPresenter; private RelativeLayout relative_progress; private Handler handler; private CartBean cartBean; private Context context; private int childIndex; private int allIndex; public ShoppingAdapter(Context context, CartBean cartBean, Handler handler, RelativeLayout relative_progress, MainPresenter1 mainPresenter) { this.context = context; this.cartBean = cartBean; this.handler = handler; this.relative_progress = relative_progress; this.mainPresenter = mainPresenter; } @Override public int getGroupCount() { return cartBean.getData().size(); } @Override public int getChildrenCount(int groupPosition) { return cartBean.getData().get(groupPosition).getList().size(); } @Override public Object getGroup(int groupPosition) { return cartBean.getData().get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return cartBean.getData().get(groupPosition).getList().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) { final GroupHolder holder; if (view == null){ view = View.inflate(context, R.layout.group_layout,null); holder = new GroupHolder(); holder.checkBox = view.findViewById(R.id.group_check); holder.textView = view.findViewById(R.id.group_text); view.setTag(holder); }else { holder = (GroupHolder) view.getTag(); } final CartBean.DataBean dataBean = cartBean.getData().get(groupPosition); //赋值 holder.textView.setText(dataBean.getSellerName()); holder.checkBox.setChecked(dataBean.isGroupChecked()); //商家的点击事件 holder.checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //显示progress relative_progress.setVisibility(View.VISIBLE); //根据商家的状态holder.checkbox.ischecked(),改变下面所有子条目的状态,,,10,,改变十次,更新完成一个之后再去执行下一个...递归 childIndex = 0; updateAllChildInGroup(dataBean,holder.checkBox.isChecked()); } }); return view; } /** * 根据商家状态使用递归改变所有的子条目 * @param dataBean * @param checked */ private void updateAllChildInGroup(final CartBean.DataBean dataBean, final boolean checked) { CartBean.DataBean.ListBean listBean = dataBean.getList().get(childIndex); Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid","72"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功一条 if (response.isSuccessful()){ //索引增加 childIndex ++; if (childIndex < dataBean.getList().size()){ //再去更新下一条 updateAllChildInGroup(dataBean,checked); }else {//全都更新完成了....重新查询购物车 mainPresenter.getCartData(ApiUtil.selectCartUrl); } } } }); } @Override public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) { ChildHolder holder; if (view == null){ view = View.inflate(context, R.layout.child_layout,null); holder = new ChildHolder(); holder.checkBox = view.findViewById(R.id.child_check); holder.text_title = view.findViewById(R.id.child_title); holder.imageView = view.findViewById(R.id.child_image); holder.text_price = view.findViewById(R.id.child_price); holder.text_jian = view.findViewById(R.id.text_jian); holder.text_num = view.findViewById(R.id.text_num); holder.text_add = view.findViewById(R.id.text_add); holder.text_delete = view.findViewById(R.id.text_delete); view.setTag(holder); }else { holder = (ChildHolder) view.getTag(); } final CartBean.DataBean.ListBean listBean = cartBean.getData().get(groupPosition).getList().get(childPosition); //赋值 holder.text_title.setText(listBean.getTitle()); holder.text_price.setText("¥"+listBean.getBargainPrice()); String[] strings = listBean.getImages().split("\\|"); Glide.with(context).load(strings[0]).into(holder.imageView); holder.checkBox.setChecked(listBean.getSelected() == 0? false:true);//根据0,1进行设置是否选中 //setText()我们使用一定是设置字符串 holder.text_num.setText(listBean.getNum()+""); //点击事件 holder.checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //此时需要显示进度条 relative_progress.setVisibility(View.VISIBLE); //更新购物车,,,,需要改变是否选中,,,如果现在显示的是0,改成1;;;1--->0 Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid","72"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected() == 0? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功之后,,,,再次查询购物车的数据进行展示 if (response.isSuccessful()){ mainPresenter.getCartData(ApiUtil.selectCartUrl); } } }); } }); //加号 holder.text_add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //此时需要显示进度条 relative_progress.setVisibility(View.VISIBLE); //更新购物车,,,,需要改变是数量,,,,需要加1 Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid","72"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected())); params.put("num", String.valueOf(listBean.getNum()+1)); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功之后,,,,再次查询购物车的数据进行展示 if (response.isSuccessful()){ mainPresenter.getCartData(ApiUtil.selectCartUrl); } } }); } }); //减号 holder.text_jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int num = listBean.getNum(); if (num == 1){ return; } //此时需要显示进度条 relative_progress.setVisibility(View.VISIBLE); //更新购物车,,,,需要改变是数量,,,,需要加1 Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid","72"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected())); params.put("num", String.valueOf(num-1)); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功之后,,,,再次查询购物车的数据进行展示 if (response.isSuccessful()){ mainPresenter.getCartData(ApiUtil.selectCartUrl); } } }); } }); //删除 holder.text_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //显示进度条 relative_progress.setVisibility(View.VISIBLE); //调用删除的接口 Map<String, String> params = new HashMap<>(); //uid=72&pid=1 params.put("uid","72"); params.put("pid", String.valueOf(listBean.getPid())); OkHttp3Util.doPost(ApiUtil.deleteCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ //再次请求购物车的数据 mainPresenter.getCartData(ApiUtil.selectCartUrl); } } }); } }); return view; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } /** * 计算总价和数量,,,并且发送给activity进行显示 */ public void sendPriceAndCount() { double price = 0; int count = 0; for (int i = 0;i<cartBean.getData().size();i++){ List<CartBean.DataBean.ListBean> listBeans = cartBean.getData().get(i).getList(); for (int j = 0; j< listBeans.size(); j++){ if (listBeans.get(j).getSelected() == 1){ price += listBeans.get(j).getBargainPrice() * listBeans.get(j).getNum(); count += listBeans.get(j).getNum(); } } } //double高精度,,,计算的时候可能会出现一串数字...保留两位 DecimalFormat decimalFormat = new DecimalFormat("0.00"); String priceString = decimalFormat.format(price); CountPriceBean countPriceBean = new CountPriceBean(priceString, count); //发送到主页面进行显示 Message msg = Message.obtain(); msg.what = 0; msg.obj = countPriceBean; handler.sendMessage(msg); } /** * 根据全选的状态更新所有商品的状态 * @param checked */ public void setAllChildsChecked(boolean checked) { //创建一个大的结合,,,存放所有商品的数据 List<CartBean.DataBean.ListBean> allList = new ArrayList<>(); for (int i= 0;i<cartBean.getData().size();i++){ List<CartBean.DataBean.ListBean> listBeans = cartBean.getData().get(i).getList(); for (int j=0;j<listBeans.size();j++){ allList.add(listBeans.get(j)); } } //显示progress relative_progress.setVisibility(View.VISIBLE); //递归更新.... allIndex = 0; updateAllChecked(allList,checked); } /** * 更新所有的商品 * @param allList * @param checked */ private void updateAllChecked(final List<CartBean.DataBean.ListBean> allList, final boolean checked) { CartBean.DataBean.ListBean listBean = allList.get(allIndex); Map<String, String> params = new HashMap<>(); //?uid=71&sellerid=1&pid=1&selected=0&num=10 params.put("uid","72"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新一条成功 if (response.isSuccessful()){ allIndex ++; if (allIndex < allList.size()){ //继续更新下一条 updateAllChecked(allList,checked); }else { //重新查询 mainPresenter.getCartData(ApiUtil.selectCartUrl); } } } }); } private class GroupHolder{ CheckBox checkBox; TextView textView; } private class ChildHolder{ CheckBox checkBox; ImageView imageView; TextView text_title; TextView text_price; TextView text_num; TextView text_jian; TextView text_add; TextView text_delete; } }
//适配器:订单
package com.example.dell.shopping1.adapter; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; import com.example.dell.shopping1.R; import com.example.dell.shopping1.holder.MyDingDanHolder; import com.example.dell.shopping1.pree.inter.Presenter; import com.example.dell.shopping1.utils.ApiUtil; import com.example.dell.shopping1.utils.OkHttp3Util; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * author:Created by WangZhiQiang on 2018/1/15. */ public class MyDingDanAdapter extends RecyclerView.Adapter<MyDingDanHolder> { private final Context context; private final List<MyDingDanBean.DataBean> list; private Presenter presenter; private int page; public MyDingDanAdapter(Context context, List<MyDingDanBean.DataBean> list, Presenter presenter, int page) { this.context = context; this.list = list; this.presenter = presenter; this.page = page; } @Override public MyDingDanHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.item_dingdan,parent, false); MyDingDanHolder holder = new MyDingDanHolder(view); return holder; } @Override public void onBindViewHolder(MyDingDanHolder holder, final int position) { holder.text_title.setText(list.get(position).getTitle()); holder.text_price.setText("价格: "+list.get(position).getPrice()); holder.text_tame.setText(list.get(position).getCreatetime()); if (list.get(position).getStatus()==0){ holder.text_daizhifu.setText("待支付"); holder.text_daizhifu.setTextColor(Color.RED); holder.text_btn.setText("取消订单"); holder.text_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("提示"); builder.setMessage("确定要取消订单吗?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Map<String, String> params=new HashMap<>(); params.put("uid","3690"); params.put("orderId", String.valueOf(list.get(position).getOrderid())); params.put("status", String.valueOf(2)); OkHttp3Util.doPost(ApiUtil.genxin, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ presenter.getDingUrl(ApiUtil.dingdan,page); } } }); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); } }); }else if (list.get(position).getStatus()==1){ holder.text_daizhifu.setText("已支付"); holder.text_daizhifu.setTextColor(Color.BLACK); holder.text_btn.setText("查看订单"); }else { holder.text_daizhifu.setText("已取消"); holder.text_daizhifu.setTextColor(Color.BLACK); holder.text_btn.setText("查看订单"); holder.text_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("提示"); builder.setMessage("确定循环利用吗?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Map<String, String> params = new HashMap<>(); params.put("uid", "3690"); params.put("orderId", String.valueOf(list.get(position).getOrderid())); params.put("status", String.valueOf(0)); OkHttp3Util.doPost(ApiUtil.genxin, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { presenter.getDingUrl(ApiUtil.dingdan, page); } } }); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); } }); } } @Override public int getItemCount() { return list.size(); }
}//Frament
//
Frag_Daizhi
package com.example.dell.shopping1.fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; 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 android.widget.RelativeLayout; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; import com.example.dell.shopping1.R; import com.example.dell.shopping1.adapter.MyDingDanAdapter; import com.example.dell.shopping1.pree.inter.Presenter; import com.example.dell.shopping1.utils.ApiUtil; import com.example.dell.shopping1.view.Iview.Main; import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener; import com.scwang.smartrefresh.layout.listener.OnRefreshListener; import java.util.ArrayList; import java.util.List; /** * Created by admin on 2018/1/13. */ public class Frag_Daizhi extends Fragment implements Main { private List<MyDingDanBean.DataBean> list = new ArrayList<>(); private View view; private RecyclerView recycler_daizhi; private int status=0; private Presenter presenter; private RelativeLayout relative_bar; private SmartRefreshLayout smart_refresh; private int page=0; private int a=0; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what==0){ page++; a=1; } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_daizhi, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); recycler_daizhi = view.findViewById(R.id.recycler_daizhi); relative_bar = view.findViewById(R.id.relative_bar); smart_refresh = view.findViewById(R.id.smart_refresh); presenter = new Presenter(this); } @Override public void onResume() { super.onResume(); relative_bar.setVisibility(View.VISIBLE); if (a==1){ //page++; // presenter.getDingUrl(ApiUtil.dingdan,page); } presenter.getDingUrl(ApiUtil.dingdan,page); } @Override public void getDingDanBean(final MyDingDanBean myDingDanBean) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { smart_refresh.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { list.clear(); list.addAll(0,myDingDanBean.getData()); myAdapter(); smart_refresh.finishRefresh(); } }); smart_refresh.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(RefreshLayout refreshlayout) { handler.sendEmptyMessage(0); list.clear(); page++; presenter.getDingUrl(ApiUtil.dingdan,page); onResume(); list.addAll(myDingDanBean.getData()); myAdapter(); smart_refresh.finishLoadmore(); } }); if (myDingDanBean!=null){ list.addAll(myDingDanBean.getData()); myAdapter(); relative_bar.setVisibility(View.GONE); } } }); } public void myAdapter(){ recycler_daizhi.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false)); MyDingDanAdapter adapter = new MyDingDanAdapter(getActivity(), list,presenter,page); recycler_daizhi.setAdapter(adapter); } }
//Frag_YiQu
package com.example.dell.shopping1.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; import com.example.dell.shopping1.R; /** * Created by admin on 2018/1/13. */ public class Frag_YiQu extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_yiqu, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } }
//Frag_YiZhi
package com.example.dell.shopping1.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; import com.example.dell.shopping1.R; /** * Created by admin on 2018/1/13. */ public class Frag_YiZhi extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_yizhi, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } }
//Holder
//MyDingDanHolder
package com.example.dell.shopping1.holder; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.TextView; import com.example.dell.shopping1.R; /** * Created by admin on 2018/1/13. */ public class MyDingDanHolder extends RecyclerView.ViewHolder { public TextView text_title; public TextView text_daizhifu; public TextView text_price; public TextView text_tame; public TextView text_btn; public MyDingDanHolder(View itemView) { super(itemView); text_title = itemView.findViewById(R.id.text_title); text_daizhifu = itemView.findViewById(R.id.text_daizhifu); text_price = itemView.findViewById(R.id.text_price); text_tame = itemView.findViewById(R.id.text_tame); text_btn = itemView.findViewById(R.id.text_btn); } }
//Model层
//ChuangJianModel
package com.example.dell.shopping1.Model; import com.example.dell.shopping1.Model.Bean.ChuangjianBean; import com.example.dell.shopping1.pree.inter.CPresenter; import com.example.dell.shopping1.utils.OkHttp3Util; import com.google.gson.Gson; import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * author:Created by WangZhiQiang on 2018/1/15. */ public class ChuangJianModel { private CPresenter cPresenter; public ChuangJianModel(CPresenter cPresenter) { this.cPresenter = cPresenter; } public void getChuang(String chuang, String s){ //Log.d("++++++++++++120",s); Map<String, String> params = new HashMap<>(); params.put("uid","72"); params.put("price",chuang); OkHttp3Util.doPost(s, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ String json = response.body().string(); //解析 ChuangjianBean jianBean = new Gson().fromJson(json,ChuangjianBean.class); //接口回调...presenter层 cPresenter.COnsueeccss(jianBean); } } }); } }
//MainModel1
package com.example.dell.shopping1.Model; import com.example.dell.shopping1.Model.Bean.CartBean; import com.example.dell.shopping1.pree.inter.Ip.IMainPresenter1; import com.example.dell.shopping1.utils.OkHttp3Util; import com.google.gson.Gson; import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * author:Created by WangZhiQiang on 2018/1/15. */ public class MainModel1 { private IMainPresenter1 iMainPresenter; public MainModel1(IMainPresenter1 iMainPresenter) { this.iMainPresenter = iMainPresenter; } //在这里真正获取购物车的数据 public void getCartData(String selectCartUrl) { Map<String, String> params = new HashMap<>(); params.put("uid","72"); params.put("source","android"); OkHttp3Util.doPost(selectCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ String json = response.body().string(); if ("null".equals(json)){ iMainPresenter.onSuccess(null); }else { //解析 CartBean cartBean = new Gson().fromJson(json,CartBean.class); //接口回调...presenter层 iMainPresenter.onSuccess(cartBean); } } } }); } }
//Model
package com.example.dell.shopping1.Model; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; import com.example.dell.shopping1.pree.inter.Presenter; import com.example.dell.shopping1.utils.OkHttp3Util; import com.google.gson.Gson; import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by admin on 2018/1/13. */ public class Model { private Presenter presenter; public Model(Presenter presenter) { this.presenter = presenter; } public void getDingUrl(String dingdan, int page) { Map<String, String> params=new HashMap<>(); params.put("uid","72"); params.put("page",page+""); OkHttp3Util.doPost(dingdan, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ String json = response.body().string(); MyDingDanBean myDingDanBean = new Gson().fromJson(json, MyDingDanBean.class); presenter.getDingDanBean(myDingDanBean); } } }); }
}
//Pree
//CPresenter
package com.example.dell.shopping1.pree.inter; import com.example.dell.shopping1.Model.Bean.ChuangjianBean; import com.example.dell.shopping1.Model.ChuangJianModel; import com.example.dell.shopping1.pree.inter.Ip.ICPresenter; import com.example.dell.shopping1.view.Iview.CView; /** * author:Created by WangZhiQiang on 2018/1/15. */ public class CPresenter implements ICPresenter { CView cView; ChuangJianModel chuangJianModel; public CPresenter(CView cView) { chuangJianModel=new ChuangJianModel(this); this.cView = cView; } @Override public void COnsueeccss(ChuangjianBean chuangjianBean) { cView.COnsueeccss(chuangjianBean); } public void getChuang(String s, String chuangjian) { chuangJianModel.getChuang(chuangjian,s); } }// MainPresenter1
package com.example.dell.shopping1.pree.inter; import com.example.dell.shopping1.Model.Bean.CartBean; import com.example.dell.shopping1.Model.MainModel1; import com.example.dell.shopping1.pree.inter.Ip.IMainPresenter1; import com.example.dell.shopping1.view.Iview.IMainActivity1; /** * Created by Dash on 2018/1/3. */ public class MainPresenter1 implements IMainPresenter1 { private MainModel1 mainModel; private IMainActivity1 iMainActivity; public MainPresenter1(IMainActivity1 iMainActivity) { this.iMainActivity = iMainActivity; //创建model mainModel = new MainModel1(this); } //当前中间者不去直接获取网络数据,,,需要让model获取,,,创建presenter的时候就去创建出model,,,构造方法中 public void getCartData(String selectCartUrl) { //需要让model获取, mainModel.getCartData(selectCartUrl); } @Override public void onSuccess(CartBean cartBean) { //回调给view层...activity iMainActivity.onCartSuccess(cartBean); } }
//Presenter
package com.example.dell.shopping1.pree.inter; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; import com.example.dell.shopping1.Model.Model; import com.example.dell.shopping1.pree.inter.Ip.PresenterPort; import com.example.dell.shopping1.view.Iview.Main; /** * Created by admin on 2018/1/13. */ public class Presenter implements PresenterPort { private Main main; private final Model model; public Presenter(Main main) { model = new Model(this); this.main = main; } @Override public void getDingDanBean(MyDingDanBean myDingDanBean) { main.getDingDanBean(myDingDanBean); } public void getDingUrl(String dingdan, int page) { model.getDingUrl(dingdan,page); } }
//p层接口
//ICPresenter
package com.example.dell.shopping1.pree.inter.Ip; import com.example.dell.shopping1.Model.Bean.ChuangjianBean; /** * author:Created by WangZhiQiang on 2018/1/15. */ public interface ICPresenter { void COnsueeccss(ChuangjianBean chuangjianBean); }
//IMainPresenter1
package com.example.dell.shopping1.pree.inter.Ip; import com.example.dell.shopping1.Model.Bean.CartBean; /** * Created by Dash on 2018/1/3. */ public interface IMainPresenter1 { void onSuccess(CartBean cartBean); }
//PresenterPort
package com.example.dell.shopping1.pree.inter.Ip; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; /** * Created by admin on 2018/1/13. */ public interface PresenterPort { void getDingDanBean(MyDingDanBean myDingDanBean); }
//Utils
//ApiUtil
package com.example.dell.shopping1.utils; /** * Created by Dash on 2018/1/3. * * ApiUtil里面放的是所有的访问路径.....公有静态 */ public class ApiUtil { //查询购物车的路径 https://www.zhaoapi.cn/product/getCarts?uid=71&source=android public static String selectCartUrl = "https://www.zhaoapi.cn/product/getCarts"; //删除购物车...https://www.zhaoapi.cn/product/deleteCart?uid=72&pid=1 public static String deleteCartUrl ="https://www.zhaoapi.cn/product/deleteCart"; //更新购物车....?uid=71&sellerid=1&pid=1&selected=0&num=10 public static String updateCartUrl = "https://www.zhaoapi.cn/product/updateCarts"; //商品详情..... //uid 用户id字段 String类型 必传 //status 订单状态 String类型 非必传(筛选订单列表时,必传) public static String dingdan="https://www.zhaoapi.cn/product/getOrders"; //uid 用户id字段 String类型 必传 //orderId 订单id参数 String类型 必传 //status 订单状态 String类型 必传 public static String genxin="https://www.zhaoapi.cn/product/updateOrder"; public static String chuangjian="https://www.zhaoapi.cn/product/createOrder"; }
//OkHttp3Util
package com.example.dell.shopping1.utils; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Environment; import android.util.Log; import android.widget.Toast; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.Cache; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; /** * Created by Dash on 2017/12/8. */ public class OkHttp3Util { /** * 懒汉 安全 加同步 * 1.私有的静态成员变量 只声明不创建 * 2.私有的构造方法 * 3.提供返回实例的静态方法 */ private static OkHttpClient okHttpClient = null; private OkHttp3Util() { } public static OkHttpClient getInstance() { if (okHttpClient == null) { //加同步安全 synchronized (OkHttp3Util.class) { if (okHttpClient == null) { //okhttp可以缓存数据....指定缓存路径 File sdcache = new File(Environment.getExternalStorageDirectory(), "cache"); //指定缓存大小 int cacheSize = 10 * 1024 * 1024; okHttpClient = new OkHttpClient.Builder()//构建器 .connectTimeout(15, TimeUnit.SECONDS)//连接超时 .writeTimeout(20, TimeUnit.SECONDS)//写入超时 .readTimeout(20, TimeUnit.SECONDS)//读取超时 .cache(new Cache(sdcache.getAbsoluteFile(), cacheSize))//设置缓存 .build(); } } } return okHttpClient; } /** * get请求 * 参数1 url * 参数2 回调Callback */ public static void doGet(String oldUrl, Callback callback) { //创建OkHttpClient请求对象 OkHttpClient okHttpClient = getInstance(); //创建Request Request request = new Request.Builder().url(oldUrl).build(); //得到Call对象 Call call = okHttpClient.newCall(request); //执行异步请求 call.enqueue(callback); } /** * post请求 * 参数1 url * 参数2 Map<String, String> params post请求的时候给服务器传的数据 * add..("","") * add() */ public static void doPost(String url, Map<String, String> params, Callback callback) { //创建OkHttpClient请求对象 OkHttpClient okHttpClient = getInstance(); //3.x版本post请求换成FormBody 封装键值对参数 FormBody.Builder builder = new FormBody.Builder(); //遍历集合,,,map集合遍历方式 for (String key : params.keySet()) { builder.add(key, params.get(key)); } //创建Request....formBody...new formBody.Builder()...add()....build() Request request = new Request.Builder().url(url).post(builder.build()).build(); Call call = okHttpClient.newCall(request); call.enqueue(callback); } /** * post请求上传文件....包括图片....流的形式传任意文件... * 参数1 url * file表示上传的文件 * fileName....文件的名字,,例如aaa.jpg * params ....传递除了file文件 其他的参数放到map集合 * */ public static void uploadFile(String url, File file, String fileName,Map<String,String> params,Callback callback) { //创建OkHttpClient请求对象 OkHttpClient okHttpClient = getInstance(); //MultipartBody多功能的请求实体对象,,,formBody只能传表单形式的数据 MultipartBody.Builder builder = new MultipartBody.Builder(); builder.setType(MultipartBody.FORM); //参数 if (params != null){ for (String key : params.keySet()){ builder.addFormDataPart(key,params.get(key)); } } //文件...参数name指的是请求路径中所接受的参数...如果路径接收参数键值是fileeeee,此处应该改变 builder.addFormDataPart("file",fileName,RequestBody.create(MediaType.parse("application/octet-stream"),file)); //构建 MultipartBody multipartBody = builder.build(); //创建Request Request request = new Request.Builder().url(url).post(multipartBody).build(); //得到Call Call call = okHttpClient.newCall(request); //执行请求 call.enqueue(callback); } /** * Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} * 参数一:请求Url * 参数二:请求的JSON * 参数三:请求回调 */ public static void doPostJson(String url, String jsonParams, Callback callback) { RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonParams); Request request = new Request.Builder().url(url).post(requestBody).build(); Call call = getInstance().newCall(request); call.enqueue(callback); } /** * 下载文件 以流的形式把apk写入的指定文件 得到file后进行安装 * 参数er:请求Url * 参数san:保存文件的文件夹....download */ public static void download(final Activity context, final String url, final String saveDir) { Request request = new Request.Builder().url(url).build(); Call call = getInstance().newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { //com.orhanobut.logger.Logger.e(e.getLocalizedMessage()); } @Override public void onResponse(Call call, final Response response) throws IOException { InputStream is = null; byte[] buf = new byte[2048]; int len = 0; FileOutputStream fos = null; try { is = response.body().byteStream();//以字节流的形式拿回响应实体内容 //apk保存路径 final String fileDir = isExistDir(saveDir); //文件 File file = new File(fileDir, getNameFromUrl(url)); fos = new FileOutputStream(file); while ((len = is.read(buf)) != -1) { fos.write(buf, 0, len); } fos.flush(); context.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, "下载成功:" + fileDir + "," + getNameFromUrl(url), Toast.LENGTH_SHORT).show(); } }); //apk下载完成后 调用系统的安装方法 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); context.startActivity(intent); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) is.close(); if (fos != null) fos.close(); } } }); } /** * 判断下载目录是否存在......并返回绝对路径 * * @param saveDir * @return * @throws IOException */ public static String isExistDir(String saveDir) throws IOException { // 下载位置 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File downloadFile = new File(Environment.getExternalStorageDirectory(), saveDir); if (!downloadFile.mkdirs()) { downloadFile.createNewFile(); } String savePath = downloadFile.getAbsolutePath(); Log.e("savePath", savePath); return savePath; } return null; } /** * @param url * @return 从下载连接中解析出文件名 */ private static String getNameFromUrl(String url) { return url.substring(url.lastIndexOf("/") + 1); } }
View层
//Dingfdangyemi
package com.example.dell.shopping1.view; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.PopupWindow; import android.widget.TextView; import com.example.dell.shopping1.R; import com.example.dell.shopping1.fragment.Frag_Daizhi; import com.example.dell.shopping1.fragment.Frag_YiQu; import com.example.dell.shopping1.fragment.Frag_YiZhi; public class Dingfdangyemian extends AppCompatActivity implements View.OnClickListener{ private ImageView image_btn; private TextView text_daizhi; private TextView text_yizhi; private TextView text_yiqu; private FrameLayout frame_layout; private View item_popup; private View view; private PopupWindow popupWindow; private TextView btn_daizhi; private TextView btn_yizhi; private TextView btn_yiqu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dingfdangyemian); image_btn = (ImageView) findViewById(R.id.image_btn); text_daizhi = (TextView) findViewById(R.id.text_daizhi); text_yizhi = (TextView) findViewById(R.id.text_yizhi); text_yiqu = (TextView) findViewById(R.id.text_yiqu); frame_layout = (FrameLayout) findViewById(R.id.frame_layout); //https://www.zhaoapi.cn/product/updateOrder?uid=4427&status=1 //https://www.zhaoapi.cn/product/updateOrder?uid=4427&orderId= //https://www.zhaoapi.cn/product/getOrders?uid=4427&status2 text_daizhi.setOnClickListener(this); text_yizhi.setOnClickListener(this); text_yiqu.setOnClickListener(this); Frag_Daizhi frag_daizhi = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi).commit(); item_popup = View.inflate(this, R.layout.item_popup, null); view = View.inflate(this, R.layout.activity_main, null); popupWindow = new PopupWindow(item_popup , ActionBar.LayoutParams.WRAP_CONTENT,ActionBar.LayoutParams.WRAP_CONTENT); popupWindow.setTouchable(true); btn_daizhi = item_popup.findViewById(R.id.btn_daizhi); btn_yizhi = item_popup.findViewById(R.id.btn_yizhi); btn_yiqu = item_popup.findViewById(R.id.btn_yiqu); btn_daizhi.setOnClickListener(this); btn_yizhi.setOnClickListener(this); btn_yiqu.setOnClickListener(this); image_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //popupWindow.showAtLocation(view, Gravity.BOTTOM,0,0); popupWindow.showAsDropDown(image_btn); } }); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.text_daizhi: Frag_Daizhi frag_daizhi = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi).commit(); break; case R.id.text_yizhi: Frag_YiZhi frag_yiZhi = new Frag_YiZhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiZhi).commit(); break; case R.id.text_yiqu: Frag_YiQu frag_yiQu = new Frag_YiQu(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiQu).commit(); break; case R.id.btn_daizhi: Frag_Daizhi frag_daizhi2 = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi2).commit(); popupWindow.dismiss(); break; case R.id.btn_yizhi: Frag_YiZhi frag_yiZhi2 = new Frag_YiZhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiZhi2).commit(); popupWindow.dismiss(); break; case R.id.btn_yiqu: Frag_YiQu frag_yiQu2 = new Frag_YiQu(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiQu2).commit(); popupWindow.dismiss(); break; } } }
//MainActivity
package com.example.dell.shopping1.view; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.example.dell.shopping1.Model.Bean.CartBean; import com.example.dell.shopping1.Model.Bean.ChuangjianBean; import com.example.dell.shopping1.Model.Bean.CountPriceBean; import com.example.dell.shopping1.R; import com.example.dell.shopping1.adapter.ShoppingAdapter; import com.example.dell.shopping1.pree.inter.CPresenter; import com.example.dell.shopping1.pree.inter.MainPresenter1; import com.example.dell.shopping1.utils.ApiUtil; import com.example.dell.shopping1.view.Iview.CView; import com.example.dell.shopping1.view.Iview.IMainActivity1; import java.text.DecimalFormat; import java.util.List; public class MainActivity extends AppCompatActivity implements IMainActivity1,CView, View.OnClickListener{ private MyExpanableListView expanableListView; private MainPresenter1 mainPresenter; private CheckBox check_all; private TextView text_total; private TextView text_buy; private RelativeLayout relative_progress; private ShoppingAdapter myAdapter; private CPresenter cPresenter; private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what == 0){ countPriceBean = (CountPriceBean) msg.obj; //设置价格和数量 text_total.setText("合计:¥"+ countPriceBean.getPriceString()); text_buy.setText("去结算("+ countPriceBean.getCount()+")"); } } }; private CountPriceBean countPriceBean; private String code; private String msg; private CartBean cartBean; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); expanableListView = (MyExpanableListView) findViewById(R.id.expanable_list_view); check_all = (CheckBox) findViewById(R.id.check_all); text_total = (TextView) findViewById(R.id.text_total); text_buy = (TextView) findViewById(R.id.text_buy); relative_progress = (RelativeLayout) findViewById(R.id.relative_progress); //去掉默认的指示器 expanableListView.setGroupIndicator(null); //获取数据....MVP mainPresenter = new MainPresenter1(this); //全选的点击事件 check_all.setOnClickListener(this); cPresenter=new CPresenter(this); text_buy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (countPriceBean.getCount()==0) { Toast.makeText(MainActivity.this,"请选择",Toast.LENGTH_SHORT).show(); }else { double price = 0; int count = 0; for (int i = 0;i<cartBean.getData().size();i++){ List<CartBean.DataBean.ListBean> list = cartBean.getData().get(i).getList(); for (int j = 0; j< list.size(); j++){ if (list.get(j).getSelected() == 1){ price += list.get(j).getBargainPrice() * list.get(j).getNum(); count += list.get(j).getNum(); } } } //double高精度,,,计算的时候可能会出现一串数字...保留两位 DecimalFormat decimalFormat = new DecimalFormat("0.00"); String priceString = decimalFormat.format(price); //Log.d("+++++++++myqian",priceString); cPresenter.getChuang(ApiUtil.chuangjian,priceString); } } }); } @Override protected void onResume() { super.onResume(); relative_progress.setVisibility(View.VISIBLE); //调用获取数据的方法 mainPresenter.getCartData(ApiUtil.selectCartUrl); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.check_all: //根据全选的状态更新所有商品的状态...check_all.isChecked() true...1;;;;false---0 myAdapter.setAllChildsChecked(check_all.isChecked()); break; } } @Override public void onCartSuccess(final CartBean cartBean) { this.cartBean = cartBean; runOnUiThread(new Runnable() { @Override public void run() { //获取数据成功...隐藏 relative_progress.setVisibility(View.GONE); if (cartBean != null){ //cartBean再设置奢配器之前需不需要改变数据 //1.在bean类中添加商家是否选中的字段....默认值的false,初始值是根据该组下面所有孩子的状态进行改变的 for (int i = 0;i<cartBean.getData().size();i++){ //当前组中所有孩子的数据 List<CartBean.DataBean.ListBean> listBeans = cartBean.getData().get(i).getList(); //设置组的初始选中状态,,,,根据所有孩子的状态 cartBean.getData().get(i).setGroupChecked(isAllChildInGroupChecked(listBeans)); } //2.根据所有商家选中的状态,改变全选的状态 check_all.setChecked(isAllGroupChecked(cartBean)); //设置适配器 myAdapter = new ShoppingAdapter(MainActivity.this, cartBean,handler,relative_progress,mainPresenter); expanableListView.setAdapter(myAdapter); //展开所有的组...expanableListView.expandGroup() for (int i = 0;i<cartBean.getData().size();i++){ expanableListView.expandGroup(i); } //3.计算总价和商品的数量 myAdapter.sendPriceAndCount(); }else { Toast.makeText(MainActivity.this,"购物车空,请添加购物车",Toast.LENGTH_SHORT).show(); } } }); } private boolean isAllGroupChecked(CartBean cartBean) { for (int i=0;i<cartBean.getData().size();i++){ //只要有一个组未选中 返回false if (! cartBean.getData().get(i).isGroupChecked()){ return false; } } return true; } private boolean isAllChildInGroupChecked(List<CartBean.DataBean.ListBean> listBeans) { for (int i=0;i<listBeans.size();i++){ if (listBeans.get(i).getSelected() == 0){ return false; } } return true; } @Override public void COnsueeccss(final ChuangjianBean chuangjianBean) { runOnUiThread(new Runnable() { @Override public void run() { code = chuangjianBean.getCode(); msg = chuangjianBean.getMsg(); if (code.equals("0")) { Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, Dingfdangyemian.class); startActivity(intent); }else { Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show(); } } }); } }
//MyExpanableListView
package com.example.dell.shopping1.view; import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * Created by Dash on 2018/1/3. */ public class MyExpanableListView extends ExpandableListView { public MyExpanableListView(Context context) { super(context); } public MyExpanableListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyExpanableListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //高度 int height = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, height); } }
//View层接口
//CView
package com.example.dell.shopping1.view.Iview; import com.example.dell.shopping1.Model.Bean.ChuangjianBean; /** * author:Created by WangZhiQiang on 2018/1/15. */ public interface CView { void COnsueeccss(ChuangjianBean chuangjianBean); }//IMainActivity1
package com.example.dell.shopping1.view.Iview; import com.example.dell.shopping1.Model.Bean.CartBean; /** * Created by Dash on 2018/1/3. */ public interface IMainActivity1 { void onCartSuccess(CartBean cartBean); }
//Main
package com.example.dell.shopping1.view.Iview; import com.example.dell.shopping1.Model.Bean.MyDingDanBean; /** * Created by admin on 2018/1/13. */ public interface Main { void getDingDanBean(MyDingDanBean myDingDanBean); }
//activity_dingfdangyemian.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.dell.shopping1.view.Dingfdangyemian"> <RelativeLayout android:background="#fff" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="20sp" android:text="订单列表"/> <ImageView android:id="@+id/image_btn" android:layout_width="25dp" android:layout_height="25dp" android:clickable="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="20dp" android:background="@drawable/lv_icon"/> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal"> <TextView android:id="@+id/text_daizhi" android:layout_width="0dp" android:layout_weight="1" android:gravity="center" android:layout_height="match_parent" android:textSize="16sp" android:background="@drawable/biankuang" android:text="待支付"/> <TextView android:id="@+id/text_yizhi" android:layout_width="0dp" android:layout_weight="1" android:gravity="center" android:layout_height="match_parent" android:textSize="16sp" android:background="@drawable/biankuang" android:text="已支付"/> <TextView android:id="@+id/text_yiqu" android:layout_width="0dp" android:layout_weight="1" android:gravity="center" android:layout_height="match_parent" android:textSize="16sp" android:background="@drawable/biankuang" android:text="已取消"/> </LinearLayout> <FrameLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout> </LinearLayout>//activity_main.xml<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"> <ScrollView android:layout_above="@+id/linear_bottom" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!--二级列表--> <com.example.dell.shopping1.view.MyExpanableListView android:id="@+id/expanable_list_view" android:layout_width="match_parent" android:layout_height="wrap_content"> </com.example.dell.shopping1.view.MyExpanableListView> <!--recyclerView展示为你推荐--> <TextView android:background="#00ff00" android:text="为你推荐" android:layout_marginTop="10dp" android:layout_gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="400dp" /> </LinearLayout> </ScrollView> <RelativeLayout android:id="@+id/relative_progress" android:visibility="gone" android:layout_above="@+id/linear_bottom" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> <LinearLayout android:orientation="horizontal" android:id="@+id/linear_bottom" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="50dp"> <CheckBox android:button="@null" android:background="@drawable/check_box_selector" android:layout_marginLeft="10dp" android:id="@+id/check_all" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/text_total" android:text="合计:¥0.00" android:layout_gravity="center_vertical" android:layout_marginLeft="10dp" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" /> <TextView android:id="@+id/text_buy" android:background="#ff0000" android:textColor="#ffffff" android:gravity="center" android:text="去结算(0)" android:layout_width="100dp" android:layout_height="match_parent" /> </LinearLayout> </RelativeLayout>//child_layout.xml<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp"> <CheckBox android:id="@+id/child_check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:background="@drawable/check_box_selector" android:button="@null" /> <ImageView android:id="@+id/child_image" android:layout_width="100dp" android:layout_height="100dp" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/child_check" /> <TextView android:id="@+id/child_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toLeftOf="@+id/text_delete" android:layout_toRightOf="@+id/child_image" android:maxLines="2" android:minLines="2" /> <TextView android:id="@+id/child_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/child_image" android:layout_marginLeft="5dp" android:layout_toRightOf="@+id/child_image" android:text="¥0.00" android:textColor="#ff0000" /> <LinearLayout android:id="@+id/linearLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/child_image" android:layout_toLeftOf="@+id/text_delete" android:orientation="horizontal"> <TextView android:id="@+id/text_jian" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bian_kuang" android:padding="5dp" android:text="-" /> <TextView android:id="@+id/text_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bian_kuang" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="5dp" android:text="1" /> <TextView android:id="@+id/text_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bian_kuang" android:padding="5dp" android:text="+" /> </LinearLayout> <TextView android:id="@+id/text_delete" android:layout_width="40dp" android:layout_height="wrap_content" android:layout_alignBottom="@+id/linearLayout" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:background="#ff0000" android:gravity="center" android:text="删除" android:textColor="#ffffff" /> </RelativeLayout>//frag_daizhi.xml<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/smart_refresh" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_daizhi" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </ScrollView> </com.scwang.smartrefresh.layout.SmartRefreshLayout> <RelativeLayout android:id="@+id/relative_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> </RelativeLayout>//frag_yiqu.xml<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout android:background="#ff0000" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.constraint.ConstraintLayout>//frag_yizhi.xml<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout android:background="#00ff00" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.constraint.ConstraintLayout>//group_layout.xml<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:padding="10dp" android:layout_width="match_parent" android:layout_height="match_parent"> <CheckBox android:button="@null" android:background="@drawable/check_box_selector" android:id="@+id/group_check" android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/group_text" android:layout_marginLeft="10dp" android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>//item_dingdan.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="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:orientation="horizontal"> <TextView android:id="@+id/text_title" android:layout_width="0dp" android:layout_weight="1" android:gravity="bottom" android:layout_height="match_parent" android:text="1111"/> <TextView android:id="@+id/text_daizhifu" android:layout_width="50dp" android:gravity="bottom" android:layout_height="match_parent" android:textColor="#ff0000" android:text="待支付"/> </LinearLayout> <TextView android:id="@+id/text_price" android:gravity="bottom" android:textColor="#ff0000" android:layout_marginLeft="20dp" android:layout_width="match_parent" android:layout_height="40dp" android:text="1111"/> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:orientation="horizontal"> <TextView android:id="@+id/text_tame" android:layout_width="0dp" android:layout_weight="1" android:gravity="bottom" android:layout_height="match_parent" android:text="1111"/> <TextView android:id="@+id/text_btn" android:layout_width="70dp" android:gravity="center" android:layout_gravity="bottom" android:layout_height="30dp" android:background="@drawable/biankuang" android:text="取消订单"/> </LinearLayout> <TextView android:layout_marginTop="15dp" android:clickable="true" android:focusable="false" android:layout_width="match_parent" android:layout_height="1dp" android:background="#9999"/> </LinearLayout>//item_popup.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="100dp" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/btn_daizhi" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center" android:layout_height="0dp" android:textSize="16sp" android:padding="15dp" android:background="@drawable/select_dianji" android:text="待支付"/> <TextView android:id="@+id/btn_yizhi" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center" android:layout_height="0dp" android:textSize="16sp" android:padding="15dp" android:background="@drawable/select_dianji" android:text="已支付"/> <TextView android:id="@+id/btn_yiqu" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center" android:layout_height="0dp" android:textSize="16sp" android:padding="15dp" android:background="@drawable/select_dianji" android:text="已取消"/> </LinearLayout> </RelativeLayout>