diff --git a/common/src/main/java/com/yunbao/common/http/API.java b/common/src/main/java/com/yunbao/common/http/API.java index 06c72a665..02c5c12ba 100644 --- a/common/src/main/java/com/yunbao/common/http/API.java +++ b/common/src/main/java/com/yunbao/common/http/API.java @@ -63,9 +63,9 @@ public class API extends BaseApi { loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Builder builder = new OkHttpClient() .newBuilder() + .addInterceptor(initQuery(isNeedUid,CommonAppContext.sInstance.getApplicationContext())) .addInterceptor(loggingInterceptor); - return create(builder.build(), GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class); } 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 22ca82f36..3c537b0e1 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -324,11 +324,12 @@ public interface PDLiveApi { @Query("GroupId") String GroupId, @Query("stream") String stream ); + /** * 加入房间推送Im欢迎语 */ @GET("/api/public/?service=Tx.leaveRoomNew") - Observable> leaveRoomNew( + Observable>> leaveRoomNew( @Query("GroupId") String GroupId, @Query("stream") String stream ); diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index b0eb06fd9..dc74d3fc9 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -25,6 +25,7 @@ import com.yunbao.common.http.base.HttpCallback; import java.util.List; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -361,14 +362,17 @@ public class LiveNetManager { * @param city * @param callback */ + private Disposable enterRoomDisposable = null; + public void enterRoomNew(String stream, String liveUid, String city, HttpCallback callback) { - API.get().pdLiveApi(mContext) + enterRoomDisposable = API.get().pdLiveApi(mContext) .enterRoomNew("g" + liveUid, stream, liveUid, city) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>() { @Override public void accept(ResponseModel enterRoomNewModelResponseModel) throws Exception { + enterRoomDisposable = null; if (callback != null) { callback.onSuccess(enterRoomNewModelResponseModel.getData().getInfo()); } @@ -376,11 +380,12 @@ public class LiveNetManager { }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { + enterRoomDisposable = null; if (callback != null) { callback.onError(throwable.getMessage()); } } - }).isDisposed(); + }); } /** @@ -389,22 +394,24 @@ public class LiveNetManager { * @param stream * @param liveUid */ + private Disposable userJoinDisposable = null; + public void userJoinRoomNew(String stream, String liveUid) { - API.get().pdLiveApi(mContext) + userJoinDisposable = API.get().pdLiveApi(mContext) .userJoinRoomNew("g" + liveUid, stream) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>() { @Override public void accept(ResponseModel stringResponseModel) throws Exception { - + userJoinDisposable = null; } }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { - + userJoinDisposable = null; } - }).isDisposed(); + }); } /** @@ -413,16 +420,16 @@ public class LiveNetManager { * @param stream * @param liveUid */ - public void leaveRoomNew(String stream, String liveUid,HttpCallback callback) { + public void leaveRoomNew(String stream, String liveUid, HttpCallback callback) { API.get().pdLiveApi(mContext) - .userJoinRoomNew("g" + liveUid, stream) + .leaveRoomNew("g" + liveUid, stream) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Consumer>() { + .subscribe(new Consumer>>() { @Override - public void accept(ResponseModel stringResponseModel) throws Exception { + public void accept(ResponseModel> listResponseModel) throws Exception { if (callback != null) { - callback.onSuccess(""); + callback.onError(""); } } }, new Consumer() { @@ -434,4 +441,16 @@ public class LiveNetManager { } }).isDisposed(); } + + /** + * 直播间取消网络请求 + */ + public void cancelLive() { + if (userJoinDisposable != null) { + userJoinDisposable.dispose(); + } + if (enterRoomDisposable != null) { + enterRoomDisposable.dispose(); + } + } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 67bbbc824..696f41a63 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -850,6 +850,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mChatRecyclerView.setLayoutManager(layoutManager); mChatRecyclerView.addItemDecoration(new TopGradual()); mLiveChatAdapter = new LiveChatAdapter(mContext); + mChatRecyclerView.setAdapter(mLiveChatAdapter); mLiveChatAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(LiveChatBean bean, int position) { @@ -878,7 +879,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } }); - mChatRecyclerView.setAdapter(mLiveChatAdapter); + mChatRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index b0b18de41..886b3fffc 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -273,6 +273,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.setTitle(data.getTitle()); mLiveRoomViewHolder.setAnchorGoodNumber(data.getGoodNum()); mLiveRoomViewHolder.clearGuardIcon(); + mLiveRoomViewHolder.clearChat(); mLiveRoomViewHolder.releaseGift(); mLiveRyLinkMicPkPresenter.setLiveUid(data.getUid(), ""); mSocketRyClient = new SocketRyClient(mLiveBean.getUid(), PortraitLiveManager.this); @@ -294,7 +295,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe .enterRoomNew(mLiveBean.getStream(), mLiveBean.getUid(), mLiveBean.getCity(), new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(EnterRoomNewModel data) { - mLiveRoomViewHolder.clearChat(); + isEnterRoom = true; //加入房间发送Im消息 LiveNetManager.get(mContext).userJoinRoomNew(mLiveBean.getStream(), mLiveBean.getUid()); @@ -527,6 +528,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onRemove(boolean isQuit) { + LiveNetManager.get(mContext).cancelLive(); LiveHttpUtil.cancel(LiveHttpConsts.CHECK_LIVE); LiveHttpUtil.cancel(LiveHttpConsts.ENTER_ROOM); LiveHttpUtil.cancel(LiveHttpConsts.ROOM_CHARGE);