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

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

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

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

import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.helper.WrapContentLinearLayoutManager;
import com.bonait.bnframework.modules.home.adapter.wdsz_adapter;
import com.orhanobut.logger.Logger;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WdszActivity extends BaseActivity {

    @BindView(R.id.topbar)
    QMUITopBarLayout mTopBar;
    @BindView(R.id.Recy_wdsz)
    RecyclerView Recy_wdsz;//温度设置
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wdsz);
        ButterKnife.bind(this);
        context=getContext();
        initTopBar();
        InitView();
    }

    private void initTopBar() {
        mTopBar.setTitle("温度设置");
        mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ConfigName.getInstance().versionSelectionEnum.equals("配料吧台"))
                {
                    ExecuteTheRecipe.WritePLC("水池排水阀-关",false,null);
                }else
                {
                    ExecuteTheRecipe.WritePLC("水池排水阀-关",true,null);
                }
                finish();
            }
        });
    }
    /**
     * 初始化界面
     */
    public void InitView() {
        Initdata();
    }


//    @OnClick({R.id.add_wl})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.add_wl:
//
//                break;
//        }
//    }


    //region 数据加载
    /**
     * 初始化数据加载
     */
    public void Initdata() {
        try {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        DataBus.getInstance().GetWdsz();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Recy_wdsz.setLayoutManager(new WrapContentLinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL,false));
                                DataBus.getInstance().wdszAdapter = new wdsz_adapter(getContext());
                                Recy_wdsz.setAdapter(DataBus.getInstance().wdszAdapter);
                            }
                        });

                        DataBus.getInstance().GetWD();

                    } catch (Exception e) {

                    }
                }
            }).start();
        } catch (Exception e) {

        }
    }
    //endregion

    @Override
    public void onDestroy() {
        super.onDestroy();
        Logger.d("我的fragment销毁");
    }

    /**
     * 当在activity设置viewPager + BottomNavigation + fragment时，
     * 为防止viewPager左滑动切换界面，与fragment左滑返回上一界面冲突引起闪退问题，
     * 必须加上此方法，禁止fragment左滑返回上一界面。
     * <p>
     * 切记！切记！切记！否则会闪退！
     * <p>
     * 当在fragment设置viewPager + BottomNavigation + fragment时，则不会出现这个问题。
     */
    @Override
    protected boolean canDragBack() {
        return false;
    }
}