feat:調整 VIP 顯示邏輯,移除公聊廳

This commit is contained in:
max
2024-08-27 16:51:36 +08:00
parent 74b2d71821
commit adf2adc173
11 changed files with 77 additions and 1157 deletions

View File

@@ -48,7 +48,6 @@ import com.chwl.app.avroom.dialog.RoomGameListDialog
import com.chwl.app.avroom.dialog.RoomGameplayDialog
import com.chwl.app.avroom.dialog.RoomOperationDialog
import com.chwl.app.avroom.presenter.BaseRoomPresenter
import com.chwl.app.avroom.public_chat.PublicChatRoomMessageWidget
import com.chwl.app.avroom.room_album.RoomAlbumModel
import com.chwl.app.avroom.view.IBaseRoomView
import com.chwl.app.avroom.widget.BottomView
@@ -157,7 +156,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
private var myUid: Long = 0
protected lateinit var messagePager: ViewPager2
protected lateinit var messageView: MessageView
protected var publicChatMessageWidget: PublicChatRoomMessageWidget? = null
protected lateinit var bottomView: BottomView
protected lateinit var inputLayout: RelativeLayout
protected lateinit var inputEdit: EditText
@@ -244,10 +242,9 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
protected open fun initMessageView() {
messagePager = mView.findViewById<ViewPager2>(R.id.message_pager)
messageView = MessageView(context)
publicChatMessageWidget = PublicChatRoomMessageWidget(requireContext())
val tabList: MutableList<String> = java.util.ArrayList(2)
tabList.add(getString(R.string.room))
tabList.add(getString(R.string.public_chat))
// tabList.add(getString(R.string.public_chat))
val messageIndicator = mView.findViewById<MagicIndicator>(R.id.message_indicator)
messagePager.offscreenPageLimit = tabList.size
messagePager.adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
@@ -255,12 +252,7 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
parent: ViewGroup,
viewType: Int
): RecyclerView.ViewHolder {
val view = if (viewType == 0) {
messageView
} else {
publicChatMessageWidget
}
view?.layoutParams = ViewGroup.LayoutParams(
messageView.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
@@ -934,7 +926,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
return
}
mvpPresenter?.sendPublicChatTextMessage(message)
publicChatMessageWidget?.getMessageView()?.setNeedAutoScroll(true) // 發送後自動滾動公屏列表
inputEdit.setText("")
}
@@ -1250,7 +1241,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
}
override fun onSendPublicChatMsgSuccess(msg: ChatRoomMessage) {
publicChatMessageWidget?.getMessageView()?.addMessages(msg)
inputEdit.setText("")
KeyBoardUtils.hideKeyBoard(activity, inputEdit)
}
@@ -1542,9 +1532,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P1 : BaseRoomPresenter<V>?> :
}
open fun initWidget() {
publicChatMessageWidget?.let {
registerWidget(PublicChatRoomMessageWidget::class.java.simpleName, it)
}
}
@Subscribe(threadMode = ThreadMode.MAIN)

View File

@@ -100,9 +100,6 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
messageView.messageListView?.let {
setMessagePagerAutoHeight(it)
}
publicChatMessageWidget?.getMessageView()?.messageListView?.let {
setMessagePagerAutoHeight(it)
}
}
override fun onClick(v: View) {

View File

@@ -1,884 +0,0 @@
package com.chwl.app.avroom.public_chat;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import com.chwl.app.R;
import com.chwl.app.UIHelper;
import com.chwl.app.avroom.activity.AVRoomActivity;
import com.chwl.app.avroom.dialog.RoomTeamPKResultDialog;
import com.chwl.app.avroom.widget.OnMsgLongClickListener;
import com.chwl.app.avroom.widget.TemplateMessageAdapter;
import com.chwl.app.common.widget.CustomImageSpan;
import com.chwl.app.common.widget.OriginalDrawStatusClickSpan;
import com.chwl.app.photo.BigPhotoActivity;
import com.chwl.app.photo.PagerOption;
import com.chwl.app.public_chat.core.viewholder.ChatRoomMessageViewHolderThumbBase;
import com.chwl.app.ui.utils.ImageLoadUtils;
import com.chwl.app.ui.utils.ImageLoadUtilsV2;
import com.chwl.app.ui.widget.DividerItemDecoration;
import com.chwl.app.ui.widget.MyItemAnimator;
import com.chwl.app.ui.widget.RecyclerViewNoViewpagerScroll;
import com.chwl.app.ui.widget.TextSpannableBuilder;
import com.chwl.app.ui.widget.magicindicator.buildins.UIUtil;
import com.chwl.app.utils.ObjectTypeHelper;
import com.chwl.app.utils.RegexUtil;
import com.chwl.core.DemoCache;
import com.chwl.core.auth.AuthModel;
import com.chwl.core.bean.attachmsg.RoomQueueMsgAttachment;
import com.chwl.core.decoration.car.bean.CarInfo;
import com.chwl.core.home.event.FollowRoomEvent;
import com.chwl.core.home.model.CollectionRoomModel;
import com.chwl.core.im.custom.bean.CustomAttachment;
import com.chwl.core.im.custom.bean.HeadlineChangedAttachment;
import com.chwl.core.im.custom.bean.MonsterHuntingResultAttachment;
import com.chwl.core.im.custom.bean.MonsterStatusAttachment;
import com.chwl.core.im.custom.bean.RoomBoxPrizeAttachment;
import com.chwl.core.im.custom.bean.RoomFollowOwnerAttachment2;
import com.chwl.core.im.custom.bean.RoomTipAttachment;
import com.chwl.core.im.custom.bean.TarotAttachment;
import com.chwl.core.level.UserLevelResourceType;
import com.chwl.core.manager.AvRoomDataManager;
import com.chwl.core.monsterhunting.bean.MonsterDataBean;
import com.chwl.core.monsterhunting.bean.MonsterHuntingResult;
import com.chwl.core.noble.NobleUtil;
import com.chwl.core.praise.PraiseModel;
import com.chwl.core.public_chat_hall.bean.HeadlineBean;
import com.chwl.core.room.bean.RoomInfo;
import com.chwl.core.room.pk.attachment.RoomPkAttachment;
import com.chwl.core.user.bean.UserInfo;
import com.chwl.core.utils.ExtensionUtil;
import com.chwl.library.common.util.Utils;
import com.chwl.library.utils.JavaUtil;
import com.chwl.library.utils.ListUtils;
import com.chwl.library.utils.ResUtil;
import com.chwl.library.utils.SingleToastUtil;
import com.chwl.library.utils.SizeUtils;
import com.example.lib_utils.UiUtils;
import com.example.lib_utils.spannable.SpannableTextBuilder;
import com.netease.nim.uikit.business.session.emoji.MoonUtil;
import com.netease.nim.uikit.common.util.media.ImageUtil;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessageExtension;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomNotificationAttachment;
import com.netease.nimlib.sdk.msg.attachment.ImageAttachment;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.NotificationType;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.reactivex.Single;
import io.reactivex.functions.Consumer;
import kotlin.jvm.functions.Function1;
/**
* 直播間消息界面
*
* @author xiaoyu
*/
public class PublicChatMessageView extends FrameLayout {
private static final String TAG = "PublicChatMessageView";
private final static int MAX_MESSAGE_SIZE = 100;//公屏最多展示條數
private final static int BLOCK_MAX_MESSAGE_SIZE = MAX_MESSAGE_SIZE * 3 / 2;//在查看消息停住的時候 最多消息條數.
private final List<ChatRoomMessage> atMessages = new ArrayList<>();
private final List<ChatRoomMessage> chatRoomMessages = new LinkedList<>();
private RecyclerView messageListView;
private TextView tvBottomTip;
private TextView tvAtTip;
private MessageAdapter mMessageAdapter;
private LinearLayoutManager layoutManger;
private int paddingWidth;
private int paddingHeight;
private int whiteColor;
private int greyColor;
private int roomTipColor;
private int badgeWidth;
private int badgeHeight;
private int expLevelHeight;
private int defTextSize = 12;
private volatile boolean needAutoScroll = true;//是否自動滾動到底部
private Consumer<String> clickConsumer;
private OnClick onClick;
private OnMsgLongClickListener onLongClickListener;
private TemplateMessageAdapter templateMessageAdapter;
public PublicChatMessageView(Context context) {
this(context, null);
}
public PublicChatMessageView(Context context, AttributeSet attr) {
this(context, attr, 0);
}
public PublicChatMessageView(Context context, AttributeSet attr, int i) {
super(context, attr, i);
init(context);
}
public void setOnLongClickListener(OnMsgLongClickListener onLongClickListener) {
this.onLongClickListener = onLongClickListener;
}
public void setClickConsumer(Consumer<String> clickConsumer) {
this.clickConsumer = clickConsumer;
}
public void setOnClick(OnClick onClick) {
this.onClick = onClick;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
}
@SuppressLint("ClickableViewAccessibility")
private void init(Context context) {
whiteColor = ContextCompat.getColor(context, R.color.white);
greyColor = ContextCompat.getColor(context, R.color.white_transparent_50);
roomTipColor = ContextCompat.getColor(context, R.color.color_FEE057);
paddingWidth = Utils.dip2px(context, 11);
paddingHeight = Utils.dip2px(context, 6);
badgeWidth = Utils.dip2px(context, 15);
badgeHeight = Utils.dip2px(context, 15);
//經驗等級圖片後臺已經更換尺寸了公屏同步下尺寸是36:18
expLevelHeight = Utils.dip2px(context, 18);
// 內容區域
layoutManger = new LinearLayoutManager(context, RecyclerView.VERTICAL, false);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
messageListView = new RecyclerViewNoViewpagerScroll(context);
messageListView.setLayoutParams(params);
messageListView.setFadingEdgeLength(60);
messageListView.setVerticalFadingEdgeEnabled(true);
messageListView.setOverScrollMode(OVER_SCROLL_NEVER);
messageListView.setHorizontalScrollBarEnabled(false);
addView(messageListView);
messageListView.setLayoutManager(layoutManger);
messageListView.addItemDecoration(new DividerItemDecoration(context, layoutManger.getOrientation(), 16, R.color.transparent));
mMessageAdapter = new MessageAdapter(getContext());
mMessageAdapter.setData(chatRoomMessages);
messageListView.setAdapter(mMessageAdapter);
messageListView.setItemAnimator(new MyItemAnimator());
messageListView.getItemAnimator().setAddDuration(0);
messageListView.getItemAnimator().setChangeDuration(0);
messageListView.getItemAnimator().setMoveDuration(0);
messageListView.getItemAnimator().setRemoveDuration(0);
((SimpleItemAnimator) messageListView.getItemAnimator()).setSupportsChangeAnimations(false);
// 底部有新消息
tvBottomTip = new TextView(context);
LayoutParams params1 = new LayoutParams(
Utils.dip2px(context, 115F), Utils.dip2px(context, 27));
params1.gravity = Gravity.BOTTOM;
params1.leftMargin = UIUtil.getScreenWidth(context) / 2 - UIUtil.dip2px(context, 115 / 2);
tvBottomTip.setBackgroundResource(R.drawable.bg_messge_view_bottom_tip);
tvBottomTip.setGravity(Gravity.CENTER);
tvBottomTip.setText(context.getString(R.string.message_view_bottom_tip));
tvBottomTip.setTextColor(context.getResources().getColor(R.color.appColor));
tvBottomTip.setLayoutParams(params1);
tvBottomTip.setVisibility(GONE);
tvBottomTip.setOnClickListener(v -> {
tvBottomTip.setVisibility(GONE);
needAutoScroll = true;
if (mMessageAdapter.getItemCount() > 0) {
messageListView.smoothScrollToPosition(mMessageAdapter.getItemCount() - 1);
}
});
addView(tvBottomTip);
//有人@我
tvAtTip = new TextView(context);
LayoutParams params2 = new LayoutParams(
Utils.dip2px(context, 115F), Utils.dip2px(context, 27));
params2.gravity = Gravity.BOTTOM;
params2.leftMargin = UIUtil.getScreenWidth(context) / 2 - UIUtil.dip2px(context, 115 / 2);
tvAtTip.setBackgroundResource(R.drawable.bg_messge_view_bottom_tip);
tvAtTip.setGravity(Gravity.CENTER);
tvAtTip.setText(context.getString(R.string.message_view_bottom_tip));
tvAtTip.setTextColor(context.getResources().getColor(R.color.color_FD85C9));
tvAtTip.setLayoutParams(params2);
tvAtTip.setVisibility(GONE);
tvAtTip.setOnClickListener(v -> {
if (!atMessages.isEmpty()) {
int scrollIndex = chatRoomMessages.indexOf(atMessages.remove(0));
if (scrollIndex != -1 && scrollIndex < mMessageAdapter.getItemCount()) {
messageListView.smoothScrollToPosition(scrollIndex);
}
}
needAutoScroll = false;
checkShowAtTip();
});
addView(tvAtTip);
messageListView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
}
@Override
public void onScrollStateChanged(final RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
// Logger.e(TAG, "onScrollStateChanged: SCROLL_STATE_DRAGGING");
needAutoScroll = false;
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
// Logger.e(TAG, "onScrollStateChanged: SCROLL_STATE_IDLE");
int lastVisibleItemPosition = layoutManger.findLastVisibleItemPosition();
if (lastVisibleItemPosition == RecyclerView.NO_POSITION) {
// Logger.e(TAG, "lastCompletelyVisibleItemPosition : RecyclerView.NO_POSITION");
needAutoScroll = true;
} else if (!atMessages.isEmpty() && atMessages.remove(chatRoomMessages.get(lastVisibleItemPosition))) {
checkShowAtTip();
}
// Log.e(TAG, "lastVisibleItemPosition:" + lastVisibleItemPosition
// + " mMessageAdapter.getItemCount()-1:" + (recyclerView.getAdapter().getItemCount()-1)
// + " dis:"+ (lastVisibleItemPosition-(recyclerView.getAdapter().getItemCount()-1)));
if (lastVisibleItemPosition >= recyclerView.getAdapter().getItemCount() - 3) {
//最後一個顯示出來了
// Logger.e(TAG, ResUtil.getString(R.string.avroom_widget_messageview_01));
needAutoScroll = true;
tvBottomTip.setVisibility(GONE);
keepSizeUnderLimit();
} else {
// Logger.e(TAG, ResUtil.getString(R.string.avroom_widget_messageview_02));
// needAutoScroll = false;
}
}
}
});
}
private TemplateMessageAdapter getTemplateMessageAdapter() {
if (templateMessageAdapter == null) {
templateMessageAdapter = new TemplateMessageAdapter(uid -> {
if (clickConsumer != null) {
Single.just(String.valueOf(uid)).subscribe(clickConsumer);
}
});
}
return templateMessageAdapter;
}
/**
* 添加公屏消息請使用 {@link AvRoomDataManager#addChatRoomMessage(ChatRoomMessage)}
*/
public void addMessages(ChatRoomMessage msg) {
if (msg == null) return;
chatRoomMessages.add(msg);
//通知adapter 刷新
mMessageAdapter.notifyItemInserted(mMessageAdapter.getItemCount() - 1);
showTipsOrScrollToBottom();
checkAtMe(msg, false);
}
public void addMessages(List<ChatRoomMessage> messages) {
if (messages == null) return;
chatRoomMessages.addAll(messages);
//通知adapter 刷新
mMessageAdapter.notifyDataSetChanged();
showTipsOrScrollToBottom();
for (ChatRoomMessage message : messages) {
checkAtMe(message, true);
}
}
public void addHistoryMessages(List<ChatRoomMessage> messages) {
chatRoomMessages.addAll(0, messages);
mMessageAdapter.notifyDataSetChanged();
messageListView.scrollToPosition(mMessageAdapter.getItemCount() - 1);
for (ChatRoomMessage message : messages) {
checkAtMe(message, true);
}
}
private void keepSizeUnderLimit() {
while (chatRoomMessages.size() > MAX_MESSAGE_SIZE) {
Log.i("keepSizeUnderLimit", "size" + chatRoomMessages.size());
ChatRoomMessage message = chatRoomMessages.remove(0);
if (atMessages.remove(message)) {
checkShowAtTip();
}
mMessageAdapter.notifyItemRemoved(0);
}
}
private void checkShowAtTip() {
tvAtTip.setText(getContext().getString(R.string.message_at_tip, atMessages.size()));
tvAtTip.setVisibility(atMessages.size() == 0 ? GONE : VISIBLE);
}
private void checkAtMe(ChatRoomMessage msg, boolean history) {
if (msg.getMsgType() != MsgTypeEnum.text) return;
List<String> atUids = ExtensionUtil.getListExtension(msg, UserInfo.AT_UIDS);
List<String> atNames = ExtensionUtil.getListExtension(msg, UserInfo.AT_NAMES);
if (!ListUtils.isListEmpty(atUids) && !ListUtils.isListEmpty(atNames)) {
for (int i = 0; i < atUids.size(); i++) {
String uid = atUids.get(i);
// 只有當被 @ 人的數組中包含自己的時候才會去變色
if (Objects.equals(uid, String.valueOf(AuthModel.get().getCurrentUid()))) {
Map<String, Long> atMap = DemoCache.readAtMsgUuid();
if (atMap == null || !atMap.containsKey(msg.getUuid())) {
if (!atMessages.contains(msg) && (!needAutoScroll || history)) {
atMessages.add(msg);
checkShowAtTip();
}
DemoCache.saveAtMsgUuid(msg.getUuid());
}
}
}
}
}
public void showTipsOrScrollToBottom() {
if (!needAutoScroll) {
tvBottomTip.setVisibility(VISIBLE);
//超過某值後自動滾動下去
if (mMessageAdapter.getItemCount() > BLOCK_MAX_MESSAGE_SIZE) {
if (mMessageAdapter.getItemCount() > 0) {
messageListView.smoothScrollToPosition(mMessageAdapter.getItemCount() - 1);
}
}
return;
}
}
public void release() {
}
public void clear() {
if (mMessageAdapter != null) {
chatRoomMessages.clear();
mMessageAdapter.notifyDataSetChanged();
}
if (tvBottomTip != null) {
needAutoScroll = true;
tvBottomTip.setVisibility(GONE);
}
}
public void setNeedAutoScroll(boolean needAutoScroll) {
this.needAutoScroll = needAutoScroll;
}
public RecyclerView getMessageListView(){
return messageListView;
}
public interface OnClick {
/**
* 公屏查看公告
*/
void onShowRoomIntroduction();
}
private class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> implements OnClickListener,Function1<Drawable, ImageSpan> {
private Context mContext;
private List<ChatRoomMessage> data;
private int ITEM_TYPE_IMAGE = 1;
public MessageAdapter(Context mContext) {
this.mContext = mContext;
}
public void setData(List<ChatRoomMessage> data) {
this.data = data;
}
@Override
public int getItemViewType(int position) {
ChatRoomMessage chatRoomMessage = data.get(position);
if (chatRoomMessage.getMsgType() == MsgTypeEnum.image) {
return ITEM_TYPE_IMAGE;
}
return super.getItemViewType(position);
}
@Override
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == ITEM_TYPE_IMAGE) {
return new MessageAdapter.MessageViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_chatroom_msg_image, parent, false));
}
return new MessageViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_chatrrom_msg, parent, false));
}
@Override
public void onBindViewHolder(MessageViewHolder holder, int position) {
if (getItemViewType(position) == ITEM_TYPE_IMAGE) {
convertImage(holder, data.get(position));
} else {
convert(holder, data.get(position));
}
}
@Override
public int getItemCount() {
return data.size();
}
protected void convertImage(MessageViewHolder baseViewHolder, ChatRoomMessage chatRoomMessage) {
TextView tvContent = baseViewHolder.tvContent;
tvContent.setLineSpacing(0, 1);
tvContent.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
tvContent.setOnClickListener(this);
tvContent.setTag(chatRoomMessage);
if (UiUtils.INSTANCE.isRtl(tvContent.getContext())) {
tvContent.setTextDirection(View.TEXT_DIRECTION_RTL);
}
try {
setVIPMessageBackground(chatRoomMessage, baseViewHolder.itemView);
ChatRoomMessageExtension extension = chatRoomMessage.getChatRoomMessageExtension();
TextSpannableBuilder text = new TextSpannableBuilder(tvContent);
addCommonTag(chatRoomMessage, text, tvContent);
String nickName = extension == null ? ResUtil.getString(R.string.avroom_widget_messageview_0116) : RegexUtil.getPrintableString(extension.getSenderNick());
text.append(nickName, new ForegroundColorSpan(greyColor));
tvContent.setText(text.build());
ImageView imageView = baseViewHolder.itemView.findViewById(R.id.iv_image);
ImageAttachment msgAttachment = (ImageAttachment) chatRoomMessage.getAttachment();
String path = msgAttachment.getThumbPath();
if (TextUtils.isEmpty(path)) {
path = msgAttachment.getPath();
}
if (TextUtils.isEmpty(path)) {
path = "";
}
ImageLoadUtilsV2.loadImage(imageView, path);
int[] bounds = new int[]{msgAttachment.getWidth(), msgAttachment.getHeight()};
ImageUtil.ImageSize imageSize = ImageUtil.getThumbnailDisplaySize(bounds[0], bounds[1], ChatRoomMessageViewHolderThumbBase.getImageMaxEdge(), ChatRoomMessageViewHolderThumbBase.getImageMinEdge());
ViewGroup.LayoutParams maskParams = imageView.getLayoutParams();
maskParams.width = imageSize.width;
maskParams.height = imageSize.height;
imageView.setLayoutParams(maskParams);
String finalPath = path;
imageView.setOnClickListener(v -> {
BigPhotoActivity.start((Activity) mContext, ObjectTypeHelper.pathToCustomItems(finalPath),
0, new PagerOption());
});
} catch (Exception e) {
e.printStackTrace();
}
}
protected void convert(MessageViewHolder baseViewHolder, ChatRoomMessage chatRoomMessage) {
if (chatRoomMessage == null) return;
TextView tvContent = baseViewHolder.tvContent;
tvContent.setLineSpacing(0, 1);
tvContent.setTextColor(Color.WHITE);
tvContent.setTextSize(defTextSize);
tvContent.setOnClickListener(this);
tvContent.setOnLongClickListener(null);
tvContent.setTag(chatRoomMessage);
tvContent.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
if (UiUtils.INSTANCE.isRtl(tvContent.getContext())) {
tvContent.setTextDirection(View.TEXT_DIRECTION_RTL);
}
clearBackground(tvContent);
try {
if (chatRoomMessage.getMsgType() == MsgTypeEnum.tip) {
// 房間通告
tvContent.setTextColor(ContextCompat.getColor(mContext, R.color.color_white));
tvContent.setText(chatRoomMessage.getContent());
tvContent.setBackgroundResource(R.drawable.shape_room_message_tip_bg);
} else if (chatRoomMessage.getMsgType() == MsgTypeEnum.text) {
setMsgText(chatRoomMessage, tvContent);
setVIPMessageBackground(chatRoomMessage, tvContent);
} else if (chatRoomMessage.getMsgType() == MsgTypeEnum.notification) {
// 加上勛章
setMsgNotification(chatRoomMessage, tvContent, baseViewHolder.getAdapterPosition());
setVIPMessageBackground(chatRoomMessage, tvContent);
} else if (chatRoomMessage.getMsgType() == MsgTypeEnum.custom) {
if (chatRoomMessage.getAttachment() != null && chatRoomMessage.getAttachment() instanceof CustomAttachment) {
CustomAttachment attachment = (CustomAttachment) chatRoomMessage.getAttachment();
int first = attachment.getFirst();
int second = attachment.getSecond();
if (first == CustomAttachment.CUSTOM_MSG_HEADLINE_CHANGED) {
if (second == CustomAttachment.CUSTOM_MSG_HEADLINE_CHANGED_SUB) {
setHeadlineMsg(chatRoomMessage, tvContent, attachment);
}
} else {
tvContent.setTextColor(Color.WHITE);
tvContent.setText(tvContent.getResources().getText(R.string.not_support_message_tip));
}
} else {
tvContent.setText("");
}
}
} catch (UnsupportedOperationException e) {
e.printStackTrace();
clearBackground(tvContent);
tvContent.setTextColor(Color.WHITE);
tvContent.setText(tvContent.getResources().getText(R.string.not_support_message_tip));
} catch (Exception e) {
clearBackground(tvContent);
tvContent.setText("");
}
}
private void clearBackground(TextView textView) {
// 清除文字
textView.setText("");
// 清除聊天氣泡
textView.setBackgroundResource(R.drawable.shape_room_message_bg);
textView.setPadding(paddingWidth, paddingHeight, paddingWidth, paddingHeight);
}
private void setNullBackground(TextView textView) {
// 清除聊天氣泡
textView.setBackground(null);
textView.setPadding(0, 0, 0, 0);
}
public void setVIPMessageBackground(ChatRoomMessage chatRoomMessage, View view) {
String androidBubbleUrl = NobleUtil.getResource(UserInfo.BUBBLE_URL_ANDROID, chatRoomMessage);
if (TextUtils.isEmpty(androidBubbleUrl)) return;
view.setPadding(paddingWidth, ScreenUtil.dip2px(10), paddingWidth, ScreenUtil.dip2px(10));
ImageLoadUtils.loadNinePatchBg(view, androidBubbleUrl);
}
/**
* {badge}{level}xxx: 文字內容
*
* @param chatRoomMessage -
* @param tvContent -
*/
private void setMsgText(ChatRoomMessage chatRoomMessage, TextView tvContent) {
TextSpannableBuilder text = new TextSpannableBuilder(tvContent);
addCommonTag(chatRoomMessage, text, tvContent);
String nickName;
if (chatRoomMessage.getFromAccount() != null && chatRoomMessage.getFromAccount().equals(AuthModel.get().getCurrentUid() + "")) {
nickName = ResUtil.getString(R.string.avroom_widget_messageview_0116);
} else {
nickName = NobleUtil.getNamePlate(UserInfo.NICK, chatRoomMessage);
}
text.append(nickName, new ForegroundColorSpan(greyColor));
text.append(": " + chatRoomMessage.getContent(), new ForegroundColorSpan(getResources().getColor(R.color.white)));
List<String> atUids = ExtensionUtil.getListExtension(chatRoomMessage, UserInfo.AT_UIDS);
List<String> atNames = ExtensionUtil.getListExtension(chatRoomMessage, UserInfo.AT_NAMES);
if (!ListUtils.isListEmpty(atUids) && !ListUtils.isListEmpty(atNames)) {
for (int i = 0; i < atUids.size(); i++) {
String name = atNames.get(i);
String uid = atUids.get(i);
// 只有當被 @ 人的數組中包含自己的時候才會去變色
if (Objects.equals(uid, String.valueOf(AuthModel.get().getCurrentUid()))) {
Pattern pattern = Pattern.compile(Pattern.quote(name));
Matcher matcher = pattern.matcher(text.build().toString());
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
text.build().setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.color_FD85C9)),
start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
}
}
}
if (Objects.equals(chatRoomMessage.getFromAccount(), String.valueOf(AuthModel.get().getCurrentUid()))) {
tvContent.setOnLongClickListener(null);
} else {
tvContent.setOnLongClickListener(v -> {
if (onLongClickListener != null) {
onLongClickListener.onLongClick(v, chatRoomMessage.getFromAccount(), nickName);
}
return true;
});
}
MoonUtil.replaceEmoticons(getContext(), text.builder.toString(), text.builder, this);
tvContent.setText(text.build());
}
private void addCommonTag(ChatRoomMessage chatRoomMessage, @NonNull TextSpannableBuilder builder, TextView tvContent) {
ChatRoomMessageExtension extension = chatRoomMessage.getChatRoomMessageExtension();
String userLevel = NobleUtil.getLevel(UserLevelResourceType.EXPER_URL, chatRoomMessage);
boolean isOfficial = NobleUtil.getIsOfficial(UserInfo.IS_OFFICIAL, chatRoomMessage);
String vipIcon = NobleUtil.getResource(UserInfo.VIP_ICON, chatRoomMessage);
builder.append(vipIcon, expLevelHeight)
.append(isOfficial ? ResourcesCompat.getDrawable(getResources(),
R.mipmap.ic_user_official_13dp, null) : null,
badgeWidth, badgeHeight)
.append(getNewUserDrawable(chatRoomMessage), badgeWidth, badgeHeight)
.append(AvRoomDataManager.get().isSuperAdmin(chatRoomMessage.getFromAccount()) ? ResourcesCompat.getDrawable(getResources(),
R.drawable.ic_room_super_admin, null) : null,
SizeUtils.dp2px(tvContent.getContext(), 23), expLevelHeight);
// 官方主播認證
String tvOfficialMask = NobleUtil.getLevel(UserInfo.OAC_NAME, chatRoomMessage).trim();
String ivOfficialMask = NobleUtil.getLevel(UserInfo.OAC_ICON, chatRoomMessage);
if (!TextUtils.isEmpty(tvOfficialMask) && !TextUtils.isEmpty(ivOfficialMask) && extension != null) { // extension != null 表示自己
builder.appendBgAndContent(ivOfficialMask, tvOfficialMask);
} else if (!TextUtils.isEmpty(ivOfficialMask)) {
builder.append(ivOfficialMask, SizeUtils.dp2px(tvContent.getContext(), 62), expLevelHeight);
}
//等級
builder.append(userLevel, expLevelHeight);
//銘牌
String tvNamePlate = NobleUtil.getNamePlate(UserInfo.NAMEPLATE_WORD, chatRoomMessage).trim();
String ivNamePlate = NobleUtil.getNamePlate(UserInfo.NAMEPLATE_PIC, chatRoomMessage);
if (!TextUtils.isEmpty(tvNamePlate) && !TextUtils.isEmpty(ivNamePlate)) { // extension != null 表示自己
builder.appendBgAndContent(ivNamePlate, tvNamePlate);
} else if (!TextUtils.isEmpty(ivNamePlate)) {
builder.append(ivNamePlate, expLevelHeight);
}
}
private void setHeadlineMsg(ChatRoomMessage chatRoomMessage, TextView tvContent, CustomAttachment attachment) {
HeadlineChangedAttachment headlineAttachment = (HeadlineChangedAttachment) attachment;
SpannableTextBuilder builder = new SpannableTextBuilder(tvContent);
if (attachment.getSecond() == CustomAttachment.CUSTOM_MSG_HEADLINE_CHANGED_SUB) {
HeadlineBean data = headlineAttachment.getHeadlineData();
String nick = null;
if (data != null) {
nick = data.getNick();
}
if (nick == null) {
nick = "";
}
builder.appendText(String.format(ResUtil.getString(R.string.headline_message_format), nick), null, null, null, null, null, null);
builder.setTextStyle(nick, ContextCompat.getColor(getContext(), R.color.color_DE3446), null, null, null, null, null);
}
tvContent.setText(builder.build());
tvContent.setTextSize(11);
setNullBackground(tvContent);
}
/**
* {badge}xxx來了
*
* @param chatRoomMessage -
* @param tvContent -
*/
private void setMsgNotification(ChatRoomMessage chatRoomMessage, TextView tvContent, int position) {
int fromType = 0;
String fromNick = "";
String fromUid = "";
Map<String, Object> remoteExtension = chatRoomMessage.getRemoteExtension();
if (remoteExtension != null) {
fromType = (int) remoteExtension.get("fromType");
fromNick = (String) remoteExtension.get("fromNick");
fromUid = (String) remoteExtension.get("fromUid");
}
ChatRoomNotificationAttachment attachment = (ChatRoomNotificationAttachment) chatRoomMessage.getAttachment();
String senderNick = "";
List<String> nicks = attachment.getTargetNicks();
if (nicks != null && nicks.size() > 0)
senderNick = RegexUtil.getPrintableString(attachment.getTargetNicks().get(0));
if (attachment.getType() != NotificationType.ChatRoomMemberIn) return;
// 座駕
String carName = NobleUtil.getCarName(CarInfo.CAR_NAME, chatRoomMessage);
carName = TextUtils.isEmpty(carName) ? "" : "\"" + carName + "\"";
TextSpannableBuilder text = new TextSpannableBuilder(tvContent);
addCommonTag(chatRoomMessage, text, tvContent);
text.append(senderNick, new ForegroundColorSpan(roomTipColor),
new OriginalDrawStatusClickSpan() {
@Override
public void onClick(@NonNull View view) {
if (clickConsumer != null) {
Single.just(chatRoomMessage.getFromAccount())
.doOnSuccess(clickConsumer).subscribe();
}
}
});
text.append(TextUtils.isEmpty(carName) ? "" : ResUtil.getString(R.string.avroom_widget_messageview_0150), new ForegroundColorSpan(greyColor))
.append(carName, new ForegroundColorSpan(roomTipColor));
String enterText = ResUtil.getString(R.string.avroom_widget_messageview_0151);
if (fromType == AVRoomActivity.FROM_TYPE_RECOMMEND) {
enterText = ResUtil.getString(R.string.avroom_widget_messageview_0152);
}
if (fromType == AVRoomActivity.FROM_TYPE_USER || fromType == AVRoomActivity.FROM_TYPE_HELLO) {
String finalFromUid = fromUid;
text.append(ResUtil.getString(R.string.avroom_widget_messageview_0153), 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 = ResUtil.getString(R.string.avroom_widget_messageview_0154);
}
if (fromType == AVRoomActivity.FROM_TYPE_GAME_RECOMMEND) {
String finalFromUid = fromUid;
text.append(ResUtil.getString(R.string.avroom_widget_messageview_0155), 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 = ResUtil.getString(R.string.avroom_widget_messageview_0156);
}
text.append(enterText, new ForegroundColorSpan(whiteColor));
tvContent.setText(text.build());
tvContent.setOnClickListener(null);
tvContent.setMovementMethod(new LinkMovementMethod());
}
@Nullable
private Drawable getNewUserDrawable(ChatRoomMessage chatRoomMessage) {
boolean newUser = NobleUtil.getIsNewUser(UserInfo.IS_NEW_USER, chatRoomMessage);
boolean isHelloUser = NobleUtil.getIsNewUser(UserInfo.IS_FROM_SAY_HELLO_CHANNEL, chatRoomMessage);
if (newUser) {
return ResourcesCompat.getDrawable(getResources(),
isHelloUser ? R.drawable.ic_new_user_hello : R.drawable.ic_new_user,
null);
}
return null;
}
@SuppressLint("CheckResult")
@Override
public void onClick(View v) {
String account = "";
ChatRoomMessage chatRoomMessage = (ChatRoomMessage) v.getTag();
if (chatRoomMessage.getMsgType() != MsgTypeEnum.tip) {
if (chatRoomMessage.getMsgType() == MsgTypeEnum.text) {
account = chatRoomMessage.getFromAccount();
} else if (chatRoomMessage.getMsgType() == MsgTypeEnum.notification) {
account = chatRoomMessage.getFromAccount();
} else if (chatRoomMessage.getMsgType() == MsgTypeEnum.custom) {
CustomAttachment attachment = (CustomAttachment) chatRoomMessage.getAttachment();
if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_ROOM_TIP) {
account = ((RoomTipAttachment) attachment).getUid() + "";
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_BOX) {
account = String.valueOf(((RoomBoxPrizeAttachment) attachment).getUid());
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_QUEUE) {
long handleUid = ((RoomQueueMsgAttachment) attachment).handleUid;
if (handleUid > 0) {
account = ((RoomQueueMsgAttachment) attachment).handleUid + "";
} else {
//ios沒用handleUid導致iOS發的自定義消息拿不到uid
account = chatRoomMessage.getFromAccount();
}
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_MONSTER_HUNTING) {
switch (attachment.getSecond()) {
case CustomAttachment.CUSTOM_MSG_SUB_TYPE_MONSTER_HUNTING:
MonsterDataBean dataBean = ((MonsterStatusAttachment) attachment).getDataBean();
RoomInfo mCurrentRoomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
if (!Objects.equals(mCurrentRoomInfo.getUid(), dataBean.getAppearRoomUid())) {
AVRoomActivity.start(getContext(), dataBean.getAppearRoomUid());
} else {
SingleToastUtil.showToast("你已經在怪獸房間內");
}
break;
case CustomAttachment.CUSTOM_NOTI_SUB_GAME_RESULT:
MonsterHuntingResult result = ((MonsterHuntingResultAttachment) attachment).getResult();
UIHelper.showMonsterResult(getContext(), String.valueOf(result.getMonster().getMonsterId()));
break;
}
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MESS_HEAD_ROOM_PK) {
if (attachment.getSecond() == CustomAttachment.CUSTOM_MESS_SUB_ROOM_PK_RESULT) {
RoomTeamPKResultDialog pkResultDialog = new RoomTeamPKResultDialog(getContext(), ((RoomPkAttachment) attachment).getRoomPkData());
pkResultDialog.show();
}
} else if (attachment instanceof RoomFollowOwnerAttachment2 && !AvRoomDataManager.get().isRoomFans) {
CollectionRoomModel.get().followRoom("1", ((RoomFollowOwnerAttachment2) attachment).getOwnerUid())
.subscribe(s -> {
AvRoomDataManager.get().isRoomFans = true;
SingleToastUtil.showToast("收藏成功!");
EventBus.getDefault().post(new FollowRoomEvent());
PraiseModel.get().setFollowRoomSuccessRoomTip(JavaUtil.str2long(chatRoomMessage.getFromAccount()));
});
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MESS_TAROT) {
if (attachment instanceof TarotAttachment) {
account = ((TarotAttachment) attachment).getTarotMsgBean().getUid() + "";
}
}
}
if (TextUtils.isEmpty(account)) return;
if (clickConsumer != null) {
Single.just(account).subscribe(clickConsumer);
}
} else {
String content = chatRoomMessage.getContent();
if (!TextUtils.isEmpty(content) && content.equals(ResUtil.getString(R.string.yizhuan_xchat_android_constants_xchatconstants_08)))
if (onClick != null) {
onClick.onShowRoomIntroduction();
}
}
}
@Override
public ImageSpan invoke(Drawable drawable) {
return new CustomImageSpan(drawable);
}
class MessageViewHolder extends RecyclerView.ViewHolder {
TextView tvContent;
public MessageViewHolder(View itemView) {
super(itemView);
tvContent = itemView.findViewById(R.id.tv_content);
}
}
}
}

View File

@@ -1,111 +0,0 @@
package com.chwl.app.avroom.public_chat
import android.content.Context
import android.util.AttributeSet
import com.chwl.app.R
import com.chwl.app.public_chat.core.ChatRoomClient
import com.chwl.app.public_chat.core.ChatRoomClientManager
import com.chwl.core.im.custom.bean.HeadlineChangedAttachment
import com.chwl.core.support.room.FrameLayoutRoomWidget
import com.chwl.core.support.room.RoomView
import com.chwl.library.utils.SingleToastUtil
import com.netease.nim.uikit.api.model.NimException
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum
import com.netease.nimlib.sdk.msg.model.QueryDirectionEnum
class PublicChatRoomMessageWidget : FrameLayoutRoomWidget {
private val messageView: PublicChatMessageView = PublicChatMessageView(context)
private var chatRoomClient: ChatRoomClient? = null
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes)
init {
addView(messageView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
}
override fun onStart(roomView: RoomView) {
super.onStart(roomView)
chatRoomClient = ChatRoomClientManager.getPublicChatClient()
if (chatRoomClient == null) {
SingleToastUtil.showToast(R.string.public_chat_not_found)
}
chatRoomClient?.let {
initChatRoom(it)
}
}
private fun onReceiveMessage(message: ChatRoomMessage) {
if (!filterMessageForMessageList(message)) {
messageView.addMessages(message)
}
}
private fun initChatRoom(chatRoomClient: ChatRoomClient) {
getCompositeDisposable().add(
chatRoomClient.enterChatRoom()
.subscribe({ requestHistory(chatRoomClient) },
{
if (it is NimException) {
SingleToastUtil.showToast(context.getString(R.string.avroom_fragment_homepartyroomfragment_011) + "(${it.code})")
} else {
SingleToastUtil.showToast(R.string.avroom_fragment_homepartyroomfragment_011)
}
})
)
getCompositeDisposable().add(chatRoomClient.messageObservable.subscribe {
it.forEach { message ->
onReceiveMessage(message)
}
})
}
private fun requestHistory(chatRoomClient: ChatRoomClient) {
val typeEnums = arrayOf(MsgTypeEnum.text, MsgTypeEnum.image)
getCompositeDisposable().add(
chatRoomClient.requestRemoteMessageType(
0,
50,
QueryDirectionEnum.QUERY_OLD,
typeEnums
).subscribe({
messageView.addHistoryMessages(it.reversed())
}, {
it.printStackTrace()
})
)
}
private fun filterMessageForMessageList(message: ChatRoomMessage): Boolean {
if (message.msgType == MsgTypeEnum.custom && message.attachment is HeadlineChangedAttachment) {
val data = (message.attachment as HeadlineChangedAttachment).headlineData
if (data == null || !data.isValid()) {
return true
}
}
return false
}
fun getMessageView() = messageView
override fun onStop() {
super.onStop()
chatRoomClient = null
}
}

View File

@@ -1,58 +0,0 @@
package com.chwl.app.home.adapter
import android.text.style.ImageSpan
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseViewHolder
import com.chwl.app.R
import com.chwl.app.ui.utils.loadAvatar
import com.chwl.core.public_chat_hall.bean.PublicChatMessageBean
import com.netease.nim.uikit.api.NimUIKit
import com.netease.nim.uikit.business.session.emoji.MoonUtil
class PublicChatLaneAdapter(private val data: MutableList<PublicChatMessageBean>) :
RecyclerView.Adapter<BaseViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
return BaseViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.public_chat_lane_item, null)
)
}
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
val item = getItem(position)
val textView = holder.getView<TextView>(R.id.tv_message)
MoonUtil.identifyFaceExpressionSmall(
NimUIKit.getContext(),
textView,
item?.content ?: "",
ImageSpan.ALIGN_CENTER
)
val avatarView = holder.getView<ImageView>(R.id.iv_avatar)
avatarView.loadAvatar(item?.fromAvatar ?: "")
}
override fun getItemCount(): Int {
return Int.MAX_VALUE
}
fun getRealItemCount(): Int {
return data.size
}
fun setNewData(list: List<PublicChatMessageBean>) {
data.clear()
data.addAll(list)
notifyDataSetChanged()
}
private fun getItem(position: Int): PublicChatMessageBean? {
if (data.isEmpty()) {
return null
}
return data[position % data.size]
}
}

View File

@@ -19,7 +19,6 @@ import com.chwl.app.avroom.adapter.CommonVPAdapter
import com.chwl.app.base.BaseViewBindingFragment
import com.chwl.app.databinding.FragmentContactListBinding
import com.chwl.app.home.HomeMessageViewModel
import com.chwl.app.home.adapter.PublicChatLaneAdapter
import com.chwl.app.home.helper.AutoScrollTask
import com.chwl.app.public_chat.ui.message.PublicChatRoomMessageActivity
import com.chwl.app.support.FragmentVisibleStateHelper
@@ -42,7 +41,6 @@ class ContactsListFragment : BaseViewBindingFragment<FragmentContactListBinding>
MainTabContentView {
private val viewModel: HomeMessageViewModel by activityViewModels()
private val publicChatAdapter = PublicChatLaneAdapter(ArrayList())
private val stateHelper = FragmentVisibleStateHelper(this).start {
onVisibleChanged(it)
@@ -64,7 +62,6 @@ class ContactsListFragment : BaseViewBindingFragment<FragmentContactListBinding>
} else {
2
}
binding.recyclerViewPublicChat.scrollBy(x, 0)
}
override fun init() {
@@ -159,37 +156,20 @@ class ContactsListFragment : BaseViewBindingFragment<FragmentContactListBinding>
return true
}
})
binding.layoutPublicChat.singleClick {
PublicChatRoomMessageActivity.start(requireContext())
}
binding.recyclerViewPublicChat.setOnTouchListener { v, event ->
gestureDetectorCompat.onTouchEvent(event)
}
binding.recyclerViewPublicChat.layoutManager =
StaggeredGridLayoutManager(2, RecyclerView.HORIZONTAL)
binding.recyclerViewPublicChat.adapter = publicChatAdapter
viewModel.topPublicChatMessageLiveData.observe(this) {
val newList = it.data
if (it.isSuccess && !newList.isNullOrEmpty()) {
publicChatAdapter.setNewData(newList)
switchPublicChatMessageScrollState(stateHelper.isVisible)
}
binding.recyclerViewPublicChat.isVisible = (publicChatAdapter.getRealItemCount() > 0)
}
}
private fun switchPublicChatMessageScrollState(isVisible: Boolean) {
if (isVisible && publicChatAdapter.getRealItemCount() > 0) {
autoScrollTask.start()
} else {
autoScrollTask.stop()
}
// if (isVisible && publicChatAdapter.getRealItemCount() > 0) {
// autoScrollTask.start()
// } else {
// autoScrollTask.stop()
// }
}
private fun onVisibleChanged(isVisible: Boolean) {
switchPublicChatMessageScrollState(isVisible)
if (isVisible) {
viewModel.getTopPublicChatMessageIfNull()
}
// switchPublicChatMessageScrollState(isVisible)
// if (isVisible) {
// viewModel.getTopPublicChatMessageIfNull()
// }
}
}

View File

@@ -63,6 +63,7 @@ class VipCenterActivity : BaseViewBindingActivity<ActivityVipCenterBinding>(),
private val authAdapter = VipAuthAdapter() // 用户权限
private val vipViewModel: VipViewModel by viewModels()
private var chargeList: List<ChargeBean>? = null
private var authInfoList: List<VipAuthInfo>? = null
private val rebateAdapter = VipRebateAdapter()
private var currentChargeInfo: ChargeBean? = null
private lateinit var rvDelegate: RVDelegate<VipAuthInfo>
@@ -105,12 +106,6 @@ class VipCenterActivity : BaseViewBindingActivity<ActivityVipCenterBinding>(),
.setAdapter(authAdapter)
.build()
authAdapter.setOnItemClickListener { _, _, position ->
authAdapter.getItem(position)?.let {
VipAuthDetailsDialog.newInstance(it.descPic, it.authName, it.authIntro).show(this)
}
}
handleAuthAdapter()
handleViewModel()
handleBinding()
@@ -198,11 +193,20 @@ class VipCenterActivity : BaseViewBindingActivity<ActivityVipCenterBinding>(),
vipViewModel.authInfosLiveData.observe(this) {
// ArrayList[VipAuthInfo] // 全部特权列表
authAdapter.setNewData(it)
it?.let {
val filteredList = it.filter { authInfo ->
authInfo.authType == 4 || authInfo.authType == 6 || authInfo.authType == 10 || authInfo.authType == 14 || authInfo.authType == 15 || authInfo.authType == 12 || authInfo.authType == 13
}
authInfoList = filteredList
authAdapter.setNewData(filteredList)
vipIdentificationsAdapter = VipCenterIdentificationsAdapter(this, it, this)
recyclerView.adapter = vipIdentificationsAdapter
}
// authAdapter.setNewData(it)
// it?.let {
// vipIdentificationsAdapter = VipCenterIdentificationsAdapter(this, it, this)
// recyclerView.adapter = vipIdentificationsAdapter
// }
}
vipViewModel.pageLiveData.observe(this) {
@@ -277,7 +281,14 @@ class VipCenterActivity : BaseViewBindingActivity<ActivityVipCenterBinding>(),
private fun handleIdentificationAreaContent(vipInfo: VipInfo) {
val exclusivePrivilegesTitle = findViewById<TextView>(R.id.center_title_2)
"${getString(R.string.vip_center_4)}\n(${vipInfo.ownAuthTypes?.size}/13)".also {
var count = 0
authInfoList?.map { info ->
if (vipInfo?.ownAuthTypes?.contains(info.authType) == true) {
count ++
}
}
"${getString(R.string.vip_center_4)}\n(${count}/${authInfoList?.size}})".also {
binding.centerTitle2.text = it
}
// exclusivePrivilegesTitle.text = R.string.vip_center_4.toString()

View File

@@ -57,7 +57,6 @@ class VipCenterBannerAdapter(
}
}
var colorHex = ""
var resourceName = "vip_center_level_${position+1}"
val resourceId = context.resources.getIdentifier(resourceName, "drawable", context.packageName)
holder.imgBackground.setImageResource(resourceId)

View File

@@ -13,56 +13,56 @@
android:src="@drawable/bg_theme_top_home"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_public_chat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/dp_44"
android:background="@drawable/public_chat_bg_lane"
app:layout_constraintDimensionRatio="375:112"
app:layout_constraintTop_toTopOf="parent">
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:id="@+id/layout_public_chat"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- android:layout_marginTop="@dimen/dp_44"-->
<!-- android:background="@drawable/public_chat_bg_lane"-->
<!-- app:layout_constraintDimensionRatio="375:112"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/line_public_chat_title_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.22" />
<!-- <androidx.constraintlayout.widget.Guideline-->
<!-- android:id="@+id/line_public_chat_title_top"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal"-->
<!-- app:layout_constraintGuide_percent="0.22" />-->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/line_public_chat_list_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.46" />
<!-- <androidx.constraintlayout.widget.Guideline-->
<!-- android:id="@+id/line_public_chat_list_top"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal"-->
<!-- app:layout_constraintGuide_percent="0.46" />-->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/line_public_chat_list_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.94" />
<!-- <androidx.constraintlayout.widget.Guideline-->
<!-- android:id="@+id/line_public_chat_list_bottom"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal"-->
<!-- app:layout_constraintGuide_percent="0.94" />-->
<TextView
android:id="@+id/tv_public_chat_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/public_chat_room"
android:textColor="#FFDDA2"
android:textSize="@dimen/dp_17"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/line_public_chat_title_top" />
<!-- <TextView-->
<!-- android:id="@+id/tv_public_chat_title"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/public_chat_room"-->
<!-- android:textColor="#FFDDA2"-->
<!-- android:textSize="@dimen/dp_17"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="@id/line_public_chat_title_top" />-->
<androidx.recyclerview.widget.RecyclerView
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/recycler_view_public_chat"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@id/line_public_chat_list_bottom"
app:layout_constraintTop_toTopOf="@id/line_public_chat_list_top" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:visibility="gone"-->
<!-- tools:visibility="visible"-->
<!-- android:id="@+id/recycler_view_public_chat"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintBottom_toBottomOf="@id/line_public_chat_list_bottom"-->
<!-- app:layout_constraintTop_toTopOf="@id/line_public_chat_list_top" />-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<LinearLayout
android:id="@+id/ll_title"
@@ -72,8 +72,9 @@
android:orientation="horizontal"
android:paddingStart="@dimen/dp_15"
android:paddingEnd="@dimen/dp_15"
android:layout_marginTop="@dimen/dp_44"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_public_chat"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginTop="@dimen/dp_44">
<com.chwl.app.ui.widget.magicindicator.MagicIndicator

View File

@@ -186,7 +186,6 @@
android:layout_marginEnd="@dimen/dp_11"
android:layout_marginBottom="@dimen/dp_10"
android:onClick="@{click}"
android:src="@drawable/room_ic_collect_no"
android:visibility="visible"
tools:visibility="visible" />

View File

@@ -1069,7 +1069,6 @@ class mapping:
fdb.ddbd.LinkIntent -> er.BJQ
cffafe.edafba.LanguageAdapter -> et.BJR
cffafe.edafba.LanguageItem -> et.BJS
bfedffaa.adfffbef.public_chat.PublicChatMessageView -> eu.BJT
caebbec.bfcfbdf.BaiShunGameWebActivity -> ev.BJU
afdf.affbd.PublicChatRoomMessageActivity -> ew.BJV
affeefb.cddaaab.DecorationStoreActivity -> cx.BJW