package com.zhaohaoting.framework.abs;

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

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


/**
 * 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 NoRefreshRecyclerFragment<DATA, RESULT_DATA> extends AbsV4Fragment implements AbsRecyclerAdapter.OnItemClickListener {

    public AbsRecyclerAdapter<DATA, RESULT_DATA> adapter;
    protected LayoutNoRefreshWidgetRecyclerviewBinding binding;

    @Override
    protected void initialize() {
        binding = (LayoutNoRefreshWidgetRecyclerviewBinding) rootDataBinding;
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerView.setItemAnimator(new DefaultItemAnimator());
        binding.recyclerView.setLayoutManager(layoutManager);
//        binding.recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
        onInit();
        binding.recyclerView.setAdapter(adapter = getAdapter());
        //https://github.com/LuckyJayce/MVCHelper/blob/master/Info.md
        adapter.addOnItemClickListener(this);
    }

    @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) {

    }

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