add:直播间新增打招呼快捷按钮
This commit is contained in:
parent
da19811ad4
commit
2130390e99
@ -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<LiveRoomFastMessageRecyclerViewAdapter.Vh> {
|
||||
private Context context;
|
||||
private List<String> 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<String> 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);
|
||||
}
|
||||
}
|
@ -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<String> greetings) {
|
||||
fastMessageRecyclerViewAdapter.setMessage(greetings);
|
||||
}
|
||||
|
||||
private static class LiveRoomHandler extends Handler {
|
||||
|
||||
private LiveRoomViewHolder mLiveRoomViewHolder;
|
||||
|
@ -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<String> 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"));
|
||||
|
9
live/src/main/res/drawable/bg_fast_meg.xml
Normal file
9
live/src/main/res/drawable/bg_fast_meg.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:width="112dp" android:height="25dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#33000000" />
|
||||
<corners android:radius="12dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
24
live/src/main/res/layout/item_fast_msg.xml
Normal file
24
live/src/main/res/layout/item_fast_msg.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/room_fast_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_fast_meg">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/room_fast_message_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:text="TextView"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1824,7 +1824,11 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true" />
|
||||
<!-- SVG 座骑-->
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/room_fast_msg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:layout_alignParentBottom="true" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user