diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveRoomFastMessageRecyclerViewAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveRoomFastMessageRecyclerViewAdapter.java new file mode 100644 index 000000000..0cbd71630 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/LiveRoomFastMessageRecyclerViewAdapter.java @@ -0,0 +1,109 @@ +package com.yunbao.live.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.live.R; + +import java.util.ArrayList; +import java.util.List; + +/** + * 直播间打招呼适配器 + */ +public class LiveRoomFastMessageRecyclerViewAdapter extends RecyclerView.Adapter { + private Context context; + private List items; + private OnSendMessageListener messageListener; + public LiveRoomFastMessageRecyclerViewAdapter(Context context) { + this.context = context; + this.items=new ArrayList<>(); + } + + /** + * 设置点击消息回调 + * @param messageListener 消息回调 + */ + public void setMessageListener(OnSendMessageListener messageListener) { + this.messageListener = messageListener; + } + + /** + * 添加消息 + * @param msg 消息 + */ + public void addMessage(String msg){ + items.add(msg); + notifyDataSetChanged(); + } + + /** + * 添加消息 + * @param items 消息组 + */ + public void setMessage(List items){ + this.items=items; + notifyDataSetChanged(); + + } + + @NonNull + @Override + public Vh onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new Vh(LayoutInflater.from(context).inflate(R.layout.item_fast_msg,parent,false)); + } + + @Override + public void onBindViewHolder(@NonNull Vh holder, int position) { + holder.setData(items.get(position)); + } + + @Override + public int getItemCount() { + return items.size(); + } + + protected class Vh extends RecyclerView.ViewHolder{ + private final TextView message; + + public Vh(@NonNull View itemView) { + super(itemView); + message=itemView.findViewById(R.id.room_fast_message_text_view); + ConstraintLayout layout = itemView.findViewById(R.id.room_fast_layout); + layout.setOnClickListener(view -> { + int position= getPosition((String) message.getTag()); + if(position==-1){{ + return; + }} + if(messageListener!=null){ + messageListener.onMessage((String) message.getTag()); + } + items.remove(position); + notifyItemRemoved(position); + }); + } + private int getPosition(String msg){ + for (int i = 0; i < items.size(); i++) { + if(items.get(i).equals(msg)){ + return i; + } + } + return -1; + } + public void setData(String msg){ + message.setTag(msg); + message.setText(msg); + } + + } + public interface OnSendMessageListener{ + void onMessage(String msg); + } +} 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 a0a00f18d..56e60553f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -24,6 +24,7 @@ import android.widget.TextView; import android.widget.ViewFlipper; import androidx.annotation.Nullable; +import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -75,6 +76,7 @@ import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.ZhuangBanActivity; import com.yunbao.live.adapter.LiveChatAdapter; +import com.yunbao.live.adapter.LiveRoomFastMessageRecyclerViewAdapter; import com.yunbao.live.adapter.LiveUserAdapter; import com.yunbao.live.bean.DrPkbean; import com.yunbao.live.bean.LiveBuyGuardMsgBean; @@ -246,6 +248,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private LinearLayout btn_event2; private ImageView imgEvent; private View btnEvent; + private RecyclerView fastMsgRecyclerView; + private LiveRoomFastMessageRecyclerViewAdapter fastMessageRecyclerViewAdapter; public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager) { super(context, parentView); @@ -847,7 +851,16 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis loadWishlistData(); //打开活动窗口 ViewClicksAntiShake.clicksAntiShake(wishListLayout, () -> startActivity(new Intent(mContext, ZhuangBanActivity.class).putExtra("url", ""))); - + //打招呼消息 + fastMsgRecyclerView = (RecyclerView) findViewById(R.id.room_fast_msg); + fastMsgRecyclerView.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.HORIZONTAL,false)); + fastMessageRecyclerViewAdapter=new LiveRoomFastMessageRecyclerViewAdapter(mContext); + fastMsgRecyclerView.setAdapter(fastMessageRecyclerViewAdapter); + fastMessageRecyclerViewAdapter.setMessageListener(msg -> { + //点击的消息发送出去 + ((LiveActivity) mContext).sendChatMessage(msg); + }); + fastMsgRecyclerView.setItemAnimator(new DefaultItemAnimator()); } private void showBanner2() { @@ -2148,6 +2161,10 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mLiveRoomHandler.removeCallbacksAndMessages(null); } + public void setFastMessage(List greetings) { + fastMessageRecyclerViewAdapter.setMessage(greetings); + } + private static class LiveRoomHandler extends Handler { private LiveRoomViewHolder mLiveRoomViewHolder; 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 5a4b13f4a..526f2ab61 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -20,6 +20,7 @@ import androidx.viewpager.widget.PagerAdapter; import com.adjust.sdk.Adjust; import com.adjust.sdk.AdjustEvent; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.GsonUtils; import com.tencent.imsdk.v2.V2TIMCallback; @@ -801,6 +802,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe LiveHttpUtil.enterRoom(mLiveBean.getUid(), mLiveBean.getStream(), new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { + List greetings; if (code == 0 && info.length > 0) { JSONObject obj = JSON.parseObject(info[0]); mDanmuPrice = obj.getString("barrage_fee"); @@ -808,6 +810,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mChatLevel = obj.getIntValue("speak_limit"); mDanMuLevel = obj.getIntValue("barrage_limit"); liveBg = obj.getIntValue("live_bg"); + greetings = JSONArray.parseArray(obj.getJSONArray("greetings").toJSONString(), String.class); if (liveBg == 1) { //直播间背景 ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack); @@ -881,6 +884,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe LivePlayKsyViewHolder.setLandscape(obj.getIntValue("landscape")); mLiveRoomViewHolder.setLiveInfo(mLiveBean.getUid(), mLiveBean.getStream(), obj.getIntValue("userlist_time") * 4000); + mLiveRoomViewHolder.setFastMessage(greetings); mLiveRoomViewHolder.setVotes(obj.getString("votestotal")); //真爱排行 数量 mLiveRoomViewHolder.setMedaRankNum(obj.getString("medalRankNum")); diff --git a/live/src/main/res/drawable/bg_fast_meg.xml b/live/src/main/res/drawable/bg_fast_meg.xml new file mode 100644 index 000000000..4b8c2a6db --- /dev/null +++ b/live/src/main/res/drawable/bg_fast_meg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_fast_msg.xml b/live/src/main/res/layout/item_fast_msg.xml new file mode 100644 index 000000000..400d66e9e --- /dev/null +++ b/live/src/main/res/layout/item_fast_msg.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index b98c66a72..68e81f2cf 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -1824,7 +1824,11 @@ android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> - +