package com.bjzc.bhzhgd.activity.regular;


import android.content.Intent;
import android.view.View;
import com.bjzc.bhzhgd.DBModel.Profession;
import com.bjzc.bhzhgd.base.BaseActivity3;
import com.google.android.material.tabs.TabLayout;
import com.bjzc.bhzhgd.R;
import com.bjzc.bhzhgd.activity.sbxdj.FragmentAdapter;
import com.bjzc.bhzhgd.adapter.MyFragmentAdapter;
import java.util.ArrayList;
import java.util.List;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;


/**
 * Created by huang on 2021/12/09
 * 定期工作-任务管理
 */
public class DqgzMainActivity extends BaseActivity3 {


    private DrawerLayout mDrawerLayout;
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private List<Fragment> fragments = new ArrayList<>();
    private List<Fragment> list;
    private MyFragmentAdapter adapter;

    private DqgzFragment dqgzFragment;
    private QtgzFragment qtgzFragment;
    private LLSJFragment lLSJFragment;

    private String type = null;
    private List<String> listPro = new ArrayList<>();
    private List<Profession> professionList = new ArrayList<>();


    @Override
    public int getLayoutId() {
        return R.layout.activity_mainxj;
    }

    @Override
    public void initView() {
//        listPro.add("运行专业");
//        listPro.add("燃料专业");

    }

    public void initData() {
        Intent intent = getIntent();
        type = intent.getStringExtra("type");
//        if(type!=null&&type.equals("YX")){
//            initToolbar("定期工作", "选择专业", this);
//            professionList = DataSupport.findAll(Profession.class);
//            if(professionList!=null&&professionList.size()>0){
//                for(Profession profession : professionList){
//                    listPro.add(profession.getZymc());
//                }
//            }
//
//        }else{
//            initToolbar("定期工作", "", this);
//        }
        initToolbar("定期工作", "", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(type.equals("YX")){
//                    ListDialog listDialog = new ListDialog(context, listPro, new ListDialog.ListDialogListener() {
//                        @Override
//                        public void selectText(String text, int position) {
//                            if(professionList!=null&&professionList.size()>0){
//                                Profession profession = professionList.get(position);
//                                Log.i("app",profession.getZyid());
//                                //刷新计划下载界面
//                                Intent intent = new Intent(Contans.ACTION_PROFESSIONCHANGE);
//                                intent.putExtra("professionId",profession.getZyid());
//                                //专业选择改变发送广播,刷新任务下载页面
//                                sendBroadcast(intent);
//                            }
//                        }
//                    });
//                    listDialog.setTvTitle("请选择专业");
//                    listDialog.show();;
                }
            }
        });

        mViewPager = findViewById(R.id.viewpager);
        dqgzFragment = DqgzFragment.newInstance(type);
        qtgzFragment = QtgzFragment.newInstance(type);
        lLSJFragment = LLSJFragment.newInstance(type);
        list = new ArrayList<>();
        list.add(dqgzFragment);
        list.add(qtgzFragment);
        list.add(lLSJFragment);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        initViewPager();

    }

    private void initViewPager() {
        mTabLayout = findViewById(R.id.tabs);
        List<String> titles = new ArrayList<>();
        titles.add("定期工作");
        titles.add("其它工作");
        titles.add("录入数据");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        fragments.add(new DqgzFragment(type));
        fragments.add(new QtgzFragment(type));
        fragments.add(new LLSJFragment(type));
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        mViewPager.setAdapter(mFragmentAdapteradapter);
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
    }
}