content: package <%= appPackage %>.lifecycle.delegate;
  
  import android.content.Context;
  import android.os.Bundle;
  import android.os.Parcel;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.view.View;
  
  import org.simple.eventbus.EventBus;
  
  import dagger.android.support.AndroidSupportInjection;
  
  /**
   * @author xiaobailong24
   * @date 2017/6/16
   * Fragment 生命周期代理接口实现类
   */
  public class FragmentDelegateImpl implements FragmentDelegate {
      private FragmentManager mFragmentManager;
      private Fragment mFragment;
      private IFragment iFragment;
  
  
      public FragmentDelegateImpl(FragmentManager fragmentManager, Fragment fragment) {
          this.mFragmentManager = fragmentManager;
          this.mFragment = fragment;
          this.iFragment = (IFragment) fragment;
      }
  
      @Override
      public void onAttach(Context context) {
          //如果要使用eventbus请将此方法返回true
          if (iFragment.useEventBus()) {
              //注册到事件主线
              EventBus.getDefault().register(mFragment);
          }
          if (iFragment.injectable()) {
              //Dagger.Android 依赖注入
              AndroidSupportInjection.inject(mFragment);
          }
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
      }
  
      @Override
      public void onCreateView(View view, Bundle savedInstanceState) {
  
      }
  
      @Override
      public void onActivityCreate(Bundle savedInstanceState) {
          iFragment.initData(savedInstanceState);
      }
  
      @Override
      public void onStart() {
  
      }
  
      @Override
      public void onResume() {
  
      }
  
      @Override
      public void onPause() {
  
      }
  
      @Override
      public void onStop() {
  
      }
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
  
      }
  
      @Override
      public void onDestroyView() {
  
      }
  
      @Override
      public void onDestroy() {
  
      }
  
      @Override
      public void onDetach() {
          //如果要使用eventbus请将此方法返回true
          if (iFragment.useEventBus()) {
              //解注册到事件主线
              EventBus.getDefault().unregister(mFragment);
          }
          this.mFragmentManager = null;
          this.mFragment = null;
          this.iFragment = null;
      }
  
      /**
       * Return true if the fragment is currently added to its activity.
       */
      @Override
      public boolean isAdded() {
          return mFragment != null && mFragment.isAdded();
      }
  
      @Override
      public int describeContents() {
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
  
      }
  
      protected FragmentDelegateImpl(Parcel in) {
          this.mFragmentManager = in.readParcelable(FragmentManager.class.getClassLoader());
          this.mFragment = in.readParcelable(Fragment.class.getClassLoader());
          this.iFragment = in.readParcelable(IFragment.class.getClassLoader());
      }
  
      public static final Creator<FragmentDelegateImpl> CREATOR = new Creator<FragmentDelegateImpl>() {
          @Override
          public FragmentDelegateImpl createFromParcel(Parcel source) {
              return new FragmentDelegateImpl(source);
          }
  
          @Override
          public FragmentDelegateImpl[] newArray(int size) {
              return new FragmentDelegateImpl[size];
          }
      };
  }
  