package com.taikor.investment.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseFragment extends Fragment {

    private Unbinder unbinder;

    //Fragment被创建
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    //初始化Fragment布局
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(this, view);//绑定界面
        initView(view, savedInstanceState);
        return view;
    }

    //activity创建结束,初始化数据
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    //销毁activity
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    //获取布局ID
    protected abstract int getLayoutId();

    //初始化页面信息，子类必须实现
    protected abstract void initView(View view, Bundle savedInstanceState);

    //初始化数据, 子类可以不实现
    public void initData() {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}

   