170 lines
5.5 KiB
Java
170 lines
5.5 KiB
Java
package com.xscm.moduleutil.widget;
|
||
|
||
import android.content.Context;
|
||
import android.text.TextUtils;
|
||
import android.util.AttributeSet;
|
||
import android.view.View;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.TextView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.annotation.Nullable;
|
||
|
||
import com.opensource.svgaplayer.SVGAImageView;
|
||
import com.xscm.moduleutil.R;
|
||
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
||
import com.xscm.moduleutil.utils.ImageUtils;
|
||
|
||
public class RoomSingWheatView extends LinearLayout {
|
||
|
||
public ImageView mRiv;
|
||
public ImageView mIvGift;
|
||
public WheatCharmView mCharmView;
|
||
public TextView mTvName;
|
||
public ImageView mIvSex;
|
||
public AvatarFrameView mIvFrame;
|
||
public AvatarFrameView mIvRipple;
|
||
public ExpressionImgView mIvFace;
|
||
public ImageView mIvShutup;
|
||
public TextView tvTime;
|
||
public TextView mTvNo;
|
||
|
||
public TextView tv_time_pk;
|
||
|
||
public RoomPitBean pitBean;//麦位数据
|
||
public String roomId;//房间id
|
||
|
||
public static final String WHEAT_BOSS = "8";//老板位
|
||
public static final String WHEAT_HOST = "9";//主持位
|
||
|
||
public float oX;
|
||
public float oY;
|
||
|
||
boolean closePhone = false;//自己麦位关闭话筒,用于判断声纹显示
|
||
|
||
public String pitNumber;
|
||
public int pitImageVId;
|
||
|
||
// public ImageView iv_on_line;
|
||
private boolean showGiftAnim = true;//显示麦位动画
|
||
private ImageView iv_tag_type;
|
||
|
||
private TextView tv_zhul;
|
||
|
||
public RoomSingWheatView(@NonNull Context context) {
|
||
this(context, null);
|
||
}
|
||
|
||
public RoomSingWheatView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||
this(context, attrs, 0);
|
||
}
|
||
|
||
public RoomSingWheatView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||
super(context, attrs, defStyleAttr);
|
||
initView(context);
|
||
}
|
||
|
||
private void initView(Context context) {
|
||
// 确保布局被正确加载
|
||
inflate(context, getLayoutId(), this);
|
||
|
||
// 初始化所有视图组件
|
||
mRiv = findViewById(R.id.riv);
|
||
mIvGift = findViewById(R.id.iv_gift);
|
||
mCharmView = findViewById(R.id.charm_view);
|
||
mTvName = findViewById(R.id.tv_name);
|
||
mIvSex = findViewById(R.id.iv_sex);
|
||
mIvFrame = findViewById(R.id.iv_frame);
|
||
mIvRipple = findViewById(R.id.iv_ripple);
|
||
mIvFace = findViewById(R.id.iv_face);
|
||
mIvShutup = findViewById(R.id.iv_shutup);
|
||
tvTime = findViewById(R.id.tv_time);
|
||
tv_time_pk = findViewById(R.id.tv_time_pk);
|
||
mTvNo = findViewById(R.id.tv_no);
|
||
// iv_on_line = findViewById(R.id.iv_online);
|
||
iv_tag_type = findViewById(R.id.iv_tag_type);
|
||
tv_zhul = findViewById(R.id.tv_zhul);
|
||
|
||
// 设置初始位置
|
||
if (mIvGift != null) {
|
||
oX = mIvGift.getX();
|
||
oY = mIvGift.getY();
|
||
}
|
||
}
|
||
|
||
protected int getLayoutId() {
|
||
return R.layout.room_view_sing_wheat;
|
||
}
|
||
|
||
public void setData(RoomPitBean bean) {
|
||
this.pitBean = bean;
|
||
if (bean == null) return;
|
||
|
||
// 添加空值检查,防止NPE
|
||
if (mTvName == null) {
|
||
// 可能布局未正确加载,尝试重新初始化
|
||
initView(getContext());
|
||
if (mTvName == null) {
|
||
// 如果仍然为null,记录日志并返回
|
||
android.util.Log.e("RoomSingWheatView", "mTvName is still null after re-initialization");
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (isOn()) {
|
||
//开启声浪
|
||
mIvRipple.startLoopingSvga("ripple3695.svga");
|
||
mIvRipple.setVisibility(VISIBLE);
|
||
mTvName.setText(bean.getNickname());
|
||
ImageUtils.loadHeadCC(bean.getAvatar(), mRiv);
|
||
|
||
if (TextUtils.isEmpty(pitBean.getDress())) {
|
||
if (mIvFrame != null) mIvFrame.setVisibility(INVISIBLE);
|
||
} else {
|
||
if (mIvFrame != null) {
|
||
mIvFrame.setVisibility(VISIBLE);
|
||
mIvFrame.setSource(pitBean.getDress(), 3);
|
||
}
|
||
}
|
||
} else {
|
||
String pitText = "-1".equals(pitNumber) ? "" :
|
||
"9".equals(pitNumber) ? "主持位" :
|
||
"10".equals(pitNumber) ? "嘉宾位" :
|
||
pitNumber + "号麦位";
|
||
mTvName.setText(pitText);
|
||
|
||
if (mIvFrame != null) mIvFrame.setVisibility(INVISIBLE);
|
||
if (mIvFace != null) mIvFace.remove();
|
||
//停止声浪
|
||
mIvRipple.stopSvga();
|
||
mIvRipple.setVisibility(GONE);
|
||
}
|
||
|
||
// 更新魅力值视图
|
||
if (mCharmView != null) {
|
||
if (pitBean.getNickname() == null || pitBean.getNickname().isEmpty()) {
|
||
mCharmView.setVisibility(GONE);
|
||
} else {
|
||
mCharmView.setVisibility(VISIBLE);
|
||
}
|
||
}
|
||
|
||
// 更新PK状态
|
||
if (tv_time_pk != null) {
|
||
if (pitBean.is_pk() && pitBean.getUser_id() != null &&
|
||
!pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||
tv_time_pk.setVisibility(VISIBLE);
|
||
if (mCharmView != null) mCharmView.setVisibility(GONE);
|
||
} else {
|
||
tv_time_pk.setVisibility(GONE);
|
||
if (mCharmView != null) mCharmView.setVisibility(VISIBLE);
|
||
}
|
||
}
|
||
}
|
||
|
||
private boolean isOn() {
|
||
return pitBean != null && !TextUtils.isEmpty(pitBean.getUser_id()) && !"0".equals(pitBean.getUser_id());
|
||
}
|
||
}
|