diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 97998d2db..f7a1e1060 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -115,6 +115,17 @@ public interface PDLiveApi { @Query("num") String num ); + /** + * 直播间上下滚动列表 + * + * @param num 请求数量 + * @return + */ + @GET("/api/public/?service=Home.anchorRecommend ") + Observable> anchorRecommend( + @Query("num") String num, @Query("type") String type + ); + /** * 获取直播间信息 * @@ -150,6 +161,7 @@ public interface PDLiveApi { */ @GET("/api/public/?service=Active.getActiveList") Observable>> getActiveList(); + /** * 获取活动 */ @@ -158,14 +170,16 @@ public interface PDLiveApi { /** * 获取日榜、周榜数据 + * * @param uid 直播间id,并非用户uid * @return 榜单结构 */ @GET("/api/public/?service=Contribute.index") - Observable> getRanksList(@Query("uid")String uid); + Observable> getRanksList(@Query("uid") String uid); /** * 直播间新人特惠信息 + * * @return 新人特惠数据 */ @GET("/api/public/?service=Live.newUserPreferential") diff --git a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java index 72f572e39..3dd5ca9b3 100644 --- a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java @@ -112,6 +112,28 @@ public class MainNetManager { }).isDisposed(); } + /** + * 猜你喜欢 + * + * @param num 请求数量 + * @return + */ + public void anchorRecommendType(String num, HttpCallback httpCallback) { + API.get().pdLiveApi(mContext).anchorRecommend(num, "1") + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(anchorRecommendModelResponseModel -> { + if (httpCallback != null) { + AnchorRecommendModel model = anchorRecommendModelResponseModel.getData().getInfo(); + httpCallback.onSuccess(model); + } + }, throwable -> { + if (httpCallback != null) { + httpCallback.onError(throwable.getMessage()); + } + }).isDisposed(); + } + /** * 搜索 * diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 903b70d5e..761ebb78a 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -71,7 +71,6 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import cn.rongcloud.rtc.api.RCRTCEngine; @@ -187,38 +186,12 @@ public class LiveAudienceActivity extends LiveActivity { * 初始化数据 */ private void initData() { - //直播间列表 - MainNetManager.get(mContext) - .anchorRecommend("30", new com.yunbao.common.http.base.HttpCallback() { - @Override - public void onSuccess(AnchorRecommendModel data) { - itemModelList = data.getList(); - //查询直播间状态 - int index = -1; - for (int i = 0; i < itemModelList.size(); i++) { - AnchorRecommendItemModel model = itemModelList.get(i); - if (TextUtils.equals(mLiveBean.getUid(), model.getUid())) { - index = i; - } - } - if (index > -1) { - Collections.swap(itemModelList, index, 0); - } else { - String json = GsonUtils.toJson(mLiveBean); - AnchorRecommendItemModel model = GsonUtils.fromJson(json, AnchorRecommendItemModel.class); - itemModelList.add(0, model); - } - mPagerAdapter = new VerticalPagerAdapter(itemModelList, mContext); - verticalViewPager.setAdapter(mPagerAdapter); - loadingView.hide(); - } - - @Override - public void onError(String error) { - } - }); - - + String json = GsonUtils.toJson(mLiveBean); + AnchorRecommendItemModel model = GsonUtils.fromJson(json, AnchorRecommendItemModel.class); + itemModelList.add(0, model); + mPagerAdapter = new VerticalPagerAdapter(itemModelList, mContext); + verticalViewPager.setAdapter(mPagerAdapter); + loadingView.hide(); verticalViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -226,10 +199,12 @@ public class LiveAudienceActivity extends LiveActivity { Log.e(TAG, "mCurrentItem:" + mCurrentItem); if (mCurrentItem == itemModelList.size() - 1) { MainNetManager.get(mContext) - .anchorRecommend("30", new com.yunbao.common.http.base.HttpCallback() { + .anchorRecommendType("30", new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(AnchorRecommendModel data) { - + if (TextUtils.equals(data.getList().get(0).getUid(), mLiveBean.getUid())) { + data.getList().remove(0); + } itemModelList.addAll(data.getList()); mPagerAdapter.notifyDataSetChanged(); } @@ -827,11 +802,15 @@ public class LiveAudienceActivity extends LiveActivity { url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; Log.i("tag", url); - Intent intent=new Intent(mContext,ZhuangBanActivity.class); + Intent intent = new Intent(mContext, ZhuangBanActivity.class); intent.putExtra("url", url); - intent.putExtra("isFull",true); + intent.putExtra("isFull", true); mContext.startActivity(intent); break; + case LIVE_ROOM_EXCEPTION: + //主播未直播时自动下滑至下一个直播间 + verticalViewPager.setCurrentItem(mCurrentPage + 1); + break; } diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index c73e74afc..758192c40 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -59,7 +59,8 @@ public class LiveAudienceEvent extends BaseModel { EFFECTS_SETTINGS(10, "特效設置"), WISH_LIST(11, "心愿单"), OPEN_PARAMETERS(12, "开放参数"), - ACTIVITY_CENTER(13, "活動中心"); + ACTIVITY_CENTER(13, "活動中心"), + LIVE_ROOM_EXCEPTION(14, "直播间异常"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java index 14be245be..5531a0158 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java @@ -9,12 +9,14 @@ import com.alibaba.fastjson.JSONObject; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.MD5Util; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.bean.LiveBean; +import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; @@ -76,6 +78,8 @@ public class LiveRoomCheckLivePresenter { } } } else { + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_ROOM_EXCEPTION)); ToastUtil.show(msg); } } @@ -119,7 +123,7 @@ public class LiveRoomCheckLivePresenter { } } }); - }else { + } else { enterLiveRoom(); isRoom = false; }