2025-10-20 10:16:44 +08:00
|
|
|
|
package com.xscm.moduleutil.widget;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
import com.hjq.toast.ToastUtils;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
import com.xscm.moduleutil.R;
|
2025-10-24 17:52:11 +08:00
|
|
|
|
import com.xscm.moduleutil.bean.RoomMessageEvent;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
2025-10-24 17:52:11 +08:00
|
|
|
|
import com.xscm.moduleutil.utils.SpUtil;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
import java.util.ArrayList;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @Author lxj$
|
|
|
|
|
|
* @Time 2025-8-6 17:29:04$ $
|
|
|
|
|
|
* @Description 二卡八显示布局$
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class WheatLayoutSingManager {
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
private final ViewGroup container;
|
|
|
|
|
|
private List<RoomPitBean> pitList;
|
|
|
|
|
|
private boolean isSingleMode = false;
|
|
|
|
|
|
private int currentSinglePit = -1;
|
|
|
|
|
|
private RoomSingSongWheatView singleWheatView;
|
2025-10-24 17:52:11 +08:00
|
|
|
|
private List<RoomSingSongWheatView> multiWheatViews=new ArrayList<>();
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
private final int[] pitIndexMap = {9, 10, 1, 2, 3, 4, 5, 6, 7, 8};
|
|
|
|
|
|
|
|
|
|
|
|
public interface OnWheatClickListener {
|
|
|
|
|
|
void onWheatClick(RoomSingSongWheatView view, int pitNumber);
|
|
|
|
|
|
|
|
|
|
|
|
void onMakeWheatClick(RoomSingSongWheatView view, int pitNumber);
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
void onMeilingClick(RoomSingSongWheatView view, int pitNumber);
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private @Nullable OnWheatClickListener wheatClickListener;
|
|
|
|
|
|
|
|
|
|
|
|
public WheatLayoutSingManager(Context context, ViewGroup container) {
|
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
this.container = container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setWheatData(List<RoomPitBean> pitList) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
this.pitList = pitList;
|
|
|
|
|
|
restoreMultiWheat();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setWheatDataPk(List<RoomPitBean> pitList, int layoutType) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
this.pitList = pitList;
|
|
|
|
|
|
restoreMultiWheatPk(layoutType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnWheatClickListener(@Nullable OnWheatClickListener listener) {
|
|
|
|
|
|
this.wheatClickListener = listener;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void showSingleWheat(int pitNumber) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (isSingleMode && this.currentSinglePit == pitNumber) return;
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
try {
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// 忽略异常,继续执行
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
if (pitNumber < 1 || pitNumber > 10 || pitList == null || pitList.size() < 10)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
RoomPitBean bean = pitList.get(pitNumber - 1);
|
|
|
|
|
|
|
|
|
|
|
|
singleWheatView = new RoomSingSongWheatView(context);
|
|
|
|
|
|
singleWheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
singleWheatView.setData(bean);
|
|
|
|
|
|
|
|
|
|
|
|
// 默认设置为 MATCH_PARENT,也可以自定义
|
|
|
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
|
|
);
|
|
|
|
|
|
params.setMargins(20, 20, 20, 20);
|
|
|
|
|
|
singleWheatView.setLayoutParams(params);
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
GifAvatarOvalView avatarView = (GifAvatarOvalView) singleWheatView.mRiv;
|
|
|
|
|
|
avatarView.setOnClickListener(v -> {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onWheatClick(singleWheatView, pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
restoreMultiWheat();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
WheatCharmView charmView = singleWheatView.mCharmView;
|
|
|
|
|
|
charmView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onMeilingClick(singleWheatView, Integer.parseInt(singleWheatView.pitNumber));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// // 添加点击事件
|
|
|
|
|
|
singleWheatView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onMakeWheatClick(singleWheatView, pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
restoreMultiWheat();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
container.addView(singleWheatView);
|
|
|
|
|
|
isSingleMode = true;
|
|
|
|
|
|
currentSinglePit = pitNumber;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void restoreMultiWheat() {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// 忽略异常,继续执行
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pitList == null || pitList.size() < 10) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
multiWheatViews.clear();
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
int screenWidth = getScreenWidth();
|
|
|
|
|
|
int itemWidth = screenWidth / 4; // 每个控件宽度为屏幕宽度的 1/4
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
|
int pitNumber = pitIndexMap[i];
|
|
|
|
|
|
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
|
|
|
|
|
wheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
wheatView.setData(pitList.get(pitNumber - 1));
|
2025-10-24 17:52:11 +08:00
|
|
|
|
multiWheatViews.add(wheatView);
|
2025-10-20 10:16:44 +08:00
|
|
|
|
LinearLayout.LayoutParams params;
|
|
|
|
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
int fixedHeightInDp = 110; // 固定高度为 100dp
|
|
|
|
|
|
int fixedHeightInPx = dpToPx(fixedHeightInDp); // 调用已有的 dpToPx 方法
|
|
|
|
|
|
// 第一个控件:左边距 86dp,右边距 100dp
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth, fixedHeightInPx);
|
|
|
|
|
|
params.rightMargin = dpToPx(50);
|
|
|
|
|
|
} else if (i == 1) {
|
|
|
|
|
|
int fixedHeightInDp = 110; // 固定高度为 100dp
|
|
|
|
|
|
int fixedHeightInPx = dpToPx(fixedHeightInDp); // 调用已有的 dpToPx 方法
|
|
|
|
|
|
// 第二个控件:右边距 86dp
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth, fixedHeightInPx);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
int fixedHeightInDp = 90; // 固定高度为 100dp
|
|
|
|
|
|
int fixedHeightInPx = dpToPx(fixedHeightInDp); // 调用已有的 dpToPx 方法
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth - 30, fixedHeightInPx + 30);
|
|
|
|
|
|
// 其他控件保持原有逻辑
|
|
|
|
|
|
|
|
|
|
|
|
params.setMargins(0, 0, 0, 0); // 不设右边距,由 row padding 控制
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wheatView.setLayoutParams(params);
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GifAvatarOvalView avatarView = (GifAvatarOvalView) wheatView.mRiv;
|
|
|
|
|
|
avatarView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onWheatClick(wheatView, pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
WheatCharmView charmView = wheatView.mCharmView;
|
|
|
|
|
|
charmView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
ToastUtils.show("点击了麦位");
|
|
|
|
|
|
wheatClickListener.onMeilingClick(wheatView, pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
wheatView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
wheatClickListener.onMeilingClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
row.addView(wheatView);
|
|
|
|
|
|
|
|
|
|
|
|
// 第一行添加两个后换行
|
|
|
|
|
|
if (i == 1) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
} else if (i > 1 && (i - 2) % 4 == 3) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 添加最后一行可能存在的剩余 view
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (row.getChildCount() > 0) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
isSingleMode = false;
|
|
|
|
|
|
currentSinglePit = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void restoreMultiWheatPk(int layoutType) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (layoutType == 1) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
try {
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// 忽略异常,继续执行
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pitList == null || pitList.size() < 10) {
|
|
|
|
|
|
return;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
int screenWidth = getScreenWidth();
|
|
|
|
|
|
int itemWidth = screenWidth / 8;
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
|
|
|
|
// 根据 layoutType 调整前两个控件的顺序
|
|
|
|
|
|
int firstPitNumber, secondPitNumber;
|
|
|
|
|
|
if (layoutType == 1) {
|
|
|
|
|
|
firstPitNumber = 10; // 第一个显示 10
|
|
|
|
|
|
secondPitNumber = 9; // 第二个显示 9
|
|
|
|
|
|
} else if (layoutType == 2) {
|
|
|
|
|
|
firstPitNumber = 9; // 第一个显示 9
|
|
|
|
|
|
secondPitNumber = 10; // 第二个显示 10
|
|
|
|
|
|
} else {
|
|
|
|
|
|
firstPitNumber = 9;
|
|
|
|
|
|
secondPitNumber = 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 添加第一个控件(10 或 9)
|
|
|
|
|
|
addWheatViewItem(row, firstPitNumber, itemWidth * 2, layoutType);
|
|
|
|
|
|
|
|
|
|
|
|
// 添加第二个控件(9 或 10)
|
|
|
|
|
|
addWheatViewItem(row, secondPitNumber, itemWidth * 2, layoutType);
|
|
|
|
|
|
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
|
|
|
|
// 添加其余 8 个控件(1~8)
|
|
|
|
|
|
for (int i = 2; i < 10; i++) {
|
|
|
|
|
|
int pitNumber = pitIndexMap[i];
|
|
|
|
|
|
addWheatViewItem(row, pitNumber, itemWidth, layoutType);
|
|
|
|
|
|
|
|
|
|
|
|
if (i > 1 && (i - 2) % 4 == 3) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (row.getChildCount() > 0) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isSingleMode = false;
|
|
|
|
|
|
currentSinglePit = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 抽取公共方法:添加单个控件
|
|
|
|
|
|
private void addWheatViewItem(LinearLayout row, int pitNumber, int itemWidth, int layoutType) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (!isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
|
|
|
|
|
wheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
wheatView.setData(pitList.get(pitNumber - 1));
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout.LayoutParams params;
|
|
|
|
|
|
|
|
|
|
|
|
if (pitNumber == 9 || pitNumber == 10) {
|
|
|
|
|
|
int fixedHeightInPx = context.getResources().getDimensionPixelSize(R.dimen.dp_90);
|
|
|
|
|
|
|
|
|
|
|
|
if (pitNumber == 9) {
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth - 40, fixedHeightInPx);
|
|
|
|
|
|
if (layoutType == 1) {
|
|
|
|
|
|
// 9号在右边,右边距10dp
|
|
|
|
|
|
params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_1);
|
|
|
|
|
|
params.setMargins(20, -30, -20, 0);
|
|
|
|
|
|
} else if (layoutType == 2) {
|
|
|
|
|
|
// 9号在左边,左边距10dp
|
|
|
|
|
|
params.leftMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_1);
|
|
|
|
|
|
params.setMargins(-30, -20, 0, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth - 80, fixedHeightInPx);
|
|
|
|
|
|
if (layoutType == 1) {
|
|
|
|
|
|
// 10号在左边,左边距15dp
|
|
|
|
|
|
params.setMargins(-30, 10, 0, 0);
|
|
|
|
|
|
} else if (layoutType == 2) {
|
|
|
|
|
|
// 10号在右边,右边距15dp
|
|
|
|
|
|
params.setMargins(0, 10, -30, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
int fixedHeightInPx = context.getResources().getDimensionPixelSize(R.dimen.dp_60);
|
|
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth + 15, fixedHeightInPx + 20);
|
|
|
|
|
|
params.setMargins(-20, -20, -20, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wheatView.setLayoutParams(params);
|
|
|
|
|
|
wheatView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
if (layoutType == 1) {
|
|
|
|
|
|
wheatClickListener.onWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wheatClickListener.onMakeWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
row.addView(wheatView);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RoomSingSongWheatView createWheatView(int pitNumber) {
|
|
|
|
|
|
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
|
|
|
|
|
wheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
wheatView.setData(pitList.get(pitNumber - 1));
|
|
|
|
|
|
return wheatView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RoomMakeWheatView createRoomMakeWheatView(int pitNumber) {
|
|
|
|
|
|
RoomMakeWheatView wheatView = new RoomMakeWheatView(context);
|
|
|
|
|
|
wheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
wheatView.setData(pitList.get(pitNumber - 1));
|
|
|
|
|
|
return wheatView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int dpToPx(int dp) {
|
|
|
|
|
|
return Math.round(dp * context.getResources().getDisplayMetrics().density);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getScreenWidth() {
|
|
|
|
|
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
|
|
|
|
|
return metrics.widthPixels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
public void setUpData(RoomMessageEvent event){
|
|
|
|
|
|
String fromPit=event.getText().getFrom_pit_number()!=null?event.getText().getFrom_pit_number():"";
|
|
|
|
|
|
String toPitNumber=event.getText().getTo_pit_number()!=null?event.getText().getTo_pit_number():"";
|
|
|
|
|
|
if (fromPit.equals("") || toPitNumber.equals("")){
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
RoomSingSongWheatView fromWheatView = findWheatViewByPitNumber(Integer.parseInt(fromPit));
|
|
|
|
|
|
RoomSingSongWheatView toWheatView = findWheatViewByPitNumber(Integer.parseInt(toPitNumber));
|
|
|
|
|
|
RoomPitBean fromPitBean=fromWheatView.pitBean;
|
|
|
|
|
|
RoomPitBean toPitBean=toWheatView.pitBean;
|
|
|
|
|
|
String tmpNumber=fromPitBean.getPit_number();
|
|
|
|
|
|
fromPitBean.setPit_number(toPitBean.getPit_number());
|
|
|
|
|
|
toPitBean.setPit_number(tmpNumber);
|
|
|
|
|
|
toWheatView.setData(fromPitBean);
|
|
|
|
|
|
fromWheatView.setData(toPitBean);
|
|
|
|
|
|
for (RoomSingSongWheatView view : multiWheatViews){
|
|
|
|
|
|
if (view.pitBean.getUser_id().equals(event.getText().getFromUserInfo().getUser_id()+"")){
|
|
|
|
|
|
if (!view.pitBean.getPit_number().equals(toPitNumber)){
|
|
|
|
|
|
RoomPitBean bean=view.pitBean;
|
|
|
|
|
|
bean.setCharm("");
|
|
|
|
|
|
bean.setUser_id("");
|
|
|
|
|
|
bean.setDress("");
|
|
|
|
|
|
bean.setAvatar("");
|
|
|
|
|
|
bean.setNickname("");
|
|
|
|
|
|
bean.setSex("");
|
|
|
|
|
|
bean.setUser_code("");
|
|
|
|
|
|
bean.setDress_picture("");
|
|
|
|
|
|
view.setData(bean);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 更新指定 pitNumber 的麦位信息(用于局部刷新)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void updateSingleWheat(RoomPitBean pitBean, int pitNumber) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是单个展示模式且不是当前麦位,不处理
|
|
|
|
|
|
if (isSingleMode && this.currentSinglePit != pitNumber) return;
|
|
|
|
|
|
|
|
|
|
|
|
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
|
|
|
|
|
if (wheatView != null) {
|
|
|
|
|
|
RoomPitBean bean = pitBean;
|
|
|
|
|
|
wheatView.setData(bean); // 刷新数据
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
public void upDataCharm(RoomPitBean pitBean, int pitNumber){
|
|
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是单个展示模式且不是当前麦位,不处理
|
|
|
|
|
|
if (isSingleMode && this.currentSinglePit != pitNumber) return;
|
|
|
|
|
|
|
|
|
|
|
|
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
|
|
|
|
|
if (wheatView != null) {
|
|
|
|
|
|
RoomPitBean bean = pitBean;
|
|
|
|
|
|
wheatView.setCharm(bean.getCharm()); // 刷新数据
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
@Nullable
|
|
|
|
|
|
private RoomSingSongWheatView findWheatViewByPitNumber(int pitNumber) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
for (int i = 0; i < container.getChildCount(); i++) {
|
|
|
|
|
|
View row = container.getChildAt(i);
|
|
|
|
|
|
if (row instanceof LinearLayout) {
|
|
|
|
|
|
LinearLayout linearRow = (LinearLayout) row;
|
|
|
|
|
|
for (int j = 0; j < linearRow.getChildCount(); j++) {
|
|
|
|
|
|
View child = linearRow.getChildAt(j);
|
|
|
|
|
|
if (child instanceof RoomSingSongWheatView) {
|
|
|
|
|
|
RoomSingSongWheatView view = (RoomSingSongWheatView) child;
|
|
|
|
|
|
if (Integer.parseInt(view.pitNumber) == pitNumber) {
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (row instanceof RoomSingSongWheatView) {
|
|
|
|
|
|
RoomSingSongWheatView view = (RoomSingSongWheatView) row;
|
|
|
|
|
|
if (Integer.parseInt(view.pitNumber) == pitNumber) {
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量刷新多个麦位状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void refreshWheatData(List<RoomPitBean> newPitList, List<Integer> changedPits) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
|
|
|
|
|
this.pitList = newPitList;
|
|
|
|
|
|
// 注意:原代码中此方法体为空,如果需要实现请取消注释下面的代码
|
|
|
|
|
|
// for (int pitNumber : changedPits) {
|
|
|
|
|
|
// updateSingleWheat(pitNumber);
|
|
|
|
|
|
// }
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateSingleOnlineWheat(UserOnlineStatusBean bean) {
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 检查容器状态
|
|
|
|
|
|
if (container == null || !isContainerValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (pitList == null || pitList.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
|
|
for (RoomPitBean pitBean : pitList) {
|
|
|
|
|
|
int pitNumber = Integer.parseInt(pitBean.getPit_number());
|
|
|
|
|
|
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
2025-10-24 17:52:11 +08:00
|
|
|
|
if (wheatView != null) {
|
|
|
|
|
|
wheatView.setOnlineStatus(); // 刷新数据
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
// 添加容器状态检查方法
|
|
|
|
|
|
private boolean isContainerValid() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 检查容器是否已附加到窗口
|
|
|
|
|
|
return container != null && container.isAttachedToWindow();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 添加资源清理方法
|
|
|
|
|
|
public void release() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
if (multiWheatViews!=null){
|
|
|
|
|
|
for (RoomSingSongWheatView wheatView : multiWheatViews) {
|
|
|
|
|
|
wheatView.releaseResources();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
if (container != null) {
|
|
|
|
|
|
// 清理所有子视图的资源
|
|
|
|
|
|
// for (int i = 0; i < container.getChildCount(); i++) {
|
|
|
|
|
|
// View child = container.getChildAt(i);
|
|
|
|
|
|
// if (child instanceof LinearLayout) {
|
|
|
|
|
|
// LinearLayout linearLayout = (LinearLayout) child;
|
|
|
|
|
|
// for (int j = 0; j < linearLayout.getChildCount(); j++) {
|
|
|
|
|
|
// View view = linearLayout.getChildAt(j);
|
|
|
|
|
|
// if (view instanceof RoomSingSongWheatView) {
|
|
|
|
|
|
// ((RoomSingSongWheatView) view).releaseResources();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } else if (child instanceof RoomSingSongWheatView) {
|
|
|
|
|
|
// ((RoomSingSongWheatView) child).releaseResources();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// 忽略异常
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 清理引用
|
|
|
|
|
|
pitList = null;
|
|
|
|
|
|
singleWheatView = null;
|
|
|
|
|
|
wheatClickListener = null;
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|