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);
}
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);
}
});
}
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);
}
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);
}
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);
}
Aggregations