/*
 * Copyright (C) 2017 grandcentrix GmbH
 * 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 net.grandcentrix.thirtyinch.test;

import net.grandcentrix.thirtyinch.TiPresenter;
import net.grandcentrix.thirtyinch.TiView;

public class TiPresenterInstructor<V extends TiView> {

    private TiPresenter<V> mPresenter;

    public TiPresenterInstructor(final TiPresenter<V> presenter) {
        mPresenter = presenter;
    }

    /**
     * attaches the new view and takes care for removing the old view when one is attached
     */
    public void attachView(final V view) {
        detachView();

        mPresenter.attachView(view);
    }

    public void create() {
        mPresenter.create();
    }

    public void destroy() {
        detachView();
        mPresenter.destroy();
    }

    /**
     * moves the presenter into state {@link net.grandcentrix.thirtyinch.TiPresenter.State#VIEW_DETACHED}
     * from every state
     */
    public void detachView() {
        final TiPresenter.State state = mPresenter.getState();
        switch (state) {
            case INITIALIZED:
                mPresenter.create();
                break;
            case VIEW_DETACHED:
                // already there
                break;
            case VIEW_ATTACHED:
                mPresenter.detachView();
                break;
            case DESTROYED:
                throw new IllegalStateException(
                        "Presenter is already destroyed, further lifecycle changes aren't allowed");
        }
    }
}

@@ -729,16 +729,55 @@
 iView;%0A%0A
+import java.util.concurrent.Executor;%0A%0A
 public c
@@ -1143,16 +1143,207 @@
 iew();%0A%0A
+        mPresenter.setUiThreadExecutor(new Executor() %7B%0A            @Override%0A            public void execute(final Runnable action) %7B%0A                action.run();%0A            %7D%0A        %7D);%0A
         
@@ -2036,32 +2036,86 @@
 r.detachView();%0A
+                mPresenter.setUiThreadExecutor(null);%0A
                 

Handle the UiThreadExecutor with the instructor