Search in sources :

Example 1 with GankIoDataBean

use of com.example.jingbin.cloudreader.bean.GankIoDataBean in project CloudReader by youlookwhat.

the class GankOtherModel method getGankIoData.

public void getGankIoData(final RequestImpl listener) {
    Subscription subscription = HttpClient.Builder.getGankIOServer().getGankIoData(id, page, per_page).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<GankIoDataBean>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            listener.loadFailed();
        }

        @Override
        public void onNext(GankIoDataBean gankIoDataBean) {
            listener.loadSuccess(gankIoDataBean);
        }
    });
    listener.addSubscription(subscription);
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription)

Example 2 with GankIoDataBean

use of com.example.jingbin.cloudreader.bean.GankIoDataBean in project CloudReader by youlookwhat.

the class WelfareFragment method setAdapter.

private void setAdapter(GankIoDataBean gankIoDataBean) {
    //        mWelfareAdapter = new WelfareAdapter();
    mWelfareAdapter.addAll(gankIoDataBean.getResults());
    //构造器中,第一个参数表示列数或者行数,第二个参数表示滑动方向,瀑布流
    bindingView.xrvWelfare.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    bindingView.xrvWelfare.setAdapter(mWelfareAdapter);
    mWelfareAdapter.notifyDataSetChanged();
    mWelfareAdapter.setOnItemClickListener(new OnItemClickListener<GankIoDataBean.ResultBean>() {

        @Override
        public void onClick(GankIoDataBean.ResultBean resultsBean, int position) {
            DebugUtil.error("-----" + imgList.toString());
            DebugUtil.error("----imgList.size():  " + imgList.size());
            Bundle bundle = new Bundle();
            // 2,大图显示当前页数,1,头像,不显示页数
            bundle.putInt("selet", 2);
            //第几张
            bundle.putInt("code", position);
            bundle.putStringArrayList("imageuri", imgList);
            Intent intent = new Intent(getContext(), ViewBigImageActivity.class);
            intent.putExtras(bundle);
            getContext().startActivity(intent);
        }
    });
    // 显示成功后就不是第一次了,不再刷新
    isFirst = false;
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Bundle(android.os.Bundle) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) ViewBigImageActivity(com.example.jingbin.cloudreader.view.viewbigimage.ViewBigImageActivity)

Example 3 with GankIoDataBean

use of com.example.jingbin.cloudreader.bean.GankIoDataBean in project CloudReader by youlookwhat.

the class WelfareFragment method loadWelfareData.

private void loadWelfareData() {
    mModel.setData("福利", mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    imgList.clear();
                    for (int i = 0; i < gankIoDataBean.getResults().size(); i++) {
                        imgList.add(gankIoDataBean.getResults().get(i).getUrl());
                    }
                    setAdapter(gankIoDataBean);
                    aCache.remove(Constants.GANK_MEIZI);
                    aCache.put(Constants.GANK_MEIZI, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvWelfare.refreshComplete();
                    mWelfareAdapter.addAll(gankIoDataBean.getResults());
                    mWelfareAdapter.notifyDataSetChanged();
                    for (int i = 0; i < gankIoDataBean.getResults().size(); i++) {
                        imgList.add(gankIoDataBean.getResults().get(i).getUrl());
                    }
                } else {
                    bindingView.xrvWelfare.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            bindingView.xrvWelfare.refreshComplete();
            if (mWelfareAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            WelfareFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 4 with GankIoDataBean

use of com.example.jingbin.cloudreader.bean.GankIoDataBean in project CloudReader by youlookwhat.

the class AndroidFragment method loadAndroidData.

private void loadAndroidData() {
    mModel.setData(mType, mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    setAdapter(gankIoDataBean);
                    mACache.remove(Constants.GANK_ANDROID);
                    // 缓存50分钟
                    mACache.put(Constants.GANK_ANDROID, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvAndroid.refreshComplete();
                    mAndroidAdapter.addAll(gankIoDataBean.getResults());
                    mAndroidAdapter.notifyDataSetChanged();
                } else {
                    bindingView.xrvAndroid.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            bindingView.xrvAndroid.refreshComplete();
            // 注意:这里不能写成 mPage == 1,否则会一直显示错误页面
            if (mAndroidAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            AndroidFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Example 5 with GankIoDataBean

use of com.example.jingbin.cloudreader.bean.GankIoDataBean in project CloudReader by youlookwhat.

the class CustomFragment method loadCustomData.

private void loadCustomData() {
    mModel.setData(mType, mPage, HttpUtils.per_page_more);
    mModel.getGankIoData(new RequestImpl() {

        @Override
        public void loadSuccess(Object object) {
            showContentView();
            GankIoDataBean gankIoDataBean = (GankIoDataBean) object;
            if (mPage == 1) {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    setAdapter(gankIoDataBean);
                    mACache.remove(Constants.GANK_CUSTOM);
                    // 缓存50分钟
                    mACache.put(Constants.GANK_CUSTOM, gankIoDataBean, 30000);
                }
            } else {
                if (gankIoDataBean != null && gankIoDataBean.getResults() != null && gankIoDataBean.getResults().size() > 0) {
                    bindingView.xrvCustom.refreshComplete();
                    mAndroidAdapter.addAll(gankIoDataBean.getResults());
                    mAndroidAdapter.notifyDataSetChanged();
                } else {
                    bindingView.xrvCustom.noMoreLoading();
                }
            }
        }

        @Override
        public void loadFailed() {
            showContentView();
            bindingView.xrvCustom.refreshComplete();
            if (mAndroidAdapter.getItemCount() == 0) {
                showError();
            }
            if (mPage > 1) {
                mPage--;
            }
        }

        @Override
        public void addSubscription(Subscription subscription) {
            CustomFragment.this.addSubscription(subscription);
        }
    });
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Subscription(rx.Subscription) RequestImpl(com.example.jingbin.cloudreader.http.RequestImpl)

Aggregations

GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)5 Subscription (rx.Subscription)4 RequestImpl (com.example.jingbin.cloudreader.http.RequestImpl)3 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 ViewBigImageActivity (com.example.jingbin.cloudreader.view.viewbigimage.ViewBigImageActivity)1