From adf2adc173592d24a17e72ebf5ce35032f543f8d Mon Sep 17 00:00:00 2001 From: max Date: Tue, 27 Aug 2024 16:51:36 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=AA=BF=E6=95=B4=20VIP=20?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E9=82=8F=E8=BC=AF=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=AC=E8=81=8A=E5=BB=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/avroom/fragment/BaseRoomFragment.kt | 17 +- .../app/avroom/fragment/GameRoomFragment.kt | 3 - .../public_chat/PublicChatMessageView.java | 884 ------------------ .../PublicChatRoomMessageWidget.kt | 111 --- .../app/home/adapter/PublicChatLaneAdapter.kt | 58 -- .../app/home/fragment/ContactsListFragment.kt | 38 +- .../com/chwl/app/vip/VipCenterActivity.kt | 27 +- .../app/vip/adapter/VipCenterBannerAdapter.kt | 1 - .../main/res/layout/fragment_contact_list.xml | 93 +- .../main/res/layout/fragment_single_room.xml | 1 - app/xml-class-mapping.txt | 1 - 11 files changed, 77 insertions(+), 1157 deletions(-) delete mode 100644 app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatMessageView.java delete mode 100644 app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt delete mode 100644 app/src/main/java/com/chwl/app/home/adapter/PublicChatLaneAdapter.kt diff --git a/app/src/main/java/com/chwl/app/avroom/fragment/BaseRoomFragment.kt b/app/src/main/java/com/chwl/app/avroom/fragment/BaseRoomFragment.kt index 75bda0ddb..863dd2c1a 100644 --- a/app/src/main/java/com/chwl/app/avroom/fragment/BaseRoomFragment.kt +++ b/app/src/main/java/com/chwl/app/avroom/fragment/BaseRoomFragment.kt @@ -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?> : 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?> : protected open fun initMessageView() { messagePager = mView.findViewById(R.id.message_pager) messageView = MessageView(context) - publicChatMessageWidget = PublicChatRoomMessageWidget(requireContext()) val tabList: MutableList = 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(R.id.message_indicator) messagePager.offscreenPageLimit = tabList.size messagePager.adapter = object : RecyclerView.Adapter() { @@ -255,12 +252,7 @@ open class BaseRoomFragment?> : 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?> : return } mvpPresenter?.sendPublicChatTextMessage(message) - publicChatMessageWidget?.getMessageView()?.setNeedAutoScroll(true) // 發送後自動滾動公屏列表 inputEdit.setText("") } @@ -1250,7 +1241,6 @@ open class BaseRoomFragment?> : } override fun onSendPublicChatMsgSuccess(msg: ChatRoomMessage) { - publicChatMessageWidget?.getMessageView()?.addMessages(msg) inputEdit.setText("") KeyBoardUtils.hideKeyBoard(activity, inputEdit) } @@ -1542,9 +1532,6 @@ open class BaseRoomFragment?> : } open fun initWidget() { - publicChatMessageWidget?.let { - registerWidget(PublicChatRoomMessageWidget::class.java.simpleName, it) - } } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/app/src/main/java/com/chwl/app/avroom/fragment/GameRoomFragment.kt b/app/src/main/java/com/chwl/app/avroom/fragment/GameRoomFragment.kt index 4e2ee4d7f..123adc780 100644 --- a/app/src/main/java/com/chwl/app/avroom/fragment/GameRoomFragment.kt +++ b/app/src/main/java/com/chwl/app/avroom/fragment/GameRoomFragment.kt @@ -100,9 +100,6 @@ class GameRoomFragment : BaseRoomFragment(), messageView.messageListView?.let { setMessagePagerAutoHeight(it) } - publicChatMessageWidget?.getMessageView()?.messageListView?.let { - setMessagePagerAutoHeight(it) - } } override fun onClick(v: View) { diff --git a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatMessageView.java b/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatMessageView.java deleted file mode 100644 index d9924005b..000000000 --- a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatMessageView.java +++ /dev/null @@ -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 atMessages = new ArrayList<>(); - private final List 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 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 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 messages) { - if (messages == null) return; - chatRoomMessages.addAll(messages); - //通知adapter 刷新 - mMessageAdapter.notifyDataSetChanged(); - showTipsOrScrollToBottom(); - for (ChatRoomMessage message : messages) { - checkAtMe(message, true); - } - } - - public void addHistoryMessages(List 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 atUids = ExtensionUtil.getListExtension(msg, UserInfo.AT_UIDS); - List 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 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 implements OnClickListener,Function1 { - - private Context mContext; - private List data; - - private int ITEM_TYPE_IMAGE = 1; - - public MessageAdapter(Context mContext) { - this.mContext = mContext; - } - - public void setData(List 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 atUids = ExtensionUtil.getListExtension(chatRoomMessage, UserInfo.AT_UIDS); - List 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 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 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); - } - } - } -} diff --git a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt b/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt deleted file mode 100644 index 17ae17d59..000000000 --- a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt +++ /dev/null @@ -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 - } -} \ No newline at end of file diff --git a/app/src/main/java/com/chwl/app/home/adapter/PublicChatLaneAdapter.kt b/app/src/main/java/com/chwl/app/home/adapter/PublicChatLaneAdapter.kt deleted file mode 100644 index c258e88e5..000000000 --- a/app/src/main/java/com/chwl/app/home/adapter/PublicChatLaneAdapter.kt +++ /dev/null @@ -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) : - RecyclerView.Adapter() { - 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(R.id.tv_message) - MoonUtil.identifyFaceExpressionSmall( - NimUIKit.getContext(), - textView, - item?.content ?: "", - ImageSpan.ALIGN_CENTER - ) - val avatarView = holder.getView(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) { - data.clear() - data.addAll(list) - notifyDataSetChanged() - } - - private fun getItem(position: Int): PublicChatMessageBean? { - if (data.isEmpty()) { - return null - } - return data[position % data.size] - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/chwl/app/home/fragment/ContactsListFragment.kt b/app/src/main/java/com/chwl/app/home/fragment/ContactsListFragment.kt index f979a8f7d..a639f3eed 100644 --- a/app/src/main/java/com/chwl/app/home/fragment/ContactsListFragment.kt +++ b/app/src/main/java/com/chwl/app/home/fragment/ContactsListFragment.kt @@ -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 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 } else { 2 } - binding.recyclerViewPublicChat.scrollBy(x, 0) } override fun init() { @@ -159,37 +156,20 @@ class ContactsListFragment : BaseViewBindingFragment 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() +// } } } \ No newline at end of file diff --git a/app/src/main/java/com/chwl/app/vip/VipCenterActivity.kt b/app/src/main/java/com/chwl/app/vip/VipCenterActivity.kt index a37c56d84..da362dc5c 100644 --- a/app/src/main/java/com/chwl/app/vip/VipCenterActivity.kt +++ b/app/src/main/java/com/chwl/app/vip/VipCenterActivity.kt @@ -63,6 +63,7 @@ class VipCenterActivity : BaseViewBindingActivity(), private val authAdapter = VipAuthAdapter() // 用户权限 private val vipViewModel: VipViewModel by viewModels() private var chargeList: List? = null + private var authInfoList: List? = null private val rebateAdapter = VipRebateAdapter() private var currentChargeInfo: ChargeBean? = null private lateinit var rvDelegate: RVDelegate @@ -105,12 +106,6 @@ class VipCenterActivity : BaseViewBindingActivity(), .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(), 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(), private fun handleIdentificationAreaContent(vipInfo: VipInfo) { val exclusivePrivilegesTitle = findViewById(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() diff --git a/app/src/main/java/com/chwl/app/vip/adapter/VipCenterBannerAdapter.kt b/app/src/main/java/com/chwl/app/vip/adapter/VipCenterBannerAdapter.kt index 2cc6eb036..c4af83732 100644 --- a/app/src/main/java/com/chwl/app/vip/adapter/VipCenterBannerAdapter.kt +++ b/app/src/main/java/com/chwl/app/vip/adapter/VipCenterBannerAdapter.kt @@ -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) diff --git a/app/src/main/res/layout/fragment_contact_list.xml b/app/src/main/res/layout/fragment_contact_list.xml index 2ae55474c..bee6604db 100644 --- a/app/src/main/res/layout/fragment_contact_list.xml +++ b/app/src/main/res/layout/fragment_contact_list.xml @@ -13,56 +13,56 @@ android:src="@drawable/bg_theme_top_home" app:layout_constraintTop_toTopOf="parent" /> - + + + + + + + + - + + + + + + - + + + + + + - + + + + + + - + + + + + + + + + + - - + + + + + + + + + diff --git a/app/xml-class-mapping.txt b/app/xml-class-mapping.txt index abd9ce561..ba05a7bfb 100644 --- a/app/xml-class-mapping.txt +++ b/app/xml-class-mapping.txt @@ -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