// Path: architect/src/main/java/architect/StackFactory.java
// public class StackFactory {
// 
//     public static Context createContext(Context parentContext, Stackable stackable) {
//         return createContext(parentContext, stackable, null);
//     }
// 
//     public static Context createContext(Context parentContext, Stackable stackable, String identifier) {
//         Preconditions.checkNotNull(parentContext, "Parent context cannot be null");
//         Preconditions.checkNotNull(stackable, "Stackable cannot be null");
// 
//         MortarScope parentScope = MortarScope.getScope(parentContext);
//         Preconditions.checkNotNull(parentScope, "Parent scope cannot be null");
// 
//         String scopeName = identifier != null ? String.format("%s_%s", stackable.getClass().getName(), identifier) : stackable.getClass().getName();
//         MortarScope mortarScope = parentScope.findChild(scopeName);
//         if (mortarScope == null) {
//             mortarScope = createScope(parentScope, stackable, scopeName);
//         }
// 
//         return mortarScope.createContext(parentContext);
//     }
// 
// //    /**
// //     * Create Mortar scope from stack scope
// //     */
// //    static MortarScope createScope(MortarScope parentScope, Stackable stackable, String scopeName) {
// //        MortarScope.Builder scopeBuilder = parentScope.buildChild();
// //
// //        StackScope.Services services = stackable.withServices(parentScope);
// //        if (services != null && !services.services.isEmpty()) {
// //            for (Map.Entry<String, Object> service : services.services.entrySet()) {
// //                scopeBuilder.withService(service.getKey(), service.getValue());
// //            }
// //        }
// //
// //        return scopeBuilder.build(scopeName);
// //    }
// 
//     /**
//      * Create Mortar scope from stackable
//      */
//     static MortarScope createScope(MortarScope parentScope, Stackable stackable, String scopeName) {
//         MortarScope.Builder scopeBuilder = parentScope.buildChild();
//         stackable.configureScope(scopeBuilder, parentScope);
//         return scopeBuilder.build(scopeName);
//     }
// }


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.Arrays;
import java.util.List;
import architect.StackablePath;
import architect.StackFactory;
import mortar.MortarScope;
package architect.commons.adapter;




/**
 * @author Lukasz Piliszczuk - lukasz.pili@gmail.com
 */
public class StackablePagerAdapter extends PagerAdapter {

    private final Context context;
    private final List<StackablePath> paths;

    public StackablePagerAdapter(Context context, StackablePath... paths) {
        this(context, Arrays.asList(paths));
    }

    public StackablePagerAdapter(Context context, List<StackablePath> paths) {
        this.context = context;
        this.paths = paths;
    }

    @Override
    public int getCount() {
        return paths.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        StackablePath path = paths.get(position);

// Path: architect/src/main/java/architect/StackFactory.java
// public class StackFactory {
// 
//     public static Context createContext(Context parentContext, Stackable stackable) {
//         return createContext(parentContext, stackable, null);
//     }
// 
//     public static Context createContext(Context parentContext, Stackable stackable, String identifier) {
//         Preconditions.checkNotNull(parentContext, "Parent context cannot be null");
//         Preconditions.checkNotNull(stackable, "Stackable cannot be null");
// 
//         MortarScope parentScope = MortarScope.getScope(parentContext);
//         Preconditions.checkNotNull(parentScope, "Parent scope cannot be null");
// 
//         String scopeName = identifier != null ? String.format("%s_%s", stackable.getClass().getName(), identifier) : stackable.getClass().getName();
//         MortarScope mortarScope = parentScope.findChild(scopeName);
//         if (mortarScope == null) {
//             mortarScope = createScope(parentScope, stackable, scopeName);
//         }
// 
//         return mortarScope.createContext(parentContext);
//     }
// 
// //    /**
// //     * Create Mortar scope from stack scope
// //     */
// //    static MortarScope createScope(MortarScope parentScope, Stackable stackable, String scopeName) {
// //        MortarScope.Builder scopeBuilder = parentScope.buildChild();
// //
// //        StackScope.Services services = stackable.withServices(parentScope);
// //        if (services != null && !services.services.isEmpty()) {
// //            for (Map.Entry<String, Object> service : services.services.entrySet()) {
// //                scopeBuilder.withService(service.getKey(), service.getValue());
// //            }
// //        }
// //
// //        return scopeBuilder.build(scopeName);
// //    }
// 
//     /**
//      * Create Mortar scope from stackable
//      */
//     static MortarScope createScope(MortarScope parentScope, Stackable stackable, String scopeName) {
//         MortarScope.Builder scopeBuilder = parentScope.buildChild();
//         stackable.configureScope(scopeBuilder, parentScope);
//         return scopeBuilder.build(scopeName);
//     }
// }


// Path: commons/src/main/java/architect/commons/adapter/StackablePagerAdapter.java
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.Arrays;
import java.util.List;
import architect.StackablePath;
import architect.StackFactory;
import mortar.MortarScope;

package architect.commons.adapter;




/**
 * @author Lukasz Piliszczuk - lukasz.pili@gmail.com
 */
public class StackablePagerAdapter extends PagerAdapter {

    private final Context context;
    private final List<StackablePath> paths;

    public StackablePagerAdapter(Context context, StackablePath... paths) {
        this(context, Arrays.asList(paths));
    }

    public StackablePagerAdapter(Context context, List<StackablePath> paths) {
        this.context = context;
        this.paths = paths;
    }

    @Override
    public int getCount() {
        return paths.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        StackablePath path = paths.get(position);

        Context pageContext = StackFactory.createContext(context, path, String.valueOf(position));