1:羽声新版本
This commit is contained in:
@@ -0,0 +1,368 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Paint;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.adapter.HeavenGiftAdapter;
|
||||
import com.xscm.moduleutil.bean.BaseListData;
|
||||
import com.xscm.moduleutil.bean.FirstChargeGiftBean;
|
||||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||||
import com.xscm.moduleutil.databinding.DialogNewPeopleBinding;
|
||||
import com.xscm.moduleutil.http.BaseObserver;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog;
|
||||
import com.zhpan.bannerview.indicator.DrawableIndicator;
|
||||
import com.zhpan.indicator.base.IIndicator;
|
||||
import com.zhpan.indicator.enums.IndicatorSlideMode;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @data
|
||||
* @description: 新人好礼
|
||||
*/
|
||||
public class NewPeopleDialog extends BaseDialog<DialogNewPeopleBinding> {
|
||||
|
||||
HeavenGiftAdapter heavenGiftAdapter;
|
||||
FirstChargeGiftBean firstChargeGiftBean;
|
||||
private int type;
|
||||
|
||||
public NewPeopleDialog(@NonNull Context context) {
|
||||
super(context, R.style.BaseDialogStyleH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_new_people;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
setCancelable(false);
|
||||
setCanceledOnTouchOutside(false);
|
||||
Window window = getWindow();
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 375.f / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.ivClose.setOnClickListener(v -> dismiss());
|
||||
|
||||
heavenGiftAdapter = new HeavenGiftAdapter();
|
||||
mBinding.bannerViewPager
|
||||
.setPageMargin(15)
|
||||
.setAutoPlay(false)
|
||||
.setRevealWidth(0, 0)
|
||||
.setIndicatorVisibility(View.VISIBLE)
|
||||
.setIndicatorView(getVectorDrawableIndicator())
|
||||
.setIndicatorSlideMode(IndicatorSlideMode.NORMAL)
|
||||
.setAdapter(heavenGiftAdapter)
|
||||
.create();
|
||||
|
||||
mBinding.rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup radioGroup, int i) {
|
||||
if (firstChargeGiftBean == null || firstChargeGiftBean.getGift_bag().size() == 0) {
|
||||
ToastUtils.showShort("暂无礼包");
|
||||
return;
|
||||
}
|
||||
|
||||
if (i == R.id.btn_0) {
|
||||
List<RoonGiftModel> list = new ArrayList<>();
|
||||
if (firstChargeGiftBean.getGift_bag().size() > 1) {
|
||||
mBinding.tvTitle1.setText(firstChargeGiftBean.getGift_bag().get(0).getTitle1());
|
||||
mBinding.tvTitle2.setText(firstChargeGiftBean.getGift_bag().get(0).getTitle2());
|
||||
mBinding.tvTitle2.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
mBinding.btn0.setText(firstChargeGiftBean.getGift_bag().get(0).getName());
|
||||
list.addAll(firstChargeGiftBean.getGift_bag().get(0).getGift_list());
|
||||
mBinding.bannerViewPager.create(baseListData(list, 4));
|
||||
}
|
||||
type = 1;
|
||||
} else if (i == R.id.btn_1) {
|
||||
List<RoonGiftModel> list = new ArrayList<>();
|
||||
if (firstChargeGiftBean.getGift_bag().size() > 2) {
|
||||
mBinding.tvTitle1.setText(firstChargeGiftBean.getGift_bag().get(1).getTitle1());
|
||||
mBinding.tvTitle2.setText(firstChargeGiftBean.getGift_bag().get(1).getTitle2());
|
||||
mBinding.tvTitle2.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
mBinding.btn1.setText(firstChargeGiftBean.getGift_bag().get(1).getName());
|
||||
list.addAll(firstChargeGiftBean.getGift_bag().get(1).getGift_list());
|
||||
mBinding.bannerViewPager.create(baseListData(list, 4));
|
||||
}
|
||||
type = 2;
|
||||
} else if (i == R.id.btn_2) {
|
||||
List<RoonGiftModel> list = new ArrayList<>();
|
||||
if (firstChargeGiftBean.getGift_bag().size() > 3) {
|
||||
if (firstChargeGiftBean.getGift_bag().get(2) != null) {
|
||||
mBinding.tvTitle1.setText(firstChargeGiftBean.getGift_bag().get(2).getTitle1());
|
||||
mBinding.tvTitle2.setText(firstChargeGiftBean.getGift_bag().get(2).getTitle2());
|
||||
mBinding.tvTitle2.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
mBinding.btn2.setText(firstChargeGiftBean.getGift_bag().get(2).getName());
|
||||
list.addAll(firstChargeGiftBean.getGift_bag().get(2).getGift_list());
|
||||
mBinding.bannerViewPager.create(baseListData(list, 4));
|
||||
type = 3;
|
||||
}
|
||||
}
|
||||
} else if (i == R.id.btn_3) {
|
||||
List<RoonGiftModel> list = new ArrayList<>();
|
||||
if (firstChargeGiftBean.getGift_bag().size() >= 4) {
|
||||
mBinding.tvTitle1.setText(firstChargeGiftBean.getGift_bag().get(3).getTitle1());
|
||||
mBinding.tvTitle2.setText(firstChargeGiftBean.getGift_bag().get(3).getTitle2());
|
||||
mBinding.btn3.setText(firstChargeGiftBean.getGift_bag().get(3).getName());
|
||||
mBinding.tvTitle2.setPaintFlags(0); // 清除所有绘制标志
|
||||
list.addAll(firstChargeGiftBean.getGift_bag().get(3).getGift_list());
|
||||
mBinding.bannerViewPager.create(baseListData(list, 4));
|
||||
type = 4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
mBinding.rg.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mBinding.tvInvite.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// RechargeDialogFragment.show(roomId, getSupportFragmentManager());
|
||||
if (listener != null) {
|
||||
listener.onFirstChargeConfirmed(firstChargeGiftBean, type);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public interface OnFirstChargeListener {
|
||||
void onFirstChargeConfirmed(FirstChargeGiftBean giftBean, int type);
|
||||
|
||||
void onFirstChargeCancelled();
|
||||
}
|
||||
|
||||
private OnFirstChargeListener listener;
|
||||
|
||||
// 设置监听器的方法
|
||||
public void setOnFirstChargeListener(OnFirstChargeListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
RetrofitClient.getInstance().getNewChargeGift(new BaseObserver<FirstChargeGiftBean>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(FirstChargeGiftBean firstChargeGiftBean) {
|
||||
if (firstChargeGiftBean != null) {
|
||||
showGift(firstChargeGiftBean);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private List<BaseListData<RoonGiftModel>> baseListData(List<RoonGiftModel> list, int chunkSize) {
|
||||
List<BaseListData<RoonGiftModel>> baseListData = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i += chunkSize) {
|
||||
BaseListData<RoonGiftModel> baseListData1 = new BaseListData<>();
|
||||
baseListData1.setData(list.subList(i, Math.min(i + chunkSize, list.size())));
|
||||
baseListData.add(baseListData1);
|
||||
}
|
||||
return baseListData;
|
||||
}
|
||||
|
||||
private IIndicator getVectorDrawableIndicator() {
|
||||
int dp6 = getResources().getDimensionPixelOffset(com.xscm.moduleutil.R.dimen.dp_6);
|
||||
return new DrawableIndicator(getContext())
|
||||
.setIndicatorGap(getResources().getDimensionPixelOffset(com.xscm.moduleutil.R.dimen.dp_2_5))
|
||||
.setIndicatorDrawable(com.xscm.moduleutil.R.drawable.banner_indicator_nornal, com.xscm.moduleutil.R.drawable.banner_indicator_focus)
|
||||
.setIndicatorSize(getResources().getDimensionPixelOffset(com.xscm.moduleutil.R.dimen.dp_13), dp6, getResources().getDimensionPixelOffset(com.xscm.moduleutil.R.dimen.dp_13), dp6);
|
||||
}
|
||||
|
||||
private Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
|
||||
public void showGift(FirstChargeGiftBean firstChargeGiftBean) {
|
||||
this.firstChargeGiftBean = firstChargeGiftBean;
|
||||
mBinding.rg.check(R.id.btn_0);
|
||||
if (firstChargeGiftBean.getGift_bag() != null && firstChargeGiftBean.getGift_bag().size() > 0) {
|
||||
if (firstChargeGiftBean.getGift_bag().size() >= 0) {
|
||||
type = 1;
|
||||
List<RoonGiftModel> list = new ArrayList<>();
|
||||
mBinding.tvTitle1.setText(firstChargeGiftBean.getGift_bag().get(0).getTitle1());
|
||||
mBinding.tvTitle2.setText(firstChargeGiftBean.getGift_bag().get(0).getTitle2());
|
||||
mBinding.btn0.setText(firstChargeGiftBean.getGift_bag().get(0).getName());
|
||||
list.addAll(firstChargeGiftBean.getGift_bag().get(0).getGift_list());
|
||||
mBinding.bannerViewPager.create(baseListData(list, 4));
|
||||
|
||||
|
||||
mBinding.btn1.setText(firstChargeGiftBean.getGift_bag().get(1).getName());
|
||||
mBinding.btn2.setText(firstChargeGiftBean.getGift_bag().get(2).getName());
|
||||
mBinding.btn3.setText(firstChargeGiftBean.getGift_bag().get(3).getName());
|
||||
|
||||
initGiftBagButtonStatus(firstChargeGiftBean);
|
||||
} else if (firstChargeGiftBean.getGift_bag().size() == 2) {
|
||||
// mBinding.rg.check(R.id.btn_0);
|
||||
// mBinding.btn1.setVisibility(View.VISIBLE);
|
||||
// mBinding.btn2.setVisibility(View.INVISIBLE);
|
||||
} else if (firstChargeGiftBean.getGift_bag().size() == 3) {
|
||||
// mBinding.rg.check(R.id.btn_0);
|
||||
// mBinding.btn1.setVisibility(View.VISIBLE);
|
||||
// mBinding.btn2.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// mBinding.rg.check(R.id.btn_0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isstatus = true;
|
||||
|
||||
private void initGiftBagButtonStatus(FirstChargeGiftBean firstChargeGiftBean) {
|
||||
// 1. 准备按钮列表:顺序与gift_bag中的元素顺序一一对应
|
||||
List<RadioButton> buttonList = Arrays.asList(
|
||||
mBinding.btn0,
|
||||
mBinding.btn1,
|
||||
mBinding.btn2
|
||||
// 未来加按钮:mBinding.btn3, mBinding.btn4...
|
||||
);
|
||||
|
||||
// 2. 空安全检查:先判断核心对象/列表非空
|
||||
if (firstChargeGiftBean != null && firstChargeGiftBean.getGift_bag() != null) {
|
||||
List<FirstChargeGiftBean.GiftBag> giftBagList = firstChargeGiftBean.getGift_bag();
|
||||
|
||||
// 3. 循环处理每个按钮
|
||||
for (int i = 0; i < buttonList.size(); i++) {
|
||||
RadioButton currentBtn = buttonList.get(i);
|
||||
// 4. 索引防护:若gift_bag列表长度不足,默认按status=0处理
|
||||
int status = (i < giftBagList.size()) ? giftBagList.get(i).getStatus() : 0;
|
||||
// 检查是否有status=0的情况,如果有则将isStatus设为false
|
||||
if (status == 0) {
|
||||
isstatus = false;
|
||||
}
|
||||
setButtonStatus(currentBtn, status, i); // 增加索引参数
|
||||
}
|
||||
updateRechargeTextViewStatus(isstatus, 0);
|
||||
|
||||
|
||||
} else {
|
||||
// 5. 兜底逻辑:数据为空时,所有按钮按status=0处理
|
||||
for (int i = 0; i < buttonList.size(); i++) {
|
||||
setButtonStatus(buttonList.get(i), 0, i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具方法:统一设置单个按钮的状态
|
||||
*
|
||||
* @param button 要设置的RadioButton
|
||||
* @param status 状态值
|
||||
* @param index 按钮索引,用于标识不同按钮
|
||||
*/
|
||||
private void setButtonStatus(RadioButton button, int status, int index) {
|
||||
if (button == null) return;
|
||||
|
||||
// 移除之前的点击监听器,避免重复设置
|
||||
button.setOnClickListener(null);
|
||||
|
||||
if (status == 1) {
|
||||
// 可用状态
|
||||
button.setEnabled(true);
|
||||
// button.setChecked(true);
|
||||
|
||||
// 恢复充值按钮状态
|
||||
updateRechargeTextViewStatus(true, index);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateRechargeTextViewStatus(true, index);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// status=0和其他状态:特殊处理
|
||||
button.setEnabled(true); // 保持可点击以响应交互
|
||||
// button.setChecked(false);
|
||||
// 设置特殊背景(根据需求修改为你的资源)
|
||||
button.setBackground(getResources().getDrawable(R.drawable.bf_e9));
|
||||
button.setTextColor(getResources().getColor(R.color.colorBlack65));
|
||||
updateRechargeTextViewStatus(false, index);
|
||||
// 添加点击事件
|
||||
button.setOnClickListener(v -> {
|
||||
// 点击时再次确认是status=0状态才处理
|
||||
button.setBackground(getResources().getDrawable(R.drawable.banner_indicator_focus));
|
||||
// 更新充值按钮状态为不可点击
|
||||
updateRechargeTextViewStatus(false, index);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查是否至少有一个元素达标(status == 1)
|
||||
*/
|
||||
public static boolean hasAnyQualified(List<FirstChargeGiftBean.GiftBag> giftBagList) {
|
||||
// 空列表处理 + 任意匹配检查
|
||||
return giftBagList != null && !giftBagList.isEmpty()
|
||||
&& giftBagList.stream()
|
||||
.anyMatch(gift -> gift.getStatus() == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新充值TextView的状态
|
||||
*
|
||||
* @param enabled 是否可点击
|
||||
* @param index 关联的按钮索引
|
||||
*/
|
||||
private void updateRechargeTextViewStatus(boolean enabled, int index) {
|
||||
TextView rechargeTv = mBinding.tvInvite; // 假设充值按钮的id是tvRecharge
|
||||
if (rechargeTv == null) return;
|
||||
|
||||
// 设置是否可点击
|
||||
rechargeTv.setEnabled(enabled);
|
||||
|
||||
// 根据状态和索引设置不同背景
|
||||
if (enabled) {
|
||||
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvInvite, ColorManager.getInstance().getPrimaryColorInt(), 53);
|
||||
mBinding.tvInvite.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// 不可点击状态的背景
|
||||
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvInvite, ColorManager.getInstance().getButtonColorInt(), 53);
|
||||
mBinding.tvInvite.setTextColor(getResources().getColor(R.color.colorBlack65));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user