content: /**
    * Copyright 2017 JessYan
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  package <%= appPackage %>.mvp;
  
  import android.app.Activity;
  
  import com.trello.rxlifecycle2.RxLifecycle;
  
  import org.simple.eventbus.EventBus;
  
  import io.reactivex.disposables.CompositeDisposable;
  import io.reactivex.disposables.Disposable;
  
  /**
   * ================================================
   * 基类 Presenter
   *
   * @see <a href="https://github.com/JessYanCoding/MVPArms/wiki#2.4.4">Presenter wiki 官方文档</a>
   * Created by JessYan on 4/28/2016
   * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
   * <a href="https://github.com/JessYanCoding">Follow me</a>
   * ================================================
   */
  public class BasePresenter<M extends IModel, V extends IView> implements IPresenter {
      protected final String TAG = this.getClass().getSimpleName();
      protected CompositeDisposable mCompositeDisposable;
  
      protected M mModel;
      protected V mRootView;
  
      /**
       * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认)
       *
       * @param model
       * @param rootView
       */
      public BasePresenter(M model, V rootView) {
          this.mModel = model;
          this.mRootView = rootView;
          onStart();
      }
  
      /**
       * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数
       *
       * @param rootView
       */
      public BasePresenter(V rootView) {
          this.mRootView = rootView;
          onStart();
      }
  
      public BasePresenter() {
          onStart();
      }
  
  
      @Override
      public void onStart() {
          if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
              EventBus.getDefault().register(this);//注册 Eventbus
      }
  
      /**
       * 在框架中 {@link Activity#onDestroy()} 会默认调用{@link IPresenter#onDestroy()}
       */
      @Override
      public void onDestroy() {
          if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
              EventBus.getDefault().unregister(this);//解除注册 Eventbus
          unDispose();//解除订阅
          if (mModel != null)
              mModel.onDestroy();
          this.mModel = null;
          this.mRootView = null;
          this.mCompositeDisposable = null;
      }
  
      /**
       * 是否使用 {@link EventBus},默认为使用(true)，
       *
       * @return
       */
      public boolean useEventBus() {
          return true;
      }
  
  
      /**
       * 将 {@link Disposable} 添加到 {@link CompositeDisposable} 中统一管理
       * 可在 {@link Activity#onDestroy()} 中使用 {@link #unDispose()} 停止正在执行的 RxJava 任务,避免内存泄漏
       * 目前框架已使用 {@link RxLifecycle} 避免内存泄漏,此方法作为备用方案
       *
       * @param disposable
       */
      public void addDispose(Disposable disposable) {
          if (mCompositeDisposable == null) {
              mCompositeDisposable = new CompositeDisposable();
          }
          mCompositeDisposable.add(disposable);//将所有 Disposable 放入集中处理
      }
  
      /**
       * 停止集合中正在执行的 RxJava 任务
       */
      public void unDispose() {
          if (mCompositeDisposable != null) {
              mCompositeDisposable.clear();//保证 Activity 结束时取消所有正在执行的订阅
          }
      }
  
  
  }
  