package com.ewei.demo.otherui.adapter;


import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.ewei.demo.R;
import com.ewei.sdk.base.BaseActivity;
import com.ewei.sdk.base.adapter.BaseMySelectListAdapter;

import java.util.List;

/**
 * Created by Administrator on 2016/5/31.
 */
public class LocationPoiListAdapter extends BaseMySelectListAdapter<PoiInfo> {

    public LocationPoiListAdapter(BaseActivity context, List<PoiInfo> pis) {
        super(context, pis);
    }

    @Override
    protected void setLayoutParams(View convertView) {

    }

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

    public void addListData(List<PoiInfo> datas) {
        getDatas().addAll(datas);
    }

    @Override
    protected AbstractViewHolder getViewHolder(View convertView) {
        CustomPoiItemViewHolder cpivh = new CustomPoiItemViewHolder();
        cpivh.mName = (TextView) convertView.findViewById(R.id.tv_poi_name);
        cpivh.mAddress = (TextView) convertView.findViewById(R.id.tv_poi_addr);
        cpivh.mChoose = (ImageView) convertView.findViewById(R.id.iv_poi_choose);
        return cpivh;
    }

    @Override
    protected void bindView(View convertView, AbstractViewHolder holder, PoiInfo poiInfo, int position) {
        CustomPoiItemViewHolder cpivh = (CustomPoiItemViewHolder) holder;
        cpivh.mName.setText(poiInfo.name);
        cpivh.mAddress.setText(poiInfo.address);
        if (getSelectIndex() == position) {
            cpivh.mChoose.setVisibility(View.VISIBLE);
        } else {
            cpivh.mChoose.setVisibility(View.GONE);
        }
    }

    private class CustomPoiItemViewHolder extends AbstractViewHolder {
        TextView mName;
        TextView mAddress;
        ImageView mChoose;
    }
}
