package com.test.rv;

import com.base.utils.tools.android.IntentUtil;
import com.frame.base.FrameApp;
import com.frame.rv.ModuleEventUtil;
import com.frame.rv.OnModuleEventListener;
import com.rv.home.rv.module.ui.login.LoginRvActivity;
import com.rv.home.rv.module.ui.main.HomeActivity;
import com.rv.rvmine.MineActivity;
import com.rv.rvmine.traveler.AddAVisitorActivity;
import com.rv.travel.GoOtherUtil;
import com.rv.travel.TravelActivity;

public class ModuleUtil {
    private static int currentModule = -1;

    public static void register() {
        ModuleEventUtil.setOnModuleEventListener(new OnModuleEventListener() {
            @Override
            public void onChanged(int module) {
                switch (module) {
                    case OnModuleEventListener.MODULE_HOME:
                        if (currentModule == OnModuleEventListener.MODULE_HOME) return;
                        if (ModuleEventUtil.currentActivity != null) {
                            IntentUtil.goActivityWithAnimationAlpha(ModuleEventUtil.currentActivity, HomeActivity.class);
                        } else {
                            IntentUtil.startActivity(FrameApp.getInstance(), HomeActivity.class);
                        }

                        break;
                    case OnModuleEventListener.MODULE_TRAVEL:
                        if (currentModule == OnModuleEventListener.MODULE_TRAVEL) return;
                        if (ModuleEventUtil.currentActivity != null) {
                            IntentUtil.goActivityWithAnimationAlpha(ModuleEventUtil.currentActivity, TravelActivity.class);
                        } else {
                            IntentUtil.startActivity(FrameApp.getInstance(), TravelActivity.class);
                        }
                        break;
                    case OnModuleEventListener.MODULE_CAMP:
                        if (currentModule == OnModuleEventListener.MODULE_CAMP) return;

                        //Toast.makeText(FrameApp.getInstance(), "营地", Toast.LENGTH_SHORT).show();

                        break;
                    case OnModuleEventListener.MODULE_FIND:
                        if (currentModule == OnModuleEventListener.MODULE_FIND) return;

                        //Toast.makeText(FrameApp.getInstance(), "发现", Toast.LENGTH_SHORT).show();

                        break;
                    case OnModuleEventListener.MODULE_MINE:
                        if (currentModule == OnModuleEventListener.MODULE_MINE) return;
                        if (ModuleEventUtil.currentActivity != null) {
                            IntentUtil.goActivityWithAnimationAlpha(ModuleEventUtil.currentActivity, MineActivity.class);
                        } else {
                            IntentUtil.startActivity(FrameApp.getInstance(), MineActivity.class);
                        }
                        break;
                }
                currentModule = module;
            }

            @Override
            public void onClear() {
                currentModule = -1;
            }

            @Override
            public void onLogin(int type) {
                switch (type) {
                    case OnModuleEventListener.MODULE_LOGIN_START:
                        //需要登录
                        if (TravelActivity.isNeedLogin) {
                            FrameApp.getInstance().startActivity(LoginRvActivity.getIntent(FrameApp.getInstance()));
                        }
                        break;
                    case OnModuleEventListener.MODULE_LOGIN_FINISH:
                        //登录完成
                        if (TravelActivity.isNeedLogin) {
                            TravelActivity.isNeedLogin = false;
                            IntentUtil.startActivity(FrameApp.getInstance(), TravelActivity.class);
                            FrameApp.getMainHandler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    GoOtherUtil.goTravelDetailWeb(GoOtherUtil.travelDetailId, FrameApp.getInstance());
                                }
                            }, 500);
                        }

                        break;
                }
            }

            @Override
            public void onPay(int type) {

            }

            @Override
            public void onTravelMember(int type) {
                switch (type) {
                    case OnModuleEventListener.MODULE_TRAVEL_MEMBER_ADD:
                        //添加出游人
                        FrameApp.getInstance().startActivity(AddAVisitorActivity.getIntent(FrameApp.getInstance()));

                        break;
                    case OnModuleEventListener.MODULE_TRAVEL_MEMBER_FINISH:
                        //添加完成


                        break;
                }
            }
        });
    }
}
