1:羽声新版本
This commit is contained in:
@@ -8,10 +8,14 @@ import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent;
|
||||
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,6 +30,7 @@ public class WheatLayoutSingManager {
|
||||
private boolean isSingleMode = false;
|
||||
private int currentSinglePit = -1;
|
||||
private RoomSingSongWheatView singleWheatView;
|
||||
private List<RoomSingSongWheatView> multiWheatViews=new ArrayList<>();
|
||||
|
||||
private final int[] pitIndexMap = {9, 10, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
@@ -34,6 +39,8 @@ public class WheatLayoutSingManager {
|
||||
|
||||
void onMakeWheatClick(RoomSingSongWheatView view, int pitNumber);
|
||||
|
||||
void onMeilingClick(RoomSingSongWheatView view, int pitNumber);
|
||||
|
||||
}
|
||||
|
||||
private @Nullable OnWheatClickListener wheatClickListener;
|
||||
@@ -44,11 +51,21 @@ public class WheatLayoutSingManager {
|
||||
}
|
||||
|
||||
public void setWheatData(List<RoomPitBean> pitList) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pitList = pitList;
|
||||
restoreMultiWheat();
|
||||
}
|
||||
|
||||
public void setWheatDataPk(List<RoomPitBean> pitList, int layoutType) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pitList = pitList;
|
||||
restoreMultiWheatPk(layoutType);
|
||||
}
|
||||
@@ -58,9 +75,19 @@ public class WheatLayoutSingManager {
|
||||
}
|
||||
|
||||
public void showSingleWheat(int pitNumber) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSingleMode && this.currentSinglePit == pitNumber) return;
|
||||
|
||||
container.removeAllViews();
|
||||
try {
|
||||
container.removeAllViews();
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,继续执行
|
||||
return;
|
||||
}
|
||||
|
||||
if (pitNumber < 1 || pitNumber > 10 || pitList == null || pitList.size() < 10)
|
||||
return;
|
||||
@@ -79,21 +106,51 @@ public class WheatLayoutSingManager {
|
||||
params.setMargins(20, 20, 20, 20);
|
||||
singleWheatView.setLayoutParams(params);
|
||||
|
||||
// 添加点击事件
|
||||
singleWheatView.setOnClickListener(v -> {
|
||||
GifAvatarOvalView avatarView = (GifAvatarOvalView) singleWheatView.mRiv;
|
||||
avatarView.setOnClickListener(v -> {
|
||||
if (wheatClickListener != null) {
|
||||
wheatClickListener.onWheatClick(singleWheatView, pitNumber);
|
||||
}
|
||||
restoreMultiWheat();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
container.addView(singleWheatView);
|
||||
isSingleMode = true;
|
||||
currentSinglePit = pitNumber;
|
||||
}
|
||||
|
||||
public void restoreMultiWheat() {
|
||||
container.removeAllViews();
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
container.removeAllViews();
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,继续执行
|
||||
return;
|
||||
}
|
||||
|
||||
if (pitList == null || pitList.size() < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
multiWheatViews.clear();
|
||||
|
||||
int screenWidth = getScreenWidth();
|
||||
int itemWidth = screenWidth / 4; // 每个控件宽度为屏幕宽度的 1/4
|
||||
@@ -106,7 +163,7 @@ public class WheatLayoutSingManager {
|
||||
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
||||
wheatView.pitNumber = String.valueOf(pitNumber);
|
||||
wheatView.setData(pitList.get(pitNumber - 1));
|
||||
|
||||
multiWheatViews.add(wheatView);
|
||||
LinearLayout.LayoutParams params;
|
||||
|
||||
if (i == 0) {
|
||||
@@ -126,20 +183,31 @@ public class WheatLayoutSingManager {
|
||||
params = new LinearLayout.LayoutParams(itemWidth - 30, fixedHeightInPx + 30);
|
||||
// 其他控件保持原有逻辑
|
||||
|
||||
|
||||
// if (i > 1 && (i - 2) % 4 != 0) {
|
||||
// params.leftMargin = 12;
|
||||
// params.rightMargin = 12;
|
||||
// }
|
||||
params.setMargins(0, 0, 0, 0); // 不设右边距,由 row padding 控制
|
||||
}
|
||||
|
||||
wheatView.setLayoutParams(params);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
wheatView.setOnClickListener(v -> {
|
||||
if (wheatClickListener != null) {
|
||||
wheatClickListener.onWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
||||
wheatClickListener.onMeilingClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
||||
}
|
||||
// showSingleWheat(Integer.parseInt(wheatView.pitNumber));
|
||||
});
|
||||
|
||||
row.addView(wheatView);
|
||||
@@ -156,91 +224,33 @@ public class WheatLayoutSingManager {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加最后一行可能存在的剩余 view
|
||||
// 添加最后一行可能存在的剩余 view
|
||||
if (row.getChildCount() > 0) {
|
||||
container.addView(row);
|
||||
}
|
||||
isSingleMode = false;
|
||||
currentSinglePit = -1;
|
||||
|
||||
}
|
||||
// public void restoreMultiWheatPk(int layoutType, int width) {
|
||||
// container.removeAllViews();
|
||||
//
|
||||
// int screenWidth = getScreenWidth();
|
||||
// int itemWidth = screenWidth / 8; // 每个控件宽度为屏幕宽度的 1/4
|
||||
//
|
||||
// LinearLayout row = new LinearLayout(context);
|
||||
// row.setOrientation(LinearLayout.HORIZONTAL);
|
||||
//
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// int pitNumber = pitIndexMap[i];
|
||||
// RoomDefaultWheatView wheatView = new RoomDefaultWheatView(context);
|
||||
// wheatView.pitNumber = String.valueOf(pitNumber);
|
||||
// wheatView.setData(pitList.get(pitNumber - 1));
|
||||
//
|
||||
// LinearLayout.LayoutParams params;
|
||||
//
|
||||
// if (i == 0) {
|
||||
// int fixedHeightInDp = 110; // 固定高度为 100dp
|
||||
// int fixedHeightInPx =context.getResources().getDimensionPixelSize(R.dimen.dp_80); // 调用已有的 dpToPx 方法
|
||||
// // 第一个控件:左边距 86dp,右边距 100dp
|
||||
// params = new LinearLayout.LayoutParams(itemWidth, fixedHeightInPx);
|
||||
// params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_50);
|
||||
// } else if (i == 1) {
|
||||
// int fixedHeightInDp = 110; // 固定高度为 100dp
|
||||
// int fixedHeightInPx = context.getResources().getDimensionPixelSize(R.dimen.dp_80); // 调用已有的 dpToPx 方法
|
||||
// // 第二个控件:右边距 86dp
|
||||
// params = new LinearLayout.LayoutParams(itemWidth, fixedHeightInPx);
|
||||
// } else {
|
||||
// int fixedHeightInDp = 90; // 固定高度为 100dp
|
||||
// int fixedHeightInPx = context.getResources().getDimensionPixelSize(R.dimen.dp_60); // 调用已有的 dpToPx 方法
|
||||
// params = new LinearLayout.LayoutParams(itemWidth -10, fixedHeightInPx + 30);
|
||||
// // 其他控件保持原有逻辑
|
||||
//
|
||||
//
|
||||
//// if (i > 1 && (i - 2) % 4 != 0) {
|
||||
//// params.leftMargin = 12;
|
||||
//// params.rightMargin = 12;
|
||||
//// }
|
||||
// params.setMargins(0, 0, 0, 0); // 不设右边距,由 row padding 控制
|
||||
// }
|
||||
//
|
||||
// wheatView.setLayoutParams(params);
|
||||
// wheatView.setOnClickListener(v -> {
|
||||
// if (wheatClickListener != null) {
|
||||
// wheatClickListener.onWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
||||
// }
|
||||
//// showSingleWheat(Integer.parseInt(wheatView.pitNumber));
|
||||
// });
|
||||
//
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// 添加最后一行可能存在的剩余 view
|
||||
// if (row.getChildCount() > 0) {
|
||||
// container.addView(row);
|
||||
// }
|
||||
// isSingleMode = false;
|
||||
// currentSinglePit = -1;
|
||||
// }
|
||||
|
||||
|
||||
public void restoreMultiWheatPk(int layoutType) {
|
||||
if (layoutType == 1) {
|
||||
container.removeAllViews();
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (layoutType == 1) {
|
||||
try {
|
||||
container.removeAllViews();
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,继续执行
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pitList == null || pitList.size() < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
int screenWidth = getScreenWidth();
|
||||
int itemWidth = screenWidth / 8;
|
||||
|
||||
@@ -292,6 +302,11 @@ public class WheatLayoutSingManager {
|
||||
|
||||
// 抽取公共方法:添加单个控件
|
||||
private void addWheatViewItem(LinearLayout row, int pitNumber, int itemWidth, int layoutType) {
|
||||
// 检查容器状态
|
||||
if (!isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
||||
wheatView.pitNumber = String.valueOf(pitNumber);
|
||||
wheatView.setData(pitList.get(pitNumber - 1));
|
||||
@@ -317,11 +332,9 @@ public class WheatLayoutSingManager {
|
||||
params = new LinearLayout.LayoutParams(itemWidth - 80, fixedHeightInPx);
|
||||
if (layoutType == 1) {
|
||||
// 10号在左边,左边距15dp
|
||||
// params.leftMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_5);
|
||||
params.setMargins(-30, 10, 0, 0);
|
||||
} else if (layoutType == 2) {
|
||||
// 10号在右边,右边距15dp
|
||||
// params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_5);
|
||||
params.setMargins(0, 10, -30, 0);
|
||||
}
|
||||
|
||||
@@ -347,7 +360,6 @@ public class WheatLayoutSingManager {
|
||||
row.addView(wheatView);
|
||||
}
|
||||
|
||||
|
||||
private RoomSingSongWheatView createWheatView(int pitNumber) {
|
||||
RoomSingSongWheatView wheatView = new RoomSingSongWheatView(context);
|
||||
wheatView.pitNumber = String.valueOf(pitNumber);
|
||||
@@ -362,7 +374,6 @@ public class WheatLayoutSingManager {
|
||||
return wheatView;
|
||||
}
|
||||
|
||||
|
||||
private int dpToPx(int dp) {
|
||||
return Math.round(dp * context.getResources().getDisplayMetrics().density);
|
||||
}
|
||||
@@ -372,10 +383,49 @@ public class WheatLayoutSingManager {
|
||||
return metrics.widthPixels;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新指定 pitNumber 的麦位信息(用于局部刷新)
|
||||
*/
|
||||
public void updateSingleWheat(RoomPitBean pitBean, int pitNumber) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
||||
|
||||
// 如果是单个展示模式且不是当前麦位,不处理
|
||||
@@ -383,15 +433,36 @@ public class WheatLayoutSingManager {
|
||||
|
||||
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
||||
if (wheatView != null) {
|
||||
|
||||
// RoomPitBean bean = pitList.get(pitNumber - 1);
|
||||
RoomPitBean bean = pitBean;
|
||||
wheatView.setData(bean); // 刷新数据
|
||||
}
|
||||
}
|
||||
|
||||
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()); // 刷新数据
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private RoomSingSongWheatView findWheatViewByPitNumber(int pitNumber) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < container.getChildCount(); i++) {
|
||||
View row = container.getChildAt(i);
|
||||
if (row instanceof LinearLayout) {
|
||||
@@ -419,21 +490,81 @@ public class WheatLayoutSingManager {
|
||||
* 批量刷新多个麦位状态
|
||||
*/
|
||||
public void refreshWheatData(List<RoomPitBean> newPitList, List<Integer> changedPits) {
|
||||
this.pitList = newPitList;
|
||||
for (int pitNumber : changedPits) {
|
||||
// updateSingleWheat(pitNumber);
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pitList = newPitList;
|
||||
// 注意:原代码中此方法体为空,如果需要实现请取消注释下面的代码
|
||||
// for (int pitNumber : changedPits) {
|
||||
// updateSingleWheat(pitNumber);
|
||||
// }
|
||||
}
|
||||
|
||||
public void updateSingleOnlineWheat(UserOnlineStatusBean bean) {
|
||||
// 检查容器状态
|
||||
if (container == null || !isContainerValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pitList == null || pitList.isEmpty()) return;
|
||||
|
||||
for (RoomPitBean pitBean : pitList) {
|
||||
int pitNumber = Integer.parseInt(pitBean.getPit_number());
|
||||
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
||||
wheatView.setOnlineStatus(bean); // 刷新数据
|
||||
if (wheatView != null) {
|
||||
wheatView.setOnlineStatus(); // 刷新数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加容器状态检查方法
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user