修改名称。
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package com.xscm.modulemain.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.modulemain.R;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
import com.xscm.moduleutil.bean.GiftBoxBean;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class TaskBoxAdapter extends BaseQuickAdapter<GiftBoxBean.GiftBean, BaseViewHolder> {
|
||||
public TaskBoxAdapter() {
|
||||
super(R.layout.item_task_box);
|
||||
}
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(int position);
|
||||
}
|
||||
private OnItemClickListener onItemClickListener;
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.onItemClickListener = listener;
|
||||
}
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, GiftBoxBean.GiftBean item) {
|
||||
int position = helper.getLayoutPosition(); // 获取当前位置
|
||||
|
||||
View itemView = helper.itemView; // 获取整个 item 的根布局
|
||||
TextView giftName = helper.getView(R.id.tv_type_name);
|
||||
TextView giftTitle = helper.getView(R.id.tv_title);
|
||||
giftName.setText(item.getName());
|
||||
giftTitle.setText(item.getTitle());
|
||||
ImageUtils.loadHeadCC(item.getIcon(), helper.getView(R.id.task_box));
|
||||
if (position == 0) {
|
||||
itemView.setBackgroundColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_FCE4ED)); // 红色
|
||||
giftName.setTextColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_E24171));
|
||||
setSpannableText(giftTitle, "最高可获得%d金币", Integer.parseInt(item.getHighest_gain()),com.xscm.moduleutil.R.color.color_E24171);
|
||||
// helper.setImageDrawable(R.id.task_box, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.task_cj));
|
||||
|
||||
|
||||
} else if (position == 1) {
|
||||
itemView.setBackgroundColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_FDE8AE)); // 黄色
|
||||
giftName.setTextColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_F35F07));
|
||||
setSpannableText(giftTitle, "最高可获得%d金币", Integer.parseInt(item.getHighest_gain()),com.xscm.moduleutil.R.color.color_F35F07);
|
||||
// helper.setImageDrawable(R.id.task_box, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.task_gj));
|
||||
|
||||
} else {
|
||||
// 其他 item 恢复默认背景(可选)
|
||||
itemView.setBackground(null);
|
||||
}
|
||||
|
||||
helper.setText(R.id.tv_jb, "满"+item.getMeet()+"金币");
|
||||
double progress = Double.parseDouble(item.getUnlock_progress()!=null?item.getUnlock_progress():"0.00");
|
||||
long progressNum = (long) (progress * 1000);
|
||||
LinearProgressIndicator progressIndicator= helper.getView(R.id.progress_indicator);
|
||||
progressIndicator.setProgress(Integer.parseInt(String.valueOf(progressNum)));
|
||||
|
||||
double unlock_num = Double.parseDouble(item.getUnlock_progress()!=null?item.getUnlock_progress():"0.00");
|
||||
long unlock_num_long = (long) (unlock_num * 1000);
|
||||
|
||||
helper.setText(R.id.tv_jb_num, Integer.parseInt(String.valueOf(unlock_num_long))/10 + "%");
|
||||
if (position==0){
|
||||
progressIndicator.setIndicatorColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_E24171));
|
||||
}else {
|
||||
progressIndicator.setIndicatorColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_F35F07));
|
||||
|
||||
}
|
||||
helper.setText(R.id.iv_unlock, item.getStatus_str());
|
||||
View unlockView = helper.getView(R.id.iv_unlock);
|
||||
if (item.getStatus().equals("0")){
|
||||
// helper.setImageDrawable(R.id.iv_unlock, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.not_unlocked));
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
// 可选:改变颜色或透明度来视觉反馈
|
||||
unlockView.setAlpha(0.9f); // 半透明表示不可点击
|
||||
}else if (item.getStatus().equals("1")){
|
||||
unlockView.setClickable(true);
|
||||
unlockView.setEnabled(true);
|
||||
unlockView.setAlpha(1.0f); // 恢复正常显示
|
||||
}else if (item.getStatus().equals("2")){
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
// helper.setImageDrawable(R.id.iv_unlock, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.unlocked));
|
||||
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
// 可选:改变颜色或透明度来视觉反馈
|
||||
unlockView.setAlpha(0.8f); // 半透明表示不可点击
|
||||
}
|
||||
|
||||
helper.getView(R.id.iv_unlock).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onItemClickListener != null) {
|
||||
int position = helper.getLayoutPosition();
|
||||
onItemClickListener.onItemClick(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 设置带部分颜色的文本
|
||||
private void setSpannableText(TextView textView, String format, int number,int color) {
|
||||
String fullText = String.format(format, number);
|
||||
SpannableString spannableString = new SpannableString(fullText);
|
||||
|
||||
// 找到数字的位置
|
||||
String numberStr = String.valueOf(number);
|
||||
int startIndex = fullText.indexOf(numberStr);
|
||||
int endIndex = startIndex + numberStr.length();
|
||||
|
||||
if (startIndex >= 0) {
|
||||
// 设置数字为红色
|
||||
spannableString.setSpan(
|
||||
new ForegroundColorSpan(ContextCompat.getColor(mContext,color)), // 使用你定义的颜色
|
||||
startIndex,
|
||||
endIndex,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
|
||||
textView.setText(spannableString);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user