/*
 *  Copyright 2015-present Lucas Nelaupe and Ferrand
 *
 *  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 kit.scyla.canvas.views;

import android.content.Context;

import kit.scyla.canvas.render.Scene;
import kit.scyla.core.ScylaView;

/**
 * Created with IntelliJ
 * Created by Ferrand
 * Date 29/11/2014
 */
public abstract class ViewHandler {
    private ScylaView m_current;
    private Scene m_scene;
    private Context m_context;

    public ViewHandler(Context context, Scene scene) {
        this.m_context = context;
        this.m_scene = scene;
        this.m_current = bootstrap(this);
    }

    public final ScylaView getCurrent() {
        return m_current;
    }

    public final void load(ScylaView stage) {
        m_current = stage;
        onNext();
    }

    public final void reload() {
        onNext();
    }

    public abstract void onNext();

    public Scene scene() {
        return m_scene;
    }

    public Context context() {
        return m_context;
    }

    public void setCurrentView(ScylaView view) {
        m_current = view;
        onNext();
    }

    public abstract ScylaView bootstrap(ViewHandler handler);

}

@@ -686,16 +686,55 @@
 ntext;%0A%0A
+import java.lang.reflect.Constructor;%0A%0A
 import k
@@ -763,16 +763,16 @@
 .Scene;%0A
-
 import k
@@ -795,16 +795,45 @@
 ylaView;
+%0Aimport rx.functions.Action0;
 %0A%0A/**%0A *
@@ -1577,32 +1577,48 @@
 context;%0A    %7D%0A%0A
+    @Deprecated%0A
     public void 
@@ -1676,16 +1676,16 @@
 = view;%0A
-
         
@@ -1693,32 +1693,805 @@
 nNext();%0A    %7D%0A%0A
+    public void setCurrentViewAtRuntime(final Class%3C? extends ScylaCanvasView%3E viewClass)%7B%0A        final ViewHandler self = this;%0A%0A        m_scene.subscribeRuntimeAction(new Action0() %7B%0A            @Override%0A            public void call() %7B%0A%0A                if (viewClass == null) %7B%0A                    return;%0A                %7D%0A%0A                try %7B%0A                    Constructor%3C? extends ScylaCanvasView%3E constructor = viewClass.getConstructor(ViewHandler.class, Context.class);%0A                    m_current = constructor.newInstance(self, m_context);%0A                    onNext();%0A                %7D catch (Exception e) %7B%0A                    e.printStackTrace();%0A                    throw new RuntimeException(e);%0A                %7D%0A%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     public abstr

Change view at runtime