package com.sheep.gamegroup.view.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kfzs.duanduan.utils.NumberFormatUtils;
import com.sheep.gamegroup.absBase.IContentContainer;
import com.sheep.gamegroup.model.entity.HomePageSearch;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;
import java.util.Locale;

/**
 * Created by realicing on 2018/11/8.
 * realicing@sina.com
 */
public class HomePageSearchAdapter extends BaseQuickAdapter<HomePageSearch, BaseViewHolder> {

    public HomePageSearchAdapter(@Nullable List<HomePageSearch> data) {
        super(R.layout.item_home_page_search, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomePageSearch item) {
        ImageView item_home_page_search_iv = helper.itemView.findViewById(R.id.item_home_page_search_iv);
        TextView item_home_page_search_content_tv = helper.itemView.findViewById(R.id.item_home_page_search_content_tv);
        TextView item_home_page_search_bonus_tv = helper.itemView.findViewById(R.id.item_home_page_search_bonus_tv);

        ViewUtil.setVisibility(item_home_page_search_bonus_tv, item.hasBonus());
        ViewUtil.setText(item_home_page_search_bonus_tv, String.format(Locale.CHINA, "+%s元", NumberFormatUtils.retainMost2(NumberFormatUtils.parseFloat(item.getBonus()))));
        if(contentContainer != null && !TextUtils.isEmpty(contentContainer.getContent()))
            ViewUtil.setColorMapText(item_home_page_search_content_tv, String.format(Locale.CHINA, "%s/%s", item.getTitle(), item.getContent()), contentContainer.getContent(), "#4889FF");
        else
            ViewUtil.setText(item_home_page_search_content_tv, String.format(Locale.CHINA, "%s/%s", item.getTitle(), item.getContent()));
        ViewUtil.setGameImage(item_home_page_search_iv, item.getIcon());
    }

    private IContentContainer<String> contentContainer;
    public void setContentContainer(IContentContainer<String> contentContainer) {
        this.contentContainer = contentContainer;
    }
}
