com.chad.library.adapter.base.BaseViewHolder Java Examples

The following examples show how to use com.chad.library.adapter.base.BaseViewHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CardWeatherAdapter.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(final BaseViewHolder helper, WeatherCity item) {
    TextView tvName = helper.getView(R.id.tv_card_city_name);
    if (helper.getAdapterPosition() == 0) {
        tvName.setCompoundDrawablesWithIntrinsicBounds(null, null,
                ThemeUtil.setTintDrawable(R.drawable.ic_location, mContext,
                        ThemeUtil.getCurrentColorPrimary(mContext)), null);
    }
    tvName.setText(item.getCityName());
    helper.setText(R.id.tv_card_weather, TextUtils.isEmpty(item.getWeatherText()) ? "NA" : item.getWeatherText());
    helper.setText(R.id.tv_card_temp, TextUtils.isEmpty(item.getWeatherTemp()) ? "NA" : item.getWeatherTemp() + "℃");
    final ImageView imageView = helper.getView(R.id.iv_card_weather);
    WeatherUtil.getInstance().getWeatherDict(item.getWeatherCode()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SimpleSubscriber<WeatherBean>() {
        @Override
        public void onNext(WeatherBean weatherBean) {
            Glide.with(mContext).load(weatherBean.getIcon()).diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
        }
    });
}
 
Example #2
Source File: WeChatAdapter.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder holder, Article article) {
    if(article == null) return;

    holder.setText(R.id.tv_title, Html.fromHtml(article.getTitle()))
            .setText(R.id.tv_author, "作者:" + article.getAuthor())
            .setText(R.id.tv_classify, "分类:" + article.getChapterName())
            .setText(R.id.tv_publish_time, article.getNiceDate())
            .addOnClickListener(R.id.iv_collection);

    if(article.isCollect()){
        holder.setImageDrawable(
                R.id.iv_collection,
                CommonUtil.getTintDrawable(
                        Objects.requireNonNull(ContextCompat.getDrawable(mContext, R.drawable.ic_home_collection)),
                        ColorStateList.valueOf(ContextCompat.getColor(mContext, R.color.colorCollected))
                )
        );
    } else{
        holder.setImageResource(R.id.iv_collection, R.drawable.ic_home_collection);
    }
}
 
Example #3
Source File: SortCategoryAdapter.java    From v9porn with MIT License 6 votes vote down vote up
@Override
protected void convert(final BaseViewHolder helper, final Category category) {
    helper.setText(R.id.tv_sort_category_name, category.getCategoryName());
    SwitchCompat switchCompat = helper.getView(R.id.sw_sort_category);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            category.setIsShow(isChecked);
        }
    });
    switchCompat.setChecked(category.getIsShow());
    ImageView imageView = helper.getView(R.id.iv_drag_handle);

    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (onStartDragListener != null) {
                //注意:这里down和up都会回调该方法
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    onStartDragListener.startDragItem(helper);
                }
            }
            return false;
        }
    });
}
 
Example #4
Source File: CategoryListAdapter.java    From AFBaseLibrary with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, CategoryEntity item) {
    boolean isNoImg = true;
    if (item.getType().equals("福利")) {
        if (TextUtils.isEmpty(item.getUrl())) {
            isNoImg = false;
        }
    } else {
        if (item.getImages() == null || item.getImages().size() == 0) {
            isNoImg = false;
        }
    }
    if (isNoImg) {
        convertNoImage(helper, item);
        return;
    }
    convertItem(helper, item);
}
 
Example #5
Source File: RvNoteListAdapter.java    From SuperNote with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 显示是否线性布局时的分组信息
 *
 * @param helper
 * @param isShow 是否显示
 * @param time   时间戳
 * @describe
 */
private void showLineraLayoutGroup(boolean isShow, BaseViewHolder helper, long time) {
    // 有分组的列,marginTop为8dp,否则,为0dp
    LinearLayout ll = helper.getView(R.id.ll_note_list_linear);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ll.getLayoutParams();
    if (isShow) {
        helper.setVisible(R.id.tv_note_list_linear_month, true);
        setLinearGroupStyle(helper, time);

        params.setMargins(SizeUtils.dp2px(0), SizeUtils.dp2px(8), SizeUtils.dp2px(0), SizeUtils.dp2px(0));
        ll.setLayoutParams(params);

    } else {
        helper.setVisible(R.id.tv_note_list_linear_month, false);
        params.setMargins(SizeUtils.dp2px(0), SizeUtils.dp2px(0), SizeUtils.dp2px(0), SizeUtils.dp2px(0));
        ll.setLayoutParams(params);
    }
}
 
Example #6
Source File: OperationListAdapter.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Operation item) {
    helper.setText(R.id.name,item.getName());
    if (StringUtil.trim(item.getInfo()).equals("")){
        helper.setText(R.id.info,item.getInfo());
    }else {
        helper.setGone(R.id.text_info,true);
    }

    if (item.getDrawable()!=null){
        helper.setGone(R.id.icon,true);
        helper.setImageDrawable(R.id.icon, item.getDrawable());
    }else {
        helper.setGone(R.id.icon,false);
    }

}
 
Example #7
Source File: TopicTimelineAdapterWithThirdLib.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder holder, RelevantTopicBean relevantTopicBean) {
    LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
    int year = date.getYear();
    int month = date.getMonthValue();
    int day = date.getDayOfMonth();
    if (year == OffsetDateTime.now().getYear()) {
        holder.setText(R.id.txt_date, mContext.getString(R.string.month__day, month, day));
    } else {
        SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
        spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
                spannableTitle.toString().indexOf("\n") + 1,
                spannableTitle.toString().indexOf("\n") + 5,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.txt_date, spannableTitle);
    }
    holder.setText(R.id.txt_topic_trace_content, relevantTopicBean.getTitle());
    holder.setVisible(R.id.view_top_line, holder.getItemViewType() == VIEW_TYPE_TOP || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
    holder.setVisible(R.id.view_bottom_line, holder.getItemViewType() == VIEW_TYPE_BOTTOM || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
}
 
Example #8
Source File: MyBaseQuickAdapter.java    From ZoomPreviewPicture with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, UserViewInfo item) {
    final ImageView thumbView = helper.getView(R.id.iv);
   if (item.getVideoUrl()==null){
       helper.getView(R.id.btnVideo).setVisibility(View.GONE);
   }else {
       helper.getView(R.id.btnVideo).setVisibility(View.VISIBLE);
   }

    Glide.with(context)
            .load(item.getUrl())
            .placeholder(R.mipmap.ic_launcher)
            .error(R.mipmap.ic_iamge_zhanwei)
            .into(thumbView);
    thumbView.setTag(R.id.iv,item.getUrl());
}
 
Example #9
Source File: MovieDetailAdapter.java    From YiZhi with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, PersonBean item) {
    helper.setText(R.id.tv_person_name, item.getName());
    helper.setText(R.id.tv_person_type, item.getType());
    try {
        //避免空指针异常
        if (StringUtils.isEmpty(item.getAvatars().getLarge()))
            return;

        Glide.with(mContext).load(item.getAvatars().getLarge()).crossFade().into((ImageView)
                helper.getView(R.id.iv_avatar_photo));
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #10
Source File: RvNoteFolderAdapter.java    From SuperNote with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, NoteFolder item) {
    helper.setText(R.id.tv_folder_list_title, item.getFolderName())
            .setText(R.id.tv_folder_list_count, item.getNoteCount() + "");


    RelativeLayout rlItem=helper.getView(R.id.rl_folder_root);
    TextView tvTitle=helper.getView(R.id.tv_folder_list_title);
    TextView tvCount=helper.getView(R.id.tv_folder_list_count);
    ImageView ivIcon=helper.getView(R.id.iv_folder_list_ic);

    if(Constans.currentFolder == helper.getLayoutPosition()-getHeaderLayoutCount()){
        rlItem.setSelected(true);
        tvTitle.setTextColor(ThemeUtils.getColorPrimary(mContext));
        tvCount.setTextColor(ThemeUtils.getColorPrimary(mContext));
        ivIcon.setBackground(MyDrawable.getIcFolderSelectedDrawable( ThemeUtils.getColorPrimary(mContext)));
    } else {
        rlItem.setSelected(false);
        tvTitle.setTextColor(MainApplication.getContext().getResources().getColor(R.color.colorBlackAlpha87));
        tvCount.setTextColor(MainApplication.getContext().getResources().getColor(R.color.colorBlackAlpha54));
        ivIcon.setBackgroundResource(R.drawable.ic_folder_un_selected);
    }
}
 
Example #11
Source File: VrVideoAdapter.java    From GoogleVR with Apache License 2.0 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, VideoItem item) {
	helper.setText(R.id.topic_init_title,item.title);
	helper.setText(R.id.date_text,new SimpleDateFormat("MM/dd/yyyy").format(item.date));
	ImageView topicImg=helper.getView(R.id.topic_init_img);
	Glide.with(helper.getConvertView().getContext()).load(item.img).into(topicImg);
	String[] tags = item.tags;
	for (int i = 0; i < tags.length; i++) {
		helper.setText(ids[i],tags[i]);
	}

	View main = helper.getView(R.id.video_layout);
	main.setTag(item);
	main.setOnClickListener(listener);

}
 
Example #12
Source File: RelateVideoAdapter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
protected void convertHead(BaseViewHolder helper, RelateVideoSection item) {
    helper.setText(R.id.tv_name,item.t.getData().getText());
    if (helper.getLayoutPosition() == 0){
        helper.getView(R.id.iv_arrow_right).setVisibility(View.VISIBLE);
        helper.getView(R.id.view).setVisibility(View.VISIBLE);
    }else {
        helper.getView(R.id.view).setVisibility(View.GONE);
    }
    helper.getView(R.id.iv_arrow_right).setVisibility(View.GONE);
}
 
Example #13
Source File: FastLoadMoreView.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
public void convert(BaseViewHolder holder) {
    super.convert(holder);
    if (holder != mHolder) {
        initView(holder);
    }
    mHolder = holder;
}
 
Example #14
Source File: FirstHierarchyAdapter.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, FirstHierarchy item) {
    if(item == null) return;
    String secondLeverText = "";
    if(!CommonUtil.isEmptyList(item.getChildren()))
            for (Tab child : item.getChildren()){
                secondLeverText += child.getName() + "  ";
            }
        helper.setText(R.id.tv_first_lever, item.getName())
                .setText(R.id.tv_second_lever, secondLeverText);
}
 
Example #15
Source File: TodayAdapter.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, MultiItem item) {
    switch (ViewType.getTypeById(helper.getItemViewType())) {
        case HEADER:
            helper.itemView.setBackgroundColor(ColorUtils.fadeColor(ColorUtils.primaryColor(), 0.8f));
            convertHeader(helper, item);
            break;
        case NORMAL:
            helper.itemView.setBackgroundResource(ColorUtils.isDarkTheme() ?
                    R.color.dark_theme_background : R.color.light_theme_background);
            convertAssignment(helper, item.assignment);
            break;
    }
}
 
Example #16
Source File: FeedListManageAdapter.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Feed item) {
    helper.setText(R.id.title,item.getName());
    //TODO:如果有自己ico图标,则显示ico图标
    helper.setImageResource(R.id.main_logo,R.drawable.ic_rss_feed_grey_24dp);

    helper.setText(R.id.not_read_num,item.getUnreadNum() + "");

    initListener(helper,item);

}
 
Example #17
Source File: CategoriesAdapter.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Category category) {
    final int categoryColor = category.getColor();

    if (isDarkTheme) helper.itemView.setBackgroundResource(R.color.dark_theme_background);

    helper.setText(R.id.tv_title, category.getName());
    helper.setText(R.id.tv_sub_title, context.getResources().getQuantityString(R.plurals.assignments_number, category.getCount(), category.getCount()));

    ((CircleImageView) helper.getView(R.id.iv_folder_background)).setFillingCircleColor(categoryColor);

    helper.addOnClickListener(R.id.iv_more);
    helper.setImageResource(R.id.iv_folder_portrait, category.getPortrait().iconRes);
}
 
Example #18
Source File: TimeLinesAdapter.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, TimeLine timeLine) {
    helper.setText(R.id.tv, getOperation(timeLine));
    helper.setImageResource(R.id.iv_operation, timeLine.getModelType().drawableRes);
    ((CircleImageView) helper.getView(R.id.civ)).setFillingCircleColor(
            UserPreferences.getInstance().getTimeLineColor(timeLine.getOperation()));
    helper.setText(R.id.tv_date, TimeUtils.getShortDate(context, timeLine.getAddedTime()));
    helper.setText(R.id.tv_time, TimeUtils.shortTime(timeLine.getAddedTime()));
    helper.setText(R.id.tv_sub, timeLine.getModelName());
    helper.setTextColor(R.id.tv_sub, ColorUtils.accentColor());
    ((Timeline) helper.getView(R.id.timeLine)).setAtomDrawable(atomDrawable());
}
 
Example #19
Source File: FeedListManageAdapter.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
private void initListener(final BaseViewHolder helper, final Feed item){
    //长按功能菜单
    helper.getView(R.id.item_view).setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            new XPopup.Builder(activity)
                    .asCustom(new FeedOperationPopupView(activity, item.getId(),item.getName(),item.getDesc(),new Help(false)))
                    .show();
            return true;
        }
    });


}
 
Example #20
Source File: ExploreSelectedTitleListAdapter.java    From C9MJ with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder viewHolder, String title) {
    viewHolder.setText(R.id.tv_title, title)
            .setTextColor(R.id.tv_title, ContextCompat.getColor(mContext, R.color.color_icons))
            .addOnClickListener(R.id.cardview);
    CardView cardView = viewHolder.getView(R.id.cardview);
    cardView.setCardBackgroundColor(ContextCompat.getColor(mContext, R.color.color_primary));
}
 
Example #21
Source File: FeedFolderListMainAdapter.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, FeedFolder item) {
    helper.setText(R.id.title,item.getName());
    helper.setGone(R.id.move_logo,false);
    helper.addOnClickListener(R.id.item_view);
    helper.getView(R.id.main_logo).setPadding(60,0,0,0);
}
 
Example #22
Source File: AuthListAdapter.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Auth item) {
    helper.setText(R.id.name,item.getName());
    helper.setText(R.id.desc,item.getDesc());

    helper.getView(R.id.ll_item).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //登录弹窗,增加账户

        }
    });
}
 
Example #23
Source File: NetWorkActivity.java    From ViewPagerHelper with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, ArticleData item) {
    String msg;
    if (!TextUtils.isEmpty(item.getSuperChapterName())){
        msg = item.getSuperChapterName()+"/"+item.getChapterName();
    }else{
        msg = item.getChapterName();
    }
    String author = (item.getAuthor() != null && item.getAuthor().length() > 0) ? item.getAuthor():item.getShareUser();
    helper.setText(R.id.item_article_author,author)
            .setText(R.id.item_article_chapat, msg)
            .setText(R.id.item_article_title,item.getTitle())
            .setText(R.id.item_article_time,item.getNiceDate());

}
 
Example #24
Source File: ProxyAdapter.java    From v9porn with MIT License 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, ProxyModel item) {
    helper.setText(R.id.tv_item_proxy_ip_address, item.getProxyIp());
    helper.setText(R.id.tv_item_proxy_port, item.getProxyPort());
    helper.setText(R.id.tv_item_proxy_anonymous, item.getAnonymous());
    helper.setText(R.id.tv_item_proxy_delay_time, item.getResponseTime());
    helper.setText(R.id.tv_item_proxy_type, item.getTypeShowStr());
    if (helper.getLayoutPosition() == clickPosition) {
        helper.itemView.setBackgroundColor(ContextCompat.getColor(helper.itemView.getContext(), R.color.colorPrimary));
    } else {
        helper.itemView.setBackgroundColor(ContextCompat.getColor(helper.itemView.getContext(), R.color.common_background));
    }
}
 
Example #25
Source File: RuleAdapter.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);

    final int pos = position;
    holder.itemView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            if (mContextMenuListener != null) {
                mContextMenuListener.onCreateItemContextMenu(menu, v, menuInfo, pos);
            }
        }
    });
}
 
Example #26
Source File: Forum9PornIndexAdapter.java    From v9porn with MIT License 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, PinnedHeaderEntity<F9PronItem> item) {
    switch (helper.getItemViewType()) {
        case TYPE_HEADER:
            helper.setText(R.id.tv_item_forum_91_porn_section_header_title, item.getPinnedHeaderName());
            break;
        case TYPE_DATA:
            helper.setText(R.id.tv_item_forum_91_porn_title, item.getData().getTitle());
            helper.setText(R.id.tv_item_forum_91_porn_author_publish_time, item.getData().getAuthor() + "\n" + item.getData().getAuthorPublishTime());
            helper.setText(R.id.tv_item_forum_91_porn_reply_view, item.getData().getReplyCount() + "/" + item.getData().getViewCount());
            helper.setText(R.id.tv_item_forum_91_porn_last_post_author_time, item.getData().getLastPostAuthor() + "\n" + item.getData().getLastPostTime());
            break;
        default:
    }
}
 
Example #27
Source File: GankIoCustomAdapter.java    From YiZhi with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, GankIoCustomItemBean item) {
    initTypeImage(helper, item);

    helper.setText(R.id.tv_item_who, StringUtils.isEmpty(item.getWho()) ? "佚名" : item
            .getWho());
    helper.setText(R.id.tv_item_type, item.getType());
    helper.setText(R.id.tv_item_time, item.getCreatedAt().substring(0, 10));

    switch (helper.getItemViewType()) {
        case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_NORMAL:
            helper.setText(R.id.tv_item_title, item.getDesc());
            initTitleColor(helper, item);
            if (item.getImages() != null) {
                if (item.getImages().size() > 0 && !TextUtils.isEmpty(item.getImages().get(0)))
                    Glide.with(mContext).load(item.getImages().get(0) + mImageSize)
                            .asBitmap()
                            .into((ImageView) helper.getView(R.id.iv_item_image));
            }
            break;
        case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_IMAGE:
            Glide.with(mContext)
                    .load(item.getUrl())
                    .asBitmap()
                    .centerCrop()
                    .placeholder(R.mipmap.img_default_meizi)
                    .into((ImageView) helper.getView(R.id.iv_item_image));
            break;
        case GankIoCustomItemBean.GANK_IO_DAY_ITEM_CUSTOM_NO_IMAGE:
            helper.setText(R.id.tv_item_title, item.getDesc());
            initTitleColor(helper, item);
            break;
        default:
            break;
    }
}
 
Example #28
Source File: ProjectAdapter.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Article item) {
    helper.setText(R.id.projectTitleTv,item.getTitle())
            .setText(R.id.projectDecsTv,item.getDesc())
            .setText(R.id.projectAuthorTv,item.getAuthor())
            .setText(R.id.projectDateTv,item.getNiceDate())
            .addOnClickListener(R.id.projectLoveIv);

    ImageUtil.loadImage(mContext,helper.getView(R.id.projectPicIv),item.getEnvelopePic());
    if(item.isCollect()){
        helper.getView(R.id.projectLoveIv).setSelected(true);
    }else{
        helper.getView(R.id.projectLoveIv).setSelected(false);
    }
}
 
Example #29
Source File: RvNoteListAdapter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, Note item) {
    if (isLinearLayoutManager())
        setLinearLayout(helper, item);
    else if (isGridLayoutManager())
        setGridLayout(helper, item);
}
 
Example #30
Source File: FirstSystemAdapter.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, FirstSystem item) {
    if(item == null) return;
    String secondSystemText = "";
    for(FirstSystem.ChildrenBean secondSystem: item.getChildren() ){
        secondSystemText += secondSystem.getName()+"   ";
    }
    helper.setText(R.id.systemItemFirstTv,item.getName())
            .setText(R.id.systemItemSecondTv,secondSystemText);
}