package com.bonait.bnframework.modules.home.fragment.from;

import static com.bonait.bnframework.MainApplication.getContext;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.modules.home.fragment.GongnengFragment;
import com.bonait.bnframework.modules.home.fragment.GuanLifragment;
import com.bonait.bnframework.modules.home.fragment.from.fragment.Jcsjgl_sxgl_fragment;
import com.bonait.bnframework.modules.home.fragment.from.fragment.Jcsjgl_wl_fragment;
import com.bonait.bnframework.modules.home.fragment.from.fragment.PlcControl_kz_fragment;
import com.bonait.bnframework.modules.home.fragment.from.fragment.PlcControl_pz_fragment;
import com.qmuiteam.qmui.arch.QMUIFragment;
import com.qmuiteam.qmui.arch.QMUIFragmentPagerAdapter;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.QMUIViewPager;
import com.qmuiteam.qmui.widget.tab.QMUITabSegment;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PlcControlActivity extends BaseActivity {

    @BindView(R.id.topbar)
    QMUITopBarLayout mTopBar;
    @BindView(R.id.tabs)
    QMUITabSegment tabs;
    @BindView(R.id.viewpager_wl)
    QMUIViewPager viewpager_wl;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_plccontrol);
        ButterKnife.bind(this);
        context=getContext();
        initTopBar();
        initFragment();
    }

    private void initTopBar() {
        mTopBar.setTitle("PLC地址配置与控制");
        mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    /**
     * viewPager里添加fragment
     */
    private void initFragment() {
        QMUIFragmentPagerAdapter adapter=new QMUIFragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return 2;
            }
            @Override
            public QMUIFragment createFragment(int position) {
                switch (position) {
                    case 0:
                        return new PlcControl_pz_fragment();
                    case 1:
                    default:
                        return new PlcControl_kz_fragment();
                }
            }
            @Override
            public CharSequence getPageTitle(int position) {
                switch (position) {
                    case 0:
                        return "PLC#地址";
                    case 1:
                    default:
                        return "控制#监控";
                }
            }
        };
        viewpager_wl.setAdapter(adapter);
        tabs.setupWithViewPager(viewpager_wl,true);
    }
    //-------------------------配置viewPager与fragment关联----------------------------//

    @Override
    public void onDestroy() {
        super.onDestroy();
        viewpager_wl.setAdapter(null);
    }

    @Override
    protected boolean canDragBack() {
        return false;
    }
}