Search in sources :

Example 1 with ApiResponse

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

the class CommentPresenter method loadComments.

@Override
public void loadComments(Audient audient) {
    String storeId = mRepository.getStoreId();
    Disposable disposable = mRepository.getComments(audient.mediaId, null, storeId, 0, 300).map(new Function<ApiResponse<CommentDataBean>, CommentDataBean>() {

        @Override
        public CommentDataBean apply(ApiResponse<CommentDataBean> commentDataBeanApiResponse) throws Exception {
            return commentDataBeanApiResponse.data;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Consumer<CommentDataBean>() {

        @Override
        public void accept(CommentDataBean commentDataBean) throws Exception {
            if (mView.isActive()) {
                mView.showCommentDataBean(commentDataBean);
                if ((commentDataBean.othersComment.comments.isEmpty())) {
                    mView.showEmpty(true);
                } else {
                    mView.showEmpty(false);
                }
            }
        }
    }).observeOn(Schedulers.io()).map(new Function<CommentDataBean, List<Comment>>() {

        @Override
        public List<Comment> apply(CommentDataBean commentDataBean) throws Exception {
            List<Comment> comments = new ArrayList<>();
            comments.addAll(commentDataBean.inStoreComment.comments);
            comments.addAll(commentDataBean.othersComment.comments);
            return comments;
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Comment>>() {

        @Override
        public void onNext(List<Comment> comments) {
            if (mView.isActive()) {
                mView.showComments(comments);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadComments error :" + t.toString());
            if (mView.isActive()) {
                mView.setLoadingIncator(false);
                mView.showEmpty(true);
                mView.showLoadingError();
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIncator(false);
                mView.showSuccessfulMessage();
            }
        }
    });
    mDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Comment(com.xinshang.audient.model.entities.Comment) ApiResponse(com.xinshang.audient.model.entities.ApiResponse) Function(io.reactivex.functions.Function) ArrayList(java.util.ArrayList) List(java.util.List) CommentDataBean(com.xinshang.audient.model.entities.CommentDataBean)

Example 2 with ApiResponse

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

the class PlaylistPresenter method loadStorePlaylist.

@Override
public void loadStorePlaylist() {
    String storeId = mRepository.getStoreId();
    mRepository.getStorePlaylist(storeId).map(new Function<ApiResponse<List<StoreSong>>, List<StoreSong>>() {

        @Override
        public List<StoreSong> apply(ApiResponse<List<StoreSong>> listApiResponse) throws Exception {
            return listApiResponse.data;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<StoreSong>>() {

        @Override
        public void onNext(List<StoreSong> storePlaylists) {
            mPlaylist = storePlaylists;
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadStorePlaylist error : " + t.getMessage());
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
            sendCommand(COMMAND_BIND);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) ArrayList(java.util.ArrayList) List(java.util.List) ByteString(okio.ByteString) StoreSong(com.xinshang.audient.model.entities.StoreSong) ApiResponse(com.xinshang.audient.model.entities.ApiResponse)

Example 3 with ApiResponse

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

the class FeedbackPresenter method sendFeedback.

@Override
public void sendFeedback(String title, String content) {
    if (isInValid(title, content)) {
        return;
    }
    if (mView.isActive()) {
        mView.setLoadingIndicator(true);
    }
    Feedback feedback = new Feedback();
    feedback.title = title;
    feedback.content = content;
    Disposable disposable = mRepository.sendFeedback(feedback).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<ApiResponse>() {

        @Override
        public void onNext(ApiResponse apiResponse) {
            if (apiResponse.resultCode == 0) {
                mView.showSuccessfulMessage();
            } else {
                mView.showFailedMessage();
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "sendFeedback error : " + t.getMessage());
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIndicator(false);
            }
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Feedback(com.xinshang.audient.model.entities.Feedback) ApiResponse(com.xinshang.audient.model.entities.ApiResponse)

Example 4 with ApiResponse

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

the class MainPresenter method loadStoreInfo.

@Override
public void loadStoreInfo() {
    Disposable disposable = mRepository.getStoreInfo(mRepository.getStoreId()).map(new Function<ApiResponse<Store>, Store>() {

        @Override
        public Store apply(ApiResponse<Store> storeApiResponse) throws Exception {
            return storeApiResponse.data;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<Store>() {

        @Override
        public void onNext(Store store) {
            if (mView != null) {
                mView.showStoreInfo(store);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadStoreInfo error : " + t.getMessage());
        }

        @Override
        public void onComplete() {
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) Store(com.xinshang.audient.model.entities.Store) ApiResponse(com.xinshang.audient.model.entities.ApiResponse)

Example 5 with ApiResponse

use of com.xinshang.audient.model.entities.ApiResponse 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)

Aggregations

ApiResponse (com.xinshang.audient.model.entities.ApiResponse)6 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)5 Disposable (io.reactivex.disposables.Disposable)5 Function (io.reactivex.functions.Function)5 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Store (com.xinshang.audient.model.entities.Store)2 Comment (com.xinshang.audient.model.entities.Comment)1 CommentDataBean (com.xinshang.audient.model.entities.CommentDataBean)1 Feedback (com.xinshang.audient.model.entities.Feedback)1 StoreDataBean (com.xinshang.audient.model.entities.StoreDataBean)1 StoreSong (com.xinshang.audient.model.entities.StoreSong)1 Toplist (com.xinshang.audient.model.entities.Toplist)1 ToplistDataBean (com.xinshang.audient.model.entities.ToplistDataBean)1 ConnectException (java.net.ConnectException)1 ByteString (okio.ByteString)1