feat:完成游戏房公聊业务
fix:公聊入口弹幕支持emoji展示
This commit is contained in:
@@ -232,7 +232,7 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
|
||||
})
|
||||
}
|
||||
|
||||
private fun initMessageView() {
|
||||
protected open fun initMessageView() {
|
||||
messagePager = mView.findViewById<ViewPager2>(R.id.message_pager)
|
||||
messageView = MessageView(context)
|
||||
publicChatMessageWidget = PublicChatRoomMessageWidget(requireContext())
|
||||
|
@@ -2,10 +2,14 @@ package com.chwl.app.avroom.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.avroom.adapter.GameMicroViewAdapter
|
||||
import com.chwl.app.avroom.adapter.GameMiniMicroViewAdapter
|
||||
@@ -20,6 +24,7 @@ import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.music.model.PlayerModel
|
||||
import com.chwl.core.room.event.FinishAvRoomEvent
|
||||
import com.chwl.library.base.factory.CreatePresenter
|
||||
import com.netease.nim.uikit.common.util.sys.ScreenUtil
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
@@ -77,6 +82,34 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
|
||||
gameBinding.ivShowMic.setOnClickListener { showMic() }
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun initMessageView() {
|
||||
super.initMessageView()
|
||||
messageView.messageListView?.let {
|
||||
setMessagePagerAutoHeight(it)
|
||||
}
|
||||
publicChatMessageWidget?.getMessageView()?.messageListView?.let {
|
||||
setMessagePagerAutoHeight(it)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun setMessagePagerAutoHeight(recyclerView: RecyclerView){
|
||||
recyclerView.setOnTouchListener(OnTouchListener { v: View?, event: MotionEvent ->
|
||||
if (recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& event.action == MotionEvent.ACTION_UP
|
||||
) {
|
||||
val layoutParams: ViewGroup.LayoutParams = messagePager.layoutParams
|
||||
val bigHeight = ScreenUtil.dip2px(200f)
|
||||
val littleHeight = ScreenUtil.dip2px(80f)
|
||||
layoutParams.height =
|
||||
if (layoutParams.height == littleHeight) bigHeight else littleHeight
|
||||
messagePager.layoutParams = layoutParams
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
|
||||
private fun showMiniMic() {
|
||||
if (isShowMiniMic) return
|
||||
isShowMiniMic = true
|
||||
|
@@ -204,19 +204,6 @@ public class PublicChatMessageView extends FrameLayout {
|
||||
messageListView.getItemAnimator().setMoveDuration(0);
|
||||
messageListView.getItemAnimator().setRemoveDuration(0);
|
||||
((SimpleItemAnimator) messageListView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
if (AvRoomDataManager.get().isOpenGame()) {
|
||||
messageListView.setOnTouchListener((v, event) -> {
|
||||
if (messageListView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& event.getAction() == MotionEvent.ACTION_UP) {
|
||||
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
||||
int bigHeight = ScreenUtil.dip2px(200);
|
||||
int littleHeight = ScreenUtil.dip2px(80);
|
||||
layoutParams.height = layoutParams.height == littleHeight ? bigHeight : littleHeight;
|
||||
setLayoutParams(layoutParams);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// 底部有新消息
|
||||
tvBottomTip = new TextView(context);
|
||||
@@ -317,15 +304,6 @@ public class PublicChatMessageView extends FrameLayout {
|
||||
return templateMessageAdapter;
|
||||
}
|
||||
|
||||
public void onCurrentRoomReceiveNewMsg(List<ChatRoomMessage> messages) {
|
||||
if (messages == null) return;
|
||||
if (messages.size() == 1) {
|
||||
addMessages(messages.get(0));
|
||||
} else {
|
||||
addHistoryMessages(messages);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加公屏消息請使用 {@link AvRoomDataManager#addChatRoomMessage(ChatRoomMessage)}
|
||||
*/
|
||||
@@ -350,7 +328,7 @@ public class PublicChatMessageView extends FrameLayout {
|
||||
}
|
||||
|
||||
public void addHistoryMessages(List<ChatRoomMessage> messages) {
|
||||
chatRoomMessages.addAll(chatRoomMessages.size() > 0 ? 1 : 0, messages);
|
||||
chatRoomMessages.addAll(0, messages);
|
||||
mMessageAdapter.notifyDataSetChanged();
|
||||
messageListView.scrollToPosition(mMessageAdapter.getItemCount() - 1);
|
||||
for (ChatRoomMessage message : messages) {
|
||||
@@ -432,6 +410,10 @@ public class PublicChatMessageView extends FrameLayout {
|
||||
this.needAutoScroll = needAutoScroll;
|
||||
}
|
||||
|
||||
public RecyclerView getMessageListView(){
|
||||
return messageListView;
|
||||
}
|
||||
|
||||
public interface OnClick {
|
||||
/**
|
||||
* 公屏查看公告
|
||||
|
@@ -126,11 +126,11 @@ class PublicChatRoomMessageWidget : FrameLayoutRoomWidget {
|
||||
|
||||
private fun updateHeadline(data: HeadlineBean?) {
|
||||
val content = data?.content
|
||||
if (content.isNullOrEmpty()) {
|
||||
binding.tvHeadlineContent.isVisible = false
|
||||
} else {
|
||||
if (data?.isValid() == true && !content.isNullOrEmpty()) {
|
||||
binding.tvHeadlineContent.text = content
|
||||
binding.tvHeadlineContent.isVisible = true
|
||||
} else {
|
||||
binding.tvHeadlineContent.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,8 @@ class PublicChatRoomMessageWidget : FrameLayoutRoomWidget {
|
||||
return true
|
||||
}
|
||||
if (message.attachment is HeadlineChangedAttachment) {
|
||||
if ((message.attachment as HeadlineChangedAttachment).headlineData == null) {
|
||||
val data = (message.attachment as HeadlineChangedAttachment).headlineData
|
||||
if (data == null || !data.isValid()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -340,19 +340,6 @@ public class MessageView extends FrameLayout {
|
||||
messageListView.getItemAnimator().setMoveDuration(0);
|
||||
messageListView.getItemAnimator().setRemoveDuration(0);
|
||||
((SimpleItemAnimator) messageListView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
if (AvRoomDataManager.get().isOpenGame()) {
|
||||
messageListView.setOnTouchListener((v, event) -> {
|
||||
if (messageListView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& event.getAction() == MotionEvent.ACTION_UP) {
|
||||
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
||||
int bigHeight = ScreenUtil.dip2px(200);
|
||||
int littleHeight = ScreenUtil.dip2px(80);
|
||||
layoutParams.height = layoutParams.height == littleHeight ? bigHeight : littleHeight;
|
||||
setLayoutParams(layoutParams);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// 底部有新消息
|
||||
tvBottomTip = new TextView(context);
|
||||
@@ -584,6 +571,10 @@ public class MessageView extends FrameLayout {
|
||||
this.needAutoScroll = needAutoScroll;
|
||||
}
|
||||
|
||||
public RecyclerView getMessageListView(){
|
||||
return messageListView;
|
||||
}
|
||||
|
||||
public interface OnClick {
|
||||
/**
|
||||
* 點擊關註
|
||||
|
@@ -64,12 +64,9 @@ public class CustomAutoWidthImageSpan extends ImageSpan {
|
||||
width = Math.round(height / ratio);
|
||||
TextView textView = reference.get();
|
||||
if (textView == null) return true;
|
||||
textView.post(() -> {
|
||||
CustomAutoWidthImageSpan.this.drawable = resource;
|
||||
CustomAutoWidthImageSpan.this.drawable.setBounds(0, 0, width, height);
|
||||
textView.setText(textView.getText());
|
||||
});
|
||||
|
||||
CustomAutoWidthImageSpan.this.drawable = resource;
|
||||
CustomAutoWidthImageSpan.this.drawable.setBounds(0, 0, width, height);
|
||||
textView.postInvalidate();
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
@@ -1,13 +1,17 @@
|
||||
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>() {
|
||||
@@ -19,7 +23,13 @@ class PublicChatLaneAdapter(private val data: MutableList<PublicChatMessageBean>
|
||||
|
||||
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.setText(R.id.tv_message, item?.content ?: "")
|
||||
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 ?: "")
|
||||
}
|
||||
|
@@ -82,13 +82,20 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
tools:layout_height="@dimen/dp_52" />
|
||||
|
||||
<com.chwl.app.avroom.widget.MessageView
|
||||
android:id="@+id/message_view"
|
||||
<com.chwl.app.ui.widget.magicindicator.MagicIndicator
|
||||
android:id="@+id/message_indicator"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_35"
|
||||
android:layout_marginTop="@dimen/dp_5"
|
||||
android:layout_above="@id/message_pager" />
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/message_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_above="@id/bottom_view"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="@dimen/dp_5"
|
||||
android:layout_marginEnd="90dp"
|
||||
android:layout_marginBottom="@dimen/dp_10" />
|
||||
|
||||
@@ -129,6 +136,15 @@
|
||||
android:background="@drawable/click_white_gray_selector"
|
||||
android:scaleType="center"
|
||||
android:src="@android:drawable/ic_menu_send" />
|
||||
|
||||
<ImageView
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:id="@+id/input_headline_send"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/room_ic_headline_send" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@@ -16,6 +16,7 @@ import com.chwl.app.public_chat.core.ChatRoomMessageAdapter;
|
||||
import com.chwl.core.im.custom.bean.HeadlineChangedAttachment;
|
||||
import com.chwl.core.module_hall.im.HallAttachment;
|
||||
import com.chwl.core.module_hall.im.HallImMsgInfo;
|
||||
import com.chwl.core.public_chat_hall.bean.HeadlineBean;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
import com.chwl.library.utils.SingleToastUtil;
|
||||
import com.netease.nim.uikit.api.NimUIKit;
|
||||
@@ -371,7 +372,8 @@ public class PublicChatRoomMessageListPanel {
|
||||
return true;
|
||||
}
|
||||
if (message.getAttachment() instanceof HeadlineChangedAttachment) {
|
||||
if (((HeadlineChangedAttachment) message.getAttachment()).getHeadlineData() == null) {
|
||||
HeadlineBean data = ((HeadlineChangedAttachment) message.getAttachment()).getHeadlineData();
|
||||
if (data == null || !data.isValid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,11 @@ class PublicChatRoomViewModel : BaseViewModel() {
|
||||
}
|
||||
|
||||
private fun updateHeadline(headline: HeadlineBean?) {
|
||||
headlineLiveData.postValue(headline)
|
||||
if (headline?.isValid() == true) {
|
||||
headlineLiveData.postValue(headline)
|
||||
} else {
|
||||
headlineLiveData.postValue(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerReceiveMessage(chatRoomClient: ChatRoomClient) {
|
||||
|
@@ -7,6 +7,6 @@
|
||||
<string name="headline_message_format">~عزيزي%s، هيا تصدر العناوين </string>
|
||||
<string name="insufficient_balance_recharge_tips">رصيد العملات الذهبية غير كافي ،هل تريد إعادة الشحن علي الفور؟</string>
|
||||
<string name="headline_input_hint">الرجاء إدخال المحتوي الذي تريد أن تتصدر عناوينهّ~ (يقتصر على 100 كلمة)</string>
|
||||
<string name="headline_input_length_limit_tips">頭條字數請勿超過100字~</string>
|
||||
<string name="sent_success">發送成功</string>
|
||||
<string name="headline_input_length_limit_tips">المحتوي الذي تريد أن تتصدر عناوينهّ يقتصر على 100 كلمة</string>
|
||||
<string name="sent_success">أرسل بنجاح</string>
|
||||
</resources>
|
@@ -7,6 +7,6 @@
|
||||
<string name="headline_message_format">Honorable %s sent a broadcast~</string>
|
||||
<string name="insufficient_balance_recharge_tips">The coin is insufficient,Would you like to recharge?</string>
|
||||
<string name="headline_input_hint">Please enter the content you want to broadcast~(100 characters)</string>
|
||||
<string name="headline_input_length_limit_tips">頭條字數請勿超過100字~</string>
|
||||
<string name="sent_success">發送成功</string>
|
||||
<string name="headline_input_length_limit_tips">Please do not exceed 100 characters for the broadcast~</string>
|
||||
<string name="sent_success">Sent successfully</string>
|
||||
</resources>
|
@@ -9,4 +9,10 @@ class HeadlineBean : Serializable {
|
||||
val id: Long? = null
|
||||
val uid: Long? = null
|
||||
val nick: String? = null
|
||||
// 0 有效 1 过期
|
||||
val recordStatus: Int? = null
|
||||
|
||||
fun isValid(): Boolean {
|
||||
return recordStatus == 0
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user