修改名称。
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.blankj.utilcode.util.AppUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.bean.AppUpdateModel;
|
||||
import com.xscm.moduleutil.databinding.DialogAppUpdateBinding;
|
||||
import com.xscm.moduleutil.utils.DownloadListener;
|
||||
import com.xscm.moduleutil.utils.DownloadUtil;
|
||||
import com.xscm.moduleutil.utils.TextViewUtils;
|
||||
import com.xscm.moduleutil.utils.logger.Logger;
|
||||
import com.xscm.moduleutil.widget.dialog.BaseDialog;
|
||||
|
||||
public class AppUpdateDialog extends BaseDialog<DialogAppUpdateBinding> implements DownloadListener, View.OnClickListener {
|
||||
|
||||
private AppUpdateModel appUpdateModel;
|
||||
private ProgressDialog mProgressDialog;
|
||||
|
||||
public AppUpdateDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_app_update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
Window window = getWindow();
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent);
|
||||
window.setLayout((int) (ScreenUtils.getScreenWidth() * 305 / 375), WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
mBinding.tvContent.setMovementMethod(new ScrollingMovementMethod());
|
||||
mBinding.btUpdate.setOnClickListener(this::onClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (appUpdateModel != null) {
|
||||
mProgressDialog = new ProgressDialog(getContext()) {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
}
|
||||
};
|
||||
mProgressDialog.setMax(100);//设置最大值
|
||||
mProgressDialog.setTitle("安装包下载");//设置标题
|
||||
mProgressDialog.setIcon(R.mipmap.ic_launcher);//设置标题小图标
|
||||
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//设置样式为横向显示进度的样式
|
||||
mProgressDialog.incrementProgressBy(0);//设置初始值为0,其实可以不用设置,默认就是0
|
||||
mProgressDialog.setIndeterminate(false);//是否精确显示对话框,flase为是,反之为否
|
||||
mProgressDialog.setCanceledOnTouchOutside(false);
|
||||
mProgressDialog.setMessage("下载中请稍等!!!");
|
||||
mProgressDialog.show();
|
||||
DownloadUtil downloadUtil = new DownloadUtil(getContext());
|
||||
downloadUtil.downloadFile(appUpdateModel.getUrl(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppUpdateModel(AppUpdateModel appUpdateModel) {
|
||||
this.appUpdateModel = appUpdateModel;
|
||||
TextViewUtils.setHtmlText(mBinding.tvContent,appUpdateModel.getContent(),false);
|
||||
//mBinding.tvContent.setText(TextUtils.isEmpty(appUpdateModel.getContent()) ? "修复旧版本已知bug" : Html.fromHtml(appUpdateModel.getContent()));
|
||||
LogUtils.d("AppUpdateDialog", "setAppUpdateModel " + appUpdateModel.getContent().toString());
|
||||
// mBinding.tvContent.setHtmlText(appUpdateModel.getContent());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
return true;
|
||||
}
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int currentLength) {
|
||||
if (mProgressDialog != null) {
|
||||
mProgressDialog.setProgress(currentLength);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(String localPath) {
|
||||
if (mProgressDialog != null && mProgressDialog.isShowing()) {
|
||||
mProgressDialog.dismiss();
|
||||
}
|
||||
try {
|
||||
AppUtils.installApp(localPath);
|
||||
} catch (Exception e) {
|
||||
Logger.e("installAppError", e);
|
||||
onFailure();
|
||||
}
|
||||
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
ToastUtils.showShort("下载失败前往浏览器手动更新");
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
Uri url = Uri.parse(appUpdateModel.getUrl());
|
||||
intent.setData(url);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.RechargeBean;
|
||||
import com.xscm.moduleutil.utils.SystemUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 充值adapter
|
||||
*/
|
||||
public class BalanceRechargeAdapter extends BaseMultiItemQuickAdapter<RechargeBean, BaseViewHolder> {
|
||||
private int selectedPosition = -1;
|
||||
private OnRechargeItemClickListener listener;
|
||||
private InputBoxVisibilityListener inputBoxVisibilityListener;
|
||||
|
||||
public static final int ITEM_TYPE_NORMAL = 0;
|
||||
public static final int ITEM_TYPE_FOOTER = 1;
|
||||
|
||||
public BalanceRechargeAdapter(@NonNull List<RechargeBean> data) {
|
||||
super(data);
|
||||
// 初始化 item 类型
|
||||
addItemType(ITEM_TYPE_NORMAL, R.layout.rv_item_balance_recharge);
|
||||
addItemType(ITEM_TYPE_FOOTER, R.layout.rv_item_footer);
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
RechargeBean item = getData().get(position);
|
||||
return item.getItemViewType(); // 使用 bean 中的 itemViewType
|
||||
}
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, RechargeBean item) {
|
||||
int type = helper.getItemViewType();
|
||||
// ConstraintLayout constraintLayout = helper.getView(R.id.cl_item);
|
||||
// ViewGroup.LayoutParams layoutParams =constraintLayout.getLayoutParams();
|
||||
// layoutParams.width = ( com.blankj.utilcode.util.ScreenUtils.getScreenWidth()-32-24)/3-24; // 使用你定义的getWidth方法
|
||||
// constraintLayout.setLayoutParams(layoutParams);
|
||||
if (type == ITEM_TYPE_NORMAL) {
|
||||
// 正常 item 显示逻辑
|
||||
helper.setText(R.id.tv_gold_num, item.getCoins());
|
||||
helper.setText(R.id.tv_money, String.format("¥%s", item.getMoney()));
|
||||
if (selectedPosition == helper.getAdapterPosition()) {
|
||||
helper.setBackgroundRes(R.id.cl_item, com.xscm.moduleutil.R.drawable.bg_10_white_sele);
|
||||
} else {
|
||||
helper.setBackgroundRes(R.id.cl_item, com.xscm.moduleutil.R.drawable.bg_r10_white);
|
||||
}
|
||||
|
||||
helper.getView(R.id.cl_item).setOnClickListener(v -> {
|
||||
selectedPosition = helper.getAdapterPosition();
|
||||
if (listener != null) {
|
||||
listener.onClick(item);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
|
||||
// 隐藏输入框
|
||||
if (inputBoxVisibilityListener != null) {
|
||||
inputBoxVisibilityListener.onInputBoxVisibilityChanged(false);
|
||||
}
|
||||
});
|
||||
} else if (type == ITEM_TYPE_FOOTER) {
|
||||
helper.setText(R.id.tv_gold_num, "自定义");
|
||||
helper.getView(R.id.tv_gold_num).setOnClickListener(v -> {
|
||||
clearSelect(); // 清除所有选中状态
|
||||
notifyDataSetChanged();
|
||||
|
||||
// 显示输入框
|
||||
if (inputBoxVisibilityListener != null) {
|
||||
inputBoxVisibilityListener.onInputBoxVisibilityChanged(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnRechargeItemClickListener {
|
||||
void onClick(RechargeBean rechargeBean);
|
||||
}
|
||||
|
||||
public void setListener(OnRechargeItemClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public interface InputBoxVisibilityListener {
|
||||
void onInputBoxVisibilityChanged(boolean isVisible);
|
||||
}
|
||||
|
||||
public void setInputBoxVisibilityListener(InputBoxVisibilityListener listener) {
|
||||
this.inputBoxVisibilityListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消所有选中
|
||||
*/
|
||||
public void clearSelect() {
|
||||
selectedPosition = -1;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.blankj.utilcode.util.TimeUtils;
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.CircleListBean;
|
||||
import com.xscm.moduleutil.bean.HeatedBean;
|
||||
import com.xscm.moduleutil.utils.MeHeadView;
|
||||
import com.xscm.moduleutil.utils.NumberFormatUtils;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.widget.MyGridView;
|
||||
import com.xscm.moduleutil.widget.img.FullScreenUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CirleListAdapter extends BaseQuickAdapter<CircleListBean, BaseViewHolder> {
|
||||
|
||||
public static final int PAGE_HOME = 0; // 首页
|
||||
public static final int PAGE_SEARCH = 2; // 点击头像进入的
|
||||
private int mPageType;
|
||||
|
||||
public CirleListAdapter(int pageType) {
|
||||
super(R.layout.item_cirle_list);
|
||||
this.mPageType = pageType;
|
||||
}
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onDianzanClick(int index,CircleListBean item);
|
||||
|
||||
void onHeadImageClick(CircleListBean item);
|
||||
|
||||
void onZsClick(int idx,CircleListBean item);
|
||||
|
||||
void onMoreClick(int idx,CircleListBean item);
|
||||
|
||||
void onPinglunClick(CircleListBean item);
|
||||
|
||||
void onRelaClick(CircleListBean item);
|
||||
|
||||
void onGensui(CircleListBean item);
|
||||
}
|
||||
|
||||
private OnItemClickListener mListener;
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
|
||||
public static final String PAYLOAD_LIKE = "like";
|
||||
|
||||
public void updateLikeStatusOnly(int position, int isLike) {
|
||||
notifyItemChanged(position, PAYLOAD_LIKE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void convertPayloads(@NonNull BaseViewHolder helper, CircleListBean item, @NonNull List<Object> payloads) {
|
||||
super.convertPayloads(helper, item, payloads);
|
||||
if (payloads.isEmpty()) {
|
||||
convert(helper, item);
|
||||
} else {
|
||||
Object payload = payloads.get(0);
|
||||
if (payload instanceof Bundle) {
|
||||
Bundle diff = (Bundle) payload;
|
||||
if (diff.containsKey("like_num")) {
|
||||
helper.setText(R.id.dy_fabulous, diff.getString("like_num"));
|
||||
if (diff.containsKey("is_like")){
|
||||
if (diff.getInt("is_like") == 1) {
|
||||
helper.setImageResource(R.id.dianzan_image, R.mipmap.dongtai_hudong_yidianzan);
|
||||
} else {
|
||||
helper.setImageResource(R.id.dianzan_image, com.xscm.moduleutil.R.mipmap.dongtai_hudong_dianzan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (diff.containsKey("comment_num")) {
|
||||
helper.setText(R.id.dy_comment, diff.getString("comment_num"));
|
||||
}
|
||||
if (diff.containsKey("rewards_num")) {
|
||||
double rewardNum = diff.getString("rewards_num") != null ? Double.parseDouble(item.getRewards_num()) : 0;
|
||||
helper.setText(R.id.dy_zs, NumberFormatUtils.formatRewardNumber(rewardNum));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, CircleListBean item) {
|
||||
helper.addOnClickListener(com.xscm.moduleutil.R.id.dianzan)
|
||||
.addOnClickListener(R.id.dy_lookmore_tv)
|
||||
.addOnClickListener(R.id.dy_head_image)
|
||||
.addOnClickListener(R.id.diandian)
|
||||
.addOnClickListener(R.id.pinglun)
|
||||
.addOnClickListener(R.id.rela)
|
||||
.addOnClickListener(R.id.gensui)
|
||||
.addOnClickListener(com.xscm.moduleutil.R.id.zs);
|
||||
|
||||
//先让单图,多图,音频的布局显示
|
||||
helper.getView(R.id.dy_image_recyc).setVisibility(VISIBLE);
|
||||
helper.getView(R.id.iv_jubao).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Intent intent = new Intent(mContext, UserHomepageActivity.class);
|
||||
// intent.putExtra("userId", SpUtil.getUserId()+"");
|
||||
// startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置点击回调
|
||||
helper.getView(com.xscm.moduleutil.R.id.dianzan).setOnClickListener(v -> {
|
||||
if (mListener != null) {
|
||||
mListener.onDianzanClick(helper.getPosition(),item);
|
||||
}
|
||||
});
|
||||
|
||||
helper.getView(com.xscm.moduleutil.R.id.dy_head_image).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onHeadImageClick(item);
|
||||
});
|
||||
|
||||
helper.getView(com.xscm.moduleutil.R.id.zs).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onZsClick(helper.getPosition(),item);
|
||||
});
|
||||
|
||||
helper.getView(R.id.diandian).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onMoreClick(helper.getPosition(),item);
|
||||
});
|
||||
|
||||
helper.getView(R.id.pinglun).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onPinglunClick(item);
|
||||
});
|
||||
|
||||
helper.getView(R.id.rela).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onRelaClick(item);
|
||||
});
|
||||
helper.getView(R.id.gensui).setOnClickListener(v -> {
|
||||
if (mListener != null) mListener.onGensui(item);
|
||||
});
|
||||
// 为整个 item 设置点击事件
|
||||
helper.itemView.setOnClickListener(v -> {
|
||||
if (mListener != null) {
|
||||
mListener.onPinglunClick(item); // 复用 onHeadImageClick 作为跳转逻辑
|
||||
}
|
||||
});
|
||||
//昵称
|
||||
helper.setText(R.id.dy_name_text, item.getNickname());
|
||||
|
||||
//头像
|
||||
// ImageUtils.loadHeadCC(item.getAvatar(), helper.getView(R.id.dy_head_image));
|
||||
MeHeadView headView = helper.getView(R.id.dy_head_image);
|
||||
headView.setData(item.getAvatar(), "", item.getSex() + "");
|
||||
//动态内容以富文本展示
|
||||
String content = item.getContent();
|
||||
if (content == null || content.length() == 0) {
|
||||
helper.getView(R.id.dy_lookmore_tv).setVisibility(GONE);
|
||||
helper.getView(R.id.dy_content_tv).setVisibility(GONE);
|
||||
} else {
|
||||
helper.getView(R.id.dy_lookmore_tv).setVisibility(VISIBLE);
|
||||
helper.getView(R.id.dy_content_tv).setVisibility(VISIBLE);
|
||||
}
|
||||
helper.getView(R.id.dy_lookmore_tv).getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
//这个回调会调用多次,获取完行数记得注销监听
|
||||
TextView view = helper.getView(R.id.dy_content_tv);
|
||||
int lineCount = view.getLineCount();
|
||||
if (lineCount >= 7) {
|
||||
helper.getView(R.id.dy_lookmore_tv).setVisibility(VISIBLE);
|
||||
helper.getView(R.id.dy_content_tv).getViewTreeObserver().removeOnPreDrawListener(this);//销毁
|
||||
} else {
|
||||
helper.getView(R.id.dy_lookmore_tv).setVisibility(GONE);
|
||||
helper.getView(R.id.dy_content_tv).getViewTreeObserver().removeOnPreDrawListener(this);//销毁
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (TextUtils.isEmpty(content)) {
|
||||
TextView view = helper.getView(R.id.dy_content_tv);
|
||||
view.setVisibility(GONE);
|
||||
} else {
|
||||
TextView view = helper.getView(R.id.dy_content_tv);
|
||||
view.setVisibility(VISIBLE);
|
||||
}
|
||||
// 创建 SpannableString 来拼接 title 并设置点击事件
|
||||
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
|
||||
spannableStringBuilder.append(content).append(" "); // 添加原始内容
|
||||
if (item.getTitle() != null) {
|
||||
|
||||
for (int i = 0; i < item.getTitle().size(); i++) {
|
||||
HeatedBean heatedBean = item.getTitle().get(i);
|
||||
String title = heatedBean != null ? heatedBean.getTitle() : "";
|
||||
|
||||
// 添加 title 到 SpannableString
|
||||
spannableStringBuilder.append(title);
|
||||
|
||||
|
||||
// 创建点击事件和颜色
|
||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
// 处理点击事件,比如跳转
|
||||
// Intent intent = new Intent(mContext, TargetActivity.class);
|
||||
// intent.putExtra("url", item.getUrl()); // 传递 URL 或其他参数
|
||||
// mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(TextPaint ds) {
|
||||
super.updateDrawState(ds);
|
||||
ds.setColor(ContextCompat.getColor(mContext, R.color.colorPrimary)); // 设置文字颜色
|
||||
ds.setUnderlineText(false); // 去掉下划线
|
||||
}
|
||||
};
|
||||
|
||||
// 设置点击效果
|
||||
spannableStringBuilder.setSpan(clickableSpan, spannableStringBuilder.length() - title.length(), spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
TextView textView = helper.getView(R.id.dy_content_tv);
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance()); // 允许点击
|
||||
textView.setHighlightColor(0); // 去掉点击时的背景色
|
||||
textView.setText(spannableStringBuilder);
|
||||
}
|
||||
|
||||
|
||||
if (item.getIs_like() == 1) {
|
||||
helper.setImageResource(R.id.dianzan_image, R.mipmap.dongtai_hudong_yidianzan);
|
||||
} else {
|
||||
helper.setImageResource(R.id.dianzan_image, com.xscm.moduleutil.R.mipmap.dongtai_hudong_dianzan);
|
||||
}
|
||||
|
||||
helper.setText(R.id.dy_fabulous, item.getLike_num());
|
||||
|
||||
if (mPageType == PAGE_SEARCH) {
|
||||
helper.setVisible(R.id.gensui, false);
|
||||
} else {
|
||||
if (item.getUser_id() == SpUtil.getUserId()) {
|
||||
helper.setVisible(R.id.gensui, false);
|
||||
} else {
|
||||
helper.setVisible(R.id.gensui, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getRoom_id() != null && !item.getRoom_id().equals("0")) {
|
||||
helper.setText(R.id.gensui, "跟随");
|
||||
} else if (item.getRoom_id() == null || item.getRoom_id().equals("0")) {
|
||||
helper.setText(R.id.gensui, "私信");
|
||||
}
|
||||
//分享数
|
||||
// helper.setText(R.id.dy_zs, item.getRewards_num() != null ? item.getRewards_num() : "0");
|
||||
double rewardNum = item.getRewards_num() != null ? Double.parseDouble(item.getRewards_num()) : 0;
|
||||
helper.setText(R.id.dy_zs, NumberFormatUtils.formatRewardNumber(rewardNum));
|
||||
|
||||
//评论数
|
||||
helper.setText(R.id.dy_comment, item.getComment_num() + "");
|
||||
|
||||
//时间
|
||||
if (!item.getCreatetime().isEmpty()) {
|
||||
try {
|
||||
helper.setText(R.id.dy_time_text, TimeUtils.millis2String(Long.parseLong(item.getCreatetime()) * 1000));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//显示图片
|
||||
if (item.getImages() != null && !item.getImages().isEmpty()) {
|
||||
String[] arrIv = item.getImages().split(",");
|
||||
OneImageYuanJiaoAdapter oneImageYuanJiaoAdapter = new OneImageYuanJiaoAdapter(mContext);
|
||||
MyGridView recyclerView = helper.getView(R.id.dy_image_recyc);
|
||||
recyclerView.setAdapter(oneImageYuanJiaoAdapter);
|
||||
oneImageYuanJiaoAdapter.getList_adapter().clear();
|
||||
|
||||
for (int j = 0; j < arrIv.length; j++) {
|
||||
oneImageYuanJiaoAdapter.getList_adapter().add(arrIv[j]);
|
||||
}
|
||||
oneImageYuanJiaoAdapter.notifyDataSetChanged();
|
||||
recyclerView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
FullScreenUtil.showFullScreenDialog(mContext, position, oneImageYuanJiaoAdapter.getList_adapter());
|
||||
});
|
||||
} else {
|
||||
helper.getView(R.id.dy_image_recyc).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (item.getLike_list() == null) {
|
||||
helper.getView(R.id.rela).setVisibility(GONE);
|
||||
helper.getView(R.id.view).setVisibility(VISIBLE);
|
||||
} else {
|
||||
helper.getView(R.id.rela).setVisibility(VISIBLE);
|
||||
helper.getView(R.id.view).setVisibility(GONE);
|
||||
RecyclerView recyclerView = helper.getView(R.id.recycle_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
|
||||
LikeUserAdapter<CircleListBean.LikeList> likeUserAdapter = new LikeUserAdapter<>();
|
||||
recyclerView.setAdapter(likeUserAdapter);
|
||||
likeUserAdapter.setNewData(item.getLike_list());
|
||||
helper.setText(R.id.pinglun_tv, item.getLike_num() + "人点赞");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.blankj.utilcode.util.TimeUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.CommentBean;
|
||||
import com.xscm.moduleutil.utils.MeHeadView;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentViewHolder> {
|
||||
public interface OnCommentInteractionListener {
|
||||
void onInputBoxShow(int id,String s,int position,String replyTo);
|
||||
|
||||
void onDetaleClick(int id,int position);
|
||||
// 新增长按回调
|
||||
void onCommentLongClick(CommentBean.CommentDetailsBean comment, CommentBean.CommentDetailsBean.Replies reply, int position);
|
||||
|
||||
}
|
||||
private OnCommentInteractionListener listener; // 新增监听器引用
|
||||
public void setOnCommentInteractionListener(OnCommentInteractionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
private List<CommentBean.CommentDetailsBean> commentList;
|
||||
private static FragmentManager fragmentManager = null;
|
||||
|
||||
public CommentAdapter(List<CommentBean.CommentDetailsBean> commentList) {
|
||||
this.commentList = commentList;
|
||||
}
|
||||
public void updateData(List<CommentBean.CommentDetailsBean> newReplyList) {
|
||||
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new CommentDiffCallback(this.commentList, newReplyList));
|
||||
this.commentList.clear();
|
||||
this.commentList.addAll(newReplyList);
|
||||
diffResult.dispatchUpdatesTo(this);
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public CommentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false);
|
||||
return new CommentViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CommentViewHolder holder, int position) {
|
||||
CommentBean.CommentDetailsBean comment = commentList.get(position);
|
||||
holder.bind(comment, listener, position);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return commentList.size();
|
||||
}
|
||||
|
||||
static class CommentViewHolder extends RecyclerView.ViewHolder {
|
||||
private MeHeadView ivAvatar;
|
||||
private TextView tvNickname;
|
||||
private TextView tvContent;
|
||||
private RecyclerView rvReplies;
|
||||
private TextView btnReply,btnDetale;
|
||||
private TextView tvTime;
|
||||
private TextView btnShowAllReplies;
|
||||
|
||||
private TextView tv_send;
|
||||
private EditText et_input;
|
||||
|
||||
public CommentViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ivAvatar = itemView.findViewById(R.id.iv_avatar);
|
||||
tvNickname = itemView.findViewById(R.id.tv_nickname);
|
||||
tvContent = itemView.findViewById(R.id.tv_content);
|
||||
rvReplies = itemView.findViewById(R.id.rv_replies);
|
||||
btnReply = itemView.findViewById(R.id.btn_reply);
|
||||
btnDetale=itemView.findViewById(R.id.btn_detale);
|
||||
tvTime = itemView.findViewById(R.id.tv_time);
|
||||
btnShowAllReplies = itemView.findViewById(R.id.btn_show_all_replies);
|
||||
tv_send= itemView.findViewById(R.id.tv_send);
|
||||
et_input= itemView.findViewById(R.id.et_input);
|
||||
// 设置子评论的适配器
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(itemView.getContext());
|
||||
rvReplies.setLayoutManager(layoutManager);
|
||||
ReplyAdapter replyAdapter = new ReplyAdapter(new ArrayList<>());
|
||||
rvReplies.setAdapter(replyAdapter);
|
||||
}
|
||||
|
||||
public void bind(CommentBean.CommentDetailsBean comment, OnCommentInteractionListener listener, int position) {
|
||||
// 绑定主评论数据
|
||||
tvNickname.setText(comment.getNickname());
|
||||
tvContent.setText(comment.getContent());
|
||||
ivAvatar.setData(comment.getAvatar(), "","");
|
||||
// 加载用户头像(使用 Glide 或其他图片加载库)
|
||||
// Glide.with(itemView).load(comment.getAvatar()).into(ivAvatar);
|
||||
|
||||
if (comment.getUser_id()==SpUtil.getUserId()){
|
||||
btnDetale.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
btnDetale.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
tvTime.setText(TimeUtils.millis2String(Long.parseLong(comment.getCreatetime()+"") * 1000));
|
||||
// 绑定子评论数据
|
||||
ReplyAdapter replyAdapter = (ReplyAdapter) rvReplies.getAdapter();
|
||||
if (replyAdapter != null) {
|
||||
if (comment.getReplies() != null&& comment.getReplies().size() > 0) {
|
||||
rvReplies.setVisibility(VISIBLE);
|
||||
replyAdapter.updateData(comment.getReplies());
|
||||
|
||||
// 控制“全部评论...”按钮的显示
|
||||
btnShowAllReplies.setVisibility(comment.getReplies().size() > 2 ? VISIBLE : GONE);
|
||||
|
||||
btnShowAllReplies.setOnClickListener(v -> {
|
||||
replyAdapter.setExpanded(true); // 展开所有评论
|
||||
btnShowAllReplies.setVisibility(GONE); // 隐藏按钮
|
||||
});
|
||||
|
||||
replyAdapter.setOnReplyClickListener((reply, position1) -> {
|
||||
if (listener != null) {
|
||||
// 构造回复内容(如 @用户名)
|
||||
String replyContent = "@" + reply.getNickname() + " ";
|
||||
listener.onInputBoxShow(reply.getPid(), replyContent, getAdapterPosition(),reply.getReply_to()+"");
|
||||
}
|
||||
});
|
||||
|
||||
replyAdapter.setOnReplyLongClickListener((reply, replyPosition) -> {
|
||||
if (listener != null) {
|
||||
// 转发到Activity
|
||||
listener.onCommentLongClick(comment,reply, replyPosition);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
rvReplies.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
// 点击回复按钮
|
||||
btnReply.setOnClickListener(v -> {
|
||||
|
||||
if (listener != null) {
|
||||
// 传递需要的参数
|
||||
listener.onInputBoxShow(comment.getId(), "", position,"");
|
||||
}
|
||||
|
||||
});
|
||||
btnDetale.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onDetaleClick(comment.getId(), position); // 点击删除按钮
|
||||
}
|
||||
});
|
||||
|
||||
// if (comment.getUser_id()!= SpUtil.getUserId()){
|
||||
// btnReply.setVisibility(GONE);
|
||||
// }else {
|
||||
// btnReply.setVisibility(VISIBLE);
|
||||
// }
|
||||
|
||||
// 添加长按监听
|
||||
itemView.setOnLongClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onCommentLongClick(comment, null,position);
|
||||
}
|
||||
return true; // 消费事件
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class CommentDiffCallback extends DiffUtil.Callback {
|
||||
|
||||
private final List<CommentBean.CommentDetailsBean> oldList;
|
||||
private final List<CommentBean.CommentDetailsBean> newList;
|
||||
|
||||
public CommentDiffCallback(List<CommentBean.CommentDetailsBean> oldList, List<CommentBean.CommentDetailsBean> newList) {
|
||||
this.oldList = oldList;
|
||||
this.newList = newList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldListSize() {
|
||||
return oldList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewListSize() {
|
||||
return newList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
return oldList.get(oldItemPosition).getId() == newList.get(newItemPosition).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
return oldList.get(oldItemPosition).equals(newList.get(newItemPosition));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/6/9
|
||||
*@description:可动态添加和删除的viewPage适配器
|
||||
*/
|
||||
public class CommonPageAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private List<Fragment> mFragmentList = new ArrayList<>();
|
||||
private List<Integer> mItemIdList = new ArrayList<>();
|
||||
private int id = 0;
|
||||
private FragmentManager mFm;
|
||||
|
||||
public CommonPageAdapter(FragmentManager fm, @NonNull List<Fragment> fragmentList) {
|
||||
super(fm);
|
||||
this.mFm = fm;
|
||||
for (Fragment fragment : fragmentList) {
|
||||
this.mFragmentList.add(fragment);
|
||||
mItemIdList.add(id++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CommonPageAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
public List<Fragment> getFragmentList() {
|
||||
return mFragmentList;
|
||||
}
|
||||
|
||||
public void addPage(int index, Fragment fragment) {
|
||||
mFragmentList.add(index, fragment);
|
||||
mItemIdList.add(index, id++);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addPage(Fragment fragment) {
|
||||
mFragmentList.add(fragment);
|
||||
mItemIdList.add(id++);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void delPage(int index) {
|
||||
mFragmentList.remove(index);
|
||||
mItemIdList.remove(index);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void updatePage(List<Fragment> fragmentList) {
|
||||
mFragmentList.clear();
|
||||
mItemIdList.clear();
|
||||
|
||||
for (int i = 0; i < fragmentList.size(); i++) {
|
||||
mFragmentList.add(fragmentList.get(i));
|
||||
mItemIdList.add(id++);//注意这里是id++,不是i++。
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return mFragmentList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFragmentList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回值有三种,
|
||||
* POSITION_UNCHANGED 默认值,位置没有改变
|
||||
* POSITION_NONE item已经不存在
|
||||
* position item新的位置
|
||||
* 当position发生改变时这个方法应该返回改变后的位置,以便页面刷新。
|
||||
*/
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
if (object instanceof Fragment) {
|
||||
|
||||
if (mFragmentList.contains(object)) {
|
||||
return mFragmentList.indexOf(object);
|
||||
} else {
|
||||
return POSITION_NONE;
|
||||
}
|
||||
|
||||
}
|
||||
return super.getItemPosition(object);
|
||||
}
|
||||
public void updateFragments(List<Fragment> newFragments) {
|
||||
this.mFragmentList.clear();
|
||||
this.mFragmentList.addAll(newFragments);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mItemIdList.get(position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.blankj.utilcode.util.ConvertUtils;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class GiftAdapter extends BaseQuickAdapter<HeavenGiftBean, BaseViewHolder> {
|
||||
//类型 1:金币,2:礼物,3:坐骑,4:头像框":
|
||||
private final int COIN_TYPE = 1;
|
||||
private final int GIFT_TYPE = 2;
|
||||
private final int MOUNT_TYPE = 3;
|
||||
private final int HEAD_TYPE = 4;
|
||||
|
||||
public GiftAdapter() {
|
||||
super(R.layout.item_gift);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, HeavenGiftBean item) {
|
||||
ImageUtils.loadHeadCC(item.getPicture(), helper.getView(R.id.iv_head));
|
||||
helper.getView(R.id.im_jb).setVisibility(View.VISIBLE);
|
||||
// if (item.getType() == COIN_TYPE) {
|
||||
// helper.setText(R.id.tv_gift_time, String.format("%s", item.getGold()));
|
||||
// } else if (item.getType() == GIFT_TYPE) {
|
||||
// helper.getView(R.id.im_jb).setVisibility(View.GONE);
|
||||
// helper.setText(R.id.tv_gift_time, String.format("*%s", item.getQuantity()));
|
||||
// } else {
|
||||
// helper.getView(R.id.im_jb).setVisibility(View.GONE);
|
||||
// helper.setText(R.id.tv_gift_time, String.format("%s天", item.getDays()));
|
||||
// }
|
||||
helper.setText(R.id.tv_head_name, item.getTitle());
|
||||
ViewGroup.LayoutParams layoutParams = helper.itemView.getLayoutParams();
|
||||
layoutParams.width = ((ScreenUtils.getScreenWidth() - ConvertUtils.dp2px(140)) / 4);
|
||||
layoutParams.height = 259;
|
||||
helper.itemView.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.GiftPackBean;
|
||||
import com.xscm.moduleutil.event.RoomGiftPackToEvent;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author lxj$
|
||||
* @Time 2025年7月29日23:36:25$ $
|
||||
* @Description 背包礼物适配器$
|
||||
*/
|
||||
public class GiftPackAdapter extends BaseAdapter {
|
||||
private final List<GiftPackBean> mDatas;
|
||||
private final LayoutInflater inflater;
|
||||
private final Context mContext;
|
||||
private final MyGestureDetector gestureDetector;
|
||||
private final String type;
|
||||
/**
|
||||
* 页数下标,从0开始(当前是第几页)
|
||||
*/
|
||||
private final int curIndex;
|
||||
/**
|
||||
* 每一页显示的个数
|
||||
*/
|
||||
private final int pageSize = 100;
|
||||
|
||||
public GiftPackAdapter(Context context, List<GiftPackBean> mDatas, int curIndex, String type) {
|
||||
inflater = LayoutInflater.from(context);
|
||||
this.mDatas = mDatas;
|
||||
this.curIndex = curIndex;
|
||||
this.mContext = context;
|
||||
this.type = type;
|
||||
this.gestureDetector = new MyGestureDetector(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 先判断数据集的大小是否足够显示满本页?mDatas.size() > (curIndex+1)*pageSize,
|
||||
* 如果够,则直接返回每一页显示的最大条目个数pageSize,
|
||||
* 如果不够,则有几项返回几,(mDatas.size() - curIndex * pageSize);(也就是最后一页的时候就显示剩余item)
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDatas.size() > (curIndex + 1) * pageSize ? pageSize : (mDatas.size() - curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GiftPackBean getItem(int position) {
|
||||
return mDatas.get(position + curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position + (long) curIndex * pageSize;
|
||||
}
|
||||
|
||||
private static class MyGestureDetector extends GestureDetector {
|
||||
private static WeakReference<GiftPackAdapter> sAdapter = new WeakReference<>(null);
|
||||
private static GiftPackBean sGiftModel;
|
||||
private GiftPackAdapter mAdapter;
|
||||
private GiftPackBean mGiftModel;
|
||||
public void setGiftModel(GiftPackAdapter adapter, GiftPackBean gift) {
|
||||
sAdapter = new WeakReference<>(adapter);
|
||||
sGiftModel = gift;
|
||||
}
|
||||
|
||||
private static final SimpleOnGestureListener sSimpleOnGestureListener = new SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftPackToEvent(sAdapter.get(), sGiftModel, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftPackToEvent(sAdapter.get(), sGiftModel, 2));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public MyGestureDetector(Context context) {
|
||||
super(context, sSimpleOnGestureListener);
|
||||
setOnDoubleTapListener(sSimpleOnGestureListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
GiftPackAdapter.ViewHolder viewHolder;
|
||||
GiftPackBean giftModel = getItem(position);
|
||||
if (convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.item_gift_room, parent, false);
|
||||
viewHolder = new GiftPackAdapter.ViewHolder();
|
||||
viewHolder.tv_gift_name = (TextView) convertView.findViewById(R.id.tv_gift_name);
|
||||
viewHolder.tv_gift_price = (TextView) convertView.findViewById(R.id.tv_gift_price);
|
||||
viewHolder.iv_gift_pic = (ImageView) convertView.findViewById(R.id.iv_gift_pic);
|
||||
viewHolder.item_layout = (ConstraintLayout) convertView.findViewById(R.id.cl_gift);
|
||||
viewHolder.ivDownOn = (ImageView) convertView.findViewById(R.id.iv_down_on);
|
||||
viewHolder.cl_iv_down_on = (ConstraintLayout) convertView.findViewById(R.id.cl_iv_down_on);
|
||||
viewHolder.integral = (TextView) convertView.findViewById(R.id.integral);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (GiftPackAdapter.ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
viewHolder.item_layout.setOnClickListener(v -> {
|
||||
// RoonGiftModel clickedModel = (RoonGiftModel) v.getTag();
|
||||
EventBus.getDefault().post(new RoomGiftPackToEvent(this, giftModel, 2));
|
||||
|
||||
});
|
||||
viewHolder.integral.setVisibility(View.VISIBLE);
|
||||
viewHolder.integral.setText("x"+giftModel.getNum());
|
||||
//设置礼物名字
|
||||
viewHolder.tv_gift_name.setText(giftModel.getGift_name());
|
||||
//设置礼物价格
|
||||
String surplusTxt = giftModel.getGift_price();
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(surplusTxt);
|
||||
//ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
|
||||
ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_FFA9A9A9));
|
||||
stringBuilder.setSpan(redSpan, surplusTxt.length(), surplusTxt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//修改最后两个字体的颜色
|
||||
viewHolder.tv_gift_price.setText(stringBuilder);
|
||||
// viewHolder.item_layout.setTag(R.id.id_gift_tag, giftModel);
|
||||
|
||||
//加载礼物图片
|
||||
ImageUtils.loadImageView(giftModel.getBase_image(), viewHolder.iv_gift_pic);
|
||||
//设置选中后的样式
|
||||
|
||||
if (giftModel.isChecked()) {//被选中
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(R.mipmap.room_gift_bjx);
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(0);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
static class ViewHolder {
|
||||
public ConstraintLayout item_layout;
|
||||
public TextView tv_gift_name, tv_gift_price, integral;
|
||||
public ImageView iv_gift_pic;
|
||||
public TextView tv_gift_change_love_values;
|
||||
public ImageView ivDownOn;
|
||||
public ConstraintLayout cl_iv_down_on;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||||
import com.xscm.moduleutil.event.RoomGiftClickToEvent;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class GiftRoomAdapter extends BaseAdapter {
|
||||
private final List<RoonGiftModel> mDatas;
|
||||
private final LayoutInflater inflater;
|
||||
private final Context mContext;
|
||||
private final MyGestureDetector gestureDetector;
|
||||
private final String type;
|
||||
/**
|
||||
* 页数下标,从0开始(当前是第几页)
|
||||
*/
|
||||
private final int curIndex;
|
||||
/**
|
||||
* 每一页显示的个数
|
||||
*/
|
||||
private final int pageSize = 100;
|
||||
|
||||
public GiftRoomAdapter(Context context, List<RoonGiftModel> mDatas, int curIndex, String type) {
|
||||
|
||||
this.mDatas = mDatas;
|
||||
this.curIndex = curIndex;
|
||||
this.mContext = context;
|
||||
this.type = type;
|
||||
this.gestureDetector = new MyGestureDetector(mContext);
|
||||
inflater = LayoutInflater.from(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 先判断数据集的大小是否足够显示满本页?mDatas.size() > (curIndex+1)*pageSize,
|
||||
* 如果够,则直接返回每一页显示的最大条目个数pageSize,
|
||||
* 如果不够,则有几项返回几,(mDatas.size() - curIndex * pageSize);(也就是最后一页的时候就显示剩余item)
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDatas.size() > (curIndex + 1) * pageSize ? pageSize : (mDatas.size() - curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoonGiftModel getItem(int position) {
|
||||
return mDatas.get(position + curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position + (long) curIndex * pageSize;
|
||||
}
|
||||
|
||||
private static class MyGestureDetector extends GestureDetector {
|
||||
private static WeakReference<GiftRoomAdapter> sAdapter = new WeakReference<>(null);
|
||||
private static RoonGiftModel sGiftModel;
|
||||
private GiftRoomAdapter mAdapter;
|
||||
private RoonGiftModel mGiftModel;
|
||||
public void setGiftModel(GiftRoomAdapter adapter, RoonGiftModel gift) {
|
||||
sAdapter = new WeakReference<>(adapter);
|
||||
sGiftModel = gift;
|
||||
}
|
||||
|
||||
private static final SimpleOnGestureListener sSimpleOnGestureListener = new SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftClickToEvent(sAdapter.get(), sGiftModel, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftClickToEvent(sAdapter.get(), sGiftModel, 2));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public MyGestureDetector(Context context) {
|
||||
super(context, sSimpleOnGestureListener);
|
||||
setOnDoubleTapListener(sSimpleOnGestureListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateData(List<RoonGiftModel> newData) {
|
||||
this.mDatas.clear();
|
||||
// 确保新数据都不处于选中状态
|
||||
for (RoonGiftModel model : newData) {
|
||||
model.setChecked(false);
|
||||
}
|
||||
this.mDatas.addAll(newData);
|
||||
}
|
||||
|
||||
|
||||
// private static class MyGestureDetector extends GestureDetector {
|
||||
// private GiftRoomAdapter mAdapter;
|
||||
// private RoonGiftModel mGiftModel;
|
||||
//
|
||||
// public MyGestureDetector(Context context) {
|
||||
// super(context, new SimpleOnGestureListener() {
|
||||
// @Override
|
||||
// public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
// if (mAdapter != null && mGiftModel != null) {
|
||||
// EventBus.getDefault().post(new RoomGiftClickToEvent(mAdapter, mGiftModel, 1));
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onDoubleTap(MotionEvent e) {
|
||||
// if (mAdapter != null && mGiftModel != null) {
|
||||
// EventBus.getDefault().post(new RoomGiftClickToEvent(mAdapter, mGiftModel, 2));
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
// setOnDoubleTapListener(getListener());
|
||||
// }
|
||||
//
|
||||
// public void setGiftModel(GiftRoomAdapter adapter, RoonGiftModel giftModel) {
|
||||
// this.mAdapter = adapter;
|
||||
// this.mGiftModel = giftModel;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
RoonGiftModel giftModel = getItem(position);
|
||||
if (convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.item_gift_room, parent, false);
|
||||
viewHolder = new ViewHolder();
|
||||
viewHolder.tv_gift_name = (TextView) convertView.findViewById(R.id.tv_gift_name);
|
||||
viewHolder.tv_gift_price = (TextView) convertView.findViewById(R.id.tv_gift_price);
|
||||
viewHolder.iv_gift_pic = (ImageView) convertView.findViewById(R.id.iv_gift_pic);
|
||||
viewHolder.item_layout = (ConstraintLayout) convertView.findViewById(R.id.cl_gift);
|
||||
viewHolder.ivDownOn = (ImageView) convertView.findViewById(R.id.iv_down_on);
|
||||
viewHolder.cl_iv_down_on = (ConstraintLayout) convertView.findViewById(R.id.cl_iv_down_on);
|
||||
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
viewHolder.item_layout.setOnClickListener(v -> {
|
||||
// RoonGiftModel clickedModel = (RoonGiftModel) v.getTag();
|
||||
EventBus.getDefault().post(new RoomGiftClickToEvent(this, giftModel, 1));
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* 在给View绑定显示的数据时,计算正确的position = position + curIndex * pageSize,
|
||||
*/
|
||||
// viewHolder.tv_gift_num.setVisibility(type.equals("1") ? View.VISIBLE : View.INVISIBLE);
|
||||
// viewHolder.tv_gift_change_love_values.setVisibility(View.GONE);
|
||||
|
||||
|
||||
//设置礼物名字
|
||||
viewHolder.tv_gift_name.setText(giftModel.getGift_name());
|
||||
//设置礼物价格
|
||||
String surplusTxt = giftModel.getGift_price();
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(surplusTxt);
|
||||
//ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
|
||||
ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_FFA9A9A9));
|
||||
stringBuilder.setSpan(redSpan, surplusTxt.length(), surplusTxt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//修改最后两个字体的颜色
|
||||
viewHolder.tv_gift_price.setText(stringBuilder);
|
||||
// viewHolder.item_layout.setTag(R.id.id_gift_tag, giftModel);
|
||||
|
||||
//加载礼物图片
|
||||
ImageUtils.loadImageView(giftModel.getBase_image(), viewHolder.iv_gift_pic);
|
||||
//设置选中后的样式
|
||||
|
||||
if (giftModel.isChecked()) {//被选中
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(R.mipmap.room_gift_bjx);
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(0);
|
||||
}
|
||||
//设置
|
||||
// //设置礼物心动值
|
||||
// if (giftModel.getCardiac().equals("0")) {
|
||||
// viewHolder.tv_gift_change_love_values.setBackgroundResource(R.mipmap.room_gift_xin_dong_reduce);
|
||||
// viewHolder.tv_gift_change_love_values.setText(String.format("%s", giftModel.getCardiac()));
|
||||
// } else {
|
||||
// viewHolder.tv_gift_change_love_values.setBackgroundResource(R.mipmap.room_gift_xin_dong_add);
|
||||
// viewHolder.tv_gift_change_love_values.setText(String.format("+%s", giftModel.getCardiac()));
|
||||
// }
|
||||
// if (giftModel.isManghe()) {
|
||||
// viewHolder.tv_gift_change_love_values.setVisibility(View.GONE);
|
||||
// }
|
||||
if (giftModel.getGift_bag() == 10) {
|
||||
|
||||
viewHolder.item_layout.setBackgroundResource(R.mipmap.gift_tkzj);
|
||||
viewHolder.tv_gift_name.setText("");
|
||||
viewHolder.tv_gift_name.setBackgroundResource(R.mipmap.gift_name_tkzj);
|
||||
} else if (giftModel.getGift_bag() == 11) {
|
||||
viewHolder.tv_gift_name.setText("");
|
||||
viewHolder.item_layout.setBackgroundResource(R.mipmap.gift_syzc);
|
||||
viewHolder.tv_gift_name.setBackgroundResource(R.mipmap.gift_name_syzc);
|
||||
} else if (giftModel.getGift_bag() == 12) {
|
||||
viewHolder.tv_gift_name.setText("");
|
||||
viewHolder.item_layout.setBackgroundResource(R.mipmap.gift_sjzd);
|
||||
viewHolder.tv_gift_name.setBackgroundResource(R.mipmap.gift_name_skzd);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
static class ViewHolder {
|
||||
public ConstraintLayout item_layout;
|
||||
public TextView tv_gift_name, tv_gift_price, tv_gift_num;
|
||||
public ImageView iv_gift_pic;
|
||||
public TextView tv_gift_change_love_values;
|
||||
public ImageView ivDownOn;
|
||||
public ConstraintLayout cl_iv_down_on;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||||
import com.xscm.moduleutil.event.RoomGiftClickEvent;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class GiftTwoAdapter extends BaseAdapter {
|
||||
private final List<RoonGiftModel> mDatas;
|
||||
private final LayoutInflater inflater;
|
||||
private final Context mContext;
|
||||
private final MyGestureDetector gestureDetector;
|
||||
private final String type;
|
||||
/**
|
||||
* 页数下标,从0开始(当前是第几页)
|
||||
*/
|
||||
private final int curIndex;
|
||||
/**
|
||||
* 每一页显示的个数
|
||||
*/
|
||||
private final int pageSize = 100;
|
||||
|
||||
public GiftTwoAdapter(Context context, List<RoonGiftModel> mDatas, int curIndex, String type) {
|
||||
inflater = LayoutInflater.from(context);
|
||||
this.mDatas = mDatas;
|
||||
this.curIndex = curIndex;
|
||||
this.mContext = context;
|
||||
this.type = type;
|
||||
this.gestureDetector = new MyGestureDetector(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 先判断数据集的大小是否足够显示满本页?mDatas.size() > (curIndex+1)*pageSize,
|
||||
* 如果够,则直接返回每一页显示的最大条目个数pageSize,
|
||||
* 如果不够,则有几项返回几,(mDatas.size() - curIndex * pageSize);(也就是最后一页的时候就显示剩余item)
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mDatas.size() > (curIndex + 1) * pageSize ? pageSize : (mDatas.size() - curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoonGiftModel getItem(int position) {
|
||||
return mDatas.get(position + curIndex * pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position + (long) curIndex * pageSize;
|
||||
}
|
||||
|
||||
private static class MyGestureDetector extends GestureDetector {
|
||||
private static WeakReference<GiftTwoAdapter> sAdapter = new WeakReference<>(null);
|
||||
private static RoonGiftModel sGiftModel;
|
||||
|
||||
public void setGiftModel(GiftTwoAdapter adapter, RoonGiftModel gift) {
|
||||
sAdapter = new WeakReference<>(adapter);
|
||||
sGiftModel = gift;
|
||||
}
|
||||
|
||||
private static final SimpleOnGestureListener sSimpleOnGestureListener = new SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftClickEvent(sAdapter.get(), sGiftModel, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
EventBus.getDefault().post(new RoomGiftClickEvent(sAdapter.get(), sGiftModel, 2));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public MyGestureDetector(Context context) {
|
||||
super(context, sSimpleOnGestureListener);
|
||||
setOnDoubleTapListener(sSimpleOnGestureListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = inflater.inflate(R.layout.room_gv_gift_item, parent, false);
|
||||
viewHolder = new ViewHolder();
|
||||
viewHolder.tv_gift_name = (TextView) convertView.findViewById(R.id.tv_gift_name);
|
||||
viewHolder.tv_gift_price = (TextView) convertView.findViewById(R.id.tv_gift_price);
|
||||
viewHolder.iv_gift_pic = (ImageView) convertView.findViewById(R.id.iv_gift_pic);
|
||||
viewHolder.item_layout = (ConstraintLayout) convertView.findViewById(R.id.cl_gift);
|
||||
viewHolder.ivDownOn = (ImageView) convertView.findViewById(R.id.iv_down_on);
|
||||
viewHolder.cl_iv_down_on = (ConstraintLayout) convertView.findViewById(R.id.cl_iv_down_on);
|
||||
viewHolder.tv_gift_num = convertView.findViewById(R.id.tv_number);
|
||||
// viewHolder.tv_gift_change_love_values = convertView.findViewById(R.id.tv_gift_change_love_values);
|
||||
viewHolder.item_layout.setOnTouchListener((v, event) -> {
|
||||
gestureDetector.setGiftModel(GiftTwoAdapter.this, (RoonGiftModel) v.getTag(R.id.id_gift_tag));
|
||||
gestureDetector.onTouchEvent(event);
|
||||
|
||||
return true;
|
||||
});
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
/*
|
||||
* 在给View绑定显示的数据时,计算正确的position = position + curIndex * pageSize,
|
||||
*/
|
||||
// viewHolder.tv_gift_num.setVisibility(type.equals("1") ? View.VISIBLE : View.INVISIBLE);
|
||||
// viewHolder.tv_gift_change_love_values.setVisibility(View.GONE);
|
||||
float[] corners = {0f, 4f, 0f, 4f};
|
||||
ThemeableDrawableUtils.setThemeableRoundedBackground( viewHolder.tv_gift_num, ColorManager.getInstance().getPrimaryColorInt(), corners);
|
||||
viewHolder.tv_gift_num.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
||||
RoonGiftModel giftModel = getItem(position);
|
||||
//设置礼物名字
|
||||
viewHolder.tv_gift_name.setText(giftModel.getGift_name());
|
||||
//设置礼物价格
|
||||
String surplusTxt = giftModel.getGift_price();
|
||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(surplusTxt);
|
||||
//ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色
|
||||
ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_FFA9A9A9));
|
||||
stringBuilder.setSpan(redSpan, surplusTxt.length(), surplusTxt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//修改最后两个字体的颜色
|
||||
viewHolder.tv_gift_price.setText(stringBuilder);
|
||||
// viewHolder.item_layout.setTag(R.id.id_gift_tag, giftModel);
|
||||
|
||||
//加载礼物图片
|
||||
ImageUtils.loadImageView(giftModel.getBase_image(), viewHolder.iv_gift_pic);
|
||||
//设置选中后的样式
|
||||
|
||||
if (giftModel.isChecked()) {//被选中
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(R.mipmap.room_gift_bjx);
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(0);
|
||||
}
|
||||
if (giftModel.getNum()==0){
|
||||
viewHolder.tv_gift_num.setVisibility(View.GONE);
|
||||
}
|
||||
viewHolder.tv_gift_num.setText(String.format("x%s", (giftModel.getNum()!=0?giftModel.getNum():"")));
|
||||
|
||||
|
||||
//设置
|
||||
// //设置礼物心动值
|
||||
// if (giftModel.getCardiac().equals("0")) {
|
||||
// viewHolder.tv_gift_change_love_values.setBackgroundResource(R.mipmap.room_gift_xin_dong_reduce);
|
||||
// viewHolder.tv_gift_change_love_values.setText(String.format("%s", giftModel.getCardiac()));
|
||||
// } else {
|
||||
// viewHolder.tv_gift_change_love_values.setBackgroundResource(R.mipmap.room_gift_xin_dong_add);
|
||||
// viewHolder.tv_gift_change_love_values.setText(String.format("+%s", giftModel.getCardiac()));
|
||||
// }
|
||||
// if (giftModel.isManghe()) {
|
||||
// viewHolder.tv_gift_change_love_values.setVisibility(View.GONE);
|
||||
// }
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
static class ViewHolder {
|
||||
public ConstraintLayout item_layout;
|
||||
public TextView tv_gift_name, tv_gift_price, tv_gift_num;
|
||||
public ImageView iv_gift_pic;
|
||||
public TextView tv_gift_change_love_values;
|
||||
public ImageView ivDownOn;
|
||||
public ConstraintLayout cl_iv_down_on;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.BaseMvpFragment;
|
||||
import com.xscm.moduleutil.bean.GiftLabelBean;
|
||||
import com.xscm.moduleutil.bean.GiftPackBean;
|
||||
import com.xscm.moduleutil.bean.GiftPackEvent;
|
||||
import com.xscm.moduleutil.bean.GiftPackListCount;
|
||||
import com.xscm.moduleutil.bean.RewardUserBean;
|
||||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||||
import com.xscm.moduleutil.bean.WalletBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomAuction;
|
||||
import com.xscm.moduleutil.databinding.RoomVpGiftBinding;
|
||||
import com.xscm.moduleutil.event.GiftDoubleClickEvent;
|
||||
import com.xscm.moduleutil.event.GiftUserRefreshEvent;
|
||||
import com.xscm.moduleutil.event.RoomGiftClickEvent;
|
||||
import com.xscm.moduleutil.event.RoomGiftClickToEvent;
|
||||
import com.xscm.moduleutil.event.RoomGiftPackToEvent;
|
||||
import com.xscm.moduleutil.presenter.RewardGiftContacts;
|
||||
import com.xscm.moduleutil.presenter.RewardGiftPresenter;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter, RoomVpGiftBinding> implements RewardGiftContacts.View {
|
||||
private String id;
|
||||
private GiftRoomAdapter roomAdapter;
|
||||
private GiftPackAdapter packAdapter;
|
||||
private String tag;
|
||||
private int pageSize = 100;//一页显示的礼物个数
|
||||
private int pageCount;//页数
|
||||
private int type;//1:房间点击进入的;2:打赏进入的
|
||||
private List<RoonGiftModel> giftList = new ArrayList<>();
|
||||
private List<GiftPackBean> giftPackList = new ArrayList<>();
|
||||
private String roomId;
|
||||
private String bdgiftId;
|
||||
|
||||
public static GiftTwoDetailsFragment newInstance(String id, int type, String roomId) {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("id", id);
|
||||
args.putInt("type", type);
|
||||
args.putString("roomId", roomId);
|
||||
GiftTwoDetailsFragment fragment = new GiftTwoDetailsFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initArgs(Bundle arguments) {
|
||||
super.initArgs(arguments);
|
||||
id = arguments.getString("id");
|
||||
type = arguments.getInt("type");
|
||||
roomId = arguments.getString("roomId");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RewardGiftPresenter bindPresenter() {
|
||||
return new RewardGiftPresenter(this, getActivity());
|
||||
}
|
||||
|
||||
public void loadDataIfNeeded(String id, int type, String roomId) {
|
||||
if (MvpPre==null){
|
||||
MvpPre = new RewardGiftPresenter(this, getActivity());
|
||||
}
|
||||
if (id.equals("0")) {
|
||||
MvpPre.giftPack();
|
||||
} else {
|
||||
if (type == 0) {
|
||||
MvpPre.getGiftList("0", type, roomId);
|
||||
} else {
|
||||
if (id == null) {
|
||||
id = "0";
|
||||
}
|
||||
MvpPre.getGiftList(id, type, roomId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onString(GiftPackEvent event) {
|
||||
if (event!=null && event.getBdid()!=null) {
|
||||
bdgiftId = event.getBdid();
|
||||
MvpPre.giftPack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
if (type==0){
|
||||
MvpPre.getGiftList("0", type, roomId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.room_vp_gift;
|
||||
}
|
||||
|
||||
|
||||
public RoonGiftModel getGiftList() {
|
||||
if (giftList != null) {
|
||||
for (RoonGiftModel item : giftList) {
|
||||
if (item.isChecked()) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GiftPackBean mGiftList() {
|
||||
if (giftPackList != null) {
|
||||
for (GiftPackBean item : giftPackList) {
|
||||
if (item.isChecked()) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGiftList(List<RoonGiftModel> data, int type) {
|
||||
giftList = new ArrayList<>();
|
||||
giftList.addAll(data);
|
||||
pageCount = (int) Math.ceil(data.size() * 1.0 / pageSize);
|
||||
|
||||
// 只需要创建一次Adapter并设置,循环设置没有意义
|
||||
if (pageCount > 0) {
|
||||
roomAdapter = new GiftRoomAdapter(getActivity(), data, 0, "0");
|
||||
mBinding.rvGift.setAdapter(roomAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void giveGift() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wallet(WalletBean walletBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reward_zone() {
|
||||
ToastUtils.showShort("打赏成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void roomAuctionJoin(RoomAuction.AuctionListBean auctionListBean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giftPack(List<GiftPackBean> giftPackBean) {
|
||||
giftPackList = new ArrayList<>();
|
||||
if (getActivity()==null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (giftPackBean != null && giftPackBean.size() > 0) {
|
||||
|
||||
if (bdgiftId != null) {
|
||||
for (GiftPackBean item : giftPackBean) {
|
||||
if (item.getGift_id().equals(bdgiftId)) {
|
||||
item.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
giftPackList.addAll(giftPackBean);
|
||||
pageCount = (int) Math.ceil(giftPackBean.size() * 1.0 / pageSize);
|
||||
for (int j = 0; j < pageCount; j++) {
|
||||
packAdapter = new GiftPackAdapter(getActivity(), giftPackBean, j, "0");
|
||||
mBinding.rvGift.setAdapter(packAdapter);
|
||||
}
|
||||
} else {
|
||||
giftPackBean = new ArrayList<>();
|
||||
pageCount = (int) Math.ceil(giftPackBean.size() * 1.0 / pageSize);
|
||||
packAdapter = new GiftPackAdapter(getActivity(), giftPackBean, 0, "0");
|
||||
mBinding.rvGift.setAdapter(packAdapter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGiftPack(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGiftPackListCount(GiftPackListCount giftPackListCount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRewardList(List<RewardUserBean> rewardUserBeanList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGiftLabel(List<GiftLabelBean> giftLabelBeans) {
|
||||
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onGiftClicRoomkEvent(RoomGiftClickEvent event) {
|
||||
if (giftList == null) {
|
||||
giftList = new ArrayList<>();
|
||||
giftList.add(event.gift);
|
||||
}
|
||||
if (event.type == 1) {
|
||||
String id = event.gift.getGift_id();
|
||||
for (int i = 0; i < giftList.size(); i++) {
|
||||
RoonGiftModel giftModel = giftList.get(i);
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
if (!giftModel.isChecked()) {
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||||
giftModel.setChecked(true);
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
} else if (event.type == 2) {
|
||||
String id = event.gift.getGift_id();
|
||||
RoonGiftModel selGift = null;
|
||||
for (int i = 0; i < giftList.size(); i++) {
|
||||
RoonGiftModel giftModel = giftList.get(i);
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
selGift = giftModel;
|
||||
if (!giftModel.isChecked()) {
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||||
giftModel.setChecked(true);
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
if (selGift != null) {
|
||||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onGiftClicPackEvent(RoomGiftPackToEvent event) {
|
||||
if (giftPackList == null) {
|
||||
giftPackList = new ArrayList<>();
|
||||
giftPackList.add(event.gift);
|
||||
}
|
||||
if (event.type == 1) {
|
||||
String id = event.gift.getGift_id();
|
||||
for (int i = 0; i < giftPackList.size(); i++) {
|
||||
GiftPackBean giftModel = giftPackList.get(i);
|
||||
RoonGiftModel roonGiftModel = new RoonGiftModel();
|
||||
roonGiftModel.setGift_id(giftModel.getGift_id());
|
||||
roonGiftModel.setGift_name(giftModel.getGift_name());
|
||||
roonGiftModel.setGift_price(giftModel.getGift_price());
|
||||
roonGiftModel.setBase_image(giftModel.getBase_image());
|
||||
roonGiftModel.setNum(Integer.parseInt(giftModel.getNum()));
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
if (!giftModel.isChecked()) {
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, roonGiftModel));
|
||||
giftModel.setChecked(true);
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
} else {
|
||||
String id = event.gift.getGift_id();
|
||||
GiftPackBean selGift = null;
|
||||
for (int i = 0; i < giftPackList.size(); i++) {
|
||||
GiftPackBean giftModel = giftPackList.get(i);
|
||||
RoonGiftModel roonGiftModel = new RoonGiftModel();
|
||||
roonGiftModel.setGift_id(giftModel.getGift_id());
|
||||
roonGiftModel.setGift_name(giftModel.getGift_name());
|
||||
roonGiftModel.setGift_price(giftModel.getGift_price());
|
||||
roonGiftModel.setBase_image(giftModel.getBase_image());
|
||||
roonGiftModel.setNum(Integer.parseInt(giftModel.getNum()));
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
selGift = giftModel;
|
||||
if (!giftModel.isChecked()) {
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, roonGiftModel));
|
||||
giftModel.setChecked(true);
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
if (selGift != null) {
|
||||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onGiftClicRoomkTEvent(RoomGiftClickToEvent event) {
|
||||
if (giftList == null) {
|
||||
giftList = new ArrayList<>();
|
||||
giftList.add(event.gift);
|
||||
}
|
||||
if (event.type == 1) {
|
||||
String id = event.gift.getGift_id();
|
||||
for (int i = 0; i < giftList.size(); i++) {
|
||||
RoonGiftModel giftModel = giftList.get(i);
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
if (giftModel.isChecked()) {
|
||||
giftModel.setChecked(false);
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||||
} else {
|
||||
giftModel.setChecked(true);
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, event.gift));
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
} else if (event.type == 2) {
|
||||
String id = event.gift.getGift_id();
|
||||
RoonGiftModel selGift = null;
|
||||
for (int i = 0; i < giftList.size(); i++) {
|
||||
RoonGiftModel giftModel = giftList.get(i);
|
||||
if (giftModel.getGift_id().equals(id)) {
|
||||
selGift = giftModel;
|
||||
if (giftModel.isChecked()) {
|
||||
giftModel.setChecked(false);
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||||
} else {
|
||||
giftModel.setChecked(true);
|
||||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||||
}
|
||||
} else {
|
||||
giftModel.setChecked(false);
|
||||
}
|
||||
}
|
||||
if (event.adapter != null && event.adapter.get() != null) {
|
||||
event.adapter.get().notifyDataSetChanged();
|
||||
}
|
||||
if (selGift != null) {
|
||||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.BaseListData;
|
||||
import com.xscm.moduleutil.bean.HeavenGiftBean;
|
||||
import com.zhpan.bannerview.BaseBannerAdapter;
|
||||
import com.zhpan.bannerview.BaseViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HeavenGiftAdapter extends BaseBannerAdapter<BaseListData> {
|
||||
List<HeavenGiftBean> list;
|
||||
private OnItemClickListener onItemClickListener;
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.onItemClickListener = listener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void bindData(BaseViewHolder<BaseListData> holder, BaseListData data, int position, int pageSize) {
|
||||
GiftTwoAdapter adapter = new GiftTwoAdapter(holder.itemView.getContext(), data.getData(), 0,"4");
|
||||
GridView recyclerView = holder.itemView.findViewById(R.id.rv_gift);
|
||||
// recyclerView.setLayoutManager(new GridLayoutManager(holder.itemView.getContext(), 4));
|
||||
recyclerView.setAdapter(adapter);
|
||||
// adapter.setNewData(data.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId(int viewType) {
|
||||
return R.layout.ietm_heaven_gift;
|
||||
}
|
||||
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(View view, HeavenGiftBean data, int position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.CircleListBean;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/6/10
|
||||
*@description: 点赞适配
|
||||
*/
|
||||
public class LikeListAdapter extends BaseQuickAdapter<CircleListBean.LikeList, BaseViewHolder> {
|
||||
public LikeListAdapter() {
|
||||
super(R.layout.item_like_list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, CircleListBean.LikeList item) {
|
||||
ImageUtils.loadHeadCC(item.getAvatar(), helper.getView(R.id.like_avatar));
|
||||
helper.setText(R.id.tv_nickname, item.getNickname());
|
||||
String s=item.getSex().equals("1")?"男":"女";
|
||||
String age=item.getAge()+"岁";
|
||||
String constellation=item.getConstellation();
|
||||
String co=s+"/"+age+"/"+constellation;
|
||||
helper.setText(R.id.tv_content, co);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.CircleListBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomOnlineBean;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/6/10
|
||||
*@description: 显示用户小头像
|
||||
*/
|
||||
public class LikeUserAdapter<T> extends BaseQuickAdapter<T, BaseViewHolder> {
|
||||
public LikeUserAdapter() {
|
||||
super(R.layout.item_like_user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper,T item) {
|
||||
if (item instanceof CircleListBean.LikeList) {
|
||||
ImageUtils.loadHeadCC(((CircleListBean.LikeList) item).getAvatar(), helper.getView(R.id.user_icon));
|
||||
} else {
|
||||
// 可扩展:通过接口回调获取头像 URL
|
||||
ImageUtils.loadHeadCC(((RoomOnlineBean) item).getAvatar(), helper.getView(R.id.user_icon));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* listview的adapter基类
|
||||
*/
|
||||
public class MyBaseAdapter<T> extends BaseAdapter {
|
||||
|
||||
public List<T> list_adapter;
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return list_adapter == null ? 0 : list_adapter.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return list_adapter.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<T> getList_adapter() {
|
||||
if (list_adapter == null)
|
||||
list_adapter = new ArrayList<>();
|
||||
return list_adapter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
|
||||
private List<Fragment> fragmentList;
|
||||
|
||||
public MyFragmentPagerAdapter(List<Fragment> list, FragmentManager fm) {
|
||||
super(fm);
|
||||
this.fragmentList = list;
|
||||
}
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
return fragmentList.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragmentList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
// super.destroyItem(container, position, object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private List<Fragment> fragments;
|
||||
private List<String> typeOnes;
|
||||
|
||||
public MyPagerAdapter(FragmentManager fm, List<Fragment> mFragments, List<String> ones) {
|
||||
super(fm);
|
||||
this.fragments = mFragments;
|
||||
this.typeOnes = ones;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragments.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return typeOnes.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return fragments.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
super.destroyItem(container, position, object);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.makeramen.roundedimageview.RoundedImageView;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class OneImageYuanJiaoAdapter extends MyBaseAdapter<String> {
|
||||
private Context context;
|
||||
public OneImageYuanJiaoAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder VH;
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(context).inflate(R.layout.gv_filter_image, null);
|
||||
VH = new ViewHolder(convertView);
|
||||
convertView.setTag(VH);
|
||||
} else {
|
||||
VH = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
VH.iv_del.setVisibility(View.GONE);
|
||||
|
||||
if (!TextUtils.isEmpty(list_adapter.get(position))) {
|
||||
ImageUtils.loadHeadCC(list_adapter.get(position),VH.tv_title);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
public static class ViewHolder {
|
||||
RoundedImageView tv_title;
|
||||
ImageView iv_del;
|
||||
|
||||
public ViewHolder(View convertView) {
|
||||
tv_title = convertView.findViewById(R.id.fiv);
|
||||
iv_del = convertView.findViewById(R.id.iv_del);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.BindType;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class PayMethodAdapter extends BaseQuickAdapter<BindType.AllData, BaseViewHolder> {
|
||||
|
||||
private int selectedPosition = -1; // -1 表示未选中
|
||||
|
||||
public PayMethodAdapter(int layoutResId) {
|
||||
super(layoutResId);
|
||||
}
|
||||
|
||||
public void setSelectedPosition(int position) {
|
||||
selectedPosition = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public int getSelectedPosition() {
|
||||
return selectedPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, BindType.AllData item) {
|
||||
helper.setText(R.id.tv_name, item.getName());
|
||||
ImageUtils.loadHeadCC(item.getIcon(), helper.getView(R.id.im_zfb));
|
||||
|
||||
// 设置选中状态样式
|
||||
boolean isSelected = helper.getAdapterPosition() == selectedPosition;
|
||||
View itemView = helper.itemView;
|
||||
itemView.setSelected(isSelected);
|
||||
ImageView imageView= helper.getView(R.id.iv_three_pay);
|
||||
// 你可以在这里修改背景、边框、图标等来表示选中状态
|
||||
if (isSelected) {
|
||||
imageView.setImageLevel(1);
|
||||
} else {
|
||||
imageView.setImageLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.blankj.utilcode.util.TimeUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.CommentBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ReplyViewHolder> {
|
||||
public interface OnReplyClickListener {
|
||||
void onReplyClick(CommentBean.CommentDetailsBean.Replies reply, int position);
|
||||
}
|
||||
// 添加回调接口
|
||||
public interface OnReplyLongClickListener {
|
||||
void onReplyLongClick(CommentBean.CommentDetailsBean.Replies reply, int position);
|
||||
}
|
||||
|
||||
private OnReplyLongClickListener longClickListener;
|
||||
|
||||
public void setOnReplyLongClickListener(OnReplyLongClickListener listener) {
|
||||
this.longClickListener = listener;
|
||||
}
|
||||
private OnReplyClickListener listener;
|
||||
|
||||
// 设置监听器的方法
|
||||
public void setOnReplyClickListener(OnReplyClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
private List<CommentBean.CommentDetailsBean.Replies> replyList;
|
||||
private boolean isExpanded = false; // 是否展开显示所有评论
|
||||
|
||||
public ReplyAdapter(List<CommentBean.CommentDetailsBean.Replies> replyList) {
|
||||
this.replyList = replyList;
|
||||
}
|
||||
|
||||
public void updateData(List<CommentBean.CommentDetailsBean.Replies> newReplyList) {
|
||||
replyList.clear();
|
||||
replyList.addAll(newReplyList);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reply, parent, false);
|
||||
return new ReplyViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) {
|
||||
CommentBean.CommentDetailsBean.Replies reply = replyList.get(position);
|
||||
if (!isExpanded && position >= 2) {
|
||||
return; // 不绑定数据
|
||||
}
|
||||
holder.bind(reply,position, listener,longClickListener);
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
isExpanded = expanded;
|
||||
notifyDataSetChanged(); // 刷新适配器
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return isExpanded ? replyList.size() : Math.min(2, replyList.size());
|
||||
}
|
||||
|
||||
class ReplyViewHolder extends RecyclerView.ViewHolder {
|
||||
private TextView tvNickname;
|
||||
private TextView tvContent;
|
||||
private TextView btnReply;
|
||||
private TextView tvTime;
|
||||
private TextView btnShowAllReplies;
|
||||
public ReplyViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
tvNickname = itemView.findViewById(R.id.tv_name);
|
||||
tvContent = itemView.findViewById(R.id.tv_reply);
|
||||
btnReply = itemView.findViewById(R.id.btn_reply);
|
||||
tvTime = itemView.findViewById(R.id.tv_time);
|
||||
// btnShowAllReplies = itemView.findViewById(R.id.btn_show_all_replies);
|
||||
}
|
||||
|
||||
public void bind(CommentBean.CommentDetailsBean.Replies reply,int position, OnReplyClickListener listener,OnReplyLongClickListener longClickListener) {
|
||||
|
||||
tvNickname.setText(reply.getNickname()+":" +(reply.getReply_to_user()!=null?reply.getReply_to_user():""));
|
||||
tvContent.setText(reply.getContent());
|
||||
tvTime.setText(TimeUtils.millis2String(Long.parseLong(reply.getCreatetime()+"") * 1000));
|
||||
btnReply.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.onReplyClick(reply, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加长按监听
|
||||
itemView.setOnLongClickListener(v -> {
|
||||
if (longClickListener != null) {
|
||||
longClickListener.onReplyLongClick(reply, position);
|
||||
return true; // 消费事件
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// 控制“全部评论...”按钮的显示
|
||||
// btnShowAllReplies.setVisibility(position > 2 ? VISIBLE : GONE);
|
||||
//
|
||||
// btnShowAllReplies.setOnClickListener(v -> {
|
||||
//// replyAdapter.setExpanded(true); // 展开所有评论
|
||||
// notifyDataSetChanged(); // 刷新适配器
|
||||
// btnShowAllReplies.setVisibility(GONE); // 隐藏按钮
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
public class RewardUserAdapter {
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.xscm.moduleutil.adapter;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
public class UserPhotoWallAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
||||
private boolean b = false;
|
||||
public static final String ADD_PHOTO = "ADD_PHOTO";
|
||||
private int longClickPos = -1;
|
||||
|
||||
public UserPhotoWallAdapter() {
|
||||
super(R.layout.me_item_user_photo_wall);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, String item) {
|
||||
helper.setGone(R.id.iv_close, false);
|
||||
if (item.equals(ADD_PHOTO)) {
|
||||
helper.setVisible(R.id.iv_close, false);
|
||||
// 显示加号图片
|
||||
helper.setImageResource(R.id.riv_user_head, com.xscm.moduleutil.R.mipmap.add_img);
|
||||
} else {
|
||||
helper.setVisible(R.id.iv_close, true);
|
||||
ImageUtils.loadCenterCrop(item, helper.getView(R.id.riv_user_head));
|
||||
}
|
||||
|
||||
// if (helper.getAdapterPosition() == 5) {
|
||||
// helper.setVisible(R.id.riv_user_head, false);
|
||||
// helper.setVisible(R.id.iv_close, false);
|
||||
// } else {
|
||||
// helper.setVisible(R.id.riv_user_head, true);
|
||||
// if (!"0".equals(item.getId())) {
|
||||
// ImageUtils.loadCenterCrop(item.getUrl(), helper.getView(R.id.riv_user_head));
|
||||
// if (longClickPos == helper.getAdapterPosition()) {
|
||||
// helper.setVisible(R.id.iv_close, true);
|
||||
// } else {
|
||||
// helper.setVisible(R.id.iv_close, false);
|
||||
// }
|
||||
// } else {
|
||||
// helper.setImageResource(R.id.riv_user_head, com.qxcm.moduleutil.R.mipmap.add_img);
|
||||
// helper.setGone(R.id.iv_close, false);
|
||||
// }
|
||||
// }
|
||||
helper.addOnClickListener(R.id.iv_close);
|
||||
helper.addOnClickListener(R.id.riv_user_head);
|
||||
helper.addOnLongClickListener(R.id.riv_user_head);
|
||||
}
|
||||
|
||||
|
||||
public void setDelete(boolean b) {
|
||||
this.b = b;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setLongClickPos(int pos) {
|
||||
this.longClickPos = pos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean getDelete() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user