首页

//activity_main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="yangchunming.bwie.com.ming.MainActivity">

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/xre">
    </com.jcodecraeer.xrecyclerview.XRecyclerView>

    <include layout="@layout/shouye_title"></include>

</RelativeLayout>

//activity_main2

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/recy"

        ></android.support.v7.widget.RecyclerView>
</LinearLayout>

//activity_banner

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"
        ></WebView>
</LinearLayout>

//item_text

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal">
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/item_img"
        android:layout_width="100dp"
        android:layout_height="100dp"
        fresco:placeholderImage="@drawable/ic_launcher_background"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/list_items"
        android:textSize="16sp"/>
</LinearLayout>

//shouye_title

<FrameLayout
    android:id="@+id/fg"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
</FrameLayout>

//shouye_tuijian

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginTop="30px">
    <TextView
        android:textSize="80px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shouye_tuijian_tv"/>
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shouye_tuijian_rc"></android.support.v7.widget.RecyclerView>
</LinearLayout>

//shouye_tuijian_zi

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="15px">
    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="300px"
        android:layout_height="300px"
        android:id="@+id/sd"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv"
        />
</LinearLayout>

//shouye_xbanner

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <com.stx.xhb.xbanner.XBanner
        android:layout_width="match_parent"
        android:layout_height="300px"
        app:AutoPlayTime="2000"
        android:id="@+id/myxbanner"
        ></com.stx.xhb.xbanner.XBanner>
</LinearLayout>

//shouyemiaosha_item

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:textColor="#ff0000"
            android:textSize="50px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/shouue_miaosha_tv"/>

        <TextView
            android:layout_gravity="center_vertical"
            android:textSize="30px"
            android:id="@+id/shouue_miaosha_tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60px" />


        <LinearLayout
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="50px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/tv_hour"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:paddingTop="3dp"
                android:paddingBottom="3dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:background="#000000"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                android:text="02"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:textStyle="bold"
                android:textColor="@android:color/black"
                android:text=":"/>
            <TextView
                android:background="#000000"
                android:id="@+id/tv_minute"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:paddingTop="3dp"
                android:paddingBottom="3dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                android:text="15"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:textStyle="bold"
                android:textColor="@android:color/black"
                android:text=":"/>
            <TextView
                android:background="#000000"
                android:id="@+id/tv_second"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:paddingTop="3dp"
                android:paddingBottom="3dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                android:text="36"/>
        </LinearLayout>
    </LinearLayout>
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/miaosha_rv"></android.support.v7.widget.RecyclerView>
</LinearLayout>

//notify_out

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="50%p"
        android:toYDelta="0"
        />

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        />
</set>

//notify_in

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="0"
        android:toYDelta="-50%p"/>

    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="1.0"
        android:toAlpha="0"

        />
</set>

//Util

public class Util {
    private  volatile  static Util util=null;

    private Util(){

    }

    public static  Util getmInstance(){
        if (util==null){
            synchronized (Util.class){
                if (util==null){
                    util=new Util();
                }
            }
        }
        return util;
    }

    public TestService getnetjson(String url){
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        TestService testService = retrofit.create(TestService.class);
        return testService;
    }
}

//FilmService

 

public interface FilmService {
    @GET("getProducts?pscid=1")
    Observable<xiangqingbena> getBean(@Query("p") int p);
}

//Getjson

public interface Getjson {
    void getnetjson(Shuyebean shouye_bean);
}

//Getnet

 

public interface Getnet {
    public static String  net="http://120.27.23.105/";
}

//Iview

 

public interface Iview {
    void  setadapter(Context context, Shuyebean shuyebean);
}

//TestService

 

public interface TestService {
    @GET("ad/getAd")
    Observable<Shuyebean> getUser();
}

//NoticeView

 

public class NoticeView extends ViewFlipper implements View.OnClickListener {

    private Context mcontext;
    private List<String> mNotices;

    public NoticeView(Context context) {
        super(context);
    }

    public NoticeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        mcontext=context;

        setFlipInterval(3000);

        setPadding(dp2px(5f),dp2px(5f),dp2px(5f),dp2px(5f));

        setInAnimation(AnimationUtils.loadAnimation(mcontext, R.anim.notify_in));
        setInAnimation(AnimationUtils.loadAnimation(mcontext, R.anim.notify_out));

    }
    public void addNotice(List<String> notices){
        removeAllViews();
        mNotices=notices;
        for(int i=0;i<notices.size();i++){

            String s = notices.get(i);
            TextView textView = new TextView(mcontext);
            textView.setSingleLine();
            textView.setText(s);
            textView.setTextSize(26);
            textView.setEllipsize(TextUtils.TruncateAt.END);
            textView.setTextColor(Color.parseColor("#666666"));
            textView.setGravity(Gravity.CENTER_VERTICAL);
            textView.setTag(i);
            textView.setOnClickListener(this);
            NoticeView.this.addView(textView,new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));

        }
    }

    @Override
    public void onClick(View v) {
        int position =(int) v.getTag();
        String s = mNotices.get(position);
        if (mOnNoticeClickListener !=null){
            mOnNoticeClickListener.onNotieClick(position,s);
        }

    }

    public interface OnNoticeClickListener{
        void onNotieClick(int position,String s);

    }
    private OnNoticeClickListener mOnNoticeClickListener;


    public void setOnNoticeClickListener(OnNoticeClickListener onNoticeClickListener){
        mOnNoticeClickListener= onNoticeClickListener;
    }
    private  int dp2px(float dpValue){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dpValue,mcontext.getResources().getDisplayMetrics());
    }
}

//Imode

public interface Imode {
    void getnetGson(Getjson getjson);
}

//myModel

public class myModel implements Imode {
    @Override
    public void getnetGson(final Getjson getjson) {
        Observable<Shuyebean> user = Util.getmInstance().getnetjson(Getnet.net).getUser();
        user.subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Shuyebean>() {
                    @Override
                    public void accept(Shuyebean shouye_bean) throws Exception {
                        getjson.getnetjson(shouye_bean);

                    }
                });
    }
}

//Ipressenter

public interface Ipressenter {
    void getmv(Context context, Iview iview, Imode imode);
}

//Mypresenter

 

public class Mypresenter implements Ipressenter {

    private Iview view;
    private myModel model;


    public Mypresenter(Iview view) {
        this.view = view;
        model = new myModel();
    }

    @Override
    public void getmv(final Context context, final Iview iview, Imode imode) {
        imode.getnetGson(new Getjson() {
            @Override
            public void getnetjson(Shuyebean shouye_bean) {
                iview.setadapter(context,shouye_bean);
            }
        });
    }
    public void onDestory(){
        view=null;
    }

}

//Miaoshaadapter

public class Miaoshaadapter extends RecyclerView.Adapter<Miaoshaadapter.Mymiaoshahodler> {

    private Context context;
    private List<Shuyebean.MiaoshaBean.ListBeanX> miaoshalist;

    public Miaoshaadapter(Context context,List<Shuyebean.MiaoshaBean.ListBeanX>miaoshalist){
        this.context=context;
        this.miaoshalist=miaoshalist;
    }
    @NonNull
    @Override
    public Mymiaoshahodler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View in=View.inflate(context,R.layout.shouye_tuijian_zi,null);
        Mymiaoshahodler  mymiaoshahodler=   new Mymiaoshahodler(in);
        return mymiaoshahodler;
    }

    @Override
    public void onBindViewHolder(@NonNull Miaoshaadapter.Mymiaoshahodler holder, int position) {
        String images = miaoshalist.get(position).getImages();
        holder.textView.setText(miaoshalist.get(position).getTitle());
        String[] split = images.split(".jpg");
        holder.sd.setImageURI(Uri.parse(split[0]+".jpg"));
        holder.sd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Main2Activity.class);
                context.startActivity(intent);
            }
        });
    }

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

    class Mymiaoshahodler extends RecyclerView.ViewHolder{
        public SimpleDraweeView sd;
        public TextView textView;
        public  TextView  textView1;
        public Mymiaoshahodler(View itemView) {
            super(itemView);
            this.sd= itemView.findViewById(R.id.sd);
            this.textView =itemView.findViewById(R.id.tv);

        }
    }
}

//Mytuijian

public class Mytuijian extends RecyclerView.Adapter<Mytuijian.Tuijianhodler> {
    private Context context;
    private List<Shuyebean.TuijianBean.ListBean> list;

    public Mytuijian(Context context, List<Shuyebean.TuijianBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public Tuijianhodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shouye_tuijian_zi, null);
        Tuijianhodler tuijianhodler=new Tuijianhodler(view);
        return tuijianhodler;
    }

    @Override
    public void onBindViewHolder(Tuijianhodler holder, int position) {
        String images = list.get(position).getImages();
        String[] split = images.split(".jpg");
        holder.sd.setImageURI(split[0]+".jpg");
    }

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

    class Tuijianhodler extends RecyclerView.ViewHolder{
        public SimpleDraweeView sd;
        public Tuijianhodler(View itemView) {
            super(itemView);
            this.sd=itemView.findViewById(R.id.sd);

        }
    }
}

//MyAdapterleibiao

public class MyAdapterleibiao extends RecyclerView.Adapter<MyAdapterleibiao.ViewHolder> {

    private Context context;
    private List<xiangqingbena.DataBean> mdatas;

    public MyAdapterleibiao(List<xiangqingbena.DataBean> mdatas, Context context) {
        this.context = context;
        this.mdatas = mdatas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate= LayoutInflater.from(context).inflate(R.layout.item_text,parent,false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.item_img.setImageURI(mdatas.get(position).getImages());
        holder.item_textview.setText(mdatas.get(position).getTitle());
    }

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

    static class ViewHolder extends RecyclerView.ViewHolder{

        private SimpleDraweeView item_img;
        private TextView item_textview;

        public ViewHolder(View itemView) {
            super(itemView);

            item_img=itemView.findViewById(R.id.item_img);
            item_textview=itemView.findViewById(R.id.list_items);
        }
    }
}

//Myadapter

 

public class Myadapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private Shuyebean shouye_bean;
    private List<String> notices;
    private Handler timeHandler;

    public Myadapter(Context context, Shuyebean shouye_bean) {
        this.context = context;
        this.shouye_bean = shouye_bean;

    }
    private long mHour = 02;
    private long mMin = 15;
    private long mSecond = 36;
    private boolean isRun = true;

    //定义常量  确定多条目加载类型
    final static int TYPE_ONE=1;
    final static int TYPE_TWO=2;
    final static int TYPE_THREE=3;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_ONE:
                View inflate1 = View.inflate(context, R.layout.shouye_tuijian, null);
                Tuijian tuijian=new Tuijian(inflate1);
                return tuijian;
            case TYPE_TWO:
                View inflate2 = View.inflate(context, R.layout.shouyemiaosha_item, null);
                Miaosha miaosha=new Miaosha(inflate2);
                return miaosha;
        }
        return null;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof Tuijian){
            ((Tuijian) holder).shouye_tuijian_tv.setText("京东推荐");
            List<Shuyebean.TuijianBean.ListBean> list = shouye_bean.getTuijian().getList();
            Mytuijian mytuijian=new Mytuijian(context,list);
            ((Tuijian) holder).shouye_tuijian_rc.setAdapter(mytuijian);
            ((Tuijian) holder).shouye_tuijian_rc.setLayoutManager(new GridLayoutManager(context,1,GridLayoutManager.HORIZONTAL,false));
        }

        if (holder instanceof Miaosha){
            ((Miaosha) holder).shouue_miaosha_tv.setText("京东秒杀");
            ((Miaosha) holder).shouue_miaosha_tv1.setText("16点场");
            startRun();
            timeHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    if (msg.what==1) {
                        computeTime();
                        if (mHour<10){
                            ((Miaosha) holder).tv_hour.setText("0"+mHour+"");
                        }else {
                            ((Miaosha) holder).tv_hour.setText("0"+mHour+"");
                        }
                        if (mMin<10){
                            ((Miaosha) holder).tv_minute.setText("0"+mMin+"");
                        }else {
                            ((Miaosha) holder).tv_minute.setText(mMin+"");
                        }
                        if (mSecond<10){
                            ((Miaosha) holder).tv_second.setText("0"+mSecond+"");
                        }else {
                            ((Miaosha) holder).tv_second.setText(mSecond+"");
                        }
                    }
                }
            };

            List<Shuyebean.MiaoshaBean.ListBeanX> miaoshalist = shouye_bean.getMiaosha().getList();
            Miaoshaadapter miaosha=new Miaoshaadapter(context,miaoshalist);
            ((Miaosha) holder).miaosha_rv.setAdapter(miaosha);
            ((Miaosha) holder).miaosha_rv.setLayoutManager(new GridLayoutManager(context,1));

        }
    }

    /**
     * 开启倒计时
     */
    private void startRun() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                while (isRun) {
                    try {
                        Thread.sleep(1000); // sleep 1000ms
                        Message message = Message.obtain();
                        message.what = 1;
                        timeHandler.sendMessage(message);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    /**
     * 倒计时计算
     */
    private void computeTime() {
        mSecond--;
        if (mSecond < 0) {
            mMin--;
            mSecond = 59;
            if (mMin < 0) {
                mMin = 59;
                mHour--;
            }
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if (position==0){
            return TYPE_ONE;
        }
        if (position==1){
            return TYPE_TWO;
        }
        return 0;
    }
    class Miaosha extends RecyclerView.ViewHolder{
        public TextView shouue_miaosha_tv;
        public TextView shouue_miaosha_tv1;
        public TextView tv_hour;
        public TextView tv_minute;
        public TextView tv_second;
        public RecyclerView miaosha_rv;
        public Miaosha(View itemView) {
            super(itemView);
            this.shouue_miaosha_tv=itemView.findViewById(R.id.shouue_miaosha_tv);
            this.shouue_miaosha_tv1=itemView.findViewById(R.id.shouue_miaosha_tv1);
            this.tv_hour=itemView.findViewById(R.id.tv_hour);
            this.tv_minute=itemView.findViewById(R.id.tv_minute);
            this.tv_second=itemView.findViewById(R.id.tv_second);
            this.miaosha_rv=itemView.findViewById(R.id.miaosha_rv);
        }
    }

    class Tuijian extends RecyclerView.ViewHolder{
        public TextView shouye_tuijian_tv;
        public RecyclerView shouye_tuijian_rc;
        public Tuijian(View itemView) {
            super(itemView);
            this.shouye_tuijian_rc=itemView.findViewById(R.id.shouye_tuijian_rc);
            this.shouye_tuijian_tv=itemView.findViewById(R.id.shouye_tuijian_tv);
        }
    }
}
//添加依赖
implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.xhb:xbanner:1.2.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.facebook.fresco:fresco:0.14.1'

//App
public class App extends Application {
    public final static float DESIGN_WIDTH = 750; //绘制页面时参照的设计图宽度
    public String BaseUrl="https://www.zhaoapi.cn/product/";
    private static Retrofit mRetrofit;

    public static Retrofit getmRetrofit() {
        return mRetrofit;
    }
    @Override
    public void onCreate() {
        super.onCreate();

        mRetrofit=new Retrofit.Builder()
                .baseUrl(BaseUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();


        Fresco.initialize(this);

        resetDensity();//注意不要漏掉
    }

    private void resetDensity() {
        Point size = new Point();
        ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getSize(size);
        getResources().getDisplayMetrics().xdpi = size.x/DESIGN_WIDTH*72f;

    }
}

//BannerActivity

public class BannerActivity extends AppCompatActivity {
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actrvity_banner);
        webView = findViewById(R.id.webview);
        Intent intent = getIntent();
        String ddd = intent.getStringExtra("ddd");
        webView.loadUrl(ddd);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);

    }
}

//Main2Activity

public class Main2Activity extends AppCompatActivity {

    private RecyclerView recy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        recy = findViewById(R.id.recy);
        recy.setLayoutManager(new LinearLayoutManager(this));
        App.getmRetrofit()
                .create(FilmService.class)
                .getBean(1)
                .subscribeOn(Schedulers.io())
                .map(new Function<xiangqingbena, List<xiangqingbena.DataBean>>() {
                    @Override
                    public List<xiangqingbena.DataBean> apply(xiangqingbena bean) throws Exception {
                        List<xiangqingbena.DataBean> list=bean.getData();
                        return list;
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<List<xiangqingbena.DataBean>>() {
                    @Override
                    public void accept(List<xiangqingbena.DataBean> dataBeans) throws Exception {
                        recy.setAdapter(new MyAdapterleibiao(dataBeans,Main2Activity.this));
                    }
                });


    }
}

//MainActivity

public class MainActivity extends AppCompatActivity implements Iview {

    private XRecyclerView xre;
    private View inflate;
    Handler handler=new Handler();
    private Myadapter myadapter;
    List<String> lunbolist=new ArrayList<>();
    private int mDistanceY;
    private List<Shuyebean.DataBean> data1;
    private Mypresenter mypresenter;

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

        xre = findViewById(R.id.xre);
        mypresenter = new Mypresenter(this);
        mypresenter.getmv(MainActivity.this,this,new myModel());
        inflate = View.inflate(this, R.layout.shouye_xbanner, null);
        xre.addHeaderView(inflate);
    }
    @Override
    public void setadapter(Context context, Shuyebean shouye_bean) {
        data1 = shouye_bean.getData();
        for (int i = 0; i < data1.size(); i++) {
            lunbolist.add(data1.get(i).getIcon());
        }
        XBanner myxbanner = inflate.findViewById(R.id.myxbanner);
        myxbanner.setData(lunbolist, null);
        myxbanner.setmAdapter(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, View view, int position) {
                Glide.with(MainActivity.this).load(lunbolist.get(position)).into((ImageView) view);
            }
        });

        //跳转网页
        myxbanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, int position) {
                String url = data1.get(position).getUrl();
                Intent intent = new Intent(MainActivity.this, BannerActivity.class);
                intent.putExtra("ddd", url);
                startActivity(intent);
            }
        });
        myadapter = new Myadapter(context, shouye_bean);
        xre.setAdapter(myadapter);
        xre.setLayoutManager(new LinearLayoutManager(context));
        xre.setLoadingMoreEnabled(false);
        xre.setLoadingListener(new XRecyclerView.LoadingListener() {

            private FrameLayout fg;

            @Override
            public void onRefresh() {
                fg = inflate.findViewById(R.id.fg);
                fg.setVisibility(View.GONE);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        fg.setVisibility(View.VISIBLE);
                        xre.refreshComplete();
                    }
                },1000);
            }

            @Override
            public void onLoadMore() {

            }
        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mypresenter.onDestory();
    }
}

https://www.zhaoapi.cn/ad/getAd

https://www.zhaoapi.cn/product/getProducts?pscid=1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值