两个RecyclerView分别实现轮播图+京东秒杀

原创 2018年04月17日 21:10:45

项目框架:MVP

图片加载用Fresco

网络请求用OKhttp+Retrofit实现,完成首页数据请求

首页只用一个Recycleview实现轮播图和秒杀活动中的布局和数据展示(Recycleview 多条目实现),完成秒杀活动,

让同时跳转到一个空Activity 中;

访问网络接口获取数据,将数据展示在列表上,使用Fresco展示图片将图片显示成圆形。接口如下

 http://result.eolinker.com/umIPmfS6c83237d9c70c7c9510c9b0f97171a308d13b611?uri=homepage

   1.权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
2.依赖:

compile 'com.squareup.okhttp3:okhttp:3.10.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.facebook.fresco:fresco:0.12.0'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.github.bumptech.glide:glide:3.7.0'
  3.主布局页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.dell.zhoukao20180416.view.MainActivity">

    <!--轮播图的RecyclerView布局-->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/img_rcv"
        android:layout_width="match_parent"
        android:layout_height="300px">
    </android.support.v7.widget.RecyclerView>

    <!--倒计时布局-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="京东秒杀"
            android:textSize="28px"
            android:textColor="#FF0000"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/tv_item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30px"
            android:text="秒杀剩余时间5s"
            />
    </LinearLayout>

    <!--秒杀的RecyclerView布局-->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_rcv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ></android.support.v7.widget.RecyclerView>

</LinearLayout>
4.M层接口

package com.example.dell.zhoukao20180416.model;

import com.example.dell.zhoukao20180416.presenter.DataPresenter;

public interface DataModel {
    //请求数据的方法
  void  getData(String url, DataPresenter presenter);
}
5.M层接收实现类

package com.example.dell.zhoukao20180416.model;

import com.example.dell.zhoukao20180416.presenter.DataPresenter;
import com.example.dell.zhoukao20180416.utils.OkhtttpUtils;
import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class MyDataModel implements DataModel{
    //请求数据的方法
    @Override
    public void getData(String url, final DataPresenter presenter) {

        OkhtttpUtils.doGet(url, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {}

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //接收返回的数据
                String json = response.body().string();

                //进行解析 得到集合
                Gson gson = new Gson();
                MyDataBean myDataBean = gson.fromJson(json, MyDataBean.class);
                MyDataBean.DataBean data = myDataBean.getData();

                //调用P层方法将数据传给P                presenter.Success(data);
            }
        });
    }
}
6.网络请求的数据Bean

package com.example.dell.zhoukao20180416.model;

import java.util.List;

public class MyDataBean {

    private int code;
    private String msg;
    private DataBean data;

    public int getCode() {
        return code;
    }

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

    public String getMsg() {
        return msg;
    }

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

    public DataBean getData() {
        return data;
    }

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

    public static class DataBean {

        private ActivityInfoBean activityInfo;
        private boolean creditRecived;
        private GoodsSpreeActivityBean goodsSpreeActivity;
        private List<SubjectsBean> subjects;
        private List<Ad1Bean> ad1;
        private List<Ad5Bean> ad5;
        private List<Ad8Bean> ad8;
        private List<DefaultGoodsListBean> defaultGoodsList;

        public ActivityInfoBean getActivityInfo() {
            return activityInfo;
        }

        public void setActivityInfo(ActivityInfoBean activityInfo) {
            this.activityInfo = activityInfo;
        }

        public boolean isCreditRecived() {
            return creditRecived;
        }

        public void setCreditRecived(boolean creditRecived) {
            this.creditRecived = creditRecived;
        }

        public GoodsSpreeActivityBean getGoodsSpreeActivity() {
            return goodsSpreeActivity;
        }

        public void setGoodsSpreeActivity(GoodsSpreeActivityBean goodsSpreeActivity) {
            this.goodsSpreeActivity = goodsSpreeActivity;
        }

        public List<SubjectsBean> getSubjects() {
            return subjects;
        }

        public void setSubjects(List<SubjectsBean> subjects) {
            this.subjects = subjects;
        }

        public List<Ad1Bean> getAd1() {
            return ad1;
        }

        public void setAd1(List<Ad1Bean> ad1) {
            this.ad1 = ad1;
        }

        public List<Ad5Bean> getAd5() {
            return ad5;
        }

        public void setAd5(List<Ad5Bean> ad5) {
            this.ad5 = ad5;
        }

        public List<Ad8Bean> getAd8() {
            return ad8;
        }

        public void setAd8(List<Ad8Bean> ad8) {
            this.ad8 = ad8;
        }

        public List<DefaultGoodsListBean> getDefaultGoodsList() {
            return defaultGoodsList;
        }

        public void setDefaultGoodsList(List<DefaultGoodsListBean> defaultGoodsList) {
            this.defaultGoodsList = defaultGoodsList;
        }

        public static class ActivityInfoBean {

            private String activityAreaDisplay;
            private List<ActivityInfoListBean> activityInfoList;

            public String getActivityAreaDisplay() {
                return activityAreaDisplay;
            }

            public void setActivityAreaDisplay(String activityAreaDisplay) {
                this.activityAreaDisplay = activityAreaDisplay;
            }

            public List<ActivityInfoListBean> getActivityInfoList() {
                return activityInfoList;
            }

            public void setActivityInfoList(List<ActivityInfoListBean> activityInfoList) {
                this.activityInfoList = activityInfoList;
            }

            public static class ActivityInfoListBean {
            

                private String id;
                private String activityImg;
                private String activityType;
                private String activityData;
                private String activityDataDetail;
                private String activityAreaDisplay;
                private String countDownEnable;
                private String remark;
                private int sort;

                public String getId() {
                    return id;
                }

                public void setId(String id) {
                    this.id = id;
                }

                public String getActivityImg() {
                    return activityImg;
                }

                public void setActivityImg(String activityImg) {
                    this.activityImg = activityImg;
                }

                public String getActivityType() {
                    return activityType;
                }

                public void setActivityType(String activityType) {
                    this.activityType = activityType;
                }

                public String getActivityData() {
                    return activityData;
                }

                public void setActivityData(String activityData) {
                    this.activityData = activityData;
                }

                public String getActivityDataDetail() {
                    return activityDataDetail;
                }

                public void setActivityDataDetail(String activityDataDetail) {
                    this.activityDataDetail = activityDataDetail;
                }

                public String getActivityAreaDisplay() {
                    return activityAreaDisplay;
                }

                public void setActivityAreaDisplay(String activityAreaDisplay) {
                    this.activityAreaDisplay = activityAreaDisplay;
                }

                public String getCountDownEnable() {
                    return countDownEnable;
                }

                public void setCountDownEnable(String countDownEnable) {
                    this.countDownEnable = countDownEnable;
                }

                public String getRemark() {
                    return remark;
                }

                public void setRemark(String remark) {
                    this.remark = remark;
                }

                public int getSort() {
                    return sort;
                }

                public void setSort(int sort) {
                    this.sort = sort;
                }
            }
        }

        public static class GoodsSpreeActivityBean {

            private String id;
            private String name;
            private String startDate;
            private String endDate;
            private String status;
            private String startSeconds;
            private String endSeconds;
            private String isChecked;
            private List<GoodsListBean> goodsList;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getStartDate() {
                return startDate;
            }

            public void setStartDate(String startDate) {
                this.startDate = startDate;
            }

            public String getEndDate() {
                return endDate;
            }

            public void setEndDate(String endDate) {
                this.endDate = endDate;
            }

            public String getStatus() {
                return status;
            }

            public void setStatus(String status) {
                this.status = status;
            }

            public String getStartSeconds() {
                return startSeconds;
            }

            public void setStartSeconds(String startSeconds) {
                this.startSeconds = startSeconds;
            }

            public String getEndSeconds() {
                return endSeconds;
            }

            public void setEndSeconds(String endSeconds) {
                this.endSeconds = endSeconds;
            }

            public String getIsChecked() {
                return isChecked;
            }

            public void setIsChecked(String isChecked) {
                this.isChecked = isChecked;
            }

            public List<GoodsListBean> getGoodsList() {
                return goodsList;
            }

            public void setGoodsList(List<GoodsListBean> goodsList) {
                this.goodsList = goodsList;
            }

            public static class GoodsListBean {
                
                private String id;
                private String goodsSpreeId;
                private String goodsId;
                private String goodsName;
                private String goodsImg;
                private double marketPrice;
                private double activityPrice;
                private int salesRatio;
                private int stockNumber;
                private int releaseNumber;

                public String getId() {
                    return id;
                }

                public void setId(String id) {
                    this.id = id;
                }

                public String getGoodsSpreeId() {
                    return goodsSpreeId;
                }

                public void setGoodsSpreeId(String goodsSpreeId) {
                    this.goodsSpreeId = goodsSpreeId;
                }

                public String getGoodsId() {
                    return goodsId;
                }

                public void setGoodsId(String goodsId) {
                    this.goodsId = goodsId;
                }

                public String getGoodsName() {
                    return goodsName;
                }

                public void setGoodsName(String goodsName) {
                    this.goodsName = goodsName;
                }

                public String getGoodsImg() {
                    return goodsImg;
                }

                public void setGoodsImg(String goodsImg) {
                    this.goodsImg = goodsImg;
                }

                public double getMarketPrice() {
                    return marketPrice;
                }

                public void setMarketPrice(double marketPrice) {
                    this.marketPrice = marketPrice;
                }

                public double getActivityPrice() {
                    return activityPrice;
                }

                public void setActivityPrice(double activityPrice) {
                    this.activityPrice = activityPrice;
                }

                public int getSalesRatio() {
                    return salesRatio;
                }

                public void setSalesRatio(int salesRatio) {
                    this.salesRatio = salesRatio;
                }

                public int getStockNumber() {
                    return stockNumber;
                }

                public void setStockNumber(int stockNumber) {
                    this.stockNumber = stockNumber;
                }

                public int getReleaseNumber() {
                    return releaseNumber;
                }

                public void setReleaseNumber(int releaseNumber) {
                    this.releaseNumber = releaseNumber;
                }
            }
        }

        public static class SubjectsBean {

            private String id;
            private String title;
            private String detail;
            private String image;
            private String start_time;
            private String end_time;
            private int show_number;
            private String state;
            private int sort;
            private String descImage;
            private String template;
            private String url;
            private String wapUrl;
            private List<GoodsListBeanX> goodsList;
            private List<String> goodsIdsList;
            private List<GoodsRelationListBean> goodsRelationList;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getTitle() {
                return title;
            }

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

            public String getDetail() {
                return detail;
            }

            public void setDetail(String detail) {
                this.detail = detail;
            }

            public String getImage() {
                return image;
            }

            public void setImage(String image) {
                this.image = image;
            }

            public String getStart_time() {
                return start_time;
            }

            public void setStart_time(String start_time) {
                this.start_time = start_time;
            }

            public String getEnd_time() {
                return end_time;
            }

            public void setEnd_time(String end_time) {
                this.end_time = end_time;
            }

            public int getShow_number() {
                return show_number;
            }

            public void setShow_number(int show_number) {
                this.show_number = show_number;
            }

            public String getState() {
                return state;
            }

            public void setState(String state) {
                this.state = state;
            }

            public int getSort() {
                return sort;
            }

            public void setSort(int sort) {
                this.sort = sort;
            }

            public String getDescImage() {
                return descImage;
            }

            public void setDescImage(String descImage) {
                this.descImage = descImage;
            }

            public String getTemplate() {
                return template;
            }

            public void setTemplate(String template) {
                this.template = template;
            }

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }

            public String getWapUrl() {
                return wapUrl;
            }

            public void setWapUrl(String wapUrl) {
                this.wapUrl = wapUrl;
            }

            public List<GoodsListBeanX> getGoodsList() {
                return goodsList;
            }

            public void setGoodsList(List<GoodsListBeanX> goodsList) {
                this.goodsList = goodsList;
            }

            public List<String> getGoodsIdsList() {
                return goodsIdsList;
            }

            public void setGoodsIdsList(List<String> goodsIdsList) {
                this.goodsIdsList = goodsIdsList;
            }

            public List<GoodsRelationListBean> getGoodsRelationList() {
                return goodsRelationList;
            }

            public void setGoodsRelationList(List<GoodsRelationListBean> goodsRelationList) {
                this.goodsRelationList = goodsRelationList;
            }

            public static class GoodsListBeanX {
               
                private String id;
                private String goods_name;
                private double shop_price;
                private double market_price;
                private String goods_img;
                private boolean reservable;
                private String efficacy;
                private int stock_number;
                private int restrict_purchase_num;
                private String goodsName;
                private String goodsImage;
                private String description;

                public String getId() {
                    return id;
                }

                public void setId(String id) {
                    this.id = id;
                }

                public String getGoods_name() {
                    return goods_name;
                }

                public void setGoods_name(String goods_name) {
                    this.goods_name = goods_name;
                }

                public double getShop_price() {
                    return shop_price;
                }

                public void setShop_price(double shop_price) {
                    this.shop_price = shop_price;
                }

                public double getMarket_price() {
                    return market_price;
                }

                public void setMarket_price(double market_price) {
                    this.market_price = market_price;
                }

                public String getGoods_img() {
                    return goods_img;
                }

                public void setGoods_img(String goods_img) {
                    this.goods_img = goods_img;
                }

                public boolean isReservable() {
                    return reservable;
                }

                public void setReservable(boolean reservable) {
                    this.reservable = reservable;
                }

                public String getEfficacy() {
                    return efficacy;
                }

                public void setEfficacy(String efficacy) {
                    this.efficacy = efficacy;
                }

                public int getStock_number() {
                    return stock_number;
                }

                public void setStock_number(int stock_number) {
                    this.stock_number = stock_number;
                }

                public int getRestrict_purchase_num() {
                    return restrict_purchase_num;
                }

                public void setRestrict_purchase_num(int restrict_purchase_num) {
                    this.restrict_purchase_num = restrict_purchase_num;
                }

                public String getGoodsName() {
                    return goodsName;
                }

                public void setGoodsName(String goodsName) {
                    this.goodsName = goodsName;
                }

                public String getGoodsImage() {
                    return goodsImage;
                }

                public void setGoodsImage(String goodsImage) {
                    this.goodsImage = goodsImage;
                }

                public String getDescription() {
                    return description;
                }

                public void setDescription(String description) {
                    this.description = description;
                }
            }

            public static class GoodsRelationListBean {

                private String id;
                private String subject_id;
                private String goods_id;
                private String goodsName;
                private String goodsImage;
                private String description;

                public String getId() {
                    return id;
                }

                public void setId(String id) {
                    this.id = id;
                }

                public String getSubject_id() {
                    return subject_id;
                }

                public void setSubject_id(String subject_id) {
                    this.subject_id = subject_id;
                }

                public String getGoods_id() {
                    return goods_id;
                }

                public void setGoods_id(String goods_id) {
                    this.goods_id = goods_id;
                }

                public String getGoodsName() {
                    return goodsName;
                }

                public void setGoodsName(String goodsName) {
                    this.goodsName = goodsName;
                }

                public String getGoodsImage() {
                    return goodsImage;
                }

                public void setGoodsImage(String goodsImage) {
                    this.goodsImage = goodsImage;
                }

                public String getDescription() {
                    return description;
                }

                public void setDescription(String description) {
                    this.description = description;
                }
            }
        }

        public static class Ad1Bean {
           

            private String id;
            private String createtime;
            private String lastupdatetime;
            private String image;
            private int ad_type;
            private int sort;
            private int position;
            private int enabled;
            private String createuser;
            private String lastupdateuser;
            private String ad_type_dynamic;
            private String ad_type_dynamic_data;
            private String ad_type_dynamic_detail;
            private String title;
            private String channelType;
            private String show_channel;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getCreatetime() {
                return createtime;
            }

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

            public String getLastupdatetime() {
                return lastupdatetime;
            }

            public void setLastupdatetime(String lastupdatetime) {
                this.lastupdatetime = lastupdatetime;
            }

            public String getImage() {
                return image;
            }

            public void setImage(String image) {
                this.image = image;
            }

            public int getAd_type() {
                return ad_type;
            }

            public void setAd_type(int ad_type) {
                this.ad_type = ad_type;
            }

            public int getSort() {
                return sort;
            }

            public void setSort(int sort) {
                this.sort = sort;
            }

            public int getPosition() {
                return position;
            }

            public void setPosition(int position) {
                this.position = position;
            }

            public int getEnabled() {
                return enabled;
            }

            public void setEnabled(int enabled) {
                this.enabled = enabled;
            }

            public String getCreateuser() {
                return createuser;
            }

            public void setCreateuser(String createuser) {
                this.createuser = createuser;
            }

            public String getLastupdateuser() {
                return lastupdateuser;
            }

            public void setLastupdateuser(String lastupdateuser) {
                this.lastupdateuser = lastupdateuser;
            }

            public String getAd_type_dynamic() {
                return ad_type_dynamic;
            }

            public void setAd_type_dynamic(String ad_type_dynamic) {
                this.ad_type_dynamic = ad_type_dynamic;
            }

            public String getAd_type_dynamic_data() {
                return ad_type_dynamic_data;
            }

            public void setAd_type_dynamic_data(String ad_type_dynamic_data) {
                this.ad_type_dynamic_data = ad_type_dynamic_data;
            }

            public String getAd_type_dynamic_detail() {
                return ad_type_dynamic_detail;
            }

            public void setAd_type_dynamic_detail(String ad_type_dynamic_detail) {
                this.ad_type_dynamic_detail = ad_type_dynamic_detail;
            }

            public String getTitle() {
                return title;
            }

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

            public String getChannelType() {
                return channelType;
            }

            public void setChannelType(String channelType) {
                this.channelType = channelType;
            }

            public String getShow_channel() {
                return show_channel;
            }

            public void setShow_channel(String show_channel) {
                this.show_channel = show_channel;
            }
        }

        public static class Ad5Bean {
           
            private String id;
            private String image;
            private int ad_type;
            private int sort;
            private int position;
            private int enabled;
            private String ad_type_dynamic;
            private String ad_type_dynamic_data;
            private String ad_type_dynamic_detail;
            private String show_channel;
            private String title;
            private String url;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getImage() {
                return image;
            }

            public void setImage(String image) {
                this.image = image;
            }

            public int getAd_type() {
                return ad_type;
            }

            public void setAd_type(int ad_type) {
                this.ad_type = ad_type;
            }

            public int getSort() {
                return sort;
            }

            public void setSort(int sort) {
                this.sort = sort;
            }

            public int getPosition() {
                return position;
            }

            public void setPosition(int position) {
                this.position = position;
            }

            public int getEnabled() {
                return enabled;
            }

            public void setEnabled(int enabled) {
                this.enabled = enabled;
            }

            public String getAd_type_dynamic() {
                return ad_type_dynamic;
            }

            public void setAd_type_dynamic(String ad_type_dynamic) {
                this.ad_type_dynamic = ad_type_dynamic;
            }

            public String getAd_type_dynamic_data() {
                return ad_type_dynamic_data;
            }

            public void setAd_type_dynamic_data(String ad_type_dynamic_data) {
                this.ad_type_dynamic_data = ad_type_dynamic_data;
            }

            public String getAd_type_dynamic_detail() {
                return ad_type_dynamic_detail;
            }

            public void setAd_type_dynamic_detail(String ad_type_dynamic_detail) {
                this.ad_type_dynamic_detail = ad_type_dynamic_detail;
            }

            public String getShow_channel() {
                return show_channel;
            }

            public void setShow_channel(String show_channel) {
                this.show_channel = show_channel;
            }

            public String getTitle() {
                return title;
            }

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

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }
        }

        public static class Ad8Bean {
         
            private String id;
            private String image;
            private int ad_type;
            private int sort;
            private int position;
            private int enabled;
            private String description;
            private String ad_type_dynamic;
            private String ad_type_dynamic_data;
            private String ad_type_dynamic_detail;
            private String show_channel;
            private String title;
            private GoodsBean goods;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getImage() {
                return image;
            }

            public void setImage(String image) {
                this.image = image;
            }

            public int getAd_type() {
                return ad_type;
            }

            public void setAd_type(int ad_type) {
                this.ad_type = ad_type;
            }

            public int getSort() {
                return sort;
            }

            public void setSort(int sort) {
                this.sort = sort;
            }

            public int getPosition() {
                return position;
            }

            public void setPosition(int position) {
                this.position = position;
            }

            public int getEnabled() {
                return enabled;
            }

            public void setEnabled(int enabled) {
                this.enabled = enabled;
            }

            public String getDescription() {
                return description;
            }

            public void setDescription(String description) {
                this.description = description;
            }

            public String getAd_type_dynamic() {
                return ad_type_dynamic;
            }

            public void setAd_type_dynamic(String ad_type_dynamic) {
                this.ad_type_dynamic = ad_type_dynamic;
            }

            public String getAd_type_dynamic_data() {
                return ad_type_dynamic_data;
            }

            public void setAd_type_dynamic_data(String ad_type_dynamic_data) {
                this.ad_type_dynamic_data = ad_type_dynamic_data;
            }

            public String getAd_type_dynamic_detail() {
                return ad_type_dynamic_detail;
            }

            public void setAd_type_dynamic_detail(String ad_type_dynamic_detail) {
                this.ad_type_dynamic_detail = ad_type_dynamic_detail;
            }

            public String getShow_channel() {
                return show_channel;
            }

            public void setShow_channel(String show_channel) {
                this.show_channel = show_channel;
            }

            public String getTitle() {
                return title;
            }

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

            public GoodsBean getGoods() {
                return goods;
            }

            public void setGoods(GoodsBean goods) {
                this.goods = goods;
            }

            public static class GoodsBean {

                private int collect_count;
                private boolean reservable;
                private int restriction;
                private int restrict_purchase_num;
                private boolean is_coupon_allowed;
                private int allocated_stock;
                private int is_gift;

                public int getCollect_count() {
                    return collect_count;
                }

                public void setCollect_count(int collect_count) {
                    this.collect_count = collect_count;
                }

                public boolean isReservable() {
                    return reservable;
                }

                public void setReservable(boolean reservable) {
                    this.reservable = reservable;
                }

                public int getRestriction() {
                    return restriction;
                }

                public void setRestriction(int restriction) {
                    this.restriction = restriction;
                }

                public int getRestrict_purchase_num() {
                    return restrict_purchase_num;
                }

                public void setRestrict_purchase_num(int restrict_purchase_num) {
                    this.restrict_purchase_num = restrict_purchase_num;
                }

                public boolean isIs_coupon_allowed() {
                    return is_coupon_allowed;
                }

                public void setIs_coupon_allowed(boolean is_coupon_allowed) {
                    this.is_coupon_allowed = is_coupon_allowed;
                }

                public int getAllocated_stock() {
                    return allocated_stock;
                }

                public void setAllocated_stock(int allocated_stock) {
                    this.allocated_stock = allocated_stock;
                }

                public int getIs_gift() {
                    return is_gift;
                }

                public void setIs_gift(int is_gift) {
                    this.is_gift = is_gift;
                }
            }
        }

        public static class DefaultGoodsListBean {

            private String id;
            private String goods_name;
            private double shop_price;
            private double market_price;
            private String goods_img;
            private boolean reservable;
            private String efficacy;
            private int stock_number;
            private int restrict_purchase_num;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getGoods_name() {
                return goods_name;
            }

            public void setGoods_name(String goods_name) {
                this.goods_name = goods_name;
            }

            public double getShop_price() {
                return shop_price;
            }

            public void setShop_price(double shop_price) {
                this.shop_price = shop_price;
            }

            public double getMarket_price() {
                return market_price;
            }

            public void setMarket_price(double market_price) {
                this.market_price = market_price;
            }

            public String getGoods_img() {
                return goods_img;
            }

            public void setGoods_img(String goods_img) {
                this.goods_img = goods_img;
            }

            public boolean isReservable() {
                return reservable;
            }

            public void setReservable(boolean reservable) {
                this.reservable = reservable;
            }

            public String getEfficacy() {
                return efficacy;
            }

            public void setEfficacy(String efficacy) {
                this.efficacy = efficacy;
            }

            public int getStock_number() {
                return stock_number;
            }

            public void setStock_number(int stock_number) {
                this.stock_number = stock_number;
            }

            public int getRestrict_purchase_num() {
                return restrict_purchase_num;
            }

            public void setRestrict_purchase_num(int restrict_purchase_num) {
                this.restrict_purchase_num = restrict_purchase_num;
            }
        }
    }
}
7.P层接口

package com.example.dell.zhoukao20180416.presenter;

import com.example.dell.zhoukao20180416.model.MyDataBean;

public interface DataPresenter {
    //成功与失败的方法
    void Success(MyDataBean.DataBean data);
    void Error();
}
8.P层接口的实现类

package com.example.dell.zhoukao20180416.presenter;

import com.example.dell.zhoukao20180416.model.MyDataBean;
import com.example.dell.zhoukao20180416.model.MyDataModel;
import com.example.dell.zhoukao20180416.view.DataView;

public class MyDataPresenter implements DataPresenter{

    DataView dataView;
    private final MyDataModel myDataModel;
    public MyDataPresenter(DataView dataView) {
        this.dataView=dataView;
        myDataModel = new MyDataModel();
    }

    //成功
    @Override
    public void Success(MyDataBean.DataBean data) {
        dataView.toBackHome(data);

    }
    //失败
    @Override
    public void Error() {}

    public void netWork(String url){
        myDataModel.getData(url,this);
    }
}
9.V层接口

package com.example.dell.zhoukao20180416.view;

import com.example.dell.zhoukao20180416.model.MyDataBean;

public interface DataView {
    //接收数据的方法
    void toBackHome(MyDataBean.DataBean data);
}
10.V层接口的实现类

package com.example.dell.zhoukao20180416.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;
import com.example.dell.zhoukao20180416.R;
import com.example.dell.zhoukao20180416.adapter.MsAdapter;
import com.example.dell.zhoukao20180416.adapter.ImgAdapter;
import com.example.dell.zhoukao20180416.model.MyDataBean;
import com.example.dell.zhoukao20180416.presenter.MyDataPresenter;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements DataView {
    String url = "http://result.eolinker.com/umIPmfS6c83237d9c70c7c9510c9b0f97171a308d13b611?uri=homepage";

    private List<MyDataBean.DataBean.Ad1Bean> imglist;
    private int item=5;

    Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //接收数据
            MyDataBean.DataBean data = (MyDataBean.DataBean) msg.obj;

            //设置轮播图 进入轮播图适配器
            imglist = data.getAd1();
            ImgAdapter imgAdapter = new ImgAdapter(MainActivity.this, imglist);
            final LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
            imgRcv.setLayoutManager(layoutManager);
            imgRcv.setHasFixedSize(true);
            imgRcv.setAdapter(imgAdapter);

            PagerSnapHelper snapHelper = new PagerSnapHelper();
            snapHelper.attachToRecyclerView(imgRcv);

            imgRcv.scrollToPosition(imglist.size() * 10);

            ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
            scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    imgRcv.smoothScrollToPosition(layoutManager.findFirstVisibleItemPosition() + 1);
                }
            }, 2000, 2000, TimeUnit.MILLISECONDS);


            //设置秒杀,进入秒杀适配器
            List<MyDataBean.DataBean.DefaultGoodsListBean> defaultGoodsList = data.getDefaultGoodsList();
            MsAdapter adapter = new MsAdapter(MainActivity.this, defaultGoodsList);
            myRcv.setAdapter(adapter);

        }
    };

    Handler handler2 = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==0){
                item--;
                tvItem.setText("秒杀剩余时间"+item+"s");
                handler2.sendEmptyMessageDelayed(0,1000);
            }
            if(item==0){
                //实现页面跳转
                Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
                finish();
            }

        }
    };
    
    @BindView(R.id.my_rcv)
    RecyclerView myRcv;
    @BindView(R.id.img_rcv)
    RecyclerView imgRcv;
    @BindView(R.id.tv_item)
    TextView tvItem;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        
        //实例化P        MyDataPresenter myDataPresenter = new MyDataPresenter(this);
        myDataPresenter.netWork(url);

        //设置管理器
        myRcv.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false));

        //设置倒计时跳转页面
        handler2.sendEmptyMessageDelayed(0,1000);
        
    }
    
    //接收数据的方法
    @Override
    public void toBackHome(MyDataBean.DataBean data) {
        Message msg = new Message();
        msg.obj = data;
        handler.sendMessage(msg);
    }


}
11.初始化Fresco使用默认配置 需在清单文件中配置name

package com.example.dell.zhoukao20180416.app;

import android.app.Application;
import com.facebook.drawee.backends.pipeline.Fresco;

public class app extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        //初始化Fresco使用默认配置
        Fresco.initialize(this);
    }
}
清单文件中:
android:name=".app.app"
12.轮播图的适配器
package com.example.dell.zhoukao20180416.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.example.dell.zhoukao20180416.R;
import com.example.dell.zhoukao20180416.model.MyDataBean;
import com.example.dell.zhoukao20180416.view.MainActivity;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.List;

public class ImgAdapter extends RecyclerView.Adapter{
    Context context;
    List<MyDataBean.DataBean.Ad1Bean> list;
    public ImgAdapter(Context context, List<MyDataBean.DataBean.Ad1Bean> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        //引入轮播图布局
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.img_item,parent,false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myViewHolder = (MyViewHolder) holder;

        //为轮播图赋图片
        myViewHolder.item_sdv.setImageURI(list.get(position%list.size()).getImage());

    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }
    class MyViewHolder extends RecyclerView.ViewHolder{

        private final SimpleDraweeView item_sdv;

        public MyViewHolder(View view) {
            super(view);

            //找到布局文件中的ID
            item_sdv = view.findViewById(R.id.item_sdv);
        }
    }
}

13.秒杀的适配器

package com.example.dell.zhoukao20180416.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.dell.zhoukao20180416.R;
import com.example.dell.zhoukao20180416.model.MyDataBean;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.List;

public class MsAdapter extends RecyclerView.Adapter{
    Context context;
    List<MyDataBean.DataBean.DefaultGoodsListBean> list;
    public MsAdapter(Context context, List<MyDataBean.DataBean.DefaultGoodsListBean> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        //引入秒杀布局文件
        View view = View.inflate(context, R.layout.ms_item, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            MyViewHolder myViewHolder = (MyViewHolder) holder;

            //为秒杀赋值
            myViewHolder.rcv_tv.setText(""+list.get(position).getShop_price());
            myViewHolder.rcv_sdv.setImageURI(list.get(position).getGoods_img());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private final SimpleDraweeView rcv_sdv;
        private final TextView rcv_tv;

        public MyViewHolder(View view) {
            super(view);
            //找到秒杀布局中的控件ID
            rcv_sdv = view.findViewById(R.id.rcv_sdv);
            rcv_tv = view.findViewById(R.id.rcv_tv);

        }
    }
}
14.Okhttp网络请求

package com.example.dell.zhoukao20180416.utils;

import android.os.Environment;

import java.io.File;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

public class OkhtttpUtils {
    
    //单例模式,把构造方法进行私有化
    //
    private OkhtttpUtils(){};
    static  OkHttpClient client;
    
    public static OkHttpClient getInstance(){

        if (client==null) {
            //更加安全
            synchronized (OkhtttpUtils.class) {
                //缓存的地方     mnt/sdcard
                File file = new File(Environment.getExternalStorageDirectory(), "cache11");
                client = new OkHttpClient().newBuilder()
                        .readTimeout(3000, TimeUnit.SECONDS)   //设置读取超时时间
                        .connectTimeout(3000, TimeUnit.SECONDS) //设置连接的超时时间

                        .cache(new Cache(file, 10 * 1024))
                        .build();
            }
        }
        return client;
    }


    /**
     * get请求
     * Callback  是一个接口
     */
    public static void doGet(String url, Callback callback){

        //1:拿到okhttpclient  对像

        OkHttpClient client = getInstance();
        //2:进行请求的操作

        Request request = new Request.Builder()
                .url(url)
                .build();
        client.newCall(request).enqueue(callback);


    }

    //post请求

    /**
     *
     * @param url  请求的地址
     * @param parms   请求的参数
     * @param callback  callback
     */
    public static void doPost(String url, Map<String,String> parms,Callback callback){

        //得到客户端的对像
        OkHttpClient client = getInstance();

        //不是FormBody,而是一个Builder
        FormBody.Builder body = new FormBody.Builder();
        //key   value
        for (String key:parms.keySet()){
            //value的值
            body.add(key,parms.get(key));
        }
        Request request = new Request.Builder()
                .url(url)
                .post(body.build())
                .build();

        client.newCall(request).enqueue(callback);

    }

    //用来上传图片的

    //url  , 图片  ,参数    Callback
    public static  void upImage(String url,File file,String filenName,Map<String,String> params,Callback callback){

        OkHttpClient client = getInstance();


        //requestBody的实现类  Formbody
        MultipartBody.Builder builder = new MultipartBody.Builder();

        if (params!=null){
            for (String key :params.keySet()){
                builder.addFormDataPart(key,params.get(key));
            }
        }

        //设置类型
        builder.setType(MultipartBody.FORM);


        builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file));

      // builder.setType(MultipartBody.FORM);
     // builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file));
        //builder.addFormDataPart("file","aa.png",builder.build());

        Request request = new Request.Builder()
                .url(url)
                .post(builder.build())
                .build();

        client.newCall(request).enqueue(callback);


    }


}
15.轮播图布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--轮播图的图片控件-->
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/item_sdv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop">
    </com.facebook.drawee.view.SimpleDraweeView>

</LinearLayout>

16.秒杀布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:padding="10px">


    <!--秒杀图的图片控件-->
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/rcv_sdv"
        android:layout_width="200px"
        android:layout_height="200px"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        fresco:actualImageScaleType="centerCrop"
        fresco:placeholderImageScaleType="centerCrop"
        fresco:roundAsCircle="true"
        fresco:placeholderImage="@drawable/ic_launcher_background" />

    <!--秒杀显示价格的控件-->
    <TextView
        android:id="@+id/rcv_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10px"
        android:layout_marginLeft="30px"
        android:layout_marginTop="20px"
        android:textColor="#FF0000"
        android:text="49.90"/>


</LinearLayout>
17.秒杀结束跳转的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.dell.zhoukao20180416.view.Main2Activity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/jy" />

</LinearLayout>

17.秒杀结束跳转的Activity

package com.example.dell.zhoukao20180416.view;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.dell.zhoukao20180416.R;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
}




PHP秒杀项目实战解决方案

-
  • 1970年01月01日 08:00

RecyclerView实现广告轮播图(一)

平时都是用RecyclerView实现列表,RecyclerView的强大毋庸置疑,今天就用它来实现广告轮播图。      效果如下   首先,在activity_main.xml里定义...
  • u014290233
  • u014290233
  • 2017-11-26 20:48:55
  • 479

jQuery实现轮播图特效,仿京东——李帅醒博客

如今轮播图已然成为网站中的最常用功能功能之一,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果。今天就教教大家做一个仿京东的轮播图。 1.首先定时器实现轮播效果。 2.图下...
  • wcslb
  • wcslb
  • 2016-11-30 18:57:58
  • 4773

京东案例js(标题栏透明度,倒计时,轮播图自动播放)

1.sublime字体放大:command++2.引入js文件,在引入css文件link下面script引入js文件http://emmet.evget.com/   查找emmet快捷键的网页   ...
  • weixin_40326021
  • weixin_40326021
  • 2018-03-21 22:21:22
  • 35

商品秒杀倒计时功能+ViewPager实现画廊效果

模式一:列表形式展示数据,倒计时完成移除此条数据效果: 涉及到的技术:RecyclerView、CardView、Fresco、CountDownTimer等,可以到本博客去查找// 倒计时...
  • Konfyt_Android
  • Konfyt_Android
  • 2016-10-21 13:30:18
  • 836

仿京东秒杀倒计时兼容ie6

仿京东秒杀倒计时兼容ie6 var limit_time; if(window.name==""){//查看是否已有记录的时间 limit_time=6000;//设置结...
  • qianqianyixiao1
  • qianqianyixiao1
  • 2015-06-08 12:59:52
  • 2764

RecyclerView实现广告轮播图

之前做的轮播图,对于十几个图片什么的能够满足,但是万一有几千张,几万张就容易造成内存泄露,使用RecyclerView做的轮播,可以利用它自身的复用机制,比较节省内存。所以这种方式感觉效果更好。 准...
  • jiang547860818
  • jiang547860818
  • 2017-03-10 16:06:27
  • 2176

仿京东商品列表---两种布局 用recycleview

view层里mainactivity-------------------------------------------------------------- package com....
  • ch5211314
  • ch5211314
  • 2018-03-31 16:06:53
  • 61

RecyclerView 实现轮播图

有的同学很想实现自己的轮播图  但是却弄了一通放弃了   现在RecyclerView出现之后 很多同学就可以放心了  他有个非常棒的方法  能够像ViewPager一样 单页横向切换,且滑动到一半 ...
  • u013297345
  • u013297345
  • 2017-07-13 14:30:30
  • 572

selenium+python京东自动登录及秒杀

运行环境: python 2.7 python安装selenium 安装webdriver(这里是firefox) 其中selenium可以采用pip安装:pip install seleniumwe...
  • u013042248
  • u013042248
  • 2017-01-01 14:20:05
  • 10387
收藏助手
不良信息举报
您举报文章:两个RecyclerView分别实现轮播图+京东秒杀
举报原因:
原因补充:

(最多只允许输入30个字)