@消息逻辑补充

This commit is contained in:
18401019693 2022-10-10 11:34:29 +08:00
parent 5060d647fb
commit ee7374d816
14 changed files with 144 additions and 26 deletions

View File

@ -112,4 +112,28 @@ public class AtTextWatcher implements TextWatcher {
} }
} }
private String atUserID, atUserName;
public String getAtUserID() {
StringBuffer stringBuffer = new StringBuffer();
for (String userID : spanMap.keySet()) {
stringBuffer.append(userID);
stringBuffer.append(",");
}
return stringBuffer.toString();
}
public String getAtUserName() {
StringBuffer stringBuffer = new StringBuffer();
for (String userID : spanMap.keySet()) {
OlineUserlistModel model = spanMap.get(userID);
stringBuffer.append(model.getUserNicename());
stringBuffer.append(",");
}
return stringBuffer.toString();
}
public void clearMsg() {
spanMap.clear();
}
} }

View File

@ -938,7 +938,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
/** /**
* 聊天 消息 * 聊天 消息
*/ */
public void sendChatMessage(String content) { public void sendChatMessage(String content, String atUserID, String atUserName) {
if (!mIsAnchor) { if (!mIsAnchor) {
UserBean u = CommonAppConfig.getInstance().getUserBean(); UserBean u = CommonAppConfig.getInstance().getUserBean();
if (u != null && u.getLevel() < mChatLevel) { if (u != null && u.getLevel() < mChatLevel) {
@ -947,7 +947,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
} }
} }
int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE; int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE;
SocketRyChatUtil.sendChatMessage(mLiveUid, content, mIsAnchor, mSocketUserType, guardType); SocketRyChatUtil.sendChatMessage(mLiveUid, content, mIsAnchor, mSocketUserType, guardType,atUserID,atUserName);
} }
/** /**

View File

@ -833,6 +833,9 @@ public class LiveAudienceActivity extends LiveActivity {
case NEW_MESSAGE_REMINDER: case NEW_MESSAGE_REMINDER:
manager.showNewMessage(); manager.showNewMessage();
break; break;
case AT_MESSAGE:
manager.showAtMessage();
break;
} }

View File

@ -24,8 +24,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.makeramen.roundedimageview.RoundedImageView; import com.makeramen.roundedimageview.RoundedImageView;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.DpUtil;
import com.yunbao.live.R; import com.yunbao.live.R;
@ -57,10 +59,13 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
private RecyclerView mRecyclerView; private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager; private LinearLayoutManager mLayoutManager;
private IMLoginModel model;
public LiveChatAdapter(Context context) { public LiveChatAdapter(Context context) {
mContext = context; mContext = context;
mList = new ArrayList<>(); mList = new ArrayList<>();
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
model = IMLoginManager.get(context).getUserInfo();
mOnClickListener = new View.OnClickListener() { mOnClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -380,7 +385,10 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
Bus.get().post(new LiveAudienceEvent() Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.NEW_MESSAGE_REMINDER)); .setType(LiveAudienceEvent.LiveAudienceType.NEW_MESSAGE_REMINDER));
} }
if (bean.getAtUserID().contains(String.valueOf(model.getId()))) {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.AT_MESSAGE));
}
} }
/** /**

View File

@ -58,6 +58,30 @@ public class LiveChatBean {
//超皇字体颜色 //超皇字体颜色
@SerializedName("contentColor") @SerializedName("contentColor")
private String contentColor = ""; private String contentColor = "";
//@名字
@SerializedName("atUserName")
private String atUserName = "";
//@ID
@SerializedName("atUserID")
private String atUserID = "";
public String getAtUserName() {
return atUserName;
}
public LiveChatBean setAtUserName(String atUserName) {
this.atUserName = atUserName;
return this;
}
public String getAtUserID() {
return atUserID;
}
public LiveChatBean setAtUserID(String atUserID) {
this.atUserID = atUserID;
return this;
}
public String getStartColor() { public String getStartColor() {
return startColor; return startColor;

View File

@ -76,6 +76,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
private long trumpetNum;//喇叭数量 private long trumpetNum;//喇叭数量
private String mLiveUid;//主播ID private String mLiveUid;//主播ID
private AtTextWatcher atTextWatcher; private AtTextWatcher atTextWatcher;
private String atUserID = null, atUserName = null;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -235,7 +236,9 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
((LiveActivity) mContext).sendDanmuMessage(content); ((LiveActivity) mContext).sendDanmuMessage(content);
break; break;
case GENERALMESSAGE: case GENERALMESSAGE:
((LiveActivity) mContext).sendChatMessage(content); ((LiveActivity) mContext).sendChatMessage(content, atTextWatcher.getAtUserID(),atTextWatcher.getAtUserName() );
atTextWatcher.clearMsg();
dismiss();
break; break;
} }
mInput.setText(""); mInput.setText("");

View File

@ -132,7 +132,8 @@ public class LiveAudienceEvent extends BaseModel {
TRUMPET_NOTIFY(20, "全服喇叭"), TRUMPET_NOTIFY(20, "全服喇叭"),
RECOMMEND_CARD_NOTIFY(21, "贵族推荐通知"), RECOMMEND_CARD_NOTIFY(21, "贵族推荐通知"),
SLIDE_SETTINGS(22, "滑動設置"), SLIDE_SETTINGS(22, "滑動設置"),
NEW_MESSAGE_REMINDER(23, "新消息提醒") NEW_MESSAGE_REMINDER(23, "新消息提醒"),
AT_MESSAGE(24, "@消息")
; ;
private int type; private int type;

View File

@ -1,5 +1,8 @@
package com.yunbao.live.socket; package com.yunbao.live.socket;
import static com.yunbao.common.CommonAppContext.logger;
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
import android.util.Log; import android.util.Log;
import com.adjust.sdk.Adjust; import com.adjust.sdk.Adjust;
@ -24,9 +27,6 @@ import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message; import io.rong.imlib.model.Message;
import io.rong.message.TextMessage; import io.rong.message.TextMessage;
import static com.yunbao.common.CommonAppContext.logger;
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
/** /**
* Created by cxf on 2018/10/9. * Created by cxf on 2018/10/9.
* 直播间发言 * 直播间发言
@ -80,7 +80,7 @@ public class SocketRyChatUtil {
/** /**
* 发言 * 发言
*/ */
public static void sendChatMessage(String mLiveUid, String content, boolean isAnchor, int userType, int guardType) { public static void sendChatMessage(String mLiveUid, String content, boolean isAnchor, int userType, int guardType, String atUserID, String atUserName) {
UserBean u = CommonAppConfig.getInstance().getUserBean(); UserBean u = CommonAppConfig.getInstance().getUserBean();
IMLoginModel model = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo(); IMLoginModel model = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo();
if (u == null) { if (u == null) {
@ -112,7 +112,8 @@ public class SocketRyChatUtil {
.param("contentColor", String.valueOf(model.getContentColor())) .param("contentColor", String.valueOf(model.getContentColor()))
.param("startColor", String.valueOf(model.getStartColor())) .param("startColor", String.valueOf(model.getStartColor()))
.param("endColor", String.valueOf(model.getEndColor())) .param("endColor", String.valueOf(model.getEndColor()))
; .param("atUserName", String.valueOf(atUserName))
.param("atUserID", String.valueOf(atUserID));
msg.create(); msg.create();
String targetId = "g" + mLiveUid; String targetId = "g" + mLiveUid;

View File

@ -1,5 +1,13 @@
package com.yunbao.live.socket; package com.yunbao.live.socket;
import static com.blankj.utilcode.util.SnackbarUtils.dismiss;
import static com.blankj.utilcode.util.ViewUtils.runOnUiThread;
import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view;
import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom;
import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.TextUtils; import android.text.TextUtils;
@ -54,14 +62,6 @@ import io.rong.imlib.IRongCoreCallback;
import io.rong.imlib.IRongCoreEnum; import io.rong.imlib.IRongCoreEnum;
import io.rong.imlib.chatroom.base.RongChatRoomClient; import io.rong.imlib.chatroom.base.RongChatRoomClient;
import static com.blankj.utilcode.util.SnackbarUtils.dismiss;
import static com.blankj.utilcode.util.ViewUtils.runOnUiThread;
import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view;
import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom;
import static com.yunbao.live.views.LiveRoomViewHolder.getIsHot;
public class SocketRyClient { public class SocketRyClient {
private static final String TAG = "socket"; private static final String TAG = "socket";
@ -609,6 +609,8 @@ public class SocketRyClient {
chatBean.setStartColor(map.getString("startColor"));//昵称开始颜色 chatBean.setStartColor(map.getString("startColor"));//昵称开始颜色
chatBean.setEndColor(map.getString("endColor"));//昵称结束颜色 chatBean.setEndColor(map.getString("endColor"));//昵称结束颜色
chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色 chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色
chatBean.setAtUserName(map.getString("atUserName"));//@名字
chatBean.setAtUserID(map.getString("atUserID"));//@ID
if (!map.getString("guard_type").equals("undefined")) { if (!map.getString("guard_type").equals("undefined")) {
chatBean.setGuardType(map.getIntValue("guard_type")); chatBean.setGuardType(map.getIntValue("guard_type"));
} }

View File

@ -206,7 +206,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
public static String mNameText; public static String mNameText;
public static String mAvatarUrl; public static String mAvatarUrl;
public static FrameLayout ft_hot_add; public static FrameLayout ft_hot_add;
public static ImageView img_hot_gif, newMessage; public static ImageView img_hot_gif, newMessage, atMessage;
//多人PK //多人PK
static TextView time; static TextView time;
@ -673,6 +673,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
mic_ico = (ImageView) findViewById(R.id.mic_ico); mic_ico = (ImageView) findViewById(R.id.mic_ico);
newMessage = (ImageView) findViewById(R.id.new_message); newMessage = (ImageView) findViewById(R.id.new_message);
atMessage = (ImageView) findViewById(R.id.at_message);
mic_ico1 = (RoundedImageView) findViewById(R.id.mic_ico1); mic_ico1 = (RoundedImageView) findViewById(R.id.mic_ico1);
mic_ico2 = (RoundedImageView) findViewById(R.id.mic_ico2); mic_ico2 = (RoundedImageView) findViewById(R.id.mic_ico2);
ViewClicksAntiShake.clicksAntiShake(newMessage, () -> { ViewClicksAntiShake.clicksAntiShake(newMessage, () -> {
@ -808,7 +809,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
mLiveChatAdapter.removetItem(bean); mLiveChatAdapter.removetItem(bean);
} else if (bean.getType() == -2) { } else if (bean.getType() == -2) {
mLiveChatAdapter.removetItem(bean); mLiveChatAdapter.removetItem(bean);
((LiveActivity) mContext).sendChatMessage("Hi~"); ((LiveActivity) mContext).sendChatMessage("Hi~", null, null);
} else if (bean.getType() == -5) { } else if (bean.getType() == -5) {
String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Turntable&a=tricky"; String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Turntable&a=tricky";
url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token="
@ -833,6 +834,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
super.onScrolled(recyclerView, dx, dy); super.onScrolled(recyclerView, dx, dy);
if (mLiveChatAdapter.isSlideToBottom(recyclerView)) { if (mLiveChatAdapter.isSlideToBottom(recyclerView)) {
newMessage.setVisibility(View.GONE); newMessage.setVisibility(View.GONE);
if (atMessage.getVisibility()==View.VISIBLE){
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) atMessage.getLayoutParams();
if (fastMsgRecyclerView.getVisibility() == View.VISIBLE) {
params1.bottomMargin = DpUtil.dp2px(38);
} else {
params1.bottomMargin = DpUtil.dp2px(8);
}
atMessage.setLayoutParams(params1);
}
} }
} }
}); });
@ -956,7 +968,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
fastMsgRecyclerView.setAdapter(fastMessageRecyclerViewAdapter); fastMsgRecyclerView.setAdapter(fastMessageRecyclerViewAdapter);
fastMessageRecyclerViewAdapter.setMessageListener(msg -> { fastMessageRecyclerViewAdapter.setMessageListener(msg -> {
//点击的消息发送出去 //点击的消息发送出去
((LiveActivity) mContext).sendChatMessage(msg); ((LiveActivity) mContext).sendChatMessage(msg, null, null);
fastMsgRecyclerView.setVisibility(View.GONE); fastMsgRecyclerView.setVisibility(View.GONE);
params1.bottomMargin = 0; params1.bottomMargin = 0;
mChatRecyclerView.setLayoutParams(params1); mChatRecyclerView.setLayoutParams(params1);
@ -3059,6 +3071,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
}); });
} }
/** /**
* 展示新消息提示 * 展示新消息提示
*/ */
@ -3066,6 +3079,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
Locale locale = mContext.getResources().getConfiguration().locale; Locale locale = mContext.getResources().getConfiguration().locale;
String language = locale.getLanguage(); String language = locale.getLanguage();
ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.new_message_cn : R.mipmap.new_message_en, newMessage); ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.new_message_cn : R.mipmap.new_message_en, newMessage);
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) newMessage.getLayoutParams(); RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) newMessage.getLayoutParams();
if (fastMsgRecyclerView.getVisibility() == View.VISIBLE) { if (fastMsgRecyclerView.getVisibility() == View.VISIBLE) {
params1.bottomMargin = DpUtil.dp2px(38); params1.bottomMargin = DpUtil.dp2px(38);
@ -3075,5 +3090,25 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
newMessage.setLayoutParams(params1); newMessage.setLayoutParams(params1);
newMessage.setVisibility(View.VISIBLE); newMessage.setVisibility(View.VISIBLE);
}
public void showAtMessage() {
Locale locale = mContext.getResources().getConfiguration().locale;
String language = locale.getLanguage();
ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.emphasis_cn : R.mipmap.emphasis_en, atMessage);
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) atMessage.getLayoutParams();
if (newMessage.getVisibility() == View.VISIBLE) {
params1.bottomMargin = DpUtil.dp2px(58);
} else {
if (fastMsgRecyclerView.getVisibility() == View.VISIBLE) {
params1.bottomMargin = DpUtil.dp2px(38);
} else {
params1.bottomMargin = DpUtil.dp2px(8);
}
}
atMessage.setLayoutParams(params1);
atMessage.setVisibility(View.VISIBLE);
} }
} }

View File

@ -1534,4 +1534,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveRoomViewHolder.showNewMessage( ); mLiveRoomViewHolder.showNewMessage( );
} }
} }
public void showAtMessage(){
if (mLiveRoomViewHolder!=null){
mLiveRoomViewHolder.showAtMessage();
}
}
} }

View File

@ -1995,6 +1995,8 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" /> android:layout_centerVertical="true" />
<!-- SVG 座骑--> <!-- SVG 座骑-->
<ImageView <ImageView
android:id="@+id/new_message" android:id="@+id/new_message"
android:layout_width="106.67dp" android:layout_width="106.67dp"
@ -2003,6 +2005,16 @@
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:visibility="gone" /> android:visibility="gone" />
<ImageView
android:id="@+id/at_message"
android:layout_width="106.67dp"
android:layout_height="27.33dp"
android:layout_above="@id/new_message"
android:layout_marginStart="10dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="35dp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/room_fast_msg" android:id="@+id/room_fast_msg"
android:layout_width="match_parent" android:layout_width="match_parent"

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB