package com.taikor.investment.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taikor.investment.R;
import com.taikor.investment.base.BaseAdapter;
import com.taikor.investment.bean.HotNew;
import com.taikor.investment.utils.GlideUtils;
import com.taikor.investment.utils.TimeUtils;

/**
 * 热点资讯列表适配器
 * Created by Any on 2017/3/31.
 */

public class HotNewAdapter extends BaseAdapter<HotNew> {

    private Context mContext;
    
    public HotNewAdapter(Activity context) {
        super(context);
        mContext=context;
    }

    @Override
    protected int getItemLayoutId(int itemViewType) {
        return R.layout.item_find_news;
    }

    @Override
    protected void handleItem(int itemViewType, int position, HotNew item, ViewHolder holder, boolean reused) {
        holder.get(R.id.tv_item_news_title, TextView.class).setText(item.getTitle());
        holder.get(R.id.tv_item_news_date, TextView.class).setText(TimeUtils.getDate(item.getPubdate()));
        TextView type1 = holder.get(R.id.tv_news_tag1, TextView.class);
        TextView type2 = holder.get(R.id.tv_news_tag2, TextView.class);
        String tag = item.getTag();
        if (!TextUtils.isEmpty(tag)) {
            String[] split = tag.split(",");
            if (split.length == 1) {
                String[] split1 = split[0].split(":");
                type1.setText(split1[0]);
                type1.setVisibility(View.VISIBLE);
                type2.setVisibility(View.GONE);
            }
            if (split.length == 2) {
                String[] split1 = split[0].split(":");
                String[] split2 = split[1].split(":");
                type1.setText(split1[0]);
                type2.setText(split2[0]);
                type1.setVisibility(View.VISIBLE);
                type2.setVisibility(View.VISIBLE);
            }
        } else {
            type1.setVisibility(View.GONE);
            type2.setVisibility(View.GONE);
        }
      
        ImageView imageView = holder.get(R.id.iv_news_image, ImageView.class);
        Glide.with(mContext)
                .load(item.getImageUrl())
                .placeholder(R.drawable.default_image)
                .error(R.drawable.default_image)
                .into(imageView);
    }
}
