package com.yc.cn.ycrecycleview.first;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.yc.cn.ycrecycleview.R;
import com.yc.cn.ycrecycleviewlib.select.SelectRecyclerView;

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

/**
 * Created by PC on 2017/12/13.
 * 作者:PC
 */

public class FirstActivity extends AppCompatActivity {

    private SelectRecyclerView selectView;
    private List<Student> lists = new ArrayList<>();
    private SelectFollowAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        init();
    }

    private void init() {
        lists.clear();
        for(int a=0 ; a<30 ; a++){
            Student student = new Student(R.drawable.chuang,"王雨",false);
            lists.add(student);
        }
        selectView = (SelectRecyclerView) findViewById(R.id.select_view);
        selectView.setLayoutManager(new GridLayoutManager(this, 4));
        adapter = new SelectFollowAdapter(this, lists);
        selectView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnListItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (adapter.data != null && adapter.data.size() > 0) {
                    adapter.toggleSelected(position);
                }
            }
        });
    }
}