Search in sources :

Example 1 with Toplist

use of com.xinshang.audient.model.entities.Toplist in project Audient by komamj.

the class TopListPresenter method loadTopList.

@Override
public void loadTopList() {
    mDisposables.clear();
    if (mView.isActive()) {
        mView.setLoadingIndictor(true);
    }
    Disposable disposable = mRepository.getToplists().map(new Function<ApiResponse<List<ToplistDataBean>>, List<ToplistDataBean>>() {

        @Override
        public List<ToplistDataBean> apply(ApiResponse<List<ToplistDataBean>> listApiResponse) throws Exception {
            return listApiResponse.data;
        }
    }).map(new Function<List<ToplistDataBean>, List<Toplist>>() {

        @Override
        public List<Toplist> apply(List<ToplistDataBean> toplistDataBeans) throws Exception {
            List<Toplist> topLists = new ArrayList<>();
            for (ToplistDataBean toplistDataBean : toplistDataBeans) {
                for (Toplist topList : toplistDataBean.topLists) {
                    if (isLegal(topList)) {
                        topLists.add(topList);
                    }
                }
            }
            return topLists;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Toplist>>() {

        @Override
        public void onNext(List<Toplist> topLists) {
            if (mView.isActive()) {
                mView.showTopLists(topLists);
            }
        }

        @Override
        public void onError(Throwable t) {
            if (t instanceof ConnectException) {
                LogUtils.e(TAG, "loadTopList connect error :");
            }
            LogUtils.e(TAG, "loadTopList error :" + t.toString());
            if (mView.isActive()) {
                mView.setLoadingIndictor(false);
                mView.showLoadingError();
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIndictor(false);
                mView.showSuccessfulMessage();
            }
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Toplist(com.xinshang.audient.model.entities.Toplist) ArrayList(java.util.ArrayList) ApiResponse(com.xinshang.audient.model.entities.ApiResponse) ConnectException(java.net.ConnectException) Function(io.reactivex.functions.Function) ArrayList(java.util.ArrayList) List(java.util.List) ToplistDataBean(com.xinshang.audient.model.entities.ToplistDataBean) ConnectException(java.net.ConnectException)

Example 2 with Toplist

use of com.xinshang.audient.model.entities.Toplist in project Audient by komamj.

the class TopListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(TopListViewHolder holder, int position) {
    Toplist topList = mData.get(position);
    mGlideRequest.load(topList.coverImage).into(holder.mAlbum);
    holder.mFirstSong.setText(buildString(topList.toplistSongs.get(0)));
    holder.mSecondSong.setText(buildString(topList.toplistSongs.get(1)));
    holder.mThirdSong.setText(buildString(topList.toplistSongs.get(2)));
}
Also used : Toplist(com.xinshang.audient.model.entities.Toplist)

Aggregations

Toplist (com.xinshang.audient.model.entities.Toplist)2 ApiResponse (com.xinshang.audient.model.entities.ApiResponse)1 ToplistDataBean (com.xinshang.audient.model.entities.ToplistDataBean)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1