赛事详情邀请进房增加昵称参数

This commit is contained in:
huangjian
2021-10-29 15:08:31 +08:00
parent f2568f88b8
commit 85b084520a
4 changed files with 265 additions and 257 deletions

View File

@@ -187,9 +187,10 @@ import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ROOM_GI
public class MessageView extends FrameLayout {
private static final String TAG = "MessageView";
private final int textColor = 0x80ffffff;
private final static int MAX_MESSAGE_SIZE = 2000;//公屏最多展示条数
private final static int BLOCK_MAX_MESSAGE_SIZE = MAX_MESSAGE_SIZE * 3 / 2;//在查看消息停住的时候 最多消息条数.
private static final int LOAD_MESSAGE_COUNT = 10;
private final int textColor = 0x80ffffff;
private RecyclerView messageListView;
private TextView tvBottomTip;
private MessageAdapter mMessageAdapter;
@@ -210,27 +211,16 @@ public class MessageView extends FrameLayout {
private int expLevelWidth;
private int expLevelHeight;
private int giftLength;
private volatile boolean needAutoScroll = true;//是否自动滚动到底部
@Setter
private Consumer<String> clickConsumer;
@Setter
private OnAcceptClick onClickListener;
@Setter
private OnClick onClick;
private DialogManager mDialogManager;
private Disposable subscribe;
private static final int LOAD_MESSAGE_COUNT = 10;
public void setDialogManager(DialogManager dialogManager) {
mDialogManager = dialogManager;
}
public MessageView(Context context) {
this(context, null);
}
@@ -244,6 +234,10 @@ public class MessageView extends FrameLayout {
init(context);
}
public void setDialogManager(DialogManager dialogManager) {
mDialogManager = dialogManager;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
@@ -449,6 +443,237 @@ public class MessageView extends FrameLayout {
mMessageAdapter.notifyItemChanged(position);
}
public void clear() {
if (mMessageAdapter != null) {
chatRoomMessages.clear();
mMessageAdapter.notifyDataSetChanged();
}
if (tvBottomTip != null) {
needAutoScroll = true;
tvBottomTip.setVisibility(GONE);
}
}
/**
* 处理接收游戏的通知
*
* @param imGameInfo
*/
public void receiveCustomNotification(ImGameInfo imGameInfo) {
if (imGameInfo.getStartUid() == AuthModel.get().getCurrentUid()) {
GameRespondAttachment attachment = new GameRespondAttachment(CustomAttachment.CUSTOM_MSG_GAME_RESPOND, CustomAttachment.CUSTOM_MSG_GAME_RESPOND_ACCEPT);
attachment.setImGameInfo(imGameInfo);
ChatRoomMessage message = ChatRoomMessageBuilder.createChatRoomCustomMessage(
// 聊天室id
AvRoomDataManager.get().getRoomId() + "",
attachment
);
addMessages(message);
PlayGameActivity.start(getContext(), imGameInfo.getGameUrl(), imGameInfo.getUuId());
changeGameStatus(imGameInfo.getUuId(), imGameInfo.getStatus());
} else {
changeGameStatus(imGameInfo.getUuId(), imGameInfo.getStatus());
}
}
/**
* 处理游戏取消的通知
*/
private void updateGameItemStatus(String fromAccount) {
int size = chatRoomMessages.size();
for (int i = size - 1; i >= (size > 100 ? size - 100 : 0); i--) {
ChatRoomMessage roomMessage = chatRoomMessages.get(i);
if (roomMessage.getAttachment() instanceof ImGameAttachment
&& fromAccount.equals(roomMessage.getFromAccount())) {
ImGameInfo imGameInfo = ((ImGameAttachment) roomMessage.getAttachment()).getImGameInfo();
imGameInfo.setStatus(ImGameInfo.INVALID);
ImGameAttachment attachment = new ImGameAttachment(CustomAttachment.CUSTOM_MSG_IM_GAME, CustomAttachment.CUSTOM_MSG_IM_REQUST_GAME);
attachment.setImGameInfo(imGameInfo);
roomMessage.setAttachment(attachment);
mMessageAdapter.notifyItemChanged(i);
}
}
}
public void changeGameStatus(String uuid, int status) {
int size = chatRoomMessages.size();
for (int i = size - 1; i >= 0; i--) {
if (chatRoomMessages.get(i).getUuid().equals(uuid)) {
ImGameAttachment attachment = (ImGameAttachment) chatRoomMessages.get(i).getAttachment();
// chatRoomMessages.get(i).setFromAccount(AuthModel.get().getCurrentUid() + "");
attachment.getImGameInfo().setStatus(status);
mMessageAdapter.notifyItemChanged(i);
break;
}
}
}
public void setNeedAutoScroll(boolean needAutoScroll) {
this.needAutoScroll = needAutoScroll;
}
public interface OnAcceptClick {
public void onAcceptGame(ChatRoomMessage chatRoomMessage, ImGameInfo imGameInfo);
}
public interface OnClick {
/**
* 点击关注
*
* @param position
*/
void onFollowClick(int position);
void onJoinMiniWorldClick(int position);
/**
* 公屏查看公告
*/
void onShowRoomIntroduction();
}
public static class SpannableBuilder {
private SpannableStringBuilder builder;
private TextView textView;
public SpannableBuilder(TextView textView) {
builder = new SpannableStringBuilder();
this.textView = textView;
}
/**
* @param text 文字
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(CharSequence text) {
if (TextUtils.isEmpty(text)) return this;
builder.append(text);
return this;
}
/**
* @param drawable -icon url
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder appendImg(String drawable) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon url
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(String drawable, int width, int height) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable, width, height);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* 文本和背景分离的情况
*/
public SpannableBuilder appendBgAndContent(String drawable, String content) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable, content);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(Drawable drawable, int width, int height) {
if (drawable == null) return this;
drawable.setBounds(0, 0, width, height);
int start = builder.length();
builder.append("-");
builder.setSpan(new CustomImageSpan(drawable), start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(Drawable drawable, int width, int height, Object... whats) {
if (drawable == null) return this;
try {
drawable.setBounds(0, 0, width, height);
int start = builder.length();
builder.append("-");
builder.setSpan(new CustomImageSpan(drawable), start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if (whats != null) {
for (int i = 0; i < whats.length; i++) {
builder.setSpan(whats[0], start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
} catch (Exception ex) {
}
return this;
}
/**
* @param text -文字
* @param what -span类型
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(CharSequence text, Object what) {
if (TextUtils.isEmpty(text)) return this;
int start = builder.length();
builder.append(text);
builder.setSpan(what, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* 支持多个spannable 对同一段文字修改
*
* @param text
* @param what
* @return
*/
public SpannableBuilder append(CharSequence text, Object... what) {
if (TextUtils.isEmpty(text)) return this;
int start = builder.length();
builder.append(text);
for (int i = 0; i < what.length; i++) {
Object o = what[i];
if (o == null) {
continue;
}
builder.setSpan(what[i], start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
return this;
}
public SpannableStringBuilder build() {
return builder;
}
}
private class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> implements OnClickListener {
@@ -479,16 +704,6 @@ public class MessageView extends FrameLayout {
return data.size();
}
class MessageViewHolder extends RecyclerView.ViewHolder {
TextView tvContent;
public MessageViewHolder(View itemView) {
super(itemView);
tvContent = itemView.findViewById(R.id.tv_content);
}
}
protected void convert(MessageViewHolder baseViewHolder, ChatRoomMessage chatRoomMessage) {
if (chatRoomMessage == null) return;
TextView tvContent = baseViewHolder.tvContent;
@@ -811,7 +1026,6 @@ public class MessageView extends FrameLayout {
}
}
private void setDatingMsg(ChatRoomMessage chatRoomMessage, TextView tvContent, int second) {
if (chatRoomMessage.getAttachment() instanceof DatingAttachment) {
DatingAttachment datingAttachment = (DatingAttachment) chatRoomMessage.getAttachment();
@@ -1578,7 +1792,7 @@ public class MessageView extends FrameLayout {
SpannableBuilder text = new SpannableBuilder(tvContent)
.append("厉害了 ", new ForegroundColorSpan(greyColor))
.append(attachment.getNick() + " ", new ForegroundColorSpan(roomTipColor))
.append(""+attachment.getBoxTypeStr() + "获得 ", new ForegroundColorSpan(greyColor))
.append("" + attachment.getBoxTypeStr() + "获得 ", new ForegroundColorSpan(greyColor))
.append(attachment.getPrizeName(), new ForegroundColorSpan(Color.WHITE));
if (attachment.getPrizeNum() > 1) {
text.append(" x" + attachment.getPrizeNum() + " ", new ForegroundColorSpan(roomTipColor));
@@ -2031,7 +2245,6 @@ public class MessageView extends FrameLayout {
tvContent.setMovementMethod(new LinkMovementMethod());
}
/**
* xxx 送给xxx,xxx,xxx... {礼物} X数量
*
@@ -2110,7 +2323,6 @@ public class MessageView extends FrameLayout {
tvContent.setMovementMethod(new LinkMovementMethod());
}
/**
* xxx 送给xxx,xxx,xxx... {魔法} X数量
*
@@ -2329,6 +2541,21 @@ public class MessageView extends FrameLayout {
});
enterText = " 进入了房间";
}
if (fromType == AVRoomActivity.FROM_TYPE_GAME_RECOMMEND) {
String finalFromUid = fromUid;
text.append(" 接受 ", new ForegroundColorSpan(whiteColor))
.append(fromNick, new ForegroundColorSpan(roomTipColor),
new OriginalDrawStatusClickSpan() {
@Override
public void onClick(@NonNull View view) {
if (clickConsumer != null) {
Single.just(finalFromUid).doOnSuccess(clickConsumer).subscribe();
}
}
});
enterText = " 的邀请,进入了房间";
}
text.append(enterText, new ForegroundColorSpan(whiteColor));
//如果自己在麦上增加一个欢迎ta的按钮并且这条消息不是自己的
@@ -2614,7 +2841,6 @@ public class MessageView extends FrameLayout {
}
/**
* 进入公聊大厅页面,加载历史记录
*/
@@ -2719,238 +2945,14 @@ public class MessageView extends FrameLayout {
}
}
}
}
class MessageViewHolder extends RecyclerView.ViewHolder {
TextView tvContent;
public static class SpannableBuilder {
private SpannableStringBuilder builder;
private TextView textView;
public SpannableBuilder(TextView textView) {
builder = new SpannableStringBuilder();
this.textView = textView;
}
/**
* @param text 文字
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(CharSequence text) {
if (TextUtils.isEmpty(text)) return this;
builder.append(text);
return this;
}
/**
* @param drawable -icon url
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder appendImg(String drawable) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon url
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(String drawable, int width, int height) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable, width, height);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* 文本和背景分离的情况
*/
public SpannableBuilder appendBgAndContent(String drawable, String content) {
if (TextUtils.isEmpty(drawable)) return this;
int start = builder.length();
builder.append("-");
CustomImageSpan imageSpan = new CustomImageSpan(new ColorDrawable(Color.TRANSPARENT), textView, drawable, content);
builder.setSpan(imageSpan, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(Drawable drawable, int width, int height) {
if (drawable == null) return this;
drawable.setBounds(0, 0, width, height);
int start = builder.length();
builder.append("-");
builder.setSpan(new CustomImageSpan(drawable), start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* @param drawable -icon
* @param width 宽
* @param height 高
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(Drawable drawable, int width, int height, Object... whats) {
if (drawable == null) return this;
try {
drawable.setBounds(0, 0, width, height);
int start = builder.length();
builder.append("-");
builder.setSpan(new CustomImageSpan(drawable), start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if (whats != null) {
for (int i = 0; i < whats.length; i++) {
builder.setSpan(whats[0], start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
} catch (Exception ex) {
}
return this;
}
/**
* @param text -文字
* @param what -span类型
* @return -返回一个spannableStringBuilder
*/
public SpannableBuilder append(CharSequence text, Object what) {
if (TextUtils.isEmpty(text)) return this;
int start = builder.length();
builder.append(text);
builder.setSpan(what, start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return this;
}
/**
* 支持多个spannable 对同一段文字修改
*
* @param text
* @param what
* @return
*/
public SpannableBuilder append(CharSequence text, Object... what) {
if (TextUtils.isEmpty(text)) return this;
int start = builder.length();
builder.append(text);
for (int i = 0; i < what.length; i++) {
Object o = what[i];
if (o == null) {
continue;
}
builder.setSpan(what[i], start, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
return this;
}
public SpannableStringBuilder build() {
return builder;
}
}
public void clear() {
if (mMessageAdapter != null) {
chatRoomMessages.clear();
mMessageAdapter.notifyDataSetChanged();
}
if (tvBottomTip != null) {
needAutoScroll = true;
tvBottomTip.setVisibility(GONE);
}
}
/**
* 处理接收游戏的通知
*
* @param imGameInfo
*/
public void receiveCustomNotification(ImGameInfo imGameInfo) {
if (imGameInfo.getStartUid() == AuthModel.get().getCurrentUid()) {
GameRespondAttachment attachment = new GameRespondAttachment(CustomAttachment.CUSTOM_MSG_GAME_RESPOND, CustomAttachment.CUSTOM_MSG_GAME_RESPOND_ACCEPT);
attachment.setImGameInfo(imGameInfo);
ChatRoomMessage message = ChatRoomMessageBuilder.createChatRoomCustomMessage(
// 聊天室id
AvRoomDataManager.get().getRoomId() + "",
attachment
);
addMessages(message);
PlayGameActivity.start(getContext(), imGameInfo.getGameUrl(), imGameInfo.getUuId());
changeGameStatus(imGameInfo.getUuId(), imGameInfo.getStatus());
} else {
changeGameStatus(imGameInfo.getUuId(), imGameInfo.getStatus());
}
}
/**
* 处理游戏取消的通知
*/
private void updateGameItemStatus(String fromAccount) {
int size = chatRoomMessages.size();
for (int i = size - 1; i >= (size > 100 ? size - 100 : 0); i--) {
ChatRoomMessage roomMessage = chatRoomMessages.get(i);
if (roomMessage.getAttachment() instanceof ImGameAttachment
&& fromAccount.equals(roomMessage.getFromAccount())) {
ImGameInfo imGameInfo = ((ImGameAttachment) roomMessage.getAttachment()).getImGameInfo();
imGameInfo.setStatus(ImGameInfo.INVALID);
ImGameAttachment attachment = new ImGameAttachment(CustomAttachment.CUSTOM_MSG_IM_GAME, CustomAttachment.CUSTOM_MSG_IM_REQUST_GAME);
attachment.setImGameInfo(imGameInfo);
roomMessage.setAttachment(attachment);
mMessageAdapter.notifyItemChanged(i);
public MessageViewHolder(View itemView) {
super(itemView);
tvContent = itemView.findViewById(R.id.tv_content);
}
}
}
public void changeGameStatus(String uuid, int status) {
int size = chatRoomMessages.size();
for (int i = size - 1; i >= 0; i--) {
if (chatRoomMessages.get(i).getUuid().equals(uuid)) {
ImGameAttachment attachment = (ImGameAttachment) chatRoomMessages.get(i).getAttachment();
// chatRoomMessages.get(i).setFromAccount(AuthModel.get().getCurrentUid() + "");
attachment.getImGameInfo().setStatus(status);
mMessageAdapter.notifyItemChanged(i);
break;
}
}
}
public void setNeedAutoScroll(boolean needAutoScroll) {
this.needAutoScroll = needAutoScroll;
}
public interface OnAcceptClick {
public void onAcceptGame(ChatRoomMessage chatRoomMessage, ImGameInfo imGameInfo);
}
public interface OnClick {
/**
* 点击关注
*
* @param position
*/
void onFollowClick(int position);
void onJoinMiniWorldClick(int position);
/**
* 公屏查看公告
*/
void onShowRoomIntroduction();
}
}

View File

@@ -470,6 +470,9 @@ public class RoomEffectView extends FrameLayout {
if (fromType == AVRoomActivity.FROM_TYPE_USER) {
enterText = " 跟随 " + fromNick + "进入了房间";
}
if (fromType == AVRoomActivity.FROM_TYPE_GAME_RECOMMEND) {
enterText = " 接受 " + fromNick + "的邀请,进入了房间";
}
text.append(enterText, new ForegroundColorSpan(Color.WHITE));
textView.setText(text.build());
playMemberInAnim("" + targetNicks.get(0) + "" + enterText, memberInSvgaPath(experLevelSeq));

View File

@@ -13,6 +13,7 @@ public class RouterConstants {
public static final String NATIVE_PAGE_ARG_CHATROOM_ID = "chatRoomID";
public static final String NATIVE_PAGE_ARG_FROM_TYPE = "chatRoomFromType";
public static final String NATIVE_PAGE_ARG_FROM_UID = "chatRoomFromUid";
public static final String NATIVE_PAGE_ARG_FROM_NICK = "chatRoomFromNick";
public static final String FLUTTER_PAGE_MAIN = "/";
public static final String FLUTTER_PAGE_MAIN_DEBUG = "debug";

View File

@@ -79,7 +79,9 @@ public class XplanFlutterBoostDelegate implements FlutterBoostDelegate {
(Integer) arguments.get(RouterConstants.NATIVE_PAGE_ARG_FROM_TYPE) : 0;
String fromUid = arguments.containsKey(RouterConstants.NATIVE_PAGE_ARG_FROM_UID) ?
(String) arguments.get(RouterConstants.NATIVE_PAGE_ARG_FROM_UID) : "";
AVRoomActivity.startForFromType(FlutterBoost.instance().currentActivity(), uid, fromType, "", fromUid);
String fromNick = arguments.containsKey(RouterConstants.NATIVE_PAGE_ARG_FROM_UID) ?
(String) arguments.get(RouterConstants.NATIVE_PAGE_ARG_FROM_NICK) : "";
AVRoomActivity.startForFromType(FlutterBoost.instance().currentActivity(), uid, fromType, fromNick, fromUid);
return;
}
}