Files
fanyin-android/modulevoice/src/main/java/com/example/modulevoice/adapter/SearchUserResultAdapter.java
2025-08-11 18:59:11 +08:00

67 lines
3.2 KiB
Java

package com.example.modulevoice.adapter;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.modulevoice.R;
import com.qxcm.moduleutil.bean.UserResultResp;
import com.qxcm.moduleutil.utils.ImageUtils;
import com.qxcm.moduleutil.utils.KeyWordUtil;
import com.qxcm.moduleutil.widget.BeautifulNameView;
/**
* 搜索用户的结果
*/
public class SearchUserResultAdapter extends BaseQuickAdapter<UserResultResp, BaseViewHolder> {
private String keyWord = "";
public SearchUserResultAdapter() {
super(R.layout.index_item_search_user_result);
}
@Override
protected void convert(BaseViewHolder helper, UserResultResp item) {
helper.setText(R.id.tv_nick_name, KeyWordUtil.matcherSearchTitle(Color.parseColor("#FFBC00"), item.getNickname(), keyWord));
TextView textViewOnLine = helper.getView(R.id.tv_online);
textViewOnLine.setText(item.getOnline_text());
if (item.getOnline_text().equals("在线")) {
Drawable drawable = mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.index_icon_online);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
textViewOnLine.setCompoundDrawables(drawable, null, null, null);
} else {
Drawable drawable = mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.index_icon_offline);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
textViewOnLine.setCompoundDrawables(drawable, null, null, null);
}
((BeautifulNameView) helper.getView(R.id.bnv_user_id)).setText(String.format(mContext.getResources().getString(R.string.common_id_formatter), item.getUser_code()));
((BeautifulNameView) helper.getView(R.id.bnv_user_id)).setTextColor(!TextUtils.isEmpty(item.getId_color()) ? Color.parseColor(item.getId_color()) : mContext.getResources().getColor(com.qxcm.moduleutil.R.color.color_FFCCCCCC));
((BeautifulNameView) helper.getView(R.id.bnv_user_id)).setPlay(!TextUtils.isEmpty(item.getId_color()));
((BeautifulNameView) helper.getView(R.id.bnv_user_id)).setImgVisible("1".equals(item.getGood_number()));
helper.setText(R.id.tv_separation, item.getFans_count());
if ("0".equals(item.getFollow())) {
helper.setText(R.id.tv_follow, "关注")
.setBackgroundRes(R.id.tv_follow, com.qxcm.moduleutil.R.drawable.common_sr_btn_bg);
((TextView)helper.getView(R.id.tv_follow)).setTextColor(Color.parseColor("#ffffff"));
} else {
helper.setText(R.id.tv_follow, "已关注")
.setBackgroundRes(R.id.tv_follow, com.qxcm.moduleutil.R.drawable.common_zr_btn_bg_unfollow);
((TextView)helper.getView(R.id.tv_follow)).setTextColor(Color.parseColor("#FFBC00"));
}
ImageUtils.loadHeadCC(item.getHead_picture(), helper.getView(R.id.riv_user_head));
helper.addOnClickListener(R.id.tv_follow);
}
public void setKeyWord(String keyWord) {
this.keyWord = keyWord;
}
}