303 lines
8.6 KiB
Java
303 lines
8.6 KiB
Java
package com.xscm.moduleutil.widget;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import com.xscm.moduleutil.R;
|
|
import com.xscm.moduleutil.bean.UserInfo;
|
|
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
|
import com.xscm.moduleutil.utils.ImageUtils;
|
|
import com.xscm.moduleutil.utils.SpUtil;
|
|
|
|
/**
|
|
* @Author lxj$
|
|
* @Time 2025-8-6 17:27:29$ $
|
|
* @Description 二卡八视图控件$
|
|
*/
|
|
public class RoomSingSongWheat2View extends BaseWheatView {
|
|
public ImageView mIvTagBoss;
|
|
public TextView mTvTime;
|
|
public TextView tv_time_pk;
|
|
public boolean isClickListenerSet = false;
|
|
private boolean showBoss;//显示老板标识
|
|
|
|
public RoomSingSongWheat2View(Context context) {
|
|
this(context, null, 0);
|
|
}
|
|
|
|
public RoomSingSongWheat2View(Context context, AttributeSet attrs) {
|
|
this(context, attrs, 0);
|
|
}
|
|
|
|
public RoomSingSongWheat2View(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
super(context, attrs, defStyleAttr);
|
|
}
|
|
|
|
@Override
|
|
protected void initPit(Context context, AttributeSet attrs) {
|
|
TypedArray typedArray = null;
|
|
try {
|
|
typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoomDefaultWheatView);
|
|
pitNumber = typedArray.getString(R.styleable.RoomDefaultWheatView_room_wheat_number);
|
|
} finally {
|
|
if (typedArray != null) {
|
|
typedArray.recycle();
|
|
}
|
|
}
|
|
mIvTagBoss = findViewById(R.id.iv_tag_boos);
|
|
mTvTime = findViewById(R.id.tv_time);
|
|
tv_time_pk = findViewById(R.id.tv_time_pk);
|
|
}
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.room_view_sing_wheat_2;
|
|
}
|
|
|
|
@Override
|
|
protected void setPitData(RoomPitBean bean) {
|
|
if (bean == null) return;
|
|
|
|
sex = bean.getSex();
|
|
pitBean = bean; // 统一使用参数 bean
|
|
if (isOn()) {
|
|
handleOnState(bean);
|
|
} else {
|
|
handleOffState(bean);
|
|
}
|
|
|
|
updateSexIcon();
|
|
// updateCharmViewVisibility(bean);
|
|
updatePkState(bean);
|
|
// iv_on_line.setVisibility(GONE);
|
|
}
|
|
|
|
private void handleOnState(RoomPitBean bean) {
|
|
|
|
mTvName.setText(bean.getNickname());
|
|
ImageUtils.loadHeadCC(bean.getAvatar(), mRiv);
|
|
mCharmView.setVisibility(VISIBLE);
|
|
if (mIvFrame != null) {
|
|
if (TextUtils.isEmpty(bean.getDress())) {
|
|
mIvFrame.stopAll();
|
|
mIvFrame.setVisibility(INVISIBLE);
|
|
} else {
|
|
mIvFrame.setVisibility(VISIBLE);
|
|
mIvFrame.setSource(bean.getDress(), 3);
|
|
}
|
|
}
|
|
|
|
if (showBoss && TextUtils.equals(WHEAT_BOSS, pitNumber)) {
|
|
mIvTagBoss.setVisibility(GONE);
|
|
}
|
|
}
|
|
|
|
private void handleOffState(RoomPitBean bean) {
|
|
mTvName.setText(getPitNumberText());
|
|
mCharmView.setVisibility(GONE);
|
|
if (showBoss && TextUtils.equals(WHEAT_BOSS, pitNumber)) {
|
|
mIvTagBoss.setVisibility(VISIBLE);
|
|
int resId = bean.getIs_lock() == 1 ? R.mipmap.index_img_room_mask : R.drawable.room_ic_wheat_default;
|
|
mRiv.setImageResource(resId);
|
|
} else {
|
|
mRiv.setImageResource(bean.getIs_lock() == 1 ? R.mipmap.index_img_room_mask : R.drawable.room_ic_wheat_default);
|
|
}
|
|
|
|
if (isMute()) {
|
|
ImageUtils.loadRes(R.mipmap.room_microphone_off, mIvSex);
|
|
}
|
|
if (mIvFrame != null) {
|
|
mIvFrame.stopAll();
|
|
mIvFrame.setVisibility(INVISIBLE);
|
|
}
|
|
mIvFace.remove();
|
|
}
|
|
|
|
private String getPitNumberText() {
|
|
if ("-1".equals(pitNumber)) return "";
|
|
if ("9".equals(pitNumber)) return "主持位";
|
|
if ("10".equals(pitNumber)) return "嘉宾位";
|
|
return pitNumber + "号麦位";
|
|
}
|
|
|
|
private void updateSexIcon() {
|
|
if (showSexIcon) {
|
|
checkSex();
|
|
}
|
|
}
|
|
|
|
private void updateCharmViewVisibility(RoomPitBean bean) {
|
|
boolean isEmptyNickname = bean.getNickname() == null || bean.getNickname().isEmpty();
|
|
mCharmView.setVisibility(isEmptyNickname ? GONE : VISIBLE);
|
|
}
|
|
|
|
private void updatePkState(RoomPitBean bean) {
|
|
if (bean.is_pk()) {
|
|
String userId = bean.getUser_id();
|
|
if (userId != null && !userId.equals("0") && !userId.isEmpty()) {
|
|
tv_time_pk.setVisibility(VISIBLE);
|
|
setSex(bean.getCharm(), false);
|
|
mCharmView.setVisibility(GONE);
|
|
} else {
|
|
tv_time_pk.setVisibility(GONE);
|
|
}
|
|
} else {
|
|
tv_time_pk.setVisibility(GONE);
|
|
if (isOn()) {
|
|
mCharmView.setVisibility(VISIBLE);
|
|
} else {
|
|
mCharmView.setVisibility(GONE);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setSex(String value, boolean format) {
|
|
if (format) {
|
|
tv_time_pk.setText(value);
|
|
} else {
|
|
try {
|
|
long xd = Long.parseLong(value);
|
|
if (xd > 9999 || xd < -9999) {
|
|
tv_time_pk.setText(String.format("%.2fw", xd / 10000.0f));
|
|
} else {
|
|
tv_time_pk.setText(value);
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
tv_time_pk.setText("0"); // 设置默认值防止UI异常
|
|
}
|
|
}
|
|
}
|
|
|
|
private boolean showSexIcon = false;
|
|
private String sex;
|
|
|
|
public boolean isMale() {
|
|
return "1".equals(sex);
|
|
}
|
|
|
|
public boolean isFemale() {
|
|
return "2".equals(sex);
|
|
}
|
|
|
|
public void setShowSexIcon(boolean show) {
|
|
showSexIcon = show;
|
|
}
|
|
|
|
public void checkSex() {
|
|
if (isOn()) {
|
|
mIvSex.setVisibility(VISIBLE);
|
|
if (!TextUtils.isEmpty(sex)) {
|
|
if (UserInfo.MALE.equals(sex)) {
|
|
mIvSex.setBackgroundResource(R.drawable.room_xq_wheat_male_mask);
|
|
if (mTvNo != null) mTvNo.setBackgroundResource(R.mipmap.ic_room_xq_wno_male);
|
|
} else {
|
|
mIvSex.setBackgroundResource(R.drawable.room_xq_wheat_female_mask);
|
|
if (mTvNo != null) mTvNo.setBackgroundResource(R.mipmap.ic_room_xq_wno_female);
|
|
}
|
|
} else {
|
|
mIvSex.setVisibility(GONE);
|
|
if (mTvNo != null) mTvNo.setBackgroundResource(getOriginNoImage());
|
|
}
|
|
} else {
|
|
mIvSex.setVisibility(GONE);
|
|
if (mTvNo != null) mTvNo.setBackgroundResource(getOriginNoImage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 是否显示老板标识
|
|
*/
|
|
public void setIsBossShow(String is_boss_pit) {
|
|
showBoss = "1".equals(is_boss_pit);
|
|
}
|
|
|
|
/**
|
|
* 开启计时
|
|
*/
|
|
public void setTime(int time) {
|
|
if (time == 0) {
|
|
mTvTime.setText("");
|
|
mTvTime.setVisibility(INVISIBLE);
|
|
} else {
|
|
mTvTime.setText(String.format("%s'%s", time / 60, time % 60));
|
|
mTvTime.setVisibility(VISIBLE);
|
|
}
|
|
}
|
|
|
|
public void hideMaoziIcon() {
|
|
View maozi = findViewById(R.id.iv_maozi);
|
|
if (maozi != null) maozi.setVisibility(GONE);
|
|
}
|
|
|
|
// 添加内存释放方法
|
|
public void releaseResources() {
|
|
// 清理头像加载
|
|
if (mRiv != null) {
|
|
mRiv.setImageBitmap(null);
|
|
}
|
|
|
|
// 清理框架视图
|
|
if (mIvFrame != null) {
|
|
mIvFrame.release(); // 清理SVGA资源
|
|
}
|
|
|
|
// 清理表情视图
|
|
if (mIvFace != null) {
|
|
mIvFace.remove();
|
|
}
|
|
|
|
// 清理其他图片资源
|
|
if (mIvSex != null) {
|
|
mIvSex.setImageBitmap(null);
|
|
}
|
|
|
|
if (mIvTagBoss != null) {
|
|
mIvTagBoss.setImageBitmap(null);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void onDetachedFromWindow() {
|
|
// 视图从窗口分离时释放资源
|
|
releaseResources();
|
|
super.onDetachedFromWindow();
|
|
}
|
|
|
|
@Override
|
|
public void onRemoteSoundLevelUpdate(String userId, int soundLevel) {
|
|
// 暂无实现
|
|
}
|
|
|
|
@Override
|
|
public void onLocalSoundLevelUpdate(int volume) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void userJoined(int userId, int elapsd) {
|
|
// 暂无实现
|
|
}
|
|
|
|
@Override
|
|
public void userOffline(int userId, int reason) {
|
|
// 暂无实现
|
|
}
|
|
|
|
@Override
|
|
public void pkOffSide(int uid) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void unRegister(Object obj) {
|
|
|
|
}
|
|
}
|