From 202aedbcf32addc4fe20d6165ed450ba92496efe Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 23 Nov 2022 14:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E4=BA=BA=E8=BF=9E?= =?UTF-8?q?=E9=BA=A6=E4=B8=BB=E6=92=AD=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/bean/LinkMicUserBean.java | 67 +++ .../com/yunbao/common/http/PDLiveApi.java | 14 +- .../bg_anchor_mic_info_btn_invite.xml | 9 + .../drawable/bg_anchor_mic_info_btn_ok.xml | 9 + .../main/res/mipmap-xxhdpi/btn_icon_quit.png | Bin 0 -> 2064 bytes common/src/main/res/values-en/strings.xml | 1 + common/src/main/res/values/strings.xml | 2 + .../live/activity/LiveRyAnchorActivity.java | 56 ++- .../adapter/AnchorUserMicInfoAdapter.java | 234 ++++++++++ .../com/yunbao/live/bean/MicUserBean.java | 9 + .../dialog/LiveMicAnchorDialogFragment.java | 407 ++++++++++++++++++ .../dialog/LiveMicUserDialogFragment.java | 3 + .../yunbao/live/event/LiveAudienceEvent.java | 4 + .../yunbao/live/socket/SocketRyClient.java | 20 + .../yunbao/live/views/LiveEndViewHolder.java | 20 +- .../res/drawable/bg_live_anchor_open_mic.xml | 9 + .../main/res/layout/anchor_open_mic_view.xml | 50 +++ .../res/layout/dialog_anchor_mic_list.xml | 94 ++++ .../main/res/layout/item_anchor_mic_info.xml | 150 +++++++ live/src/main/res/layout/no_more_mic_view.xml | 1 + 20 files changed, 1151 insertions(+), 8 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/LinkMicUserBean.java create mode 100644 common/src/main/res/drawable/bg_anchor_mic_info_btn_invite.xml create mode 100644 common/src/main/res/drawable/bg_anchor_mic_info_btn_ok.xml create mode 100644 common/src/main/res/mipmap-xxhdpi/btn_icon_quit.png create mode 100644 live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java create mode 100644 live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java create mode 100644 live/src/main/res/drawable/bg_live_anchor_open_mic.xml create mode 100644 live/src/main/res/layout/anchor_open_mic_view.xml create mode 100644 live/src/main/res/layout/dialog_anchor_mic_list.xml create mode 100644 live/src/main/res/layout/item_anchor_mic_info.xml diff --git a/common/src/main/java/com/yunbao/common/bean/LinkMicUserBean.java b/common/src/main/java/com/yunbao/common/bean/LinkMicUserBean.java new file mode 100644 index 000000000..b677d931e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/LinkMicUserBean.java @@ -0,0 +1,67 @@ +package com.yunbao.common.bean; + +public class LinkMicUserBean extends BaseModel { + private String uname; + private String avatar; + private String dress_avatar; + private String uid = ""; + private String action; + private int level; + private int sex; + + public String getUname() { + return uname; + } + + public void setUname(String uname) { + this.uname = uname; + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getDress_avatar() { + return dress_avatar; + } + + public void setDress_avatar(String dress_avatar) { + this.dress_avatar = dress_avatar; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } +} 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 8ebe3d505..a77531577 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -268,5 +268,17 @@ public interface PDLiveApi { * PK排位赛接口 */ @GET("/api/public/?service=Ranking.getAnchorRankData") - Observable> getPkRanksList(@Query("anchor_id") String anchorId,@Query("anchor_id2")String pkUid); + Observable> getPkRanksList(@Query("anchor_id") String anchorId,@Query("anchor_id2")String pkUid); /** + * PK排位赛接口 + */ + @GET("/api/public/?service=Live.createDrLm") + Observable> createDrLm(); + /* PK排位赛接口 + */ + @GET("/api/public/?service=Live.delDrLm") + Observable> delDrLm(); + /* PK排位赛接口 + */ + @GET("/api/public/?service=Live.killDrLm") + Observable> killDrLm(@Query("uid")String uid,@Query("roomid")String roomId); } diff --git a/common/src/main/res/drawable/bg_anchor_mic_info_btn_invite.xml b/common/src/main/res/drawable/bg_anchor_mic_info_btn_invite.xml new file mode 100644 index 000000000..ee73ee2f4 --- /dev/null +++ b/common/src/main/res/drawable/bg_anchor_mic_info_btn_invite.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/drawable/bg_anchor_mic_info_btn_ok.xml b/common/src/main/res/drawable/bg_anchor_mic_info_btn_ok.xml new file mode 100644 index 000000000..2db049480 --- /dev/null +++ b/common/src/main/res/drawable/bg_anchor_mic_info_btn_ok.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/mipmap-xxhdpi/btn_icon_quit.png b/common/src/main/res/mipmap-xxhdpi/btn_icon_quit.png new file mode 100644 index 0000000000000000000000000000000000000000..796ff75b6b345c7fe8c81f4c8c09ae97b8a44777 GIT binary patch literal 2064 zcmX9;30P8D8zytf!liXeO{+=E_JvB#CCw%m+(;Y4N;8}MwZ+n`?9XztCNj%3&8!@2 zD$V>Y1;ix?Eky|h5jSu_MGX)U;c|fsI#>Sloco>kd%y3z=e_qi&&34?9yVKOwGe?o znECp6W8f7#_biwXM~mc&9q?j!)-%8pfv9-ANPEf%&gUg!4tpWW+iZjggh5a+I`q)t z1hi5G&FY5|gp{C0Kj#=Yg(Cpyu@X`$l_029f?7}o=>Z%;rBbU@X~F+@>bHa7EZm@0 zYhY3@2v@ZV1*B3z0H6U?S_pywPzz{aeOOJSRKpEA7yv4GsuZxe3g#hLRt~CRZ*VGC zt6{at$w@%1owEcV3c@_3($2!X9E6o&pj9d%KsnbBmlQCmHvnT8@OZN-l}@F%3h$N6 z)%w%t-gnNYTHg!{sNK_w;gmd;3J< z$=cdF0)c?X<4L6IDH+g0|1roP>E-sx6<|vXoj@Q8MG}Evyt=xksfji;B&e(VGAW&= zQtKIv*00q1n%de4$&^$omrW~$LJ5WPmB;IEXLE*!M<*n*FJH(L6H@7vqJMx-Bv#4g zAf3*bmMi-Qhj_e!#zvX~P_fw@u~^Dtv1zmxK&c-8DV~xkIyyRgdU-8$#uqZVxtTsT zE*=~lg1=8!cW-BB_t?0wxw&O@Oh_hE+S@y*^$qY)j}{+??^#?DCh!Qt*kK8W&reZSX+EsRYNH8bVBeZ9%`|QB0w4#(kK3C)fUv{Cd zw`XYhx5nqfh^43##KgA8_sac{%yZ{E7%G)3Pl0 zWwp}Z|JlWT)3r@V;m(|T<%=m`^gXXhTq=g_BOShuw>?i}KFE5>F{`b8RgB)SSMupp zeu3^qV1A&atYc4U$WzRVtDW(3BsFJkP{ge+8#A}-5f`}T#-F2;-;Q4Je?RiaS(~<{ z_2nap=4WFzZ`iQ>*zE&(Z`R-Cv$I3ZEPZpZm{NodczNB%VD-mK>HN&nbh9EK>m{Mq zIF`{F2!?Ie%?GP*}<(o(M{`9rTQT}G}jBEIbldU?|;GaxA3)7&iY zp=IsLv%yYRTkm!7PdszAdT?+LhUCO`6Rdi`5)co4rvFoS=StX~JBPns#AmwAG~QZ^ zCX*u{R+kyZzIVyOUiMtp-@%)uE?)Z!PF_JDUGm5|z(DfVkp2l-jM|;yjz1ydBwu>E zJ_TCUWeXt9td6_d2~0lRjN=p;EhNOtw}lD72YjIv9Mf`?{7Qbduu+z@RZ%rsm_LR?z%{AW4x_7Bqc?EaCD>(2DuNE*W3c+owLDzexr780Rf^YKoGmnknt;MUdgG$s7Cp@= z;riUk+qNOIv!3mCxDsQ34qEp&-9PV~Q#b({8;*tnwaKI11ul$)9 zfB*DT_Y&v#&msy@#jMx<1tX?M-NWd=yPrAFObKahs%Mzn3m!3?&iL1_XkdZ`Z{9^E zY7STBB;h&{CfqkyP7IKK*yuKqLy9koc6HhY p+$!8T8R&tH7sau~R)U&Ygy=#PxBA4=bof_`@I4ghUG5e2=fBZBApplyMic Cancel Mic + Close Mic Quit Mic Birthday Gender diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 1ba3b46b0..96b1d70fb 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -70,6 +70,7 @@ 性別 申请連麥 取消申請 + 關閉連麥 退出連麥 所在地 編輯個人資料 @@ -617,6 +618,7 @@ 魅力榜 豪氣榜 當前沒有人在語音連麥中 + 語音連麥未開啟 網絡請求失敗 請檢查網絡連接後重試~ 加載中 diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 18749ed6a..600c7c318 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -39,6 +39,7 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.dialog.NotCancelableDialog; @@ -56,6 +57,7 @@ import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.LogUtil; import com.yunbao.common.utils.ScreenDimenUtil; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.faceunity.FaceManager; @@ -63,7 +65,9 @@ import com.yunbao.live.R; import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.live.bean.LiveUserGiftBean; import com.yunbao.live.dialog.LiveLinkMicListDialogFragment; +import com.yunbao.live.dialog.LiveMicAnchorDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; import com.yunbao.live.dialog.LiveNewWishListDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; @@ -91,7 +95,9 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.io.File; +import java.util.ArrayList; import java.util.List; +import java.util.TreeMap; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; @@ -142,7 +148,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 private FaceManager manager; - + private TreeMap mMicQueueList = new TreeMap<>(); + private List mAudienceList = new ArrayList<>(); @Override protected int getLayoutId() { @@ -231,6 +238,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl */ int mrr = 0; public int leave = 0; + private LiveMicAnchorDialogFragment.OnMicListener micListener = null; @Override public void onClick(int functionID) { @@ -239,7 +247,18 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl ToastUtil.show("開發中,敬請期待"); break; case Constants.LIVE_FUNC_MIC://語音 - ToastUtil.show("開發中,敬請期待"); + //ToastUtil.show("開發中,敬請期待"); + + LiveMicAnchorDialogFragment fragment = new LiveMicAnchorDialogFragment(); + Bundle bundle = new Bundle(); + bundle.putString(Constants.LIVE_UID, mLiveUid); + bundle.putString(Constants.STREAM, mStream); + bundle.putString("By", "1"); + fragment.setArguments(bundle); + micListener = fragment.getMicListener(); + fragment.setMicQueueList(mMicQueueList); + fragment.setAudienceList(mAudienceList); + fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveMicAnchorDialogFragment"); break; case Constants.LIVE_FUNC_DR://多人PK if (isDRPK != 1) { @@ -1301,6 +1320,39 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl leaveLive(); } break; + case LINK_MIC: + if(!StringUtil.isEmpty(((LinkMicUserBean) event.getObject()).getUid())) { + mMicQueueList.put(((LinkMicUserBean) event.getObject()).getUid(), (LinkMicUserBean) event.getObject()); + } + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + } + break; + case LINK_MIC_CANCEL: + mMicQueueList.remove(((LinkMicUserBean) event.getObject()).getUid()); + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + } + break; + case LINK_MIC_UPDATE_MIC_LIST: + List list = (List) event.getObject(); + mMicQueueList.clear(); + for (LinkMicUserBean bean : list) { + if(!StringUtil.isEmpty(bean.getUid())) { + mMicQueueList.put(bean.getUid(), bean); + } + } + if (micListener != null) { + micListener.updateMicList(mMicQueueList); + } + break; + case LINK_MIC_UPDATE_AUDIENCE_LIST: + mAudienceList = (List) event.getObject(); + if (micListener != null) { + micListener.updateAudienceList(mAudienceList); + } + break; } } + } diff --git a/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java new file mode 100644 index 000000000..bef0e705e --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/AnchorUserMicInfoAdapter.java @@ -0,0 +1,234 @@ +package com.yunbao.live.adapter; + +import android.content.Context; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.opensource.svgaplayer.SVGADrawable; +import com.opensource.svgaplayer.SVGAImageView; +import com.opensource.svgaplayer.SVGAParser; +import com.opensource.svgaplayer.SVGAVideoEntity; +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.Constants; +import com.yunbao.common.adapter.RefreshAdapter; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LevelBean; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.API; +import com.yunbao.common.http.ResponseModel; +import com.yunbao.common.utils.CommonIconUtil; +import com.yunbao.common.utils.SVGAViewUtils; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.bean.MicUserBean; +import com.yunbao.live.event.LiveRoomChangeEvent; +import com.yunbao.live.socket.SocketSendBean; + +import org.greenrobot.eventbus.EventBus; + +import java.net.MalformedURLException; +import java.net.URL; + +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.message.TextMessage; + +public class AnchorUserMicInfoAdapter extends RefreshAdapter { + public static final int TYPE_MIC_LIST = 1;//连麦列表 + public static final int TYPE_MIC_REQUEST = 2;//请求连麦 + public static final int TYPE_MIC_INVITE = 3;//邀请连麦 + + private AbsDialogFragment fragments; + private String mLiveUid; + + public AnchorUserMicInfoAdapter(Context context, AbsDialogFragment fragment) { + super(context); + this.fragments = fragment; + } + + + @Override + public int getItemViewType(int position) { + + return position; + } + + public void setLiveUid(String mLiveUid) { + this.mLiveUid = mLiveUid; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + return new AnchorUserMicInfoAdapter.Vh(mInflater.inflate(R.layout.item_anchor_mic_info, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder vh, int position) { +// vh.setIsRecyclable(false); + ((AnchorUserMicInfoAdapter.Vh) vh).setData(mList.get(position), position); + + } + + @Override + public int getItemCount() { + return mList.size(); + } + + + class Vh extends RecyclerView.ViewHolder { + ImageView mAvatar; + TextView mName; + ImageView mSex; + ImageView mLevel; + ImageView mClose; + SVGAImageView gift_svga; + Button mBtn; + + public Vh(@NonNull View itemView) { + super(itemView); + mAvatar = (ImageView) itemView.findViewById(R.id.avatar); + mName = (TextView) itemView.findViewById(R.id.name); + mSex = (ImageView) itemView.findViewById(R.id.sex); + mLevel = (ImageView) itemView.findViewById(R.id.level); + gift_svga = (SVGAImageView) itemView.findViewById(R.id.gift_svga); + mBtn = itemView.findViewById(R.id.mic_btn); + mClose = itemView.findViewById(R.id.mic_exit); + mBtn.setOnClickListener(v -> { + if (v.getTag() != null) { + MicUserBean tag = (MicUserBean) v.getTag(); + if(tag.getType()==TYPE_MIC_REQUEST) { + applyMic(tag, 4,createSocketSendBean()); + }else if(tag.getType()==TYPE_MIC_INVITE){ + SocketSendBean bean = createSocketSendBean().param("targetId", tag.getId()); + applyMic(tag, 1,bean); + } + } + }); + mClose.setOnClickListener(v -> { + if (v.getTag() != null) { + API.get().createPDLiveApi(true) + .killDrLm(((MicUserBean) v.getTag()).getId(), mLiveUid) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel stringResponseModel) throws Exception { + applyMic((MicUserBean) v.getTag(), 8,createSocketSendBean()); + } + }, Throwable::printStackTrace).isDisposed(); + + } + }); + } + SocketSendBean createSocketSendBean(){ + return new SocketSendBean() + .param("_method_", Constants.LIAN_MAI) + .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("uid", CommonAppConfig.getInstance().getUid()); + } + void applyMic(MicUserBean bean, int action,SocketSendBean msg) { + msg.param("action", action); + msg.create(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(bean.getId(), conversationType, messageContent); + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + errorCode.toString()); + } + }); + } + + void setData(final MicUserBean bean, int position) { + + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ((LiveActivity) mContext).showUserDialog(bean.getId()); + fragments.dismiss(); + } + }); + mClose.setTag(bean); + mBtn.setTag(bean); + switch (bean.getType()) { + case TYPE_MIC_LIST: + mClose.setVisibility(View.VISIBLE); + mBtn.setVisibility(View.GONE); + break; + case TYPE_MIC_REQUEST: + case TYPE_MIC_INVITE: + mClose.setVisibility(View.GONE); + mBtn.setVisibility(View.VISIBLE); + break; + } + if (bean.getType() == TYPE_MIC_REQUEST) { + mBtn.setText("同意"); + mBtn.setBackgroundResource(R.drawable.bg_anchor_mic_info_btn_ok); + } else if (bean.getType() == TYPE_MIC_INVITE) { + mBtn.setText("邀请"); + mBtn.setBackgroundResource(R.drawable.bg_anchor_mic_info_btn_invite); + } + ImgLoader.display(mContext, bean.getAvatar(), mAvatar); + if (bean.getDress_avatar() != null) { + if (bean.getDress_avatar().contains("svga")) { + try { + new SVGAParser(mContext).parse(new URL(bean.getDress_avatar()), new SVGAParser.ParseCompletion() { + @Override + public void onComplete(SVGAVideoEntity videoItem) { + SVGADrawable drawable = new SVGADrawable(videoItem); + gift_svga.setImageDrawable(drawable); + SVGAViewUtils.playEndClear(gift_svga); + } + + @Override + public void onError() { + } + }); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } else { + ImgLoader.display(mContext, bean.getDress_avatar(), gift_svga); + } + } + + mName.setText(bean.getUserNiceName()); + + mSex.setImageResource(CommonIconUtil.getSexIcon(bean.getSex())); + LevelBean levelBean = CommonAppConfig.getInstance().getLevel(bean.getLevel()); + if (levelBean != null) { + ImgLoader.display(mContext, levelBean.getThumb(), mLevel); + } + } + } + + +} diff --git a/live/src/main/java/com/yunbao/live/bean/MicUserBean.java b/live/src/main/java/com/yunbao/live/bean/MicUserBean.java index 6e4faec8e..c2d7b9d0c 100644 --- a/live/src/main/java/com/yunbao/live/bean/MicUserBean.java +++ b/live/src/main/java/com/yunbao/live/bean/MicUserBean.java @@ -9,6 +9,7 @@ public class MicUserBean { protected int level; protected int sex; protected String dress_avatar; + protected int type; @JSONField(name = "dress_avatar") public String getDress_avatar() { @@ -65,4 +66,12 @@ public class MicUserBean { public void setAvatar(String avatar) { this.avatar = avatar; } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } } diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java new file mode 100644 index 000000000..23b1b9fb5 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/LiveMicAnchorDialogFragment.java @@ -0,0 +1,407 @@ +package com.yunbao.live.dialog; + +import static com.yunbao.live.views.LivePlayRyViewHolder.Micing; + +import android.app.ActionBar; +import android.app.Dialog; +import android.graphics.Color; +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.yunbao.common.Constants; +import com.yunbao.common.adapter.RefreshAdapter; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LinkMicUserBean; +import com.yunbao.common.custom.CommonRefreshView; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.http.API; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.ResponseModel; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveActivity; +import com.yunbao.live.adapter.AnchorUserMicInfoAdapter; +import com.yunbao.live.bean.LiveGuardInfo; +import com.yunbao.live.bean.LiveUserGiftBean; +import com.yunbao.live.bean.MicUserBean; +import com.yunbao.live.http.LiveHttpUtil; +import com.yunbao.live.utils.LiveImDeletUtil; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.TreeMap; + +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; + +/** + * 连麦列表 + * 主播端 + */ +public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements View.OnClickListener { + + private CommonRefreshView mRefreshView; + private View view_no; + private AnchorUserMicInfoAdapter userMicInfoAdapter; + private String mLiveUid; + private String stream; + private LiveGuardInfo mLiveGuardInfo; + public static LiveActivity activity = null; + public eightbitlab.com.blurview.BlurView blurView; + + public TextView listMicbtn, requestMicBtn, inviteMicBtn, mDisconnectMic; + private TextView mNoMoreDesc; + private String Tips = "1"; + private String type = "guanzhong"; + View mOpenMicLayout, no_more; + View mOpenMicBtn; + private TreeMap mMicQueueList = new TreeMap<>(); + private List mAudienceList = new ArrayList<>(); + private LiveImDeletUtil liveImDeletUtil; + private OnMicListener micListener; + + @Override + protected int getLayoutId() { + return R.layout.dialog_anchor_mic_list; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + params.width = ActionBar.LayoutParams.MATCH_PARENT; + params.height = DpUtil.dp2px(460); + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + public void setLiveGuardInfo(LiveGuardInfo info) { + mLiveGuardInfo = info; + } + + public void setMicQueueList(TreeMap mMicQueueList) { + this.mMicQueueList = mMicQueueList; + } + + public void setAudienceList(List mAudienceList) { + this.mAudienceList = mAudienceList; + } + + public OnMicListener getMicListener() { + if (micListener == null) { + micListener = new OnMicListener() { + @Override + public void updateMicList(TreeMap list) { + mMicQueueList = list; + if ("2".equals(Tips)) { + mRefreshView.initData(); + } + } + + @Override + public void updateAudienceList(List list) { + mAudienceList = list; + if ("3".equals(Tips)) { + mRefreshView.initData(); + } + } + }; + } + return micListener; + } + + int nums = 0; + int pg = 1; + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + Bundle bundle = getArguments(); + if (bundle == null) { + return; + } + liveImDeletUtil = new LiveImDeletUtil(); + + mLiveUid = bundle.getString(Constants.LIVE_UID); + stream = bundle.getString(Constants.STREAM); + listMicbtn = mRootView.findViewById(R.id.audience_btn); + mOpenMicLayout = mRootView.findViewById(R.id.anchor_open_mic); + no_more = mRootView.findViewById(R.id.no_more); + mOpenMicBtn = mRootView.findViewById(R.id.open_mic); + mNoMoreDesc = mRootView.findViewById(R.id.no_more_desc); + Tips = bundle.getString("By"); + + listMicbtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!isOpenRoom()) { + return; + } + Tips = "1"; + Up(); + type = "guanzhong"; + mRefreshView.initData(); + } + }); + requestMicBtn = mRootView.findViewById(R.id.guard_btn); + requestMicBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!isOpenRoom()) { + return; + } + Tips = "2"; + Up(); + type = "guard"; + mRefreshView.initData(); + } + }); + inviteMicBtn = mRootView.findViewById(R.id.fans_btn); + inviteMicBtn.setVisibility(View.VISIBLE); + inviteMicBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!isOpenRoom()) { + return; + } + Tips = "3"; + Up(); + type = "fans"; + mRefreshView.initData(); + } + }); + mOpenMicBtn.setOnClickListener(v -> { + API.get().pdLiveApi(mContext) + .createDrLm() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel stringResponseModel) throws Exception { + mOpenMicLayout.setVisibility(View.GONE); + mRefreshView.setVisibility(View.VISIBLE); + mDisconnectMic.setVisibility(View.VISIBLE); + isOpenRoom = true; + mRefreshView.initData(); + } + }, Throwable::printStackTrace) + .isDisposed(); + }); + + mRefreshView = mRootView.findViewById(R.id.refreshView); + view_no = mRootView.findViewById(R.id.view_no); + mDisconnectMic = mRootView.findViewById(R.id.apply_btn); + mDisconnectMic.setBackgroundResource(R.drawable.background_eb6877); + mDisconnectMic.setText(R.string.close_mic); + mDisconnectMic.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + closeMic(); + + } + }); + userMicInfoAdapter = new AnchorUserMicInfoAdapter(mContext, LiveMicAnchorDialogFragment.this); + userMicInfoAdapter.setLiveUid(mLiveUid); + Up(); + mRefreshView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); + mRefreshView.setDataHelper(new CommonRefreshView.DataHelper() { + @Override + public RefreshAdapter getAdapter() { + userMicInfoAdapter.notifyDataSetChanged(); + return userMicInfoAdapter; + } + + @Override + public void loadData(int p, HttpCallback callback) { + Log.e("tag111", p + "ssss"); + LiveHttpUtil.getMicList(mLiveUid, p, callback); + pg = p; + if (p == 1) { + no_more.setVisibility(View.VISIBLE); + mRefreshView.setVisibility(View.GONE); + } + } + + @Override + public List processData(String[] info) { + Log.e("tag222", Tips + "ssss" + Micing); + JSONObject obj = JSON.parseObject(info[0]); + List data = new ArrayList<>(); + + if (Tips.equals("2")) { + for (String uid : mMicQueueList.keySet()) { + LinkMicUserBean userBean = mMicQueueList.get(uid); + MicUserBean bean = new MicUserBean(); + bean.setAvatar(userBean.getAvatar()); + bean.setId(uid); + bean.setUserNiceName(userBean.getUname()); + bean.setSex(userBean.getSex()); + bean.setDress_avatar(userBean.getDress_avatar()); + bean.setLevel(userBean.getLevel()); + bean.setType(AnchorUserMicInfoAdapter.TYPE_MIC_REQUEST); + data.add(bean); + } + } else if ("3".equals(Tips)) { + for (LiveUserGiftBean userBean : mAudienceList) { + MicUserBean bean = new MicUserBean(); + bean.setAvatar(userBean.getAvatar()); + bean.setId(userBean.getId()); + bean.setUserNiceName(userBean.getUserNiceName()); + bean.setSex(userBean.getSex()); + bean.setDress_avatar(userBean.getDress().getAvatar_frame()); + bean.setLevel(userBean.getLevel()); + bean.setType(AnchorUserMicInfoAdapter.TYPE_MIC_INVITE); + data.add(bean); + } + } else { + data = JSON.parseArray(obj.getString("userlist"), MicUserBean.class); + for (MicUserBean bean : data) { + bean.setType(AnchorUserMicInfoAdapter.TYPE_MIC_LIST); + } + if (data.size() != 0) { + data.remove(0); + } + } + if (data.size() > 0 && pg == 1) { + nums = 0; + view_no.setVisibility(View.GONE); + if (nums == 0) { + view_no.setVisibility(View.VISIBLE); + } + mRefreshView.mRecyclerView.getRecycledViewPool().setMaxRecycledViews(0, data.size()); + mRefreshView.setVisibility(View.VISIBLE); + no_more.setVisibility(View.GONE); + } + return data; + } + + @Override + public void onRefreshSuccess(List list, int listCount) { + + } + + @Override + public void onRefreshFailure() { + + } + + @Override + public void onLoadMoreSuccess(List loadItemList, int loadItemCount) { + Log.e("tag333", "是" + nums); + } + + @Override + public void onLoadMoreFailure() { + } + }); + mRefreshView.initData(); + initData(); + } + + @Override + public void onClick(View v) { + dismiss(); + } + + @Override + public void onDestroy() { + mLiveGuardInfo = null; + LiveHttpUtil.cancel("getUserLists"); + super.onDestroy(); + } + + void Up() { + if (Tips.equals("1")) { + listMicbtn.setTextColor(Color.parseColor("#fff6f7fb")); + requestMicBtn.setTextColor(Color.parseColor("#ff646464")); + inviteMicBtn.setTextColor(Color.parseColor("#ff646464")); + mNoMoreDesc.setText(R.string.no_more_mic); + type = "guanzhong"; + } else if (Tips.equals("2")) { + listMicbtn.setTextColor(Color.parseColor("#ff646464")); + requestMicBtn.setTextColor(Color.parseColor("#fff6f7fb")); + inviteMicBtn.setTextColor(Color.parseColor("#ff646464")); + mNoMoreDesc.setText("當前沒有人申請"); + type = "guard"; + } else if (Tips.equals("3")) { + listMicbtn.setTextColor(Color.parseColor("#ff646464")); + requestMicBtn.setTextColor(Color.parseColor("#ff646464")); + inviteMicBtn.setTextColor(Color.parseColor("#fff6f7fb")); + mNoMoreDesc.setText("當前沒有觀眾"); + type = "fans"; + } + } + + private boolean isOpenRoom = false; + + private void initData() { + LiveHttpUtil.getMicList(mLiveUid, 0, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + if (code != 0) { + mOpenMicLayout.setVisibility(View.VISIBLE); + mRefreshView.setVisibility(View.GONE); + no_more.setVisibility(View.GONE); + mDisconnectMic.setVisibility(View.INVISIBLE); + } else { + isOpenRoom = true; + } + } + }); + } + + private boolean isOpenRoom() { + return isOpenRoom; + } + + private void closeMic() { + DialogUitl.showSimpleDialog(mContext, "是否確認關閉語音連麥", new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + API.get().pdLiveApi(mContext) + .delDrLm() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel stringResponseModel) throws Exception { + System.out.println("stringResponseModel.getData() = " + stringResponseModel.getData()); + LiveMicAnchorDialogFragment.this.dismiss(); + } + }, Throwable::printStackTrace) + .isDisposed(); + } + }); + + } + + public interface OnMicListener { + void updateMicList(TreeMap list); + + void updateAudienceList(List list); + } + +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java index 18e98352f..0acd3643e 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveMicUserDialogFragment.java @@ -183,7 +183,10 @@ public class LiveMicUserDialogFragment extends AbsDialogFragment implements View .param("_method_", Constants.LIAN_MAI) .param("action", 3) .param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()) + .param("sex", CommonAppConfig.getInstance().getUserBean().getSex()) + .param("level", CommonAppConfig.getInstance().getUserBean().getLevel()) .param("avatar", CommonAppConfig.getInstance().getUserBean().getAvatar()) + .param("dress_avatar", CommonAppConfig.getInstance().getUserBean().getDress().getAvatar_frame()) .param("uid", CommonAppConfig.getInstance().getUid()); msg1.create(); 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 183e6bf26..b6d6b7c6b 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -189,6 +189,10 @@ public class LiveAudienceEvent extends BaseModel { PK_TWO_START(36, "双人PK开始"), PK_TWO_UPDATE_HEAD_DATA(37, "更新PK头像信息"), PK_TWO_END(38, "双人PK开始"), + LINK_MIC(39, "连麦"), + LINK_MIC_CANCEL(40, "取消连麦"), + LINK_MIC_UPDATE_MIC_LIST(41, "更新连麦列表"), + LINK_MIC_UPDATE_AUDIENCE_LIST(42, "更新观众/可邀请列表"), ; private int type; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 835d68fdd..b75ef4e28 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -16,6 +16,7 @@ import android.view.View; import android.widget.LinearLayout; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.yunbao.common.CommonAppConfig; @@ -23,6 +24,7 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.FansMedalBean; +import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.PkRankBean; import com.yunbao.common.bean.SocketModel; @@ -170,6 +172,10 @@ public class SocketRyClient { } else if (actions == 5) { JSONObject mic_data = map.getJSONObject("ct"); LiveRoomViewHolder.updataMicList(mic_data.getJSONArray("userlist")); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_MIC_LIST) + .setObject(JSONArray.parseArray(mic_data.getJSONArray("userlist").toString(),LinkMicUserBean.class)) + ); } else if (actions == 6) { ToastUtil.show("主播已關閉當前語音連麥功能"); LiveRoomViewHolder.updataCleanMic(); @@ -177,10 +183,24 @@ public class SocketRyClient { } else if (actions == 8) { ToastUtil.show("您已被移出多人語音連麥"); EventBus.getDefault().post("endMic"); + }else if(actions==3){ + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC) + .setObject(map.toJavaObject(LinkMicUserBean.class)) + ); + }else if (actions==7){//取消连麦 + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_CANCEL) + .setObject(map.toJavaObject(LinkMicUserBean.class)) + ); } break; case Constants.UP_USER_LIST: mListener.onUpUserList(map.getJSONObject("ct")); + EventBus.getDefault().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.LINK_MIC_UPDATE_AUDIENCE_LIST) + .setObject(JSON.parseArray(map.getJSONObject("ct").getString("userlist"), LiveUserGiftBean.class)) + ); break; case Constants.CARD: // LiveLinkMicPresenter.setHD(map.getString("ct")); diff --git a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java index 0ee9fb147..a0efdbaa6 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveEndViewHolder.java @@ -200,12 +200,22 @@ public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickList public static void upData(String votes, String length, int nums, String uname) { Log.e("收", votes + "votes" + length + "length" + nums + "nums"); if (type == LiveOfType.USER) { - liveDurationUser.setText(length); - liveNameUser.setText(uname); + if (liveDurationUser != null) { + liveDurationUser.setText(length); + } + if (liveNameUser != null) { + liveNameUser.setText(uname); + } } else { - liveDurationAnchor.setText(length); - liveVotes.setText(votes); - liveWatchNum.setText(StringUtil.toWan(nums)); + if (liveDurationAnchor != null) { + liveDurationAnchor.setText(length); + } + if (liveVotes != null) { + liveVotes.setText(votes); + } + if (liveWatchNum != null) { + liveWatchNum.setText(StringUtil.toWan(nums)); + } } } diff --git a/live/src/main/res/drawable/bg_live_anchor_open_mic.xml b/live/src/main/res/drawable/bg_live_anchor_open_mic.xml new file mode 100644 index 000000000..df73ed351 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_anchor_open_mic.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/anchor_open_mic_view.xml b/live/src/main/res/layout/anchor_open_mic_view.xml new file mode 100644 index 000000000..7d11c3aa3 --- /dev/null +++ b/live/src/main/res/layout/anchor_open_mic_view.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_anchor_mic_list.xml b/live/src/main/res/layout/dialog_anchor_mic_list.xml new file mode 100644 index 000000000..49a0d3d15 --- /dev/null +++ b/live/src/main/res/layout/dialog_anchor_mic_list.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_anchor_mic_info.xml b/live/src/main/res/layout/item_anchor_mic_info.xml new file mode 100644 index 000000000..1c254dd47 --- /dev/null +++ b/live/src/main/res/layout/item_anchor_mic_info.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +