public abstract class Context extends ContextBase implements IContext {

    protected IInjector _injector;
    protected IReflector _reflector;
    protected Boolean _autoStartup;
    protected Object _contextView;
    protected ICommandMap _commandMap;
    protected IMediatorMap _mediatorMap;

    /**
     * private
     */
    protected IViewMap _viewMap;

    // ---------------------------------------------------------------------
    // Constructor
    // ---------------------------------------------------------------------

    /**
     * Abstract Context Implementation
     * 抽象的背景下实现
     * Extend this class to create a Framework or Application context
     * 扩展这个类来创建一个框架或应用程序上下文
     *
     * @param contextView The root view node of the context. The context will listen for
     *                    ADDED_TO_STAGE events on this node
     *                    视图上下文的根节点。上下文将监听ADDED_TO_STAGE事件在这个节点
     * @param autoStartup Should this context automatically invoke it's
     *                    <code>startup</code> method when it's <code>contextView</code>
     *                    arrives on Stage? 应该contextView到达阶段这种情况下,自动调用它的startup方法吗?
     */
    public Context(Object contextView, Boolean autoStartup) {
        super();
        this._contextView = contextView;
        this._autoStartup = autoStartup;
        if (this._contextView != null) {
            this.mapInjections();
            this.checkAutoStartup();
        }
    }

    // ---------------------------------------------------------------------
    // API
    // ---------------------------------------------------------------------

    /**
     * The Startup Hook
     * 启动
     * Override this in your Application context
     * 重写在你的应用程序上下文
     * event Startup complete ContextEvent.STARTUP_COMPLETE Dispatched at the
     * end of the <code>startup()</code> method's execution. This is
     * often used to trigger startup/bootstrapping commands by wiring
     * them to this event and calling <code>super.startup()</code> in the
     * last line of your <code>startup()</code> override.
     * 在startup方法的执行结束后开始完成ContextEvent
     * .STARTUP_COMPLETE的分发.这通常是用来触发启动/引导命令通过布线这一事件和调用super
     * .startup(),在startup总结覆盖的最后一行.
     */
    public void startup() {
        this.dispatchEvent(new ContextEvent(ContextEvent.STARTUP_COMPLETE));
        this.setMvcRelation();
    }

    /**
     * set your mvc relation
     * 设置你的mvc关系
     * Add the view map
     * Link the View and View the corresponding Mediator
     * 添加view映射
     * 将View 和 View 对应的 Mediator 联系起来
     * Injection as an singleton, instantiate the singleton
     * 注入实例，实例化单例
     * Add Event (Event) with the connection of the Command
     * 添加事件（Event）与Command的联系
     */
    public abstract void setMvcRelation();

    /**
     * The Shutdown Hook
     * 关闭
     * Override this in your Application context
     * 重写在你的应用程序上下文
     */
    public void shutdown() {
        this.dispatchEvent(new ContextEvent(ContextEvent.SHUTDOWN_COMPLETE));
    }

    /**
     * The <code>DisplayObjectContainer</code> that scopes this
     * <code>IContext</code>
     * IContext范围的DisplayObjectContainer
     *
     * @return The Context View
     */
    public Object getContextView() {
        return this._contextView;
    }

    /**
     * Set The ContextView
     * 设置ContextView
     *
     * @param value value
     */
    public void setContextView(View value) {
        if (value == this._contextView)
            return;

        if (this._contextView != null) {
            throw new ContextError(ContextError.E_CONTEXT_VIEW_OVR);
        }

        this._contextView = value;
        this.mapInjections();
        this.checkAutoStartup();
    }

    // ---------------------------------------------------------------------
    // Protected, Lazy Getters and Setters
    // ---------------------------------------------------------------------

    /**
     * @return The <code>IInjector</code> for this <code>IContext</code>
     */
    protected IInjector getInjector() {
        if (this._injector != null) {
            return this._injector;
        } else {
            this._injector = this.createInjector();
            return this._injector;
        }
    }

    /**
     * @param value value
     */
    protected void setInjector(IInjector value) {
        this._injector = value;
    }

    /**
     * @return The <code>IReflector</code> for this <code>IContext</code>
     */
    protected IReflector getReflector() {
        if (this._reflector != null) {
            return this._reflector;
        } else {
            this._reflector = new SwiftSuspendersReflector();
            return this._reflector;
        }
    }

    /**
     * @param value value
     *              private
     */
    protected void setReflector(IReflector value) {
        this._reflector = value;
    }

    /**
     * The <code>ICommandMap</code> for this <code>IContext</code>
     *
     * @return ICommandMap
     */
    protected ICommandMap getCommandMap() {
        if (this._commandMap != null) {
            return this._commandMap;
        } else {
            this._commandMap = new CommandMap(this.getEventDispatcher(),
                    this.createChildInjector(), this.getReflector());
            return this._commandMap;
        }
    }

    /**
     * private
     * @param value value
     */
    protected void setCommandMap(ICommandMap value) {
        this._commandMap = value;
    }

    /**
     * The <code>IMediatorMap</code> for this <code>IContext</code>
     * @return IMediatorMap
     */
    protected IMediatorMap getMediatorMap() {
        if (this._mediatorMap != null) {
            return this._mediatorMap;
        } else {
            this._mediatorMap = new MediatorMap(this.getContextView(),
                    this.createChildInjector(), this.getReflector());
            return this._mediatorMap;
        }
    }

    /**
     * @param value value
     *              private
     */
    protected void setMediatorMap(IMediatorMap value) {
        this._mediatorMap = value;
    }

    /**
     * The <code>IViewMap</code> for this <code>IContext</code>
     *
     * @return IViewMap
     */
    protected IViewMap getViewMap() {
        if (this._viewMap != null) {
            return this._viewMap;
        } else {
            this._viewMap = new ViewMap(this.getContextView(),
                    this.getInjector());
            return this._viewMap;
        }
    }

    /**
     * @param value value
     */
    protected void setViewMap(IViewMap value) {
        this._viewMap = value;
    }

    // ---------------------------------------------------------------------
    // Framework Hooks
    // ---------------------------------------------------------------------

    /**
     * Injection Mapping Hook
     * Override this in your Framework context to change the default
     * configuration
     * 覆写这个在你的框架Context去改变默认配置
     * Beware of collisions in your container
     * 谨防碰撞在你的容器
     */
    protected void mapInjections() {
        this.getInjector().mapValue(IReflector.class, this.getReflector(), "");
        this.getInjector().mapValue(IInjector.class, this.getInjector(), "");
        this.getInjector().mapValue(IEventDispatcher.class,
                this.getEventDispatcher(), "");
        this.getInjector().mapValue(Object.class, this.getContextView(), "");
        this.getInjector()
                .mapValue(ICommandMap.class, this.getCommandMap(), "");
        this.getInjector().mapValue(IMediatorMap.class, this.getMediatorMap(),
                "");
        this.getInjector().mapValue(IViewMap.class, this.getViewMap(), "");
        this.getInjector().mapClass(IEventMap.class, EventMap.class, "");
    }

    // ---------------------------------------------------------------------
    // Internal
    // ---------------------------------------------------------------------

    /**
     * private
     */
    protected void checkAutoStartup() {
        if (this._autoStartup && (this.getContextView() != null)) {
            this.startup();
        }
    }

    /**
     * private
     * @return IInjector
     */
    protected IInjector createInjector() {
        return new SwiftSuspendersInjector(null);
    }

    /**
     * private
     * @return IInjector
     */
    protected IInjector createChildInjector() {
        return this.getInjector().createChild();
    }

    /**
     * @param view view
     */
    public void injectMediator(Object view) {
        this.getMediatorMap().addMediator(view);
    }

    /**
     * @param view view
     */
    public void removeMediator(Object view) {
        this.getMediatorMap().unInjectMediator(view);
    }

} public class Login extends Command {

    private static final String TAG = "Login";

    @Inject
    public UserModel userModel;

    @Inject
    public LoginEvent event;


    /**
     * TODO - The Command subclass must inherit the execute method
     * 备忘录 - Command子类必须继承execute方法
     */
    @Override
    public void execute() {
        switch (event.getType()) {
            case LoginEvent.USER_LOGIN: {
                userModel.login(event.name, event.password);
                break;
            }
            case LoginEvent.USER_LOGOUT: {
                userModel.logout();
                break;
            }
            case LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_CONTROLLER: {
                Log.i(TAG, "This Login Controller know the user login success");

                /*
                 * send an USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW type of event to View layer
                 * 发送一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的事件到View层
                 */
                this.dispatch(new LoginEvent(LoginEvent.USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW));
                break;
            }
        }
    }
} public class LoginEvent extends Event {

    public static final String USER_LOGIN = "user_login";
    public static final String USER_LOGOUT = "user_logout";

    public static final String USER_LOGIN_SUCCESS_FROM_MODEL_TO_CONTROLLER = "user_login_success_from_model_to_controller";
    public static final String USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW = "user_login_success_from_model_to_view";
    public static final String USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW = "user_login_success_from_controller_to_view";

    public String name;
    public String password;

    public User user;

    public LoginEvent(String type) {
        super(type);
    }

} public class UserModel extends Actor {

    public void login(String name,String password) {

        // TODO Do you want to network requests

        User user = new User();
        user.name = "CaMnter";
        user.sign = "Save you from anything";

        /*
         * you can send a your custom event from Model layer to View layer
         * 你可以发送一个你自定义的事件从Model层到View层
         */
        LoginEvent loginEvent = new LoginEvent(LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW);
        loginEvent.user = user;
        this.dispatch(loginEvent);
        this.dispatch(new LoginEvent(LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_CONTROLLER));
    }

    public boolean logout(){

        // TODO Do you want to network requests

        return true;
    }


} public class MainActivity extends RobotlegsFragmentActivity {

    /**
     * Please set the fragment layout id
     * 请设置Fragment的布局Id
     *
     * @return
     */
    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

} public class MainActivityMediator extends Mediator {

    private MainActivity activity;

    private TabLayout tabLayout;
    private ViewPager viewPager;

    /**
     * {@inheritDoc}
     * {@linkplain IMediator #onRegister}
     */
    @Override
    public void onRegister() {
        this.activity = (MainActivity) this.getViewComponent();
        this.initViews();
        this.initData();
        this.initListeners();
    }

    private void initViews() {
        this.tabLayout = (TabLayout) this.activity.findViewById(R.id.tab_layout_tl);
        this.viewPager = (ViewPager) this.activity.findViewById(R.id.view_pager_vp);
    }

    private void initData() {
        String[] tabTitles = {"ONE", "TWO", "THR", "FOU"};
        Fragment[] fragments = {
                TabLayoutFirstFragment.getInstance(),
                TabLayoutSecondFragment.getInstance(),
                TabLayoutThirdFragment.getInstance(),
                TabLayoutFourthFragment.getInstance()
        };
        MainActivityAdapter adapter = new MainActivityAdapter(this.activity.getSupportFragmentManager(), fragments, tabTitles);
        this.viewPager.setAdapter(adapter);
        this.viewPager.setOffscreenPageLimit(adapter.getCount());
        this.tabLayout.setupWithViewPager(this.viewPager);
    }

    private void initListeners() {
        /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Controller layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的LoginEvent）
         * 在这里监听从Controller层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW, new ControllerListeners(), null, false, 0, false);
    }

    private class ControllerListeners extends Listener {
        /**
         * {@inheritDoc}
         * <p/>
         * {@linkplain IListener #onHandle}
         *
         * @param event
         */
        @Override
        public void onHandle(Event event) {
            if (event instanceof LoginEvent) {
                Toast.makeText(MainActivityMediator.this.activity, "MainActivityMediator:Please see the TWO、THR and FOU", Toast.LENGTH_LONG).show();
            }
        }
    }

} public class TabLayoutFirstFragment extends RobotlegsFragment {

    private static TabLayoutFirstFragment instance;

    private TabLayoutFirstFragment() {
    }

    public static TabLayoutFirstFragment getInstance() {
        if (instance == null) instance = new TabLayoutFirstFragment();
        return instance;
    }

    /**
     * Please set the fragment layout id
     * 请设置Fragment的布局Id
     *
     * @return
     */
    @Override
    public int getLayoutId() {
        return R.layout.tablayout_first_fragment;
    }

} public class TabLayoutFirstFragmentMediator extends Mediator implements View.OnClickListener {

    public TabLayoutFirstFragment fragment;
    public FragmentActivity activity;

    private Button firstBT;
    private TextView firstTV;
    private ImageView firstIV;
    private TextView controllerTV;


    /**
     * {@inheritDoc}
     * {@linkplain IMediator #onRegister}
     */
    @Override
    public void onRegister() {
        this.fragment = (TabLayoutFirstFragment) this.getViewComponent();

        this.activity = this.fragment.getActivity();
        this.initViews();
        this.initData();
        this.initListeners();
    }

    private void initViews() {
        this.firstBT = (Button) this.fragment.self.findViewById(R.id.first_bt);
        this.firstTV = (TextView) this.fragment.self.findViewById(R.id.first_tv);
        this.firstIV = (ImageView) this.fragment.self.findViewById(R.id.first_iv);
        this.controllerTV = (TextView) this.fragment.self.findViewById(R.id.first_controller_tv);
    }

    private void initData() {
        this.firstTV.setText("The ONE created by robotlegs4android frame");
    }

    private void initListeners() {
        this.firstBT.setOnClickListener(this);

        /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Model layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_MODEL_TO_CONTROLLER_AND_VIEW类型的LoginEvent）
         * 在这里监听从Model层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW, new Listener() {
                    /**
                     * {@inheritDoc}
                     * <p/>
                     * {@linkplain IListener #onHandle}
                     *
                     * @param event
                     */
                    @Override
                    public void onHandle(Event event) {
                        if (event instanceof LoginEvent) {
                            TabLayoutFirstFragmentMediator.this.firstIV.setVisibility(View.VISIBLE);
                        }
                    }
                }, null,
                false, 0, true);

        /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Controller layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的LoginEvent）
         * 在这里监听从Controller层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW, new Listener() {
            /**
             * {@inheritDoc}
             * <p/>
             * {@linkplain IListener #onHandle}
             *
             * @param event
             */
            @Override
            public void onHandle(Event event) {
                if (event instanceof LoginEvent) {
                    TabLayoutFirstFragmentMediator.this.controllerTV.setVisibility(View.VISIBLE);
                }
            }
        }, null, false, 0, true);

    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.first_bt: {
                /*
                 * you can send a your custom event from Model layer to Controller layer,and the
                 * frame will search the event configuration from your custom context
                 * 你可以发送一个你自定义的事件从Model层到Controller层，并且框架会去你自定义的context搜索
                 * 这个事件的配置
                 */
                LoginEvent loginEvent = new LoginEvent(LoginEvent.USER_LOGIN);
                loginEvent.name = "CaMnter";
                loginEvent.password = "Save you from anything";
                this.dispatch(loginEvent);
            }
        }
    }
} public class TabLayoutFourthFragment extends RobotlegsFragment {

    private static TabLayoutFourthFragment instance;

    private TabLayoutFourthFragment() {
    }

    public static TabLayoutFourthFragment getInstance() {
        if (instance == null) instance = new TabLayoutFourthFragment();
        return instance;
    }


    /**
     * Please set the fragment layout id
     * 请设置Fragment的布局Id
     *
     * @return
     */
    @Override
    public int getLayoutId() {
        return R.layout.tablayout_fourth_fragment;
    }

} public class TabLayoutFourthFragmentMediator extends Mediator {

    private TabLayoutFourthFragment fragment;

    private RecyclerView fourthRV;

    /**
     * {@inheritDoc}
     * {@linkplain IMediator #onRegister}
     */
    @Override
    public void onRegister() {
        super.onRegister();
        this.fragment = (TabLayoutFourthFragment) this.getViewComponent();
        this.initViews();
        this.initListeners();
    }

    private void initViews() {
        this.fourthRV = (RecyclerView) this.fragment.self.findViewById(R.id.fourth_rv);
        FourthRecyclerViewAdapter adapter = new FourthRecyclerViewAdapter();
        List<Integer> resIds = new LinkedList<>();
        resIds.add(R.mipmap.mm_8);
        resIds.add(R.mipmap.mm_9);
        resIds.add(R.mipmap.mm_10);
        resIds.add(R.mipmap.mm_11);
        resIds.add(R.mipmap.mm_12);
        resIds.add(R.mipmap.mm_13);
        resIds.add(R.mipmap.mm_14);
        resIds.add(R.mipmap.mm_15);
        resIds.add(R.mipmap.mm_16);
        resIds.add(R.mipmap.mm_17);
        resIds.add(R.mipmap.mm_18);
        resIds.add(R.mipmap.mm_19);
        resIds.add(R.mipmap.mm_20);
        this.fourthRV.setAdapter(adapter);
        adapter.setList(resIds);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);


        this.fourthRV.setLayoutManager(staggeredGridLayoutManager);
        this.fourthRV.setItemAnimator(new DefaultItemAnimator());
        this.fourthRV.setHasFixedSize(true);

    }

    private void initListeners() {
        /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Controller layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的LoginEvent）
         * 在这里监听从Controller层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW, new Listener() {
            /**
             * {@inheritDoc}
             * <p/>
             * {@linkplain IListener #onHandle}
             *
             * @param event
             */
            @Override
            public void onHandle(Event event) {
                if (event instanceof LoginEvent) {
                    TabLayoutFourthFragmentMediator.this.fourthRV.setVisibility(View.VISIBLE);
                }
            }
        }, null, false, 0, true);
    }

    public class FourthRecyclerViewAdapter extends EasyRecyclerViewAdapter {

        private static final long MIN = 500L;
        private static final long MAX = 1000L;

        @Override
        public int[] getItemLayouts() {
            return new int[]{R.layout.item_fourth_recycler};
        }

        @Override
        public void onBindRecycleViewHolder(EasyRecyclerViewHolder easyRecyclerViewHolder, int i) {
            int resId = (int) this.getList().get(i);
            ImageView fourthRV = easyRecyclerViewHolder.findViewById(R.id.fourth_recycler_iv);
            fourthRV.setImageResource(resId);
            ViewGroup.LayoutParams params =  fourthRV.getLayoutParams();
            params.height  = (int) Math.round(Math.random() * (MAX - MIN) + MIN);
            fourthRV.setLayoutParams(params);
        }

        @Override
        public int getRecycleViewItemType(int i) {
            return 0;
        }

    }

} public class TabLayoutSecondFragment extends RobotlegsFragment {

    private static TabLayoutSecondFragment instance;

    private TabLayoutSecondFragment() {
    }

    public static TabLayoutSecondFragment getInstance() {
        if (instance == null) instance = new TabLayoutSecondFragment();
        return instance;
    }


    /**
     * Please set the fragment layout id
     * 请设置Fragment的布局Id
     *
     * @return
     */
    @Override
    public int getLayoutId() {
        return R.layout.tablayout_second_fragment;
    }
} public class TabLayoutSecondFragmentMediator extends Mediator {

    private TabLayoutSecondFragment fragment;

    private RecyclerView secondRV;

    /**
     * {@inheritDoc}
     * {@linkplain IMediator #onRegister}
     */
    @Override
    public void onRegister() {
        super.onRegister();
        this.fragment = (TabLayoutSecondFragment) this.getViewComponent();
        this.initViews();
        this.initListeners();
    }

    private void initViews() {
        this.secondRV = (RecyclerView) this.fragment.self.findViewById(R.id.second_rv);
        SecondRecyclerViewAdapter adapter = new SecondRecyclerViewAdapter();
        List<Integer> resIds = new LinkedList<>();
        resIds.add(R.mipmap.mm_1);
        resIds.add(R.mipmap.mm_2);
        resIds.add(R.mipmap.mm_3);
        this.secondRV.setAdapter(adapter);
        adapter.setList(resIds);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.fragment.getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        this.secondRV.setLayoutManager(linearLayoutManager);
        this.secondRV.setItemAnimator(new DefaultItemAnimator());
        this.secondRV.addItemDecoration(new DividerItemDecoration(this.fragment.getActivity(), DividerItemDecoration.VERTICAL_LIST));
        this.secondRV.setHasFixedSize(true);
    }

    private void initListeners() {
         /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Controller layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的LoginEvent）
         * 在这里监听从Controller层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW, new Listener() {
            /**
             * {@inheritDoc}
             * <p/>
             * {@linkplain IListener #onHandle}
             *
             * @param event
             */
            @Override
            public void onHandle(Event event) {
                if (event instanceof LoginEvent) {
                    TabLayoutSecondFragmentMediator.this.secondRV.setVisibility(View.VISIBLE);
                }
            }
        }, null, false, 0, true);
    }

    public class SecondRecyclerViewAdapter extends EasyRecyclerViewAdapter {

        @Override
        public int[] getItemLayouts() {
            return new int[]{R.layout.item_second_recycler};
        }

        @Override
        public void onBindRecycleViewHolder(EasyRecyclerViewHolder easyRecyclerViewHolder, int i) {
            int resId = (int) this.getList().get(i);
            ImageView secondIV = easyRecyclerViewHolder.findViewById(R.id.second_recycler_iv);
            secondIV.setImageResource(resId);
        }

        @Override
        public int getRecycleViewItemType(int i) {
            return 0;
        }

    }

} public class TabLayoutThirdFragment extends RobotlegsFragment {

    private static TabLayoutThirdFragment instance;

    private TabLayoutThirdFragment() {
    }

    public static TabLayoutThirdFragment getInstance() {
        if (instance == null) instance = new TabLayoutThirdFragment();
        return instance;
    }


    /**
     * Please set the fragment layout id
     * 请设置Fragment的布局Id
     *
     * @return
     */
    @Override
    public int getLayoutId() {
        return R.layout.tablayout_third_fragment;
    }
    
} public class TabLayoutThirdFragmentMediator extends Mediator {

    private TabLayoutThirdFragment fragment;

    private RecyclerView thirdRV;

    /**
     * {@inheritDoc}
     * {@linkplain IMediator #onRegister}
     */
    @Override
    public void onRegister() {
        super.onRegister();
        this.fragment = (TabLayoutThirdFragment) this.getViewComponent();
        this.initViews();
        this.initListeners();
    }

    private void initViews() {
        this.thirdRV = (RecyclerView) this.fragment.self.findViewById(R.id.third_rv);
        ThirdRecyclerViewAdapter adapter = new ThirdRecyclerViewAdapter();
        List<Integer> resIds = new LinkedList<>();
        resIds.add(R.mipmap.mm_8);
        resIds.add(R.mipmap.mm_9);
        resIds.add(R.mipmap.mm_10);
        resIds.add(R.mipmap.mm_11);
        resIds.add(R.mipmap.mm_12);
        resIds.add(R.mipmap.mm_13);
        resIds.add(R.mipmap.mm_14);
        resIds.add(R.mipmap.mm_15);
        resIds.add(R.mipmap.mm_16);
        resIds.add(R.mipmap.mm_17);
        resIds.add(R.mipmap.mm_18);
        resIds.add(R.mipmap.mm_19);
        resIds.add(R.mipmap.mm_20);
        this.thirdRV.setAdapter(adapter);
        adapter.setList(resIds);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(this.fragment.getActivity(), 2);

        this.thirdRV.setLayoutManager(gridLayoutManager);
        this.thirdRV.setItemAnimator(new DefaultItemAnimator());
        this.thirdRV.setHasFixedSize(true);
    }

    private void initListeners() {
        /*
         * listening your custom event（such as listening to an USER_LOGIN_SUCCESS type of LoginEvent）
         * listening from Controller layer to View layer in here
         * 监听你的自定义事件（例如监听一个USER_LOGIN_SUCCESS_FROM_CONTROLLER_TO_VIEW类型的LoginEvent）
         * 在这里监听从Controller层到View层
         */
        this.getEventMap().mapListener(this.getEventDispatcher(), LoginEvent.USER_LOGIN_SUCCESS_FROM_MODEL_TO_VIEW, new Listener() {
            /**
             * {@inheritDoc}
             * <p/>
             * {@linkplain IListener #onHandle}
             *
             * @param event
             */
            @Override
            public void onHandle(Event event) {
                if (event instanceof LoginEvent) {
                    TabLayoutThirdFragmentMediator.this.thirdRV.setVisibility(View.VISIBLE);
                }
            }
        }, null, false, 0, true);
    }

    public class ThirdRecyclerViewAdapter extends EasyRecyclerViewAdapter {

        @Override
        public int[] getItemLayouts() {
            return new int[]{R.layout.item_third_recycler};
        }

        @Override
        public void onBindRecycleViewHolder(EasyRecyclerViewHolder easyRecyclerViewHolder, int i) {
            int resId = (int) this.getList().get(i);
            ImageView thirdRV = easyRecyclerViewHolder.findViewById(R.id.third_recycler_iv);
            thirdRV.setImageResource(resId);
        }

        @Override
        public int getRecycleViewItemType(int i) {
            return 0;
        }

    }

}
import com.camnter.robotlegs4android.mvcs.Context;
import com.camnter.robotlegs4android.test.controller.Login;
import com.camnter.robotlegs4android.test.event.LoginEvent;
import com.camnter.robotlegs4android.test.model.UserModel;
import com.camnter.robotlegs4android.test.view.activity.MainActivity;
import com.camnter.robotlegs4android.test.view.activity.MainActivityMediator;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutFirstFragment;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutFirstFragmentMediator;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutFourthFragment;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutFourthFragmentMediator;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutSecondFragment;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutSecondFragmentMediator;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutThirdFragment;
import com.camnter.robotlegs4android.test.view.fragment.TabLayoutThirdFragmentMediator;
/*
 * Copyright (C) 2015 CaMnter 421482590@qq.com
 *
 * 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 com.camnter.robotlegs4android.test.robotlegscontext;


/**
 * Description：MainContext
 * Created by：CaMnter
 * Time：2015-11-06 16:22
 */
public class MainContext extends Context {

    public MainContext(Object contextView, Boolean autoStartup) {
        super(contextView, autoStartup);
    }

    /**
     * set your mvc relation
     * 设置你的mvc关系
     * <p/>
     * Add the view map
     * Link the View and View the corresponding Mediator
     * 添加view映射
     * 将View 和 View 对应的 Mediator 联系起来
     * <p/>
     * Injection as an singleton, instantiate the singleton
     * 注入实例，实例化单例
     * <p/>
     * Add Event (Event) with the connection of the Command
     * 添加事件（Event）与Command的联系
     */
    @Override
    public void setMvcRelation() {

        /*
         * view映射
         * 将View 和 View 对应的 Mediator 联系起来
         * Add the view map
         * Link the View and View the corresponding Mediator
         */
        this.getMediatorMap().mapView(MainActivity.class, MainActivityMediator.class, null, true, true);
        this.getMediatorMap().mapView(TabLayoutFirstFragment.class, TabLayoutFirstFragmentMediator.class, null, true, true);
        this.getMediatorMap().mapView(TabLayoutSecondFragment.class, TabLayoutSecondFragmentMediator.class, null, true, true);
        this.getMediatorMap().mapView(TabLayoutThirdFragment.class, TabLayoutThirdFragmentMediator.class, null, true, true);
        this.getMediatorMap().mapView(TabLayoutFourthFragment.class, TabLayoutFourthFragmentMediator.class, null, true, true);

        /*
         * 注入实现 实例化单例
         * Injection as an singleton, instantiate the singleton
         */
        this.getInjector().mapSingleton(UserModel.class, "");

        /*
         * 添加事件与Command的联系
         * Add Event (Event) with the connection of the Command
         */
        this.getCommandMap().mapEvent(LoginEvent.USER_LOGIN, Login.class,