package com.ewei.demo.article.adatper;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.ewei.demo.R;
import com.ewei.sdk.base.BaseListAdapter;
import com.ewei.sdk.entity.Article;


/**
 * Created by Administrator on 2016/8/16.
 */
public class ArticleListAdatper extends BaseListAdapter<Article> {

    public ArticleListAdatper(Context context) {
        super(context);
    }

    @Override
    protected int getLayout() {
        return R.layout.listview_item_article;
    }

    @Override
    protected AbstractViewHolder getViewHolder(View convertView) {
        ItemViewHolder ivh = new ItemViewHolder();
        ivh.mTvTitle = (TextView) convertView.findViewById(R.id.tv_article_title);
        ivh.mTvAuthor = (TextView) convertView.findViewById(R.id.tv_article_author);
        return ivh;
    }

    @Override
    protected void bindView(AbstractViewHolder viewHolder, Article question, int position) {
        ItemViewHolder ivh = (ItemViewHolder) viewHolder;
        ivh.mTvTitle.setText(question.title);
        String content = String.format("%1$s 发表于%2$s", question.author.name, question.createdAt);
        ivh.mTvAuthor.setText(content);
    }

    private class ItemViewHolder extends AbstractViewHolder {
        TextView mTvTitle;
        TextView mTvAuthor;
    }
}
