整合

API:

APIservice:

package com.example.com.moni.inter;

import com.example.com.moni.bean.FeileiBean;
import com.example.com.moni.bean.LeftBean;
import com.example.com.moni.bean.Loginbean;
import com.example.com.moni.bean.MessageBean;
import com.example.com.moni.bean.RightBean;
import com.example.com.moni.bean.SeeBean;
import com.example.com.moni.bean.ShouyeBean;
import com.example.com.moni.bean.XiangBean;

import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;

/**
 * Created by 丶未央 on 2018/4/29.
 */

public interface ApiService {

    @GET("user/login")
    Observable<MessageBean<Loginbean>> getlogin(@Query("mobile")String mobile, @Query("password")String password);

    @GET("user/reg")
    Observable<MessageBean> getzc(@Query("mobile")String mobile, @Query("password")String password);

    @GET("ad/getAd")
    Observable<ShouyeBean> getfirst();
    @GET("product/getCatagory")
    Observable<FeileiBean<List<LeftBean>>> getLeftbean();

    @GET("product/getProductCatagory")
    Observable<FeileiBean<List<RightBean>>> getrightbean(@Query("cid") String cid);

    @GET("product/getProductDetail?source=android")
    Observable<XiangBean> getfeng(@Query("pid") String pid);

    //https://www.zhaoapi.cn/product/addCart?uid=71&pid=55
    @GET("product/addCart?source=android")
    Observable<MessageBean> getAddUrl(@Query("uid") String uid,@Query("pid") String pid);
    //https://www.zhaoapi.cn/product/getCarts?uid
    @GET("product/getCarts?source=android")
    Observable<SeeBean> getSeeUrl(@Query("uid") String uid);
}
 
 
ServiceURL类:

public class ServiceURL {
    public static final String BASE_URL="https://www.zhaoapi.cn/";
}

 HttpUtils
package com.example.com.moni.inter;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 丶未央 on 2018/4/29.
 */

public class HttpUtils {
    private static volatile HttpUtils instance;
    private final OkHttpClient client;
    private final HttpLoggingInterceptor interceptor;
    private  Retrofit retrofit;

    private HttpUtils(){
        //日志拦截器
        interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        client = new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .build();

        retrofit = new Retrofit.Builder()
                .baseUrl(ServiceURL.BASE_URL)
                .client(client)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public static HttpUtils getInstance(){

        if(instance==null){
            synchronized (HttpUtils.class){
                if(instance==null){
                    instance = new HttpUtils();
                }
            }
        }
        return instance ; }
        public ApiService getService(){

        return retrofit.create(ApiService.class);
        }
}

Bean类:

MessageBean

package com.example.com.moni.bean;

/**
 * Created by 丶未央 on 2018/4/29.
 */

public class MessageBean<T> {

    /**
     * code : 0
     * data : {"appkey":"c946bd788a382809","appsecret":"C738A026EEDD178A5A5F7946EB17C803","createtime":"2018-04-29T10:19:40","mobile":"17611525516","password":"8F669074CAF5513351A2DE5CC22AC04C","token":"ACA7FC85CBA7EFF22A0FD66F64CA98C2","uid":14179,"username":"17611525516"}
     * msg : 登录成功
     */

    private String code;
    private T data;
    private String msg;

    public String getCode() {
        return code;
    }

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

    public T getData() {
        return data;
    }

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

    public String getMsg() {
        return msg;
    }

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

    public static class DataBean {
    }
}



XiangBean:

package com.example.com.moni.bean;

/**
 * Created by 丶未央 on 2018/5/3.
 */

public class XiangBean {


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



SeeBean:

package com.example.com.moni.bean;

import java.util.List;

/**
 * Created by 丶未央 on 2018/5/3.
 */

public class SeeBean {

    /**
     * msg : 请求成功
     * code : 0
     * data : [{"list":[],"sellerName":"","sellerid":"0"},{"list":[{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":2,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":1999,"createtime":"2017-10-10T16:09:02","detailUrl":"https://item.m.jd.com/product/5025971.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t7210/232/3738666823/232298/9004583e/59c3a9a7N8de42e15.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8356/82/2107423621/109733/c019b8c6/59c3a9a6Ne9a4bdd7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t10219/74/25356012/171379/7d55e296/59c3a9a8N82fa6e02.jpg!q70.jpg","num":2,"pid":49,"price":333,"pscid":39,"selected":0,"sellerid":5,"subhead":"vivo X20 带你开启全面屏时代!逆光也清晰,照亮你的美!","title":"vivo X20 全面屏手机 全网通 4GB+64GB 金色 移动联通电信4G手机 双卡双待"}],"sellerName":"商家5","sellerid":"5"},{"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":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":55,"price":5999,"pscid":39,"selected":0,"sellerid":11,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家11","sellerid":"11"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":56,"price":99,"pscid":39,"selected":0,"sellerid":12,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家12","sellerid":"12"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":2,"pid":79,"price":888,"pscid":40,"selected":0,"sellerid":23,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家23","sellerid":"23"}]
     */

    private String msg;
    private String code;
    private List<DataBean> data;


    public String getMsg() {
        return msg;
    }

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

    public String getCode() {
        return code;
    }

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

    public List<DataBean> getData() {
        return data;
    }

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

    public static class DataBean {
        /**
         * list : []
         * sellerName :
         * sellerid : 0
         */

        private String sellerName;
        private String sellerid;
        private List<ItemBean> list;

        public boolean isIscheck() {
            return ischeck;
        }

        public void setIscheck(boolean ischeck) {
            this.ischeck = ischeck;
        }

        private boolean ischeck;


        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<ItemBean> getList() {
            return list;
        }

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

        public class ItemBean {

            /**
             * bargainPrice : 11800.0
             * createtime : 2017-10-03T23:53:28
             * detailUrl : https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1
             * images : https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg
             * num : 2
             * pid : 79
             * price : 888.0
             * pscid : 40
             * selected : 0
             * sellerid : 23
             * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)
             * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G
             */

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

            public boolean isIsscheck() {
                return isscheck;
            }

            public void setIsscheck(boolean isscheck) {
                this.isscheck = isscheck;
            }

            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;
            }
        }
    }
}
 
 
Fragmentone 
package com.example.com.moni.fragment;

import android.content.Intent;
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.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.com.moni.R;
import com.example.com.moni.abapter.ShoufirstAbapter;
import com.example.com.moni.abapter.ShousecondAbapter;
import com.example.com.moni.abapter.tupianAbapter;
import com.example.com.moni.bean.ShouyeBean;
import com.example.com.moni.inter.IView;
import com.example.com.moni.inter.OnitemClickListent;
import com.example.com.moni.presenter.ShoufirstPresenter;
import com.example.com.moni.view.Main4Activity;

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

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 丶未央 on 2018/5/1.
 */

public class Fragmentone extends Fragment implements IView<ShouyeBean>{

    @BindView(R.id.scan)
    LinearLayout scan;
    @BindView(R.id.search)
    TextView search;
    @BindView(R.id.linearLayout)
    LinearLayout linearLayout;
    @BindView(R.id.news)
    LinearLayout news;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.imageone)
    ImageView imageone;
    @BindView(R.id.rlvone)
    RecyclerView rlvone;
    @BindView(R.id.rlvtwo)
    RecyclerView rlvtwo;
    Unbinder unbinder;


    List list;
    private Handler handerone=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            viewpager.setCurrentItem(msg.what);
            ye++;
            handerone.sendEmptyMessageDelayed(ye,2000);
        }
    };
    private int ye;
    private ShoufirstPresenter shoufirstPresenter;
    private List<ShouyeBean.TuijianBean.ListBeanX> list1;
    private ShousecondAbapter shousecondAbapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.one, container, false);
        unbinder = ButterKnife.bind(this, view);
        //图片轮播
        list = new ArrayList<>();

        list.add("https://image.yunifang.com/yunifang/images/goods/ad0/170823222049920659891841095.jpg");
        list.add("https://image.yunifang.com/yunifang/images/goods/ad0/170905143499118006873413769.jpg");
        list.add("https://image.yunifang.com/yunifang/images/goods/ad0/170905143497021095281713081.jpg");
        tupianAbapter tupianAbapter = new tupianAbapter(getActivity(), list);
        viewpager.setCurrentItem(10000);
        viewpager.setAdapter(tupianAbapter);
        ye = viewpager.getCurrentItem();

        handerone.sendEmptyMessageDelayed(ye,2000);

        shoufirstPresenter = new ShoufirstPresenter(this);
        shoufirstPresenter.getData();


        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void OnSuccess(ShouyeBean shouyeBean) {

        List<ShouyeBean.MiaoshaBean.ListBean> data = shouyeBean.getMiaosha().getList();
        list1 = shouyeBean.getTuijian().getList();


        rlvone.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.HORIZONTAL));

        ShoufirstAbapter shoufirstAbapter = new ShoufirstAbapter(getActivity(), data);
        rlvone.setAdapter(shoufirstAbapter);


        rlvtwo.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

        shousecondAbapter = new ShousecondAbapter(getActivity(), list1);

        rlvtwo.setAdapter(shousecondAbapter);

        shousecondAbapter.setListener(new OnitemClickListent() {
            @Override
            public void onItemClick(int position) {

                int pid = list1.get(position).getPid();
                Intent intent = new Intent(getActivity(), Main4Activity.class);
                intent.putExtra("pid",pid);
                startActivity(intent);
            }
        });

    }


}

 
 
Main4Activity 
package com.example.com.moni.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.com.moni.R;
import com.example.com.moni.bean.MessageBean;
import com.example.com.moni.bean.XiangBean;
import com.example.com.moni.inter.IView;
import com.example.com.moni.inter.SView;
import com.example.com.moni.presenter.AddPresenter;
import com.example.com.moni.presenter.XiangPresenter;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Main4Activity extends AppCompatActivity implements IView<XiangBean>, SView {

    @BindView(R.id.goods_img)
    SimpleDraweeView goodsImg;
    @BindView(R.id.goods_title)
    TextView goodsTitle;
    @BindView(R.id.goods_prices)
    TextView goodsPrices;
    @BindView(R.id.goods_name)
    TextView goodsName;
    @BindView(R.id.add_btn)
    Button addBtn;
    private int pid;
    private int uid;
    private AddPresenter addPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        ButterKnife.bind(this);
        addPresenter = new AddPresenter(this);

        Intent intent = getIntent();
        pid = intent.getIntExtra("pid", 0);
        SharedPreferences addShop = getSharedPreferences("addShop", MODE_PRIVATE);
        uid = addShop.getInt("uid", 0);
        XiangPresenter xpresenter = new XiangPresenter(this);
        xpresenter.getData("" + pid);
    }

    @Override
    public void OnSuccess(XiangBean xiangBean) {
        XiangBean.DataBean data = xiangBean.getData();
        Log.i("--", "OnSuccess: " + xiangBean.getCode());

        String[] split = data.getImages().split("\\|");


        //给控件赋值
        goodsImg.setImageURI(split[0]);
        goodsName.setText(data.getSubhead());
        goodsPrices.setText("¥" + data.getPrice());
        goodsTitle.setText(data.getTitle());
    }


    @Override
    public void onSuccess(MessageBean messageBean) {
        Toast.makeText(Main4Activity.this,messageBean.getMsg(),Toast.LENGTH_SHORT).show();
    }

    @OnClick(R.id.add_btn)
    public void onViewClicked() {
        addPresenter.getData(uid+"",pid+"");
    }
}布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"

    tools:context="com.example.com.moni.view.Main4Activity">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/goods_img"
            android:scaleType="centerCrop"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            fresco:placeholderImage="@mipmap/ic_launcher" />

        <LinearLayout
            android:orientation="vertical"
            android:padding="20dp"

            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/goods_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="按时打算打算大撒打算打算打算的" />

            <TextView
                android:id="@+id/goods_prices"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="$199999" />

            <TextView
                android:id="@+id/goods_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="我是商家" />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="50dp">
        <Button
            android:id="@+id/add_btn"
            android:text="加入购物车"
            android:background="#f00"
            android:textColor="#fff"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
        <Button
            android:text="立即购买"
            android:background="#efaf0d"
            android:layout_weight="1"
            android:textColor="#fff"

            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
    </LinearLayout>
</RelativeLayout>

package com.example.com.moni.fragment;

import android.content.Context;
import android.content.SharedPreferences;
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 android.widget.Button;
import android.widget.CheckBox;

import android.widget.ExpandableListView;
import android.widget.TextView;


import com.example.com.moni.R;
import com.example.com.moni.abapter.SeeExpandableListAdapter;

import com.example.com.moni.bean.SeeBean;
import com.example.com.moni.inter.IView;
import com.example.com.moni.presenter.SeePresenter;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 丶未央 on 2018/5/1.
 */

public class Fragmentfour extends Fragment implements IView<SeeBean>,SeeExpandableListAdapter.ChangeData {
    @BindView(R.id.elv)
    ExpandableListView elv;
    @BindView(R.id.checkbox2)
    CheckBox checkbox2;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_num)
    TextView tvNum;
    Unbinder unbinder;
    private SeePresenter seePresenter;
    private int uid;

    private List<SeeBean.DataBean> listAll = new ArrayList<>();
    private SeeExpandableListAdapter adapter;
    private List<SeeBean.DataBean> data;
    private List<SeeBean.DataBean.ItemBean> list;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.four, container, false);
        unbinder = ButterKnife.bind(this, view);

        SharedPreferences addShop = getActivity().getSharedPreferences("addShop", Context.MODE_PRIVATE);
        uid = addShop.getInt("uid", 0);
        seePresenter = new SeePresenter(this);
        seePresenter.getData(uid + "");




        checkbox2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(checkbox2.isChecked()){
                    for (int i = 0; i < data.size(); i++) {
                        SeeBean.DataBean dataBean = data.get(i);
                        dataBean.setIscheck(true);
                        for (int j = 0; j < dataBean.getList().size(); j++) {
                            SeeBean.DataBean.ItemBean itemBean = dataBean.getList().get(j);
                            itemBean.setIsscheck(true);
                        }
                    }
                }else {
                    for (int i = 0; i < data.size(); i++) {
                        SeeBean.DataBean dataBean = data.get(i);
                        dataBean.setIscheck(false);
                        for (int j = 0; j < dataBean.getList().size(); j++) {
                            SeeBean.DataBean.ItemBean itemBean = dataBean.getList().get(j);
                            itemBean.setIsscheck(false);
                        }
                    }
                }
                getMoney();
            }
        });
        return view;

    }

    @Override
    public void OnSuccess(SeeBean seeBean) {
        data = seeBean.getData();

        listAll.clear();
        listAll.addAll(data);
        adapter = new SeeExpandableListAdapter(getActivity(),listAll);
        elv.setAdapter(adapter);
        adapter.setShoping(Fragmentfour.this);
        for (int i = 0; i < data.size(); i++) {
            elv.expandGroup(i);
        }

    }

    @Override
    public void onHiddenChanged(boolean hidden) {

        getData();

        super.onHiddenChanged(hidden);
    }

    private void getData() {

        seePresenter.getData(uid+"");

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void getMoney() {
        DecimalFormat df   = new DecimalFormat("######0.00");

        double zon = 0;
        int num = 0;
        for (int i = 0; i < listAll.size(); i++) {
            list = listAll.get(i).getList();
            for (int j = 0; j < list.size() ; j++) {
                if(list.get(j).isIsscheck()){
                    zon += list.get(j).getNum() * list.get(j).getPrice();
                    num += list.get(j).getNum();
                }

            }
        }
        tvPrice.setText("总价:" + df.format(zon));
        tvNum.setText("结算("+num+")");
        adapter.notifyDataSetChanged();
    }

    @Override
    public void jiaNum(int i, int position) {

        List<SeeBean.DataBean.ItemBean> listone = data.get(i).getList();
        int num = listone.get(position).getNum();
        num++;
        listone.get(position).setNum(num);

        getMoney();
    }

    @Override
    public void jianNum(int i, int position, Button but) {
        List<SeeBean.DataBean.ItemBean> listone = data.get(i).getList();
        int num = listone.get(position).getNum();
        num--;
        listone.get(position).setNum(num);

        getMoney();
    }

    @Override
    public void click(int i,int i1,boolean checked) {

        data.get(i).getList().get(i1).setIsscheck(checked);

        getMoney();
    }

    @Override
    public void groupclick(int i, boolean ischeck) {
        data.get(i).setIscheck(ischeck);

        List<SeeBean.DataBean.ItemBean> list = data.get(i).getList();

        for (int j = 0; j < list.size(); j++) {
            if(data.get(i).isIscheck()){
                list.get(j).setIsscheck(true);
            }else{
                list.get(j).setIsscheck(false);
            }
        }

        getMoney();
    }

    @Override
    public void removeMoney() {
        getMoney();
    }








}



适配器:


package com.example.com.moni.abapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.moni.R;
import com.example.com.moni.bean.SeeBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * Created by 丶未央 on 2018/5/3.
 */

public class SeeExpandableListAdapter extends BaseExpandableListAdapter{
    Context context;
    List<SeeBean.DataBean> data;
    List<SeeBean.DataBean.ItemBean> list;
    public SeeExpandableListAdapter(Context context, List<SeeBean.DataBean> data) {
        this.context=context;
        this.data=data;
    }

    ChangeData changeData;

    public void setShoping(ChangeData changeData){
        this.changeData = changeData;
    }

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

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

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

    @Override
    public Object getChild(int i, int i1) {
        return data.get(i).getList().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 GroupViewHolder holder;
        if (view == null) {
            holder = new GroupViewHolder();
            view = view.inflate(context, R.layout.shouitemone, null);
            holder.ck = view.findViewById(R.id.cb_parent);
            holder.name = view.findViewById(R.id.tv_number);
            view.setTag(holder);
        } else {
            holder = (GroupViewHolder) view.getTag();
        }
        final SeeBean.DataBean dataBean = data.get(i);
        holder.ck.setChecked(dataBean.isIscheck());
//        holder.tv_number.setText(dataBean.getTitle());
        holder.name.setText(dataBean.getSellerName());

        //一级checkbox
        holder.ck.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                changeData.groupclick(i,holder.ck.isChecked());
            }
        });

        return view;
    }

    @Override
    public View getChildView(final int i, final int i1, final boolean b, View view, ViewGroup viewGroup) {
        final ChildViewHolder holder;
        if (view == null) {
            holder = new ChildViewHolder();
            view = view.inflate(context,R.layout.shouitemtwo, null);
            holder.cck = view.findViewById(R.id.cb_child);
            holder.name = view.findViewById(R.id.tv_tel);
            holder.num =view.findViewById(R.id.et_number);
            holder.img = (SimpleDraweeView) view.findViewById(R.id.my_image_view);
            holder.price = view.findViewById(R.id.tv_pri);
            holder.rem = view.findViewById(R.id.tv_del);
            holder.add = view.findViewById(R.id.but_add);
            holder.delete = view.findViewById(R.id.but_delete);
            view.setTag(holder);
        } else {
            holder = (ChildViewHolder) view.getTag();
        }
        final SeeBean.DataBean.ItemBean datasBean = data.get(i).getList().get(i1);

        holder.cck.setChecked(datasBean.isIsscheck());
        holder.name.setText(datasBean.getTitle());

        holder.price.setText("¥"+datasBean.getPrice() );

        if(datasBean.getNum() == 1){
            holder.delete.setEnabled(false);
        } else{
            holder.delete.setEnabled(true);
        }
        holder.num.setText(datasBean.getNum()+"");

        String images = datasBean.getImages().trim();
        String[] split = images.split("[\\|]");
        holder.img.setImageURI(Uri.parse(split[0]));

        //删除
        holder.rem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        list.get(i).setIsscheck(false);
                        changeData.removeMoney();
                        list.remove(i);

                        notifyDataSetChanged();
                    }
                });
                builder.setTitle("警告");
                builder.setMessage("确定删除嘛?");
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

            }
        });

        //加
        holder.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeData.jiaNum(i,i1);
            }
        });
        //减
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeData.jianNum(i,i1,holder.delete);
            }
        });

        //二级checkbox
       holder.cck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //设置该条目对象里的checked属性值
                changeData.click(i,i1,holder.cck.isChecked());
            }
        });


        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
    class GroupViewHolder{
        CheckBox ck;
        TextView name;
    }
    class ChildViewHolder{
        CheckBox cck;
        ImageView img;
        TextView name,price,num,rem;
        Button add,delete;
    }
    public interface ChangeData{
        void jiaNum(int i, int i1);
        void jianNum(int i, int i1, Button but);
        void click(int i,int i1,boolean ischeck);
        void groupclick(int i,boolean ischeck);
        void removeMoney();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值