|
@@ -1,6 +1,10 @@
|
|
|
package com.cooleshow.student.presenter.main;
|
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.data.net.BaseResponse;
|
|
|
import com.cooleshow.base.presenter.BasePresenter;
|
|
|
import com.cooleshow.base.rx.BaseObserver;
|
|
|
import com.cooleshow.base.utils.RequestBodyUtil;
|
|
@@ -14,6 +18,7 @@ import com.cooleshow.student.bean.HomeStyleBean;
|
|
|
import com.cooleshow.student.bean.HotAlbumBean;
|
|
|
import com.cooleshow.student.bean.RecommendTalentListBean;
|
|
|
import com.cooleshow.student.bean.StudentUserInfo;
|
|
|
+import com.cooleshow.student.bean.TempLiveTeacherListBean;
|
|
|
import com.cooleshow.student.contract.HomeContract;
|
|
|
|
|
|
import org.json.JSONException;
|
|
@@ -22,6 +27,17 @@ import org.json.JSONObject;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.rxjava3.annotations.NonNull;
|
|
|
+import io.reactivex.rxjava3.core.Observable;
|
|
|
+import io.reactivex.rxjava3.core.ObservableEmitter;
|
|
|
+import io.reactivex.rxjava3.core.ObservableOnSubscribe;
|
|
|
+import io.reactivex.rxjava3.core.ObservableSource;
|
|
|
+import io.reactivex.rxjava3.core.Observer;
|
|
|
+import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
+import io.reactivex.rxjava3.functions.Function;
|
|
|
+import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
+
|
|
|
/**
|
|
|
* 创建日期:2022/5/26 10:09
|
|
|
*
|
|
@@ -180,6 +196,102 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void getTalentStyle() {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.putOpt("platform", "android");
|
|
|
+ jsonObject.putOpt("version", "1");
|
|
|
+ jsonObject.putOpt("page", 1);
|
|
|
+ jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Observable<BaseResponse<HomeStyleBean>> observable = create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString()));
|
|
|
+ Observable<BaseResponse<ArrayList<TempLiveTeacherListBean>>> tempLiveObservable = create(APIService.class).getTempLiveList();
|
|
|
+ tempLiveObservable.flatMap(new Function<BaseResponse<ArrayList<TempLiveTeacherListBean>>, ObservableSource<BaseResponse<HomeStyleBean>>>() {
|
|
|
+ @Override
|
|
|
+ public ObservableSource<BaseResponse<HomeStyleBean>> apply(BaseResponse<ArrayList<TempLiveTeacherListBean>> arrayListBaseResponse) throws Throwable {
|
|
|
+ return observable.map(new Function<BaseResponse<HomeStyleBean>, BaseResponse<HomeStyleBean>>() {
|
|
|
+ @Override
|
|
|
+ public BaseResponse<HomeStyleBean> apply(BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) throws Throwable {
|
|
|
+ Log.i("pq", "匹配直播线程:" + Thread.currentThread().getName());
|
|
|
+ if (arrayListBaseResponse != null) {
|
|
|
+ ArrayList<TempLiveTeacherListBean> data = arrayListBaseResponse.getData();
|
|
|
+ if (data != null && data.size() > 0) {
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ TempLiveTeacherListBean tempLiveTeacherListBean = data.get(i);
|
|
|
+ if (homeStyleBeanBaseResponse != null && homeStyleBeanBaseResponse.getData() != null && homeStyleBeanBaseResponse.getData().rows != null && homeStyleBeanBaseResponse.getData().rows.size() > 0) {
|
|
|
+ for (int j = 0; j < homeStyleBeanBaseResponse.getData().rows.size(); j++) {
|
|
|
+ HomeStyleBean.RowsBean rowsBean = homeStyleBeanBaseResponse.getData().rows.get(j);
|
|
|
+ if (TextUtils.equals(tempLiveTeacherListBean.teacherId, String.valueOf(rowsBean.id))) {
|
|
|
+ Log.i("pq", "匹配直播老师id:" + tempLiveTeacherListBean.teacherId);
|
|
|
+ rowsBean.liveCoverImg = tempLiveTeacherListBean.liveCoverImg;
|
|
|
+ rowsBean.liveTitle = tempLiveTeacherListBean.liveTitle;
|
|
|
+ rowsBean.roomUid = tempLiveTeacherListBean.roomUid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.i("pq", "直播列表为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return homeStyleBeanBaseResponse;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).subscribeOn(Schedulers.newThread())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new Observer<BaseResponse<HomeStyleBean>>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(@NonNull Disposable d) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(@NonNull BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) {
|
|
|
+ if (getView() != null && homeStyleBeanBaseResponse != null) {
|
|
|
+ getView().getStylePageSuccess(homeStyleBeanBaseResponse.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
+ if (getView() != null) {
|
|
|
+ getView().onError(e);
|
|
|
+ getView().hideLoading();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+ if (getView() != null) {
|
|
|
+ getView().hideLoading();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // addSubscribe(create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomeStyleBean>(getView()) {
|
|
|
+// @Override
|
|
|
+// protected void onSuccess(HomeStyleBean data) {
|
|
|
+// if (getView() != null) {
|
|
|
+// getView().getStylePageSuccess(data);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onComplete() {
|
|
|
+// super.onComplete();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onError(Throwable e) {
|
|
|
+// super.onError(e);
|
|
|
+//
|
|
|
+// }
|
|
|
+// });
|
|
|
+ }
|
|
|
+
|
|
|
public void queryUserInfo() {
|
|
|
addSubscribe(create(APIService.class).queryUserInfo(), new BaseObserver<StudentUserInfo>(getView()) {
|
|
|
@Override
|
|
@@ -192,8 +304,6 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public void queryCountOfUnread() {
|
|
|
|
|
|
addSubscribe(create(APIService.class).queryCountOfUnread(), new BaseObserver<List<CountOfUnreadBean>>(getView()) {
|
|
@@ -210,7 +320,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
|
|
|
/**
|
|
|
* 获取热门曲目
|
|
|
*/
|
|
|
- public void getHotMusicSheetList(){
|
|
|
+ public void getHotMusicSheetList() {
|
|
|
if (getView() != null) {
|
|
|
getView().showLoading();
|
|
|
}
|
|
@@ -233,7 +343,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
|
|
|
/**
|
|
|
* 获取推荐达人列表
|
|
|
*/
|
|
|
- public void getRecommendTalentList(){
|
|
|
+ public void getRecommendTalentList() {
|
|
|
addSubscribe(create(APIService.class).getRecommendTalentList(), new BaseObserver<ArrayList<RecommendTalentListBean>>(getView()) {
|
|
|
@Override
|
|
|
protected void onSuccess(ArrayList<RecommendTalentListBean> data) {
|