动画加商品详情加商品购物车

初始动画布局


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">


    <ImageView
        android:id="@+id/img_animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>

LinearLayout>

对应的动画代码

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.Toast;

public class SplashActivity extends AppCompatActivity {

    private ImageView img_animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        img_animation= (ImageView) findViewById(R.id.img_animation);
        ObjectAnimator moveIn = ObjectAnimator.ofFloat(img_animation, "translationY", 0f, 500f);
        ObjectAnimator rotate = ObjectAnimator.ofFloat(img_animation, "rotation", 0f, 360f);
        ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(img_animation, "alpha", 1f, 0f);
        ObjectAnimator scale=ObjectAnimator.ofFloat(img_animation,"scaleY",2f,1f);
        AnimatorSet animSet = new AnimatorSet();
        animSet.play(rotate).with(fadeInOut).with(moveIn).with(scale);
        animSet.setDuration(3000);

        animSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);

                Toast.makeText(SplashActivity.this,"动画播放结束",Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(SplashActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
        animSet.start();
    }
}

商品详情的布局


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_shop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="商品详情"
        android:textSize="20dp"
        android:gravity="center_horizontal"/>
    <ImageView
        android:layout_below="@id/tv_shop"
        android:id="@+id/img_shop"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:src="@mipmap/ic_launcher"/>
    <TextView
        android:layout_below="@id/img_shop"
        android:layout_marginTop="20dp"
        android:id="@+id/tv_shop_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" 纯子见过手机 前后双蛇 照亮你的美"/>
    <TextView
        android:layout_below="@id/tv_shop_title"
        android:layout_marginTop="20dp"
        android:id="@+id/tv_shop_old"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="原价:9999"/>
    <TextView
        android:layout_below="@id/tv_shop_old"
        android:layout_marginTop="20dp"
        android:id="@+id/tv_shop_new"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="优惠价:999"
        android:textColor="#F53908"/>
    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">
        <Button
            android:id="@+id/btn_shop1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="购物车"/>
        <Button
            android:id="@+id/btn_shop2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="加入购物车"/>
    LinearLayout>
RelativeLayout>

商品详情代码

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.ningkesong1510c1220monthmoni.bean.Addbean;
import com.bwie.ningkesong1510c1220monthmoni.bean.ShopBean;
import com.bwie.ningkesong1510c1220monthmoni.presenter.Addpresenter;
import com.bwie.ningkesong1510c1220monthmoni.presenter.IAddpresenter;
import com.bwie.ningkesong1510c1220monthmoni.presenter.IShoppresenter;
import com.bwie.ningkesong1510c1220monthmoni.presenter.Shoppresenter;
import com.bwie.ningkesong1510c1220monthmoni.utils.ImageloaderUtil;
import com.bwie.ningkesong1510c1220monthmoni.view.IAddview;
import com.bwie.ningkesong1510c1220monthmoni.view.IShopview;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class MainActivity extends AppCompatActivity implements IShopview,IAddview{

    private ImageView img_shop;
    private TextView tv_shop_title;
    private TextView tv_shop_old;
    private TextView tv_shop_new;
    private Button btn_shop1;
    private Button btn_shop2;
    private IShoppresenter iShoppresenter;
     int uid=1;
     int pid=100;
    private IAddpresenter iAddpresenter;
    private Addbean addbean;

    private List.DataBean> dataBeen;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        iShoppresenter=new Shoppresenter(MainActivity.this);
        iShoppresenter.getmData();
        iAddpresenter=new Addpresenter(MainActivity.this,uid,pid);
        iAddpresenter.getmData();
        btn_shop1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentcar=new Intent(MainActivity.this,CarActivity.class);
                startActivity(intentcar);
            }
        });

    }
    public void init(){// 查找控件的方法
        img_shop= (ImageView) findViewById(R.id.img_shop);
        tv_shop_title= (TextView) findViewById(R.id.tv_shop_title);
        tv_shop_old= (TextView) findViewById(R.id.tv_shop_old);
        tv_shop_new= (TextView) findViewById(R.id.tv_shop_new);
        btn_shop1= (Button) findViewById(R.id.btn_shop1);
        btn_shop2= (Button) findViewById(R.id.btn_shop2);
    }

    @Override
    public void getData(List.DataBean> dataBeen) {
        this.dataBeen=dataBeen;
        String[] split = dataBeen.get(0).getImages().split("\\|");
        ImageLoader.getInstance().displayImage(split[0],img_shop,ImageloaderUtil.getImageOptions());
        tv_shop_title.setText(dataBeen.get(0).getTitle());
        tv_shop_old.setText("原价:"+dataBeen.get(0).getPrice());
        tv_shop_old.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG);
        tv_shop_new.setText("优惠价:"+dataBeen.get(0).getBargainPrice());
        //pid=dataBeen.get(0).getPid();

    }

    @Override
    public void getData(final Addbean addbean) {
        this.addbean=addbean;
        // 添加购物车的点击事件
        btn_shop2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,addbean.getMsg()+"",Toast.LENGTH_LONG).show();
            }
        });
    }
}

购物车的三个布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ExpandableListView
        android:id="@+id/ealv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >ExpandableListView>

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/lin"
        android:background="#fff"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CheckBox
            android:id="@+id/quanxuan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:textStyle="bold"
            android:layout_marginLeft="10dp"
            android:textSize="23sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="全选"
            />

        <LinearLayout
            android:padding="10dp"
            android:layout_marginLeft="10dp"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content">

            <TextView
                android:textColor="#e53e42"
                android:id="@+id/total_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:text="总价 : ¥0元"
                />

            <TextView
                android:id="@+id/total_num"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:text="共0件商品"
                />

        LinearLayout>

        <TextView
            android:id="@+id/qujiesuan"
            android:gravity="center"
            android:textSize="25sp"
            android:text="去结算"
            android:textColor="#fff"
            android:background="@drawable/qujiesuan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    LinearLayout>

RelativeLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">



    <CheckBox
        android:id="@+id/shop_checkbox"
        android:layout_width="50dp"
        android:layout_height="50dp" />

    <TextView
        android:layout_marginLeft="20dp"
        android:text="良品铺子"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="23sp"
        android:textStyle="bold"
        android:id="@+id/shop_name"
        />

LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:padding="15dp"
    android:layout_height="match_parent">



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

        <CheckBox
            android:id="@+id/item_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageView
            android:id="@+id/item_face"
            android:src="@mipmap/ic_launcher"
            android:layout_width="120dp"
            android:layout_height="120dp" />

        <LinearLayout
            android:layout_marginLeft="10dp"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/text_name"
                android:textSize="20sp"
                android:text="三只松鼠"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_height="0dp"
                />

            <TextView
                android:textColor="#f00"
                android:id="@+id/item_price"
                android:textSize="23sp"
                android:text="299"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/btn_jia"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:text="+"
                    android:textSize="20dp"/>
                <EditText
                    android:id="@+id/edit_car"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1"/>
                <Button
                    android:id="@+id/btn_jian"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:text="-"
                    android:textSize="20dp"/>
            LinearLayout>

        LinearLayout>

        <ImageView
            android:id="@+id/item_delete"
            android:src="@drawable/delect"
            android:layout_marginRight="10dp"
            android:layout_width="30dp"
            android:layout_height="30dp" />
    LinearLayout>
LinearLayout>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="200dp"/>
    <solid android:color="#e53e42"/>
    <size android:height="60dp" android:width="130dp"/>
shape>

购物车代码

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.bwie.ningkesong1510c1220monthmoni.adapter.MyAdapter;
import com.bwie.ningkesong1510c1220monthmoni.bean.CarPriceAndCount;
import com.bwie.ningkesong1510c1220monthmoni.bean.Carbean;
import com.bwie.ningkesong1510c1220monthmoni.presenter.Carpresenter;
import com.bwie.ningkesong1510c1220monthmoni.presenter.ICarpresenter;
import com.bwie.ningkesong1510c1220monthmoni.view.ICarview;

import java.util.ArrayList;
import java.util.List;

public class CarActivity extends AppCompatActivity implements ICarview{

    private ExpandableListView ealv;
    private static CheckBox quanxuan;
    private static TextView total_price;
    private static TextView total_num;
    private TextView qujiesuan;
    private MyAdapter adapter;
    private ICarpresenter iCarpresenter;
    private static String price="";
    private List> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car);
        init();
        iCarpresenter=new Carpresenter(this);
        iCarpresenter.getmData();

        quanxuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                adapter.allOrNot(quanxuan.isChecked());
            }
        });
        qujiesuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(CarActivity.this,QueRenActivity.class);
                intent.putExtra("price",price);
                startActivity(intent);
            }
        });

    }
    public void init(){
        ealv= (ExpandableListView) findViewById(R.id.ealv);
        quanxuan= (CheckBox) findViewById(R.id.quanxuan);
        total_price= (TextView) findViewById(R.id.total_price);
        total_num= (TextView) findViewById(R.id.total_num);
        qujiesuan= (TextView) findViewById(R.id.qujiesuan);
    }

    @Override
    public void getData(List dataBeen) {
        for (int i = 0; i new MyAdapter(CarActivity.this,dataBeen,list);
        ealv.setAdapter(adapter);
        ealv.setGroupIndicator(null);
        // 展开
        for (int i=0;ipublic static void selectAllOrNot(boolean bool){
        quanxuan.setChecked(bool);
    }
    /**
     * 设置价格和数量
     */
    public static void setPriceAndCount(CarPriceAndCount priceandcount){
        price=priceandcount.getPrice()+"";
        total_num.setText("去结算("+priceandcount.getCount()+")");
        total_price.setText("合计:"+priceandcount.getPrice());
    }

}

二级列表的适配器>

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.ningkesong1510c1220monthmoni.CarActivity;
import com.bwie.ningkesong1510c1220monthmoni.R;
import com.bwie.ningkesong1510c1220monthmoni.bean.CarPriceAndCount;
import com.bwie.ningkesong1510c1220monthmoni.bean.Carbean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by songsong on 2017/12/20.
 */

public class MyAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List data;
    private List> list;

    public MyAdapter(Context context, List data, List> list) {
        this.context = context;
        this.data = data;
        this.list = list;
    }

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

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

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

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

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

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

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

    @Override
    public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
        final Carbean.DataBean dataBean = data.get(i);
        final ViewHolder holder;
        if(view==null){
            view=view.inflate(context,R.layout.car_group,null);
            holder=new ViewHolder();
            holder.shop_checkbox= (CheckBox) view.findViewById(R.id.shop_checkbox);
            holder.shop_name= (TextView) view.findViewById(R.id.shop_name);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.shop_checkbox.setChecked(dataBean.isCheck());
        holder.shop_name.setText(dataBean.getSellerName());
        holder.shop_checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dataBean.setCheck(holder.shop_checkbox.isChecked());
                checkfangfa(i,holder.shop_checkbox.isChecked());
                CarActivity.selectAllOrNot(isAllGgroupCbChecked());

                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
        final Carbean.DataBean.ListBean listBean = list.get(i).get(i1);
        final ViewHOlder2 holder2;
        if(view==null){
            view=view.inflate(context,R.layout.car_child,null);
            holder2=new ViewHOlder2();
            holder2.item_checkbox= (CheckBox) view.findViewById(R.id.item_checkbox);
            holder2.item_face= (ImageView) view.findViewById(R.id.item_face);
            holder2.text_name= (TextView) view.findViewById(R.id.text_name);
            holder2.item_price= (TextView) view.findViewById(R.id.item_price);
            holder2.btn_jia= (Button) view.findViewById(R.id.btn_jia);
            holder2.btn_jian= (Button) view.findViewById(R.id.btn_jian);
            holder2.edit_car= (EditText) view.findViewById(R.id.edit_car);
            holder2.item_delete= (ImageView) view.findViewById(R.id.item_delete);
            view.setTag(holder2);
        }else{
            holder2= (ViewHOlder2) view.getTag();
        }
        String[] split = listBean.getImages().split("\\|");
        ImageLoader.getInstance().displayImage(split[0],holder2.item_face);
        holder2.text_name.setText(listBean.getTitle());
        holder2.item_price.setText("¥"+listBean.getPrice()+"");
        holder2.edit_car.setText(listBean.getNum()+"");
        holder2.item_checkbox.setChecked(list.get(i).get(i1).isChecked());
        CarActivity.selectAllOrNot(isAllGgroupCbChecked());
        holder2.item_checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listBean.setChecked(holder2.item_checkbox.isChecked());
                data.get(i).setCheck(isAllChildCbChecked(i));
                notifyDataSetChanged();
            }
        });
        //增加一个商品
        holder2.btn_jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count=listBean.getNum();
                count++;
                listBean.setNum(count);
                setPriceAndCount();
                notifyDataSetChanged();
            }
        });
        //减少一件商品
        holder2.btn_jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count=listBean.getNum();
                if(count<=1){
                    count=1;
                }else{
                    count--;
                }
                listBean.setNum(count);
                setPriceAndCount();
                notifyDataSetChanged();
            }
        });
        //删除
        holder2.item_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List listbeen = list.get(i);
                if(listbeen.size()>0){
                    listbeen.remove(i1);
                }
                if(listbeen.size()==0){
                    list.remove(i);
                    data.remove(i);
                }
                setPriceAndCount();
                CarActivity.selectAllOrNot(isAllGgroupCbChecked());
                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
    class ViewHolder{
        CheckBox shop_checkbox;
        TextView shop_name;
    }
    class ViewHOlder2{
        CheckBox item_checkbox;
        ImageView item_face;
        TextView text_name;
        TextView item_price;
        Button btn_jia;
        Button btn_jian;
        EditText edit_car;
        ImageView item_delete;
    }
    // 根据一级列表的状态去设置二级列表的状态
    private void checkfangfa(int groupPosition,boolean bool){
        List listBeen = list.get(groupPosition);

        for (int i = 0; i // 判断二级列表的状态
    private boolean isAllChildCbChecked(int groupPosition) {
        List listBeen = list.get(groupPosition);
        for (int i = 0; i < listBeen.size(); i++) {
            if (!listBeen.get(i).isChecked()) {
                return false;
            }
        }
        return true;
    }
    // 判断一级列表的状态
    public boolean isAllGgroupCbChecked(){
        if(data.size()<0){
            return false;
        }
        for (int i = 0; i if(!data.get(i).isCheck()){
                return false;
            }
        }
        return true;
    }
    // 进行全选全不选
    public void allOrNot(boolean bool){
        for (int i = 0; i < data.size(); i++) {
            data.get(i).setCheck(bool);
            checkfangfa(i,bool);
            setPriceAndCount();
        }
        notifyDataSetChanged();
    }
    /**
     * 设置钱和数量
     */
    private void setPriceAndCount(){
        CarActivity.setPriceAndCount(compute());
    }
    // 设置钱和数量
    private CarPriceAndCount compute(){
        double price = 0;
        int count = 0;
        for (int i = 0; i < data.size(); i++) {
             List listBeans = list.get(i);
            for (int j = 0; j if(listBeans.get(j).isChecked()){
                    price+=listBeans.get(j).getPrice()*listBeans.get(j).getNum();
                    count+=listBeans.get(j).getNum();
                }
            }
        }
        return new CarPriceAndCount(price,count);
    }
}

确认订单的布局


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <TextView
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="确认订单"
        android:textSize="30dp"
        android:background="#3F48CC"/>

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text_money"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:text="实付款:1234.4"
            android:textColor="#F53908"/>
        <TextView
            android:id="@+id/text_xiadan"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="下订单"
            android:background="#F53908"/>
    LinearLayout>
RelativeLayout>

确认订单的代码

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class QueRenActivity extends AppCompatActivity {

    private TextView text_money;
    private TextView text_xiadan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_que_ren);
        text_money= (TextView) findViewById(R.id.text_money);
        text_xiadan= (TextView) findViewById(R.id.text_xiadan);
        Intent intent = getIntent();
        String price = intent.getStringExtra("price");
        text_money.setText(price);
    }
}

引用块内容
商品详情的bean

public class ShopBean {

    /**
     * msg :
     * seller : {"description":"我是商家17","icon":"http://120.27.23.105/images/icon.png","name":"商家17","productNums":999,"score":5,"sellerid":17}
     * code : 0
     * data : {"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","itemtype":1,"pid":1,"price":118,"pscid":1,"salenum":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}
     */

    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 : 我是商家17
         * icon : http://120.27.23.105/images/icon.png
         * name : 商家17
         * productNums : 999
         * score : 5.0
         * sellerid : 17
         */

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

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

购物车的bean

import java.util.List;

/**
 * Created by songsong on 2017/12/20.
 */

public class Carbean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"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":10,"price":555.55,"pscid":1,"selected":0,"sellerid":3,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":50,"price":444,"pscid":39,"selected":0,"sellerid":6,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家6","sellerid":"6"},{"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":100,"price":2200,"pscid":112,"selected":0,"sellerid":11,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"}],"sellerName":"商家11","sellerid":"11"},{"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":21,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"}]
     */

    private String msg;
    private String code;
    private List 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 getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

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

        private boolean isCheck;

        public boolean isCheck() {
            return isCheck;
        }

        public void setCheck(boolean check) {
            isCheck = check;
        }

        private String sellerName;
        private String sellerid;
        private List list;

        public String getSellerName() {
            return sellerName;
        }

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

        public String getSellerid() {
            return sellerid;
        }

        public void setSellerid(String sellerid) {
            this.sellerid = sellerid;
        }

        public List getList() {
            return list;
        }

        public void setList(List list) {
            this.list = list;
        }



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

            private boolean isChecked;

            public boolean isChecked() {
                return isChecked;
            }

            public void setChecked(boolean checked) {
                isChecked = checked;
            }

            private double bargainPrice;
            private String createtime;
            private String detailUrl;
            private String images;
            private int num;
            private int pid;
            private double price;
            private int pscid;
            private int selected;
            private int sellerid;
            private String subhead;
            private String title;

            public double getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(double bargainPrice) {
                this.bargainPrice = bargainPrice;
            }

            public String getCreatetime() {
                return createtime;
            }

            public void setCreatetime(String createtime) {
                this.createtime = createtime;
            }

            public String getDetailUrl() {
                return detailUrl;
            }

            public void setDetailUrl(String detailUrl) {
                this.detailUrl = detailUrl;
            }

            public String getImages() {
                return images;
            }

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

            public int getNum() {
                return num;
            }

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

            public int getPid() {
                return pid;
            }

            public void setPid(int pid) {
                this.pid = pid;
            }

            public double getPrice() {
                return price;
            }

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

            public int getPscid() {
                return pscid;
            }

            public void setPscid(int pscid) {
                this.pscid = pscid;
            }

            public int getSelected() {
                return selected;
            }

            public void setSelected(int selected) {
                this.selected = selected;
            }

            public int getSellerid() {
                return sellerid;
            }

            public void setSellerid(int sellerid) {
                this.sellerid = sellerid;
            }

            public String getSubhead() {
                return subhead;
            }

            public void setSubhead(String subhead) {
                this.subhead = subhead;
            }

            public String getTitle() {
                return title;
            }

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

计算价钱还有数量的bean

public class CarPriceAndCount {
    private double price;
    private int count;

    public CarPriceAndCount(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;
    }
}

添加购物车的bean

public class Addbean {

    /**
     * msg : 加购成功
     * code : 0
     */

    private String msg;
    private String code;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}

那个okhttputi

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by songsong on 2017/12/20.
 */
public class CommonParamsinterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {

        //得到原始的请求对象
        Request request = chain.request();

        //得到请求方式
        String method = request.method();

        if ("GET".equals(method)) {
            //去除原始的URL
            String oldurl = request.url().toString();

            //拼接公共参数
            String newurl = oldurl + "&source=android";

            //构建新的request
            request = new Request.Builder()
                    .url(newurl)
                    .build();


        } else if ("POST".equals(method)) {
            //取出旧的参数和URL
            FormBody body = (FormBody) request.body();

            String oldUrl = request.url().toString();

            //构建新的FromBody
            FormBody.Builder newFormBody = new FormBody.Builder();

            for (int i = 0; i < body.size(); i++) {

                String key = body.name(i);//keywors
                String value = body.value(i);//value

                newFormBody.add(key, value);
            }
            //公共参数
            newFormBody.add("source", "android");

            //新构建的reqeust
            request = new Request.Builder()
                    .url(oldUrl)
                    .post(newFormBody.build())
                    .build();
        }
        return chain.proceed(request);
    }
}
import android.os.Handler;
import android.util.Log;

import java.io.IOException;
import java.util.Map;

import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
 * Created by songsong on 2017/12/20.
 */


public class OkHttpUtils {
    private static OkHttpUtils okHttpUtils = null;
    private static Handler handler = new Handler();

    private OkHttpUtils(){}
    /**
     * 获取当前这个类的实例
     * @return
     */
    public static OkHttpUtils getInstance(){
        if(null == okHttpUtils){
            synchronized (OkHttpUtils.class){
                if(null == okHttpUtils){
                    okHttpUtils = new OkHttpUtils();
                }
            }
        }
        return okHttpUtils;
    }
    /**
     * get请求
     * @param path
     * @param map
     */
    public void doGet(String path, Map map, final OnFinishListener onFinishListener){



        StringBuilder sb = null;

        for (String key : map.keySet()) {

            //login?name=124e3434&p=ere

            if(null == sb){
                sb = new StringBuilder();
                sb.append("?");
            }else{

                sb.append("&");

            }

            //拼接参数
            sb.append(key).append("=").append(map.get(key));
        }


        OkHttpClient okHttpClient = new OkHttpClient();
         //应用拦截器
        OkHttpClient okHttpClient1=new OkHttpClient.Builder()
            .addInterceptor(new CommonParamsinterceptor())
            .build();
        final Request request = new Request.Builder()
                .url(path+sb.toString())
                .get()
                .build();
        Log.d("gggg",path+sb.toString());

        okhttp3.Call call = okHttpClient1/*使用拦截器此处需要换上拦截器名*/.newCall(request);
        call.enqueue(new Callback() {

            public void onFailure(okhttp3.Call call, final IOException e) {

                //在子线程
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        onFinishListener.onFailed(e.getMessage());

                    }
                });
            }

            public void onResponse(okhttp3.Call call, final Response response) throws IOException {


                final String result = response.body().string();


                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        try {

                            onFinishListener.onSuccess(result);

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });

            }
        });

    }
}

OnFinishListener接口类

public interface OnFinishListener {
    void onSuccess(String result);
    void onFailed(String msg);
}

mvp M层

添加购物车的两个model


public interface IAddmodel {
    void getData(IAddpresenter iAddpresenter,int uid,int pid);
}

public class Addmodel implements IAddmodel {
    String path="http://120.27.23.105/product/addCart";
    Map map=new HashMap();

    @Override
    public void getData(final IAddpresenter iAddpresenter, int uid, int pid) {
        map.put("uid",uid+"");
        map.put("pid",pid+"");
        OkHttpUtils.getInstance().doGet(path, map, new OnFinishListener() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();
                Addbean addbean = gson.fromJson(result, Addbean.class);
                iAddpresenter.getData(addbean);
            }

            @Override
            public void onFailed(String msg) {

            }
        });
    }
}

查看购物车的两个model

public interface ICarmodel {
    void getData(ICarpresenter iCarpresenter);
}

public class Carmodel implements ICarmodel{

    String path="http://120.27.23.105/product/getCarts";
    Map map=new HashMap();
    @Override
    public void getData(final ICarpresenter iCarpresenter) {
        map.put("uid","100");
        OkHttpUtils.getInstance().doGet(path, map, new OnFinishListener() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();
                Carbean carbean = gson.fromJson(result, Carbean.class);
                List data = carbean.getData();
                iCarpresenter.getData(data);
            }

            @Override
            public void onFailed(String msg) {

            }
        });
    }
}

商品详情的model

public interface IShopmodel {
    void getData(IShoppresenter iShoppresenter);
}

public class Shopmodel implements IShopmodel {

    String path="http://120.27.23.105/product/getProductDetail";
    Map map=new HashMap();
    List list=new ArrayList<>();
    @Override
    public void getData(final IShoppresenter iShoppresenter) {
        map.put("pid","1");
        OkHttpUtils.getInstance().doGet(path, map, new OnFinishListener() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();
                ShopBean shopBean = gson.fromJson(result, ShopBean.class);
                ShopBean.DataBean data = shopBean.getData();
                list.add(data);
                iShoppresenter.getData(list);
            }

            @Override
            public void onFailed(String msg) {

            }
        });
    }
}

P层 添加购物车的presenter

public interface IAddpresenter {
    void getmData();
    void getData(Addbean addbean);
}

public class Addpresenter implements IAddpresenter {

    private IAddmodel iAddmodel;
    private IAddview iAddview;
    private int pid;
    private int uid;

    public Addpresenter(IAddview iAddview, int uid, int pid) {
        this.iAddview = iAddview;
        iAddmodel=new Addmodel();
    }

    @Override
    public void getmData() {
        iAddmodel.getData(this,uid,pid);
    }

    @Override
    public void getData(Addbean addbean) {
        iAddview.getData(addbean);
    }
}

查看购物车的presenter

public interface ICarpresenter {
    void getmData();
    void getData(List dataBeen);
}

public class Carpresenter implements ICarpresenter {
    private ICarview iCarview;
    private ICarmodel iCarmodel;

    public Carpresenter(ICarview iCarview) {
        this.iCarview = iCarview;
        iCarmodel=new Carmodel();
    }

    @Override
    public void getmData() {
        iCarmodel.getData(this);
    }

    @Override
    public void getData(List dataBeen) {
        iCarview.getData(dataBeen);
    }
}

商品详情的presenter

public interface IShoppresenter {
    void getmData();
    void getData(List dataBeen);
}

public class Shoppresenter implements IShoppresenter {

    private IShopview iShopview;
    private IShopmodel iShopmodel;

    public Shoppresenter(IShopview iShopview) {
        this.iShopview = iShopview;
        iShopmodel=new Shopmodel();
    }

    @Override
    public void getmData() {
        iShopmodel.getData(this);
    }

    @Override
    public void getData(List dataBeen) {

        iShopview.getData(dataBeen);
    }
}

V层 添加购物车的view
还有查看购物车的view,商品详情的view

public interface IAddview {
      void getData(Addbean addbean);
}
public interface ICarview {
    void getData(List dataBeen);
}
public interface IShopview {
    void getData(List dataBeen);
}

你可能感兴趣的:(动画加商品详情加商品购物车)