package com.example.bpa.view.from;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.example.bpa.Model.IWriteCallBack;
import com.example.bpa.R;
import com.example.bpa.app.DeviceData;
import com.example.bpa.db.QueryDB;
import com.example.bpa.helper.T;
import com.example.bpa.view.control.ItemClickListener;
import com.example.bpa.view.control.MainMeunAdapter;
import com.example.bpa.view.control.MyLayoutManager;
import com.example.bpa.view.mode.MenuMode;

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

/**
 * 电子秤校验
 */
public class dzcjy_activity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    //region 变量
    /**
     * 返回按钮
     */
    ImageView gongneng_fanhui;
    /**
     * 标题设置
     */
    TextView gongneng_title;
    /**
     * out_switch:称重模块校准
     * marialmode_switch:出口称重模块校准
     */
    Switch out_switch,marialmode_switch;
    /**
     * mwSave_button:物料砝码值保存
     * owSave_button:出口砝码值保存
     * materilwrite_button:物料砝码值写入
     * calibration_button:物料校准
     * zeroweight_button:重量清零
     * outWrite_button:出口砝码值写入
     * zerocalibration_button:零点校准
     */
    Button mwSave_button,owSave_button,materilwrite_button,calibration_button,zeroweight_button,outWrite_button,zerocalibration_button;

    EditText  materialweight_edit,outweight_edit;

    //endregion

    //region 私有函数
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dzcjy);
        Init();
        initEvents();
        Initdata();    }
    //endregion

    //region 公共函数

    /**
     * 初始化
     */
    private void Init(){
        gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui);
        gongneng_title = this.findViewById(R.id.gongneng_title);
        //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据
        String msg=getIntent().getStringExtra("data");
        gongneng_title.setText(msg);
        //edittext
        materialweight_edit = this.findViewById(R.id.materialweight_edit);
        outweight_edit = this.findViewById(R.id.outweight_edit);
        //switch
        out_switch = this.findViewById(R.id.out_switch);
        marialmode_switch = this.findViewById(R.id.marialmode_switch);
        //button
        mwSave_button = this.findViewById(R.id.mwSave_button);
        owSave_button = this.findViewById(R.id.owSave_button);
        materilwrite_button = this.findViewById(R.id.materilwrite_button);
        calibration_button = this.findViewById(R.id.calibration_button);
        zeroweight_button = this.findViewById(R.id.zeroweight_button);
        outWrite_button = this.findViewById(R.id.outWrite_button);
        zerocalibration_button = this.findViewById(R.id.zerocalibration_button);



    }

    /**
     * 初始化按钮事件
     */
    private void initEvents() {
        gongneng_fanhui.setOnClickListener(this);
        mwSave_button.setOnClickListener(this);
        owSave_button.setOnClickListener(this);
        materilwrite_button.setOnClickListener(this);
        calibration_button.setOnClickListener(this);
        zeroweight_button.setOnClickListener(this);
        outWrite_button.setOnClickListener(this);
        zerocalibration_button.setOnClickListener(this);

        out_switch.setOnCheckedChangeListener(this);
        marialmode_switch.setOnCheckedChangeListener(this);


    }

    /**
     * 初始化数据
     */
    private void Initdata() {
        marialmode_switch.setChecked(DeviceData.Get().getCalibrationMode());
        out_switch.setChecked(DeviceData.Get().getWeightCalibrationMode());
        materialweight_edit.setText("0");
        outweight_edit.setText("0");
    }
    //endregion

    //region 点击事件
    /**
     * 本页面点击事件监听
     *
     * @param v
     */
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.gongneng_fanhui://返回按钮
                this.finish();

            break;
            case R.id.mwSave_button://物料砝码值保存
                String res = materialweight_edit.getText().toString().trim();
                if(!res.equals("")){

                }
                break;
            case R.id.owSave_button://出口砝码值保存
                break;
            case R.id.materilwrite_button://物料砝码值写入
                break;
            case R.id.calibration_button://物料校准
                break;
            case R.id.zeroweight_button://重量清零
                break;
            case R.id.outWrite_button://出口砝码值写入
                break;
            case R.id.zerocalibration_button://零点校准
                break;

        }
    }
    /**
     * 本页面switch点击事件监听
     *
     * @param
     */
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.out_switch://称重模块校准
                DeviceData.Get().setCalibrationMode(isChecked, new IWriteCallBack() {
                    @Override
                    public void onSuccess() {

                    }

                    @Override
                    public void onFailure(String ErrorMsg) {

                    }
                });

                break;
            case R.id.marialmode_switch://出口称重模块校准
                DeviceData.Get().setWeightCalibrationMode(isChecked, new IWriteCallBack() {

                    @Override
                    public void onSuccess() {

                    }

                    @Override
                    public void onFailure(String ErrorMsg) {

                    }
                });
                break;
        }
    }
    //endregion
}