package com.zhaohaoting.framework.abs;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;

import com.zhaohaoting.framework.R;
import com.zhaohaoting.framework.abs.adapter.AbsRecyclerAdapter;
import com.zhaohaoting.framework.abs.presenter.BasePresenter;


/**
 * author：Created by ZHT on 2018/1/22 16:44
 * email：526309416@qq.com
 * desc：列表类activity基类 RESULT_DATA为BaseListEntity<DATA>或者List<DATA>（尽量规范）  此类也可不要泛型
 */
public abstract class NoRefreshRecyclerActivity<DATA,RESULT_DATA> extends BaseActivity implements AbsRecyclerAdapter.OnItemClickListener {

    public AbsRecyclerAdapter<DATA,RESULT_DATA> adapter;
    protected RecyclerView recyclerView;
    protected FrameLayout flTitle;

    @Override
    public int getLayoutResId() {
        return R.layout.layout_no_refresh_widget_recyclerview;
    }

    @Override
    protected void initialize() {
        recyclerView = findViewById(R.id.recycler_view);
        flTitle = findViewById(R.id.fl_title);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(layoutManager);
//        recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        onInit();
        recyclerView.setAdapter(adapter = getAdapter());
        addHeadViews(adapter);
        //https://github.com/LuckyJayce/MVCHelper/blob/master/Info.md
        adapter.addOnItemClickListener(this);
    }

    protected  void addHeadViews(AbsRecyclerAdapter<DATA, RESULT_DATA> adapter){}

    @Override
    public void onItemClick(AbsRecyclerAdapter.BaseViewHolder vh, int position) {
        itemClicked(vh, position);
    }

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    protected abstract void onInit();

    protected abstract AbsRecyclerAdapter<DATA,RESULT_DATA> getAdapter();

    protected void itemClicked(AbsRecyclerAdapter.BaseViewHolder vh, int position) {
    }

}