/*
 * 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 me.jessyan.art.base.delegate;

import android.app.Activity;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.os.Bundle;

import org.simple.eventbus.EventBus;

import me.jessyan.art.mvp.IPresenter;

/**
 * ================================================
 * {@link ActivityDelegate} 默认实现类
 * <p>
 * Created by JessYan on 26/04/2017 20:23
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public class ActivityDelegateImpl implements ActivityDelegate {
    private Activity mActivity;
    private IActivity iActivity;
    private IPresenter iPresenter;


    public ActivityDelegateImpl(Activity activity) {
        this.mActivity = activity;
        this.iActivity = (IActivity) activity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        //如果要使用 EventBus 请将此方法返回 true
        if (iActivity.useEventBus()) {
            //注册到事件主线
            EventBus.getDefault().register(mActivity);
        }
        this.iPresenter = iActivity.obtainPresenter();
        iActivity.setPresenter(iPresenter);
        //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
        if (mActivity != null && mActivity instanceof LifecycleOwner
                && iPresenter != null && iPresenter instanceof LifecycleObserver){
            ((LifecycleOwner) mActivity).getLifecycle().addObserver((LifecycleObserver) iPresenter);
        }
    }

    @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 onDestroy() {
        //如果要使用 EventBus 请将此方法返回 true
        if (iActivity != null && iActivity.useEventBus())
            EventBus.getDefault().unregister(mActivity);
        //释放资源
        if (iPresenter != null) iPresenter.onDestroy();
        this.iActivity = null;
        this.mActivity = null;
        this.iPresenter = null;
    }
}

@@ -773,16 +773,103 @@
 .Bundle;
+%0Aimport android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;
 %0A%0Aimport
@@ -1453,16 +1453,25 @@
 ateImpl(
+@NonNull 
 Activity
@@ -1607,24 +1607,34 @@
 id onCreate(
+@Nullable 
 Bundle saved

Improve ActivityDelegateImpl