package com.vondear.rxui.view.wavesidebar.adapter;


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

import com.vondear.rxui.R;
import com.vondear.rxui.model.ModelContactCity;

import java.util.List;


/**
 * 此适配性仅供参考借鉴
 * @author vondear
 */
public class AdapterContactCity extends BaseWaveSideAdapter<ModelContactCity, BaseViewHolder> {

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

    public AdapterContactCity(Context context, List<ModelContactCity> data) {
        super(context, data);
    }

    @Override
    protected int getDefItemViewType(int position) {
        ModelContactCity city = getItem(position);
        return city.type;
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 0) {
            return new CityHolder(inflateItemView(R.layout.item_wave_contact, parent));
        } else {
            return new PinnedHolder(inflateItemView(R.layout.item_pinned_header, parent));
        }
    }


    @Override
    protected void convert(BaseViewHolder holder, ModelContactCity item) {
        if (holder instanceof CityHolder) {
            ((CityHolder) holder).city_name.setText(item.name);
        }else {
            String letter = item.pys.substring(0, 1);
            ((PinnedHolder) holder).city_tip.setText(letter);
        }
    }

    public int getLetterPosition(String letter){
        for (int i = 0 ; i < getData().size(); i++){
            if(getData().get(i).type ==1 && getData().get(i).pys.equals(letter)){
                return i;
            }
        }
        return -1;
    }

    class CityHolder extends BaseViewHolder {

        TextView city_name;

        public CityHolder(View view) {
            super(view);
            city_name = findViewById(R.id.tv_contact_name);
        }
    }


    class PinnedHolder extends BaseViewHolder {

        TextView city_tip;

        public PinnedHolder(View view) {
            super(view);
            city_tip = findViewById(R.id.city_tip);
        }
    }
}

@@ -283,9 +283,9 @@
  %E6%AD%A4%E9%80%82%E9%85%8D
-%E6%80%A7
+%E5%99%A8
 %E4%BB%85%E4%BE%9B%E5%8F%82%E8%80%83

update RxUI.