feat:公聊厅消息列表支持头饰展示

This commit is contained in:
max
2024-05-10 11:23:31 +08:00
parent af0ba80b30
commit a7a04c2950
4 changed files with 102 additions and 29 deletions

View File

@@ -17,6 +17,7 @@ import androidx.core.util.Consumer;
import com.chwl.app.public_chat.core.ChatRoomMessageAdapter;
import com.chwl.app.ui.utils.ImageLoadUtils;
import com.chwl.app.ui.widget.TextSpannableBuilder;
import com.chwl.core.decoration.headwear.bean.HeadWearInfo;
import com.chwl.core.level.UserLevelResourceType;
import com.chwl.core.noble.NobleUtil;
import com.chwl.core.user.bean.UserInfo;
@@ -64,6 +65,10 @@ public abstract class ChatRoomMessageViewHolderBase extends RecyclerViewHolder<B
protected View.OnLongClickListener longClickListener;
private HeadImageView avatarLeft;
private HeadImageView avatarRight;
private ImageView headWearLeft;
private ImageView headWearRight;
private View headWearLeftLayout;
private View headWearRightLayout;
private int expLevelHeight = UiUtils.INSTANCE.dip2px(18f);
public ChatRoomMessageViewHolderBase(BaseMultiItemFetchLoadAdapter adapter) {
@@ -185,6 +190,10 @@ public abstract class ChatRoomMessageViewHolderBase extends RecyclerViewHolder<B
timeTextView = findViewById(R.id.message_item_time);
avatarLeft = findViewById(R.id.message_item_portrait_left);
avatarRight = findViewById(R.id.message_item_portrait_right);
headWearLeftLayout = findViewById(R.id.message_item_portrait_left_layout);
headWearRightLayout = findViewById(R.id.message_item_portrait_right_layout);
headWearLeft = findViewById(R.id.message_item_head_wear_left);
headWearRight = findViewById(R.id.message_item_head_wear_right);
alertButton = findViewById(R.id.message_item_alert);
progressBar = findViewById(R.id.message_item_progress);
nameTextView = findViewById(R.id.message_item_nickname);
@@ -257,25 +266,48 @@ public abstract class ChatRoomMessageViewHolderBase extends RecyclerViewHolder<B
}
private void setHeadImageView() {
HeadImageView show = isReceivedMessage() ? avatarLeft : avatarRight;
HeadImageView hide = isReceivedMessage() ? avatarRight : avatarLeft;
hide.setVisibility(View.GONE);
View showLayout = isReceivedMessage() ? headWearLeftLayout : headWearRightLayout;
View hideLayout = isReceivedMessage() ? headWearRightLayout : headWearLeftLayout;
HeadImageView showAvatarView = isReceivedMessage() ? avatarLeft : avatarRight;
ImageView showHeadWearView = isReceivedMessage() ? headWearLeft : headWearRight;
ImageView hideHeadWearView = isReceivedMessage() ? headWearRight : headWearLeft;
hideLayout.setVisibility(View.GONE);
clearHeadWear(hideHeadWearView);
if (!isShowHeadImage()) {
show.setVisibility(View.GONE);
clearHeadWear(showHeadWearView);
showLayout.setVisibility(View.GONE);
return;
}
if (isMiddleItem()) {
show.setVisibility(View.GONE);
clearHeadWear(showHeadWearView);
showLayout.setVisibility(View.GONE);
} else {
show.setVisibility(View.VISIBLE);
String avatar = NobleUtil.getLevel(UserInfo.AVATAR, message);
showLayout.setVisibility(View.VISIBLE);
String avatar = NobleUtil.getResource(UserInfo.AVATAR, message);
if (avatar.length() != 0) {
show.loadAvatar(avatar);
showAvatarView.loadAvatar(avatar);
} else {
show.loadBuddyAvatar(message);
showAvatarView.loadBuddyAvatar(message);
}
String headWear = NobleUtil.getResource(HeadWearInfo.HEAD_WEAR, message);
if (headWear.length() != 0) {
if (!headWear.equals(showHeadWearView.getTag(com.chwl.app.R.id.mic_item_head_wear))) {
showHeadWearView.setVisibility(View.VISIBLE);
showHeadWearView.setTag(com.chwl.app.R.id.mic_item_head_wear, headWear);
NobleUtil.loadMicHeadWear(headWear, showHeadWearView, com.chwl.app.R.id.mic_item_head_wear, headWear);
}
} else {
clearHeadWear(showHeadWearView);
}
}
}
private void clearHeadWear(ImageView view) {
if (view == null) return;
view.clearAnimation();
view.setImageDrawable(null);
view.setTag(com.chwl.app.R.id.mic_item_head_wear, null);
view.setVisibility(View.GONE);
}
private void setOnClickListener() {

View File

@@ -275,7 +275,7 @@ public class PublicChatRoomMessageListPanel {
if (needRefresh) {
sortMessages(items);
if (items.size() > maxMessageCount) {
for (int i = 0; i < maxMessageCount / 2; i++) {
for (int i = 0; i < maxMessageCount / 3; i++) {
items.remove(0);
}
}

View File

@@ -17,6 +17,7 @@ import lombok.Setter;
public class HeadWearInfo extends BaseDecoration implements Serializable {
public static final String PIC = "pic";
public static final String EFFECT = "effect";
public static final String HEAD_WEAR = "headWearUrl";
public static final int STATUS_IN_USED = 1;
public static final int STATUS_OUT_OF_DATE = 2;
@@ -69,6 +70,11 @@ public class HeadWearInfo extends BaseDecoration implements Serializable {
}
map.put(PIC, pic);
map.put(EFFECT, effect);
if (effect != null && effect.length() > 0) {
map.put(HEAD_WEAR, effect);
} else {
map.put(HEAD_WEAR, pic);
}
return map;
}

View File

@@ -1,53 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingStart="15dp"
android:paddingEnd="15dp">
android:paddingTop="6dp"
android:paddingEnd="15dp"
android:paddingBottom="6dp">
<TextView
android:id="@+id/message_item_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/bubble_time_layout_margin_bottom"
android:layout_marginTop="@dimen/bubble_time_layout_margin_top"
android:layout_marginBottom="@dimen/bubble_time_layout_margin_bottom"
android:paddingStart="7dip"
android:paddingEnd="7dip"
android:textColor="#666666"
android:textSize="11sp"
android:visibility="gone" />
<com.netease.nim.uikit.common.ui.imageview.HeadImageView
android:id="@+id/message_item_portrait_left"
<FrameLayout
android:id="@+id/message_item_portrait_left_layout"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_below="@id/message_item_time"
android:layout_alignParentStart="true"
android:layout_below="@id/message_item_time"
android:layout_marginEnd="8dp"
android:clipChildren="false"
android:visibility="gone"
tools:visibility="visible" />
tools:visibility="visible">
<com.netease.nim.uikit.common.ui.imageview.HeadImageView
android:id="@+id/message_item_portrait_right"
<com.netease.nim.uikit.common.ui.imageview.HeadImageView
android:id="@+id/message_item_portrait_left"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/message_item_head_wear_left"
android:layout_width="59.4dp"
android:layout_height="59.4dp"
android:layout_marginStart="-7.2dp"
android:layout_marginTop="-7.2dp"
android:visibility="gone"
tools:visibility="visible" />
</FrameLayout>
<FrameLayout
android:id="@+id/message_item_portrait_right_layout"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/message_item_time"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:visibility="gone" />
android:visibility="gone"
tools:visibility="visible">
<com.netease.nim.uikit.common.ui.imageview.HeadImageView
android:id="@+id/message_item_portrait_right"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/message_item_head_wear_right"
android:layout_width="59.4dp"
android:layout_height="59.4dp"
android:layout_marginStart="-7.2dp"
android:layout_marginTop="-7.2dp"
android:visibility="gone"
tools:visibility="visible" />
</FrameLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/message_item_name_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/message_item_time"
android:layout_toStartOf="@id/message_item_portrait_right"
android:layout_toEndOf="@id/message_item_portrait_left"
android:layout_marginTop="10dp"
android:layout_toStartOf="@id/message_item_portrait_right_layout"
android:layout_toEndOf="@id/message_item_portrait_left_layout"
android:orientation="horizontal">
<ImageView
@@ -57,10 +92,10 @@
android:visibility="gone" />
<TextView
android:layout_marginBottom="10dp"
android:id="@+id/message_item_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxWidth="200dip"
@@ -74,8 +109,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/message_item_name_layout"
android:layout_toStartOf="@id/message_item_portrait_right"
android:layout_toEndOf="@id/message_item_portrait_left">
android:layout_toStartOf="@id/message_item_portrait_right_layout"
android:layout_toEndOf="@id/message_item_portrait_left_layout">
<LinearLayout
android:id="@+id/message_item_body"