Search in sources :

Example 1 with ImagePath

use of bean.ImagePath in project GomoTest by suReZj.

the class MainActivity method setImage.

public void setImage(final int page) {
    if ((pathList.size() != 0) && (list.size() < pathList.size())) {
        if (list.size() % 18 == 0) {
            System.gc();
        }
        index = list.size() + 9;
        start = list.size();
        end = start;
        for (int i = list.size(); i < index; i++) {
            showPath = new showPath();
            showPath.setPath(pathList.get(i).getPath());
            showList.add(showPath);
            list.add(pathList.get(i).getPath());
            adapter.notifyItemInserted(end);
            end++;
        }
        if (page != 1) {
            springView.onFinishFreshAndLoad();
        }
    } else {
        getData = retrofit.create(getData.class);
        getData.getWelfare("9", page).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<gson_welfare>() {

            private Disposable disposable;

            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;
            }

            @Override
            public void onNext(gson_welfare value) {
                if (list.size() % 18 == 0) {
                    System.gc();
                }
                results = value.getResults();
                start = list.size();
                end = start;
                for (int i = 0; i < results.size(); i++) {
                    imagePath = new ImagePath();
                    showPath = new showPath();
                    if (error.equals(results.get(i).getUrl())) {
                        list.add("http://img.gank.io/anri.kumaki_23_10_2017_12_27_30_151.jpg");
                        imagePath.setPath("http://img.gank.io/anri.kumaki_23_10_2017_12_27_30_151.jpg");
                        imagePath.save();
                        showPath.setPath("http://img.gank.io/anri.kumaki_23_10_2017_12_27_30_151.jpg");
                    } else if (results.get(i).getUrl().equals("https://ws1.sinaimg.cn/large/610dc034ly1fhfmsbxvllj20u00u0q80.jpg")) {
                        list.add("http://ww2.sinaimg.cn/large/7a8aed7bgw1esbmanpn0tj20hr0qo0w8.jpg");
                        imagePath.setPath("http://ww2.sinaimg.cn/large/7a8aed7bgw1esbmanpn0tj20hr0qo0w8.jpg");
                        imagePath.save();
                        showPath.setPath("http://ww2.sinaimg.cn/large/7a8aed7bgw1esbmanpn0tj20hr0qo0w8.jpg");
                    } else {
                        list.add(results.get(i).getUrl());
                        imagePath.setPath(results.get(i).getUrl());
                        imagePath.save();
                        showPath.setPath(results.get(i).getUrl());
                    }
                    showList.add(showPath);
                    adapter.notifyItemInserted(end);
                    end++;
                    imagePath = null;
                }
                if (page != 1) {
                    springView.onFinishFreshAndLoad();
                }
            }

            @Override
            public void onError(Throwable e) {
                disposable.dispose();
                if (page != 1) {
                    springView.onFinishFreshAndLoad();
                }
                Toast.makeText(MainActivity.this, "网络出现问题", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onComplete() {
            }
        });
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) ImagePath(bean.ImagePath) bean.showPath(bean.showPath) retrofit.getData(retrofit.getData) gson.gson_welfare(gson.gson_welfare)

Aggregations

ImagePath (bean.ImagePath)1 bean.showPath (bean.showPath)1 gson.gson_welfare (gson.gson_welfare)1 Disposable (io.reactivex.disposables.Disposable)1 retrofit.getData (retrofit.getData)1