package com.rehome.sgbaxj.activity.sbxdj;

import com.google.android.material.tabs.TabLayout;
import com.rehome.sgbaxj.R;
import com.rehome.sgbaxj.adapter.MyFragmentAdapter;
import com.rehome.sgbaxj.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

/**
 * 设备巡点检管理--现场点检
 */
public class DjMainActivity extends BaseActivity {

    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private List<Fragment> fragments = new ArrayList<>();
    private List<Fragment> list;
    private MyFragmentAdapter adapter;
    private XzjhFragment xzjh;
    private DjdscFragment djdsc;


    @Override
    public int getContentViewID() {
        return R.layout.activity_maindj;
    }

    protected void initView() {

    }

    public void initData() {
        setTitle("点检数据管理");
        mViewPager = findViewById(R.id.viewpager);
        setBack();
        xzjh = XzjhFragment.newInstance();
        djdsc = DjdscFragment.newInstance();
        list = new ArrayList<>();
        list.add(xzjh);
        list.add(djdsc);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), list);
        initViewPager();

    }

    private void initViewPager() {
        mTabLayout = findViewById(R.id.tabs);
        List<String> titles = new ArrayList<>();
        titles.add("数据下载");
        titles.add("数据上传");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        fragments.add(new XzjhFragment());
        fragments.add(new DjdscFragment());
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        mViewPager.setAdapter(mFragmentAdapteradapter);
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
    }

}