content: package <%= appPackage %>.base;
  
  import android.arch.lifecycle.LifecycleObserver;
  import android.arch.lifecycle.ViewModelProvider;
  import android.databinding.ViewDataBinding;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import javax.inject.Inject;
  
  import <%= appPackage %>.lifecycle.delegate.IFragment;
  import <%= appPackage %>.mvvm.IViewModel;
  
  /**
   * Created by xiaobailong24 on 2017/6/16.
   * MVVM ArmsFragment
   */
  public abstract class ArmsFragment<DB extends ViewDataBinding, VM extends IViewModel>
          extends Fragment implements IFragment {
      protected final String TAG = this.getClass().getName();
      protected boolean mVisible = false;//是否可见
      protected boolean mFirst = true;//是否第一次加载
      private View mRootView;
  
      //DataBinding
      protected DB mBinding;
  
      //MVVM ViewModel
      @Inject
      protected ViewModelProvider.Factory mViewModelFactory;
      protected VM mViewModel;//instance in subclass; 自动销毁
  
  
      public ArmsFragment() {
          setArguments(new Bundle());
      }
  
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          mRootView = initView(inflater, container, savedInstanceState);
          if (mViewModel != null)
              getLifecycle().addObserver((LifecycleObserver) mViewModel);
          if (mVisible && mFirst)//可见，并且是首次加载
              onFragmentVisibleChange(true);
          return mRootView;
      }
  
  
      @Override
      public boolean injectable() {
          return true;//默认进行依赖注入
      }
  
  
      public boolean useEventBus() {
          return true;
      }
  
      @Override
      public void setUserVisibleHint(boolean isVisibleToUser) {
          super.setUserVisibleHint(isVisibleToUser);
          mVisible = isVisibleToUser;
          if (mRootView == null)
              return;
          //可见，并且首次加载时才调用
          onFragmentVisibleChange(mVisible & mFirst);
      }
  
      /**
       * 当前 Fragment 可见状态发生变化时会回调该方法。
       * 如果当前 Fragment 是第一次加载，等待 onCreateView 后才会回调该方法，
       * 其它情况回调时机跟 {@link #setUserVisibleHint(boolean)}一致
       * 在该回调方法中你可以做一些加载数据操作，甚至是控件的操作.
       *
       * @param isVisible true  不可见 -> 可见
       *                  false 可见  -> 不可见
       */
      protected void onFragmentVisibleChange(boolean isVisible) {
      }
  
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          this.mBinding = null;
          this.mRootView = null;
          this.mViewModelFactory = null;
          if (getLifecycle() != null && mViewModel != null)//移除LifecycleObserver
              getLifecycle().removeObserver((LifecycleObserver) mViewModel);
          this.mViewModel = null;
      }
  }
  