2025-08-26 19:34: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;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xscm.moduleutil.R;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class WheatLayoutManager {
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
private final ViewGroup container;
|
|
|
|
|
|
private List<RoomPitBean> pitList;
|
|
|
|
|
|
private boolean isSingleMode = false;
|
|
|
|
|
|
private int currentSinglePit = -1;
|
|
|
|
|
|
private RoomDefaultWheatView singleWheatView;
|
|
|
|
|
|
|
2025-08-30 19:02:09 +08:00
|
|
|
|
// 麦位索引映射:9,10,1~8
|
2025-08-26 19:34:44 +08:00
|
|
|
|
private final int[] pitIndexMap = {9, 10, 1, 2, 3, 4, 5, 6, 7, 8};
|
|
|
|
|
|
|
|
|
|
|
|
public interface OnWheatClickListener {
|
|
|
|
|
|
void onWheatClick(RoomDefaultWheatView view, int pitNumber);
|
|
|
|
|
|
void onMakeWheatClick(RoomDefaultWheatView view, int pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private @Nullable OnWheatClickListener wheatClickListener;
|
|
|
|
|
|
|
|
|
|
|
|
public WheatLayoutManager(Context context, ViewGroup container) {
|
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
this.container = container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setWheatData(List<RoomPitBean> pitList) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (pitList == null || pitList.size() < 10) return;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
this.pitList = pitList;
|
|
|
|
|
|
restoreMultiWheat();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setWheatDataPk(List<RoomPitBean> pitList, int layoutType) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (pitList == null || pitList.size() < 10) return;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
this.pitList = pitList;
|
|
|
|
|
|
restoreMultiWheatPk(layoutType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnWheatClickListener(@Nullable OnWheatClickListener listener) {
|
|
|
|
|
|
this.wheatClickListener = listener;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void showSingleWheat(int pitNumber) {
|
|
|
|
|
|
if (isSingleMode && this.currentSinglePit == pitNumber) return;
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (pitNumber < 1 || pitNumber > 10 || pitList == null || pitList.size() < 10) return;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
|
|
|
|
|
|
RoomPitBean bean = pitList.get(pitNumber - 1);
|
|
|
|
|
|
singleWheatView = new RoomDefaultWheatView(context);
|
|
|
|
|
|
singleWheatView.pitNumber = String.valueOf(pitNumber);
|
|
|
|
|
|
singleWheatView.setData(bean);
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
|
|
);
|
|
|
|
|
|
params.setMargins(20, 20, 20, 20);
|
|
|
|
|
|
singleWheatView.setLayoutParams(params);
|
|
|
|
|
|
|
|
|
|
|
|
singleWheatView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onWheatClick(singleWheatView, pitNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
restoreMultiWheat();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
container.addView(singleWheatView);
|
|
|
|
|
|
isSingleMode = true;
|
|
|
|
|
|
currentSinglePit = pitNumber;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void restoreMultiWheat() {
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
|
|
|
|
|
|
int screenWidth = getScreenWidth();
|
2025-08-30 19:02:09 +08:00
|
|
|
|
int itemWidth = screenWidth / 4;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
LinearLayout row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
|
int pitNumber = pitIndexMap[i];
|
2025-08-30 19:02:09 +08:00
|
|
|
|
RoomDefaultWheatView wheatView = createWheatView(pitNumber);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
LinearLayout.LayoutParams params;
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (i == 0 || i == 1) {
|
|
|
|
|
|
int fixedHeightInPx = dpToPx(110);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth, fixedHeightInPx);
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (i == 0) params.rightMargin = dpToPx(50);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
} else {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
int fixedHeightInPx = dpToPx(90);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth - 30, fixedHeightInPx + 30);
|
2025-08-30 19:02:09 +08:00
|
|
|
|
params.setMargins(0, 0, 0, 0);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wheatView.setLayoutParams(params);
|
|
|
|
|
|
wheatView.setOnClickListener(v -> {
|
|
|
|
|
|
if (wheatClickListener != null) {
|
|
|
|
|
|
wheatClickListener.onWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
row.addView(wheatView);
|
|
|
|
|
|
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (i == 1 || (i > 1 && (i - 2) % 4 == 3)) {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (row.getChildCount() > 0) {
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
isSingleMode = false;
|
|
|
|
|
|
currentSinglePit = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void restoreMultiWheatPk(int layoutType) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
int screenWidth = getScreenWidth();
|
|
|
|
|
|
int itemWidth = screenWidth / 8;
|
|
|
|
|
|
|
|
|
|
|
|
LinearLayout row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
2025-08-30 19:02:09 +08:00
|
|
|
|
int firstPitNumber = layoutType == 1 ? 10 : 9;
|
|
|
|
|
|
int secondPitNumber = layoutType == 1 ? 9 : 10;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
2025-08-30 19:02:09 +08:00
|
|
|
|
addWheatViewItem(row, firstPitNumber, itemWidth * 2, layoutType);
|
|
|
|
|
|
addWheatViewItem(row, secondPitNumber, itemWidth * 2, layoutType);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
container.addView(row);
|
|
|
|
|
|
row = new LinearLayout(context);
|
|
|
|
|
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 2; i < 10; i++) {
|
|
|
|
|
|
int pitNumber = pitIndexMap[i];
|
|
|
|
|
|
addWheatViewItem(row, pitNumber, itemWidth, layoutType);
|
|
|
|
|
|
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if ((i - 2) % 4 == 3) {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
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-08-30 19:02:09 +08:00
|
|
|
|
RoomDefaultWheatView wheatView = createWheatView(pitNumber);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
LinearLayout.LayoutParams params;
|
|
|
|
|
|
if (pitNumber == 9 || pitNumber == 10) {
|
|
|
|
|
|
int fixedHeightInPx = context.getResources().getDimensionPixelSize(R.dimen.dp_90);
|
|
|
|
|
|
if (pitNumber == 9) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
params = new LinearLayout.LayoutParams(itemWidth - 40, fixedHeightInPx);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
if (layoutType == 1) {
|
|
|
|
|
|
params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dp_1);
|
|
|
|
|
|
params.setMargins(20, -30, -20, 0);
|
2025-08-30 19:02:09 +08:00
|
|
|
|
} else {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
params.setMargins(-30, 10, 0, 0);
|
2025-08-30 19:02:09 +08:00
|
|
|
|
} else {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
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) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (layoutType == 1) {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
wheatClickListener.onWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
2025-08-30 19:02:09 +08:00
|
|
|
|
} else {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
wheatClickListener.onMakeWheatClick(wheatView, Integer.parseInt(wheatView.pitNumber));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
row.addView(wheatView);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RoomDefaultWheatView createWheatView(int pitNumber) {
|
|
|
|
|
|
RoomDefaultWheatView wheatView = new RoomDefaultWheatView(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-09-02 23:03:08 +08:00
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
public void updateSingleWheat(RoomPitBean pitBean, int pitNumber) {
|
|
|
|
|
|
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
|
|
|
|
|
if (isSingleMode && this.currentSinglePit != pitNumber) return;
|
|
|
|
|
|
|
|
|
|
|
|
RoomDefaultWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
|
|
|
|
|
if (wheatView != null) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
wheatView.setData(pitBean);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-13 15:36:44 +08:00
|
|
|
|
public void updateSingleCharm(RoomPitBean pitBean, int pitNumber) {
|
|
|
|
|
|
if (pitList == null || pitList.isEmpty() || pitNumber < 1 || pitNumber > 10) return;
|
|
|
|
|
|
if (isSingleMode && this.currentSinglePit != pitNumber) return;
|
|
|
|
|
|
|
|
|
|
|
|
RoomDefaultWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
|
|
|
|
|
if (wheatView != null) {
|
|
|
|
|
|
wheatView.setCharm(pitBean.getCharm());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
@Nullable
|
|
|
|
|
|
private RoomDefaultWheatView findWheatViewByPitNumber(int pitNumber) {
|
|
|
|
|
|
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 RoomDefaultWheatView) {
|
|
|
|
|
|
RoomDefaultWheatView view = (RoomDefaultWheatView) child;
|
|
|
|
|
|
if (Integer.parseInt(view.pitNumber) == pitNumber) {
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (row instanceof RoomDefaultWheatView) {
|
|
|
|
|
|
RoomDefaultWheatView view = (RoomDefaultWheatView) row;
|
|
|
|
|
|
if (Integer.parseInt(view.pitNumber) == pitNumber) {
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void refreshWheatData(List<RoomPitBean> newPitList, List<Integer> changedPits) {
|
|
|
|
|
|
this.pitList = newPitList;
|
|
|
|
|
|
for (int pitNumber : changedPits) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
updateSingleWheat(pitList.get(pitNumber - 1), pitNumber);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-30 19:02:09 +08:00
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
public void updateSingleOnlineWheat(UserOnlineStatusBean bean) {
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (pitList == null || pitList.isEmpty() || bean == null) return;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
for (RoomPitBean pitBean : pitList) {
|
|
|
|
|
|
int pitNumber = Integer.parseInt(pitBean.getPit_number());
|
|
|
|
|
|
RoomDefaultWheatView wheatView = findWheatViewByPitNumber(pitNumber);
|
2025-08-30 19:02:09 +08:00
|
|
|
|
if (wheatView != null) {
|
|
|
|
|
|
wheatView.setOnlineStatus(bean);
|
|
|
|
|
|
}
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-30 19:02:09 +08:00
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
|
|
container.removeAllViews();
|
|
|
|
|
|
pitList = null;
|
|
|
|
|
|
singleWheatView = null;
|
|
|
|
|
|
isSingleMode = false;
|
|
|
|
|
|
currentSinglePit = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clearData() {
|
|
|
|
|
|
pitList = null;
|
|
|
|
|
|
singleWheatView = null;
|
|
|
|
|
|
isSingleMode = false;
|
|
|
|
|
|
currentSinglePit = -1;
|
|
|
|
|
|
}
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|