/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * 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 org.hawkular.client.android.util;

import android.app.Activity;
import android.app.Fragment;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ViewAnimator;

import butterknife.ButterKnife;

public final class ViewDirector {
    private final Activity activity;
    private final Fragment fragment;

    private int animatorId;

    public static ViewDirector of(@NonNull Activity activity) {
        return new ViewDirector(activity, null);
    }

    public static ViewDirector of(@NonNull Fragment fragment) {
        return new ViewDirector(null, fragment);
    }

    private ViewDirector(Activity activity, Fragment fragment) {
        this.activity = activity;
        this.fragment = fragment;
    }

    public ViewDirector using(@IdRes int animatorId) {
        this.animatorId = animatorId;
        return this;
    }

    public void show(@IdRes int viewId) {
        ViewAnimator animator = findView(animatorId);
        View view = findView(viewId);

        if (animator.getDisplayedChild() != animator.indexOfChild(view)) {
            animator.setDisplayedChild(animator.indexOfChild(view));
        }
    }

    private <T extends View> T findView(int viewId) {
        if (activity != null) {
            return ButterKnife.findById(activity, viewId);
        } else {
            return ButterKnife.findById(fragment.getView(), viewId);
        }
    }
}
@@ -923,41 +923,8 @@
 r;%0A%0A
-import butterknife.ButterKnife;%0A%0A
 publ
@@ -975,62 +975,22 @@
 nal 
-Activity activity;%0A    private final Fragment fragment
+View sceneView
 ;%0A%0A 
@@ -1125,14 +1125,35 @@
 vity
-, null
+.getWindow().getDecorView()
 );%0A 
@@ -1258,22 +1258,16 @@
 tor(
-null, 
 fragment
 );%0A 
@@ -1262,16 +1262,26 @@
 fragment
+.getView()
 );%0A    %7D
@@ -1311,114 +1311,60 @@
 tor(
-Activity activity, Fragment fragment) %7B%0A        this.activity = activity;%0A        this.fragment = fragment
+View sceneView) %7B%0A        this.sceneView = sceneView
 ;%0A  
@@ -1461,16 +1461,17 @@
 atorId;%0A
+%0A
         
@@ -1564,24 +1564,49 @@
 mator = 
+(ViewAnimator) sceneView.
 findView
 (animato
@@ -1597,16 +1597,20 @@
 findView
+ById
 (animato
@@ -1635,24 +1635,34 @@
  view = 
+sceneView.
 findView
 (viewId)
@@ -1653,16 +1653,20 @@
 findView
+ById
 (viewId)
@@ -1831,254 +1831,6 @@
    %7D
-%0A%0A    private %3CT extends View%3E T findView(int viewId) %7B%0A        if (activity != null) %7B%0A            return ButterKnife.findById(activity, viewId);%0A        %7D else %7B%0A            return ButterKnife.findById(fragment.getView(), viewId);%0A        %7D%0A    %7D
 %0A%7D

Change ViewDirector internals to be more simple.