package com.navinfo.outdoor.activity;

import android.os.Bundle;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.base.BaseActivity;
import com.navinfo.outdoor.fragment.AboutFragment;
import com.navinfo.outdoor.fragment.CapacityEvaluationFragment;
import com.navinfo.outdoor.fragment.CapacityEvaluationFragment2;
import com.navinfo.outdoor.fragment.CapacityMeasurementFragment;
import com.navinfo.outdoor.fragment.ChargingPileFragment;
import com.navinfo.outdoor.fragment.ContactFragment;
import com.navinfo.outdoor.fragment.EventPrefectureFragment;
import com.navinfo.outdoor.fragment.FilterFragment;
import com.navinfo.outdoor.fragment.FindFragment;
import com.navinfo.outdoor.fragment.ForgetPawFragment;
import com.navinfo.outdoor.fragment.GatheringFragment;
import com.navinfo.outdoor.fragment.GradeFragment;
import com.navinfo.outdoor.fragment.HasSubmitFragment;
import com.navinfo.outdoor.fragment.IssueFragment;
import com.navinfo.outdoor.fragment.IssueWebFragment;
import com.navinfo.outdoor.fragment.MapDownloadFragment;
import com.navinfo.outdoor.fragment.MessageFragment;
import com.navinfo.outdoor.fragment.MineFragment;
import com.navinfo.outdoor.fragment.OtherFragment;
import com.navinfo.outdoor.fragment.PoiFragment;
import com.navinfo.outdoor.fragment.PoiTaskFragment;
import com.navinfo.outdoor.fragment.PrivilegeFragment;
import com.navinfo.outdoor.fragment.RecordFragment;
import com.navinfo.outdoor.fragment.RoadFragment;
import com.navinfo.outdoor.fragment.SetFragment;
import com.navinfo.outdoor.fragment.StaySubmitFragment;
import com.navinfo.outdoor.fragment.TaskExWebFragment;
import com.navinfo.outdoor.fragment.TaskExplainFragment;
import com.navinfo.outdoor.fragment.TaskExplainFragment2;
import com.navinfo.outdoor.fragment.TaskPrefectureFragment;

import com.navinfo.outdoor.fragment.RegisterFragment;
import com.navinfo.outdoor.fragment.TreasureFragment;
import com.navinfo.outdoor.fragment.UserAttestationFragment;
import com.navinfo.outdoor.fragment.WithdrawFragment;
import com.gyf.immersionbar.ImmersionBar;
import com.navinfo.outdoor.fragment.WithdrawalRecordFragment;


import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

/**
 * fragment 管理作用：
 */

public class FragmentManagement extends BaseActivity {
    private FragmentManager fragmentManager;
    private int fourthly_tag;
    private MineFragment mineFragment;//我的fragment -1
    private FindFragment findFragment;//发现的fragment -2
    private RecordFragment recordFragment;//纪录的fragment -3
    private TreasureFragment treasureFragment;//寻宝的fragment -4
    private RegisterFragment registerFragment;//注册的fragment -5
    private ForgetPawFragment forgetPawFragment;//忘记密码fragment -6
    private TaskPrefectureFragment taskPrefectureFragment;//发现-任务专区的fragment -7
    private TaskExplainFragment taskExplainFragment;//发现-任务说明的fragment -8
    private EventPrefectureFragment eventPrefectureFragment;//发现-活动专区的fragment  -9
    private TaskExplainFragment2 taskExplainFragment2;//发现-任务说明点击Item进入fragment -10
    private CapacityEvaluationFragment capacityEvaluationFragment;//发现-能力测评fragment -11
    private CapacityEvaluationFragment2 capacityEvaluationFragment2;//发现-能力测评2的fragment -12
    private TaskExWebFragment taskExWebFragment;//发现-任务说明点击Item进入Web页面的fragment  -13
    private CapacityMeasurementFragment capacityMeasurementFragment;//发现-能力测评item点击跳转web的fragment  -14
    private WithdrawFragment withdrawFragment;//我的-提现的fragment -15
    private IssueWebFragment issueWebFragment;//我的-常见问题-web的fragment  -16
    private GradeFragment gradeFragment;//我的-我的等级的fragment -17
    private PrivilegeFragment privilegeFragment;//我的-我的特权的fragment  -18
    private MapDownloadFragment mapDownloadFragment;//我的-地图下载的fragment  -19
    private IssueFragment issueFragment;//我的-常见问题的fragment  -20
    private ContactFragment contactFragment;//我的-联系我们的fragment  -21
    private SetFragment setFragment;//我的-设置的fragment  -22
    private AboutFragment aboutFragment;//我的-关于的fragment  -23
    private GatheringFragment gatheringFragment;//我的-用户资料-收款信息的fragment  -24
    private UserAttestationFragment userAttestationFragment;//我的-用户资料-实名认证的fragment  -25
    private WithdrawalRecordFragment withdrawalRecordFragment;//我的-提现-提现记录的fragment  -26
    private PoiFragment poiFragment;//寻宝-上传-POI的fragment -27
    private RoadFragment roadFragment;//寻宝-上传-道路的fragment -28
    private StaySubmitFragment staySubmitFragment;//记录-待提交的fragment -29
    private HasSubmitFragment hasSubmitFragment;//记录-已提交的fragment -30
    private PoiTaskFragment poiTaskFragment;//记录-已提交-POI任务列表的fragment -31
    private FilterFragment filterFragment;//寻宝-筛选界面 -32
    private OtherFragment otherFragment;//寻宝-上传-其他的fragment -33
    private ChargingPileFragment chargingPileFragment;//寻宝-上传-充电站-充电桩的fragment-34
    private MessageFragment messageFragment;//寻宝 -消息的fragment -35

    @Override
    protected int getLayout() {
        return R.layout.management_fragment;
    }

    @Override
    protected void initView() {
        super.initView();
        fourthly_tag = getIntent().getIntExtra("tag", 0);
        fragmentManager = getSupportFragmentManager();
        if (fourthly_tag != 0) {
            selectorFragment(fourthly_tag);
        }
        setZtlTextColor();
    }

    //隐藏所有Fragment
    private void hideAllFragment(FragmentTransaction fragmentTransaction) {
        if (mineFragment != null)//我的fragment -1
            fragmentTransaction.hide(mineFragment);
        if (findFragment != null)//发现的fragment -2
            fragmentTransaction.hide(findFragment);
        if (recordFragment != null)//记录的fragment -3
            fragmentTransaction.hide(recordFragment);
        if (treasureFragment != null)//寻宝的fragment -4
            fragmentTransaction.hide(treasureFragment);
        if (registerFragment != null)//注册的fragment -5
            fragmentTransaction.hide(registerFragment);
        if (forgetPawFragment != null)//忘记密码fragment -6
            fragmentTransaction.hide(forgetPawFragment);
        if (taskPrefectureFragment != null)//发现-任务专区的fragment -7
            fragmentTransaction.hide(taskPrefectureFragment);
        if (taskExplainFragment != null) //发现 - 任务说明的fragment -8
            fragmentTransaction.hide(taskExplainFragment);
        if (eventPrefectureFragment != null)//发现-活动专区的fragment  -9
            fragmentTransaction.hide(eventPrefectureFragment);
        if (taskExplainFragment2 != null)//发现-任务说明点击Item进入fragment -10
            fragmentTransaction.hide(taskExplainFragment2);
        if (capacityEvaluationFragment != null)//发现-能力测评fragment -11
            fragmentTransaction.hide(capacityEvaluationFragment);
        if (capacityEvaluationFragment2 != null)//发现-能力测评2的fragment -12
            fragmentTransaction.hide(capacityEvaluationFragment2);
        if (taskExWebFragment != null)//发现-任务说明点击Item进入Web页面的fragment  -13
            fragmentTransaction.hide(taskExWebFragment);
        if (capacityMeasurementFragment != null)//发现-能力测评item点击跳转web的fragment  -14
            fragmentTransaction.hide(capacityMeasurementFragment);
        if (withdrawFragment != null)//我的-提现的fragment -15
            fragmentTransaction.hide(withdrawFragment);
        if (issueWebFragment != null)//我的-常见问题-web的fragment -27
            fragmentTransaction.hide(issueWebFragment);
        if (gradeFragment != null)//我的-我的等级的fragment -17
            fragmentTransaction.hide(gradeFragment);
        if (privilegeFragment != null)//我的-我的特权的fragment  -18
            fragmentTransaction.hide(privilegeFragment);
        if (mapDownloadFragment != null)//我的-地图下载的fragment  -19
            fragmentTransaction.hide(mapDownloadFragment);
        if (issueFragment != null)//我的-常见问题的fragment  -20
            fragmentTransaction.hide(issueFragment);
        if (contactFragment != null)//我的-联系我们的fragment  -21
            fragmentTransaction.hide(contactFragment);
        if (setFragment != null)//我的-设置的fragment  -22
            fragmentTransaction.hide(setFragment);
        if (aboutFragment != null)//我的-关于的fragment  -23
            fragmentTransaction.hide(aboutFragment);
        if (gatheringFragment != null)//我的-用户资料-收款信息的fragment  -24
            fragmentTransaction.hide(gatheringFragment);
        if (userAttestationFragment != null)//我的-用户资料-实名认证的fragment-25
            fragmentTransaction.hide(userAttestationFragment);
        if (withdrawalRecordFragment != null)//我的-提现-提现记录的fragment  -26
            fragmentTransaction.hide(withdrawalRecordFragment);
        if (poiFragment != null) //寻宝-上传-POI的fragment -27
            fragmentTransaction.hide(poiFragment);
        if (roadFragment != null) //寻宝-上传-道路的fragment -28
            fragmentTransaction.hide(roadFragment);
        if (staySubmitFragment != null) //记录-待提交的fragment -29
            fragmentTransaction.hide(staySubmitFragment);
        if (hasSubmitFragment != null) //记录-已提交的fragment -30
            fragmentTransaction.hide(hasSubmitFragment);
        if (poiTaskFragment != null) //记录-已提交-任务列表的fragment -31
            fragmentTransaction.hide(poiTaskFragment);
        if (filterFragment != null)//寻宝-筛选 -32
            fragmentTransaction.hide(filterFragment);
        if (otherFragment != null)//寻宝-上传-其他 -33
            fragmentTransaction.hide(otherFragment);
        if (chargingPileFragment!=null)//寻宝-上传-充电站-充电桩的fragment-34
            fragmentTransaction.hide(chargingPileFragment);
        if (messageFragment!=null){//寻宝 -消息的Fragment -35
            fragmentTransaction.hide(messageFragment);
        }


    }

    public void selectorFragment(int i) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        hideAllFragment(fragmentTransaction);
        switch (i) {
            case 1://我的fragment
                if (mineFragment == null) {
                    mineFragment = MineFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, mineFragment);
                } else {
                    fragmentTransaction.show(mineFragment);
                }
/*              Bundle bundle1 = new Bundle();
                bundle1.putString("grad", getIntent().getStringExtra("grad"));
                mineFragment.setArguments(bundle1);*/
                break;
            case 2://发现的fragment
                if (findFragment == null) {
                    findFragment =FindFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, findFragment);
                } else {
                    fragmentTransaction.show(findFragment);
                }
                break;
            case 3://纪录的fragment
                if (recordFragment == null) {
                    recordFragment = RecordFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, recordFragment);
                } else {
                    fragmentTransaction.show(recordFragment);
                }
                break;
            case 4://寻宝的fragment
                if (treasureFragment == null) {
                    treasureFragment =TreasureFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, treasureFragment);
                } else {
                    fragmentTransaction.show(treasureFragment);
                }
                break;
            case 5://注册的fragment
                if (registerFragment == null) {
                    registerFragment =RegisterFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, registerFragment);
                } else {
                    fragmentTransaction.show(registerFragment);
                }
                break;
            case 6://忘记密码fragment
                if (forgetPawFragment == null) {
                    forgetPawFragment =ForgetPawFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, forgetPawFragment);
                } else {
                    fragmentTransaction.show(forgetPawFragment);
                }
                break;
            case 7://发现-任务专区的fragment
                if (taskPrefectureFragment == null) {
                    taskPrefectureFragment =TaskPrefectureFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, taskPrefectureFragment);
                } else {
                    fragmentTransaction.show(taskPrefectureFragment);
                }
                break;
            case 8: //发现 - 任务说明的fragment
                if (taskExplainFragment == null) {
                    taskExplainFragment = TaskExplainFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, taskExplainFragment);
                } else {
                    fragmentTransaction.show(taskExplainFragment);
                }
                break;
            case 9://发现-活动专区的fragment
                if (eventPrefectureFragment == null) {
                    eventPrefectureFragment =EventPrefectureFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, eventPrefectureFragment);
                } else {
                    fragmentTransaction.show(eventPrefectureFragment);
                }
                break;
            case 10://发现-任务说明点击Item进入fragment
                if (taskExplainFragment2 == null) {
                    taskExplainFragment2 =TaskExplainFragment2.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, taskExplainFragment2);
                } else {
                    fragmentTransaction.show(taskExplainFragment2);
                }
                break;
            case 11://发现-能力测评fragment -
                if (capacityEvaluationFragment == null) {
                    capacityEvaluationFragment = CapacityEvaluationFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, capacityEvaluationFragment);
                } else {
                    fragmentTransaction.show(capacityEvaluationFragment);
                }
                break;
            case 12://发现-能力测评2的fragment -
                if (capacityEvaluationFragment2 == null) {
                    capacityEvaluationFragment2 =CapacityEvaluationFragment2.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, capacityEvaluationFragment2);
                } else {
                    fragmentTransaction.show(capacityEvaluationFragment2);
                }
                break;
            case 13://发现-任务说明点击Item进入Web页面的fragment
                if (taskExWebFragment == null) {
                    taskExWebFragment =TaskExWebFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, taskExWebFragment);
                } else {
                    fragmentTransaction.show(taskExWebFragment);
                }
                break;
            case 14://发现-能力测评item点击跳转测试的fragment
                if (capacityMeasurementFragment == null) {
                    capacityMeasurementFragment =  CapacityMeasurementFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, capacityMeasurementFragment);
                } else {
                    fragmentTransaction.show(capacityMeasurementFragment);
                }
                break;
            case 15://我的-提现的fragment
                if (withdrawFragment == null) {
                    withdrawFragment = WithdrawFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, withdrawFragment);
                } else {
                    fragmentTransaction.show(withdrawFragment);
                }
                break;
            case 16://我的-常见问题-web的fragment
                if (issueWebFragment == null) {
                    issueWebFragment = IssueWebFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, issueWebFragment);
                } else {
                    fragmentTransaction.show(issueWebFragment);
                }
                break;
            case 17://我的-我的等级的fragment
                if (gradeFragment == null) {
                    gradeFragment = GradeFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, gradeFragment);
                } else {
                    fragmentTransaction.show(gradeFragment);
                }
                break;
            case 18://我的-我的特权的fragment
                if (privilegeFragment == null) {
                    privilegeFragment = PrivilegeFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, privilegeFragment);
                } else {
                    fragmentTransaction.show(privilegeFragment);
                }
                break;
            case 19://我的-地图下载的fragment
                if (mapDownloadFragment == null) {
                    mapDownloadFragment = MapDownloadFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, mapDownloadFragment);
                } else {
                    fragmentTransaction.show(mapDownloadFragment);
                }
                break;
            case 20://我的-常见问题的fragment
                if (issueFragment == null) {
                    issueFragment =IssueFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, issueFragment);
                } else {
                    fragmentTransaction.show(issueFragment);
                }
                break;
            case 21://我的-联系我们的fragment
                if (contactFragment == null) {
                    contactFragment =ContactFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, contactFragment);
                } else {
                    fragmentTransaction.show(contactFragment);
                }
                break;
            case 22://我的-设置的fragment
                if (setFragment == null) {
                    setFragment = SetFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, setFragment);
                } else {
                    fragmentTransaction.show(setFragment);
                }
                break;
            case 23://我的-关于的fragment
                if (aboutFragment == null) {
                    aboutFragment = AboutFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, aboutFragment);
                } else {
                    fragmentTransaction.show(aboutFragment);
                }
                break;
            case 24://我的-用户资料-收款信息的fragment
                if (gatheringFragment == null) {
                    gatheringFragment = GatheringFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, gatheringFragment);
                } else {
                    fragmentTransaction.show(gatheringFragment);
                }
                break;
            case 25://我的-用户资料-实名认证的fragment
                if (userAttestationFragment == null) {
                    userAttestationFragment = UserAttestationFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, userAttestationFragment);
                } else {
                    fragmentTransaction.show(userAttestationFragment);
                }
                break;
            case 26://我的-提现-提现记录的fragment
                if (withdrawalRecordFragment == null) {
                    withdrawalRecordFragment =WithdrawalRecordFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, withdrawalRecordFragment);
                } else {
                    fragmentTransaction.show(withdrawalRecordFragment);
                }
                break;
            case 27://寻宝-上传-POI的fragment -
                if (poiFragment == null) {
                    poiFragment = PoiFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, poiFragment);
                } else {
                    fragmentTransaction.show(poiFragment);
                }
                break;
            case 28://寻宝-上传-道路的fragment
                if (roadFragment == null) {
                    roadFragment =RoadFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, roadFragment);
                } else {
                    fragmentTransaction.show(roadFragment);
                }
                break;
            case 29:////记录-待提交的fragment -29
                if (staySubmitFragment == null) {
                    staySubmitFragment = StaySubmitFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, staySubmitFragment);
                } else {
                    fragmentTransaction.show(staySubmitFragment);
                }
                break;
            case 30://记录-已提交的fragment
                if (hasSubmitFragment == null) {
                    hasSubmitFragment = HasSubmitFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, hasSubmitFragment);
                } else {
                    fragmentTransaction.show(hasSubmitFragment);
                }
                break;
            case 31://记录-已提交-任务列表的fragment
                if (poiTaskFragment == null) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("type",getIntent().getIntExtra("type",0));
                    poiTaskFragment =PoiTaskFragment.newInstance(bundle);
                    fragmentTransaction.add(R.id.frame_layout, poiTaskFragment);
                } else {
                    fragmentTransaction.show(poiTaskFragment);
                }
                break;
            case 32://寻宝- 筛选
                if (filterFragment == null) {
                    filterFragment = FilterFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, filterFragment);
                } else {
                    fragmentTransaction.show(filterFragment);
                }
                break;
            case 33://寻宝- 上传-其他
                if (otherFragment == null) {
                    otherFragment = OtherFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, otherFragment);
                } else {
                    fragmentTransaction.show(otherFragment);
                }
                break;
            case 34://寻宝-上传-充电站-充电桩
                if (chargingPileFragment ==null){
                    chargingPileFragment =ChargingPileFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout,chargingPileFragment);
                }else {
                    fragmentTransaction.show(chargingPileFragment);
                }
                break;
            case 35://寻宝-消息
                if (messageFragment == null) {
                    messageFragment = MessageFragment.newInstance(new Bundle());
                    fragmentTransaction.add(R.id.frame_layout, messageFragment);
                } else {
                    fragmentTransaction.show(messageFragment);
                }
                break;
        }
        fragmentTransaction.commit();
    }


    private void setZtlTextColor() {
        ImmersionBar.with(this).statusBarDarkFont(true, 0.2f)
                //原理：如果当前设备支持状态栏字体变色，会设置状态栏字体为黑色，如果当前设备不支持状态栏字体变色，会使当前状态栏加上透明度，否则不执行透明度
                .init();
    }

}
