@消息逻辑补充

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) {
UserBean u = CommonAppConfig.getInstance().getUserBean();
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;
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:
manager.showNewMessage();
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.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.live.R;
@ -57,10 +59,13 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager;
private IMLoginModel model;
public LiveChatAdapter(Context context) {
mContext = context;
mList = new ArrayList<>();
mInflater = LayoutInflater.from(context);
model = IMLoginManager.get(context).getUserInfo();
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -289,7 +294,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
} else if (bean.getType() == LiveChatBean.SYSTEM) {
boolean isContains = false;
for (LiveChatBean model : mList) {
if (!TextUtils.isEmpty(model.getContent()) && (model.getContent().contains("堅決維護青少年群體精神文明健康")||model.getContent().contains("click to register if you like. pdlive conducts"))) {
if (!TextUtils.isEmpty(model.getContent()) && (model.getContent().contains("堅決維護青少年群體精神文明健康") || model.getContent().contains("click to register if you like. pdlive conducts"))) {
isContains = true;
}
}
@ -374,13 +379,16 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
mList.add(beanNull);
notifyItemChanged(size + 1);
if (isSlideToBottom(mRecyclerView)){
if (isSlideToBottom(mRecyclerView)) {
mRecyclerView.scrollToPosition(size + 1);
}else {
} else {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.NEW_MESSAGE_REMINDER));
}
if (bean.getAtUserID().contains(String.valueOf(model.getId()))) {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.AT_MESSAGE));
}
}
/**
@ -389,7 +397,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
* @param recyclerView
* @return
*/
public boolean isSlideToBottom(RecyclerView recyclerView) {
public boolean isSlideToBottom(RecyclerView recyclerView) {
if (recyclerView == null) return false;
if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset()
>= recyclerView.computeVerticalScrollRange())

View File

@ -58,6 +58,30 @@ public class LiveChatBean {
//超皇字体颜色
@SerializedName("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() {
return startColor;

View File

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

View File

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

View File

@ -1,5 +1,8 @@
package com.yunbao.live.socket;
import static com.yunbao.common.CommonAppContext.logger;
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
import android.util.Log;
import com.adjust.sdk.Adjust;
@ -24,9 +27,6 @@ import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
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.
* 直播间发言
@ -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();
IMLoginModel model = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo();
if (u == null) {
@ -112,7 +112,8 @@ public class SocketRyChatUtil {
.param("contentColor", String.valueOf(model.getContentColor()))
.param("startColor", String.valueOf(model.getStartColor()))
.param("endColor", String.valueOf(model.getEndColor()))
;
.param("atUserName", String.valueOf(atUserName))
.param("atUserID", String.valueOf(atUserID));
msg.create();
String targetId = "g" + mLiveUid;

View File

@ -1,5 +1,13 @@
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.Message;
import android.text.TextUtils;
@ -54,14 +62,6 @@ import io.rong.imlib.IRongCoreCallback;
import io.rong.imlib.IRongCoreEnum;
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 {
private static final String TAG = "socket";
@ -609,6 +609,8 @@ public class SocketRyClient {
chatBean.setStartColor(map.getString("startColor"));//昵称开始颜色
chatBean.setEndColor(map.getString("endColor"));//昵称结束颜色
chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色
chatBean.setAtUserName(map.getString("atUserName"));//@名字
chatBean.setAtUserID(map.getString("atUserID"));//@ID
if (!map.getString("guard_type").equals("undefined")) {
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 mAvatarUrl;
public static FrameLayout ft_hot_add;
public static ImageView img_hot_gif, newMessage;
public static ImageView img_hot_gif, newMessage, atMessage;
//多人PK
static TextView time;
@ -673,6 +673,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
mic_ico = (ImageView) findViewById(R.id.mic_ico);
newMessage = (ImageView) findViewById(R.id.new_message);
atMessage = (ImageView) findViewById(R.id.at_message);
mic_ico1 = (RoundedImageView) findViewById(R.id.mic_ico1);
mic_ico2 = (RoundedImageView) findViewById(R.id.mic_ico2);
ViewClicksAntiShake.clicksAntiShake(newMessage, () -> {
@ -808,7 +809,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
mLiveChatAdapter.removetItem(bean);
} else if (bean.getType() == -2) {
mLiveChatAdapter.removetItem(bean);
((LiveActivity) mContext).sendChatMessage("Hi~");
((LiveActivity) mContext).sendChatMessage("Hi~", null, null);
} else if (bean.getType() == -5) {
String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Turntable&a=tricky";
url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token="
@ -833,6 +834,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
super.onScrolled(recyclerView, dx, dy);
if (mLiveChatAdapter.isSlideToBottom(recyclerView)) {
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);
fastMessageRecyclerViewAdapter.setMessageListener(msg -> {
//点击的消息发送出去
((LiveActivity) mContext).sendChatMessage(msg);
((LiveActivity) mContext).sendChatMessage(msg, null, null);
fastMsgRecyclerView.setVisibility(View.GONE);
params1.bottomMargin = 0;
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;
String language = locale.getLanguage();
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();
if (fastMsgRecyclerView.getVisibility() == View.VISIBLE) {
params1.bottomMargin = DpUtil.dp2px(38);
@ -3075,5 +3090,25 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
newMessage.setLayoutParams(params1);
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

@ -1531,7 +1531,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
*/
public void showNewMessage() {
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.showNewMessage();
mLiveRoomViewHolder.showNewMessage( );
}
}
public void showAtMessage(){
if (mLiveRoomViewHolder!=null){
mLiveRoomViewHolder.showAtMessage();
}
}
}

View File

@ -1995,6 +1995,8 @@
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<!-- SVG 座骑-->
<ImageView
android:id="@+id/new_message"
android:layout_width="106.67dp"
@ -2003,6 +2005,16 @@
android:layout_marginStart="10dp"
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
android:id="@+id/room_fast_msg"
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