package ir.almahdi.sandogh_bsa_aza.Add_OtherOzv_pay;

import android.widget.Filter;

import java.util.ArrayList;
import java.util.List;

import ir.almahdi.sandogh_bsa_aza.Add_OtherOzv_pay.model.md_kol_aza;

/**
 * Created by Hp on 3/17/2016.
 */
public class CustomFilter_kolAza extends Filter{

    KolAza_adapter adapter;
   List<md_kol_aza> filterList;


    public CustomFilter_kolAza(List<md_kol_aza> filterList, KolAza_adapter adapter)
    {
        this.adapter=adapter;
        this.filterList=filterList;

    }



    //FILTERING OCURS
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults results=new FilterResults();

        //CHECK CONSTRAINT VALIDITY
        if(constraint != null && constraint.length() > 0)
        {
            //CHANGE TO UPPER
            constraint=constraint.toString().toUpperCase();
            //STORE OUR FILTERED karbars
            ArrayList<md_kol_aza> filteredkarbars=new ArrayList<>();

            for (int i=0;i<filterList.size();i++)
            {
                //CHECK
                if(filterList.get(i).getLastname_ozv().toUpperCase().contains(constraint))
                {
                    //ADD karbar TO FILTERED karbars
                    filteredkarbars.add(filterList.get(i));
                }
            }

            results.count=filteredkarbars.size();
            results.values=filteredkarbars;
        }else
        {
            results.count=filterList.size();
            results.values=filterList;

        }


        return results;
    }

    @Override
    protected void publishResults(CharSequence constraint, FilterResults results) {

       adapter.myVamList_other= (List<md_kol_aza>) results.values;

        //REFRESH
        adapter.notifyDataSetChanged();
    }
}
