package com.kfzs.duanduan.adp;

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

import com.kfzs.android.view.tag.FlowLayout;
import com.kfzs.android.view.tag.TagAdapter;
import com.kfzs.android.view.tag.TagFlowLayout;
import com.kfzs.appstore.utils.adapter.MDLAdpater;
import com.kfzs.appstore.utils.adapter.MDLViewHolderHelper;
import com.sheep.jiuyan.samllsheep.R;
import com.kfzs.duanduan.bean.QueryCondition;
import com.kfzs.duanduan.proto.GameTypeOuterClass;
import com.kfzs.duanduan.view.FilterWindow;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * Created by HooRang on 2017/2/15.
 */
public class FilterWindowAdapter extends MDLAdpater<QueryCondition> {

    public static final String FLOW_LAYOUT_TAG = "FLOW_LAYOUT_TAG_";
    private Context mContext ;

    private Map<String,TagAdapter<GameTypeOuterClass.GameType>> qcItemsAdapterContainer = new HashMap<>();


    public FilterWindowAdapter(Context context) {
        super(context, R.layout.listview_item_query_condition);
        this.mContext = context;
    }



    @Override
    protected void fillData(MDLViewHolderHelper helper, int position, QueryCondition model) {
        helper.setImageResource(R.id.query_condition_category_icon, model.getCategoryIcon());
        String iTag = FLOW_LAYOUT_TAG  + position;
        TagFlowLayout tagList = helper.getView(R.id.query_condition_tags);
        tagList.setTag(iTag);
        TagAdapter<GameTypeOuterClass.GameType> tagAdapter = new TagAdapter<GameTypeOuterClass.GameType>(model.getTags()) {
            @Override
            public View getView(FlowLayout parent, int position, GameTypeOuterClass.GameType o) {

                TextView tv = (TextView)LayoutInflater.from(mContext).inflate(R.layout.hot_tag_item,parent,false);
                tv.setText(o.getTypeName());
                tv.setTag(o.getId());
                return tv;
            }
        };

        if (!qcItemsAdapterContainer.containsKey(iTag)){
            qcItemsAdapterContainer.put(iTag , tagAdapter);
        }


        tagList.setAdapter(tagAdapter);
        tagAdapter.setSelectedList(FilterWindow.getCheckedTagsContainer().get(position));
    }


}
