package xn.hxp.ui.plan.add;

import android.app.Activity;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.kongzue.dialogx.dialogs.PopTip;
import com.rc.httpcore.bean.BelongingPersonBean;
import com.rc.httpcore.bean.ChemicalTypeBean;
import com.rc.httpcore.bean.HxpChemicalVo;
import com.rc.httpcore.bean.TopicDataBean;
import com.rc.httpcore.client.ApiRepository;
import com.rc.httpcore.client.HttpTool;
import com.rc.httpcore.exception.NetException;

import java.util.List;

import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.Response;
import xn.hxp.ui.plan.room.bean.input_add.HxpChemical;
import xn.hxp.weidith.BelongingPersonDialog;
import xn.hxp.weidith.SelectChemicalDialog;
import xn.hxp.weidith.SelectTopicDialog;
import xn.hxp.weidith.ble.BluetoothWeighDialog;
import xn.hxp.weidith.prin_label_dialog.PrintLabelDialog;

/**
 * activity帮助类 不得占用上下文
 */
public class AddActivityHelp {
    private AddActivity activity;
    private PrintLabelDialog printLabelDialog;
    private BluetoothWeighDialog bluetoothWeighDialog;

    public AddActivityHelp(AddActivity addActivity) {
        super();
        this.activity = addActivity;
    }

    /**
     * 课题组查询
     *
     * @param userId 归属人ID
     */
    public void topicSearch(String userId) {
        activity.showLoading("查询中...");
        activity.addDisposable(ApiRepository.INSTANCE.getTopicList(userId).subscribe(topicDataBeans -> {
            activity.dismissLoading();
            new SelectTopicDialog(activity, topicDataBeans, topicDataBean -> {
                activity.topicDataBean = topicDataBean;
                String topicName = topicDataBean.getTopicName();
                activity.binding.topicET.setText(TextUtils.isEmpty(topicName) ? "" : topicName);
                activity.binding.topicET.setTag(topicDataBean.getTopicId());
            }).show();
        }, throwable -> {
            LogUtils.e(Log.getStackTraceString(throwable));
            activity.dismissLoading();
            activity.showNetError(throwable);
        }));
    }

    /**
     * 归属人搜索
     */
    public void belongSearch(Editable belongETText) {
        activity.showLoading("查询中...");
        activity.addDisposable(ApiRepository.INSTANCE.getSelects(belongETText.toString()).subscribe(belongingPersonBeans -> {
            activity.dismissLoading();
            new BelongingPersonDialog(activity, belongingPersonBeans, data -> {
                activity.belongingPerson = data;
                String userName = data.getUserName();
                userName = TextUtils.isEmpty(userName) ? "" : userName;
                String account = data.getAccount();
                account = TextUtils.isEmpty(account) ? "" : account;
                activity.binding.belongET.setText(userName + "-" + account);
                activity.binding.belongET.setTag(data.getUserId());
            }).show();
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e(Log.getStackTraceString(throwable));
                activity.dismissLoading();
                activity.showNetError(throwable);
            }
        }));
    }

    /**
     * 化学品搜索
     */
    public void hxpSearch(Editable chemicalSearchETText) {
        activity.showLoading("查询中...");
        ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<List<HxpChemicalVo>>() {
            @Override
            public List<HxpChemicalVo> doInBackground() throws Throwable {
                Response response = HttpTool.searchchemical(chemicalSearchETText.toString(), "");
                if (response.isSuccessful()) {
                    String json = response.body().string();
                    HxpChemical hxpChemical = GsonUtils.fromJson(json, HxpChemical.class);
                    if (hxpChemical.getCode() == 200) {
                        List<HxpChemicalVo> hxpChemicalVoList = hxpChemical.getData();
                        if (null != hxpChemicalVoList && !hxpChemicalVoList.isEmpty()) {
                            return hxpChemicalVoList;
                        }
                    } else {
                        throw new NetException("" + hxpChemical.getCode(), hxpChemical.getMessage());
                    }
                } else {
                    throw new NetException("" + response.code(), response.message());
                }
                return null;
            }

            @Override
            public void onSuccess(List<HxpChemicalVo> hxpChemicalVoList) {
                activity.dismissLoading();
                new SelectChemicalDialog(activity, hxpChemicalVoList, new SelectChemicalDialog.SelectedListener() {
                    @Override
                    public void selected(HxpChemicalVo hxpChemicalVo) {
                        chemicalSearchResult(hxpChemicalVo);
                    }
                }).show();
            }

            @Override
            public void onFail(Throwable t) {
                super.onFail(t);
                LogUtils.e(Log.getStackTraceString(t));
                activity.showNetError(t);
                activity.dismissLoading();
            }
        });
    }

    /**
     * 化学品名查询结果
     */
    private void chemicalSearchResult(HxpChemicalVo hxpChemicalVo) {
        // 化学品名
        String chemicalName = hxpChemicalVo.getChemicalName();
        activity.binding.chemicalSearchET.setText(TextUtils.isEmpty(chemicalName) ? "" : chemicalName);
        activity.hxpChemicalVo.setChemicalName(chemicalName);
        // CAS
        String casNum = hxpChemicalVo.getCasNum();
        activity.binding.casET.setText(TextUtils.isEmpty(casNum) ? "" : casNum);
        activity.hxpChemicalVo.setCasNum(casNum);
        // 密度
        double chemicalDensity = hxpChemicalVo.getChemicalDensity();
        activity.binding.chemicalDensityET.setText("" + chemicalDensity);
        activity.hxpChemicalVo.setChemicalDensity(chemicalDensity);
        // 规格值
        double specNum = hxpChemicalVo.getSpecNum();
        activity.binding.chemicalSpecET.setText("" + specNum);
        activity.hxpChemicalVo.setSpecNum(specNum);
        // 规格单位 ml/g
        String specUnit = hxpChemicalVo.getSpecUnit();
        if ("ml".equals(specUnit)) {
            activity.binding.chemicalSpecRG.check(activity.binding.chemicalSpecMlRB.getId());
            activity.binding.netWtTV.setText("ml");
        } else {
            activity.binding.chemicalSpecRG.check(activity.binding.chemicalSpecGRB.getId());
            activity.binding.netWtTV.setText("g");
        }
        activity.hxpChemicalVo.setSpecUnit(specUnit);
        // 化学品类别
        String chemicalCategory = hxpChemicalVo.getChemicalCategory();
        String chemicalCategoryName = hxpChemicalVo.getChemicalCategoryName();
        activity.binding.chemicalCategoryTV.setText(TextUtils.isEmpty(chemicalCategoryName) ? "" : chemicalCategoryName);
        activity.binding.chemicalCategoryTV.setTag(chemicalCategory);
        activity.hxpChemicalVo.setChemicalCategory(chemicalCategory);

        // 管控
        if (hxpChemicalVo.getChemicalLevel() == 1) {
            activity.binding.cmRG.check(activity.binding.controlledRB.getId());
        }
        // 非管控
        else {
            activity.binding.cmRG.check(activity.binding.uncontrolledRB.getId());
        }
        activity.hxpChemicalVo.setChemicalLevel(hxpChemicalVo.getChemicalLevel());
        // 化学品id
        activity.hxpChemicalVo.setChemicalId(hxpChemicalVo.getChemicalId());
    }

    /**
     * 添加待入库
     *
     * @param isWeigh 是否需要称重
     */
    public void save(boolean isWeigh) {
        // 化学品名
        Editable chemicalSearchETText = activity.binding.chemicalSearchET.getText();
        if (null == chemicalSearchETText || TextUtils.isEmpty(chemicalSearchETText)) {
            activity.binding.chemicalSearchET.setError("请输入化学品名称");
            activity.binding.chemicalSearchET.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setChemicalName(chemicalSearchETText.toString());

        // CAS
        Editable casETText = activity.binding.casET.getText();
        if (null == casETText || TextUtils.isEmpty(casETText)) {
            activity.binding.casET.setError("请输入CAS码");
            activity.binding.casET.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setCasNum(casETText.toString());

        // 类别
        String categoryTVTag = (String) activity.binding.chemicalCategoryTV.getTag();
        if (null == categoryTVTag || TextUtils.isEmpty(categoryTVTag)) {
            activity.binding.chemicalCategoryTV.setError("请选择化学品类别");
            activity.binding.chemicalCategoryTV.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setChemicalCategory(categoryTVTag);

        CharSequence chemicalCategoryTVText = activity.binding.chemicalCategoryTV.getText();
        if (null == chemicalCategoryTVText || TextUtils.isEmpty(chemicalCategoryTVText)) {
            activity.binding.chemicalCategoryTV.setError("请选择化学品类别");
            activity.binding.chemicalCategoryTV.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setChemicalCategoryName(chemicalCategoryTVText.toString());

        // 规格
        Editable chemicalSpecETText = activity.binding.chemicalSpecET.getText();
        if (null == chemicalSpecETText || TextUtils.isEmpty(chemicalSpecETText)) {
            activity.binding.chemicalSpecET.setError("请输入规格");
            activity.binding.chemicalSpecET.requestFocus();
            return;
        }
        double specNum = -1.0;
        try {
            specNum = Double.parseDouble(chemicalSpecETText.toString());
        } catch (Exception e) {
            activity.binding.chemicalSpecET.setError("请检查规格内容正确");
            activity.binding.chemicalSpecET.requestFocus();
            return;
        }
        if (specNum < 0) {
            activity.binding.chemicalSpecET.setError("请检查规格内容正确");
            activity.binding.chemicalSpecET.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setSpecNum(specNum);

        // 规格单位
        if (activity.binding.chemicalSpecMlRB.getId() == activity.binding.chemicalSpecRG.getCheckedRadioButtonId()) {
            activity.hxpChemicalVo.setSpecUnit("ml");
        } else {
            activity.hxpChemicalVo.setSpecUnit("g");
        }

        // 密度
        Editable chemicalDensityETText = activity.binding.chemicalDensityET.getText();
        if (null == chemicalDensityETText || TextUtils.isEmpty(chemicalDensityETText)) {
            activity.binding.chemicalDensityET.setError("请输入密度");
            activity.binding.chemicalDensityET.requestFocus();
            return;
        }
        double density = -1.0;
        try {
            density = Double.parseDouble(chemicalDensityETText.toString());
        } catch (Exception e) {
            activity.binding.chemicalDensityET.setError("请检查密度内容正确");
            activity.binding.chemicalDensityET.requestFocus();
            return;
        }
        if (density <= 0) {
            activity.binding.chemicalDensityET.setError("请检查密度内容正确");
            activity.binding.chemicalDensityET.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setChemicalDensity(density);

        // 净含量
        Editable netWtETText = activity.binding.netWtET.getText();
        if (null == netWtETText || TextUtils.isEmpty(netWtETText)) {
            activity.binding.netWtET.setError("请输入净含量");
            activity.binding.netWtET.requestFocus();
            return;
        }
        double netWt = -1.0;
        try {
            netWt = Double.parseDouble(netWtETText.toString());
        } catch (Exception e) {
            activity.binding.netWtET.setError("请检查净含量内容正确");
            activity.binding.netWtET.requestFocus();
            return;
        }
        if (netWt <= 0) {
            activity.binding.netWtET.setError("请检查净含量内容正确");
            activity.binding.netWtET.requestFocus();
            return;
        }
        activity.hxpChemicalVo.setNetContent(netWt);

        // 数量
        activity.inventoryItemBean.setSize(1);

        /*-- 非必填 --*/
        // 纯度
        Editable purityETText = activity.binding.purityET.getText();
        if (null != purityETText && !TextUtils.isEmpty(purityETText)) {
            activity.hxpChemicalVo.setChemicalPurity(purityETText.toString());
        }
        // 厂家
        Editable factoryETText = activity.binding.factoryET.getText();
        if (null != factoryETText && !TextUtils.isEmpty(factoryETText)) {
            activity.hxpChemicalVo.setFactory(factoryETText.toString());
        }


        // 已选择归属人
        if (activity.binding.belongTypeRG.getCheckedRadioButtonId() == activity.binding.belongRB.getId()) {
            // 归属人
            String userId = (String) activity.binding.belongET.getTag();
            LogUtils.d(userId);
            if (activity.belongingPerson == null || activity.belongingPerson.getUserId().isEmpty() || null == userId || TextUtils.isEmpty(userId) || !activity.belongingPerson.getUserId().equals(userId)) {
                activity.binding.belongET.setError("请先搜索并选择归属人");
                activity.binding.belongET.requestFocus();
                return;
            }
            // SQL归属人信息
            activity.inventoryItemBean.setBelongingPersonBean(activity.belongingPerson);
        }
        // 已选择课题组
        else if (activity.binding.belongTypeRG.getCheckedRadioButtonId() == activity.binding.topicRB.getId()) {
            // 课题组
            String topicId = (String) activity.binding.topicET.getTag();
            LogUtils.d(topicId);
            if (activity.topicDataBean == null || activity.topicDataBean.getTopicId().isEmpty() || null == topicId || TextUtils.isEmpty(topicId) || !activity.topicDataBean.getTopicId().equals(topicId)) {
                activity.binding.topicET.setError("请先搜索并选择课题组");
                activity.binding.topicET.requestFocus();
                return;
            }
            // SQL课题组信息
            activity.inventoryItemBean.setTopicDataBean(activity.topicDataBean);
        }

        // SQL化学品信息
        activity.inventoryItemBean.setHxpChemicalVo(activity.hxpChemicalVo);

        // 化学品基础信息配置
        activity.addDisposable(ApiRepository.INSTANCE.getControlConfigs(activity.hxpChemicalVo.getChemicalLevel()).subscribe(hxpControlConfig -> {
            activity.hxpControlConfig = hxpControlConfig;
            // 化学品新增确定
            activity.addDisposable(ApiRepository.INSTANCE.certitude(activity.hxpChemicalVo).subscribe(hxpChemicalVo -> {
                activity.hxpChemicalVo.setChemicalId(hxpChemicalVo.getChemicalId());
                CharSequence charSequence = activity.binding.cabinetLayerSelectTV.getText();
                // 是否是扫码添加化学品
                if (isQR) {
                    // 是否需要称重
                    if (isWeigh) {
                        startBluetoothWeigh();
                    } else {
                        saveEnd();
                    }
                } else {
                    if (null != printLabelDialog) {
                        printLabelDialog.dismiss();
                        printLabelDialog = null;
                    }
                    printLabelDialog = new PrintLabelDialog(activity, activity.inventoryItemBean,
                            TextUtils.isEmpty(charSequence) ? "" : charSequence.toString(),
                            activity.hxpControlConfig.isQrCodePrint(),
                            new PrintLabelDialog.PrintLabelCallBack() {
                                @Override
                                public void confirm() {
                                    startBluetoothWeigh();
                                }

                                @Override
                                public void close() {
                                    PopTip.show("取消存储");
                                }
                            }
                    );
                    printLabelDialog.show();
                }
            }, throwable -> {
                LogUtils.e(Log.getStackTraceString(throwable));
                PopTip.show(throwable.getMessage());
            }));
        }, throwable -> {
            LogUtils.e(Log.getStackTraceString(throwable));
            PopTip.show(throwable.getMessage());
        }));
    }

    /**
     * 启动称重
     */
    private void startBluetoothWeigh() {
        if (null != bluetoothWeighDialog) {
            bluetoothWeighDialog.dismiss();
            bluetoothWeighDialog = null;
        }
        bluetoothWeighDialog = new BluetoothWeighDialog(activity, activity.hxpChemicalVo, new BluetoothWeighDialog.DialogCallBack() {
            @Override
            public void confirm(BluetoothWeighDialog bluetoothWeighDialog) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        bluetoothWeighDialog.dismiss();
                        saveEnd();
                    }
                });
            }

            @Override
            public void cancel(BluetoothWeighDialog bluetoothWeighDialog, String msg) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(ActivityUtils.getTopActivity(), msg, Toast.LENGTH_LONG).show();
                        bluetoothWeighDialog.dismiss();
                    }
                });
            }
        });
        bluetoothWeighDialog.show();
    }

    private void saveEnd() {
        Toast.makeText(ActivityUtils.getTopActivity(), "添加成功", Toast.LENGTH_SHORT).show();
        activity.hxpInventoryDAO.insert(activity.inventoryItemBean);
        activity.setResult(Activity.RESULT_OK);
        activity.finish();
    }

    private boolean isQR = false;

    public void reset() {
        activity.hxpChemicalVo = null;
        activity.hxpChemicalVo = new HxpChemicalVo();
        activity.binding.chemicalSearchET.setText("");
        activity.binding.chemicalSearchET.setTag(null);
        activity.binding.chemicalSpecET.setText("");
        activity.binding.chemicalSpecET.setTag(null);
        activity.binding.casET.setText("");
        activity.binding.casET.setTag(null);
        activity.binding.chemicalDensityET.setText("");
        activity.binding.chemicalDensityET.setTag(null);
        activity.binding.netWtET.setText("");
        activity.binding.netWtET.setTag(null);
        activity.binding.sizeET.setText("1");
        activity.binding.sizeET.setTag(null);
        activity.binding.purityET.setText("");
        activity.binding.purityET.setTag(null);
        activity.binding.belongET.setText("");
        activity.binding.belongET.setTag(null);
        activity.binding.topicET.setText("");
        activity.binding.topicET.setTag(null);
        activity.binding.factoryET.setText("");
        activity.binding.factoryET.setTag(null);
    }

    /**
     * 扫码进入
     */
    public void qrInit() {
        isQR = true;
        HxpChemicalVo chemicalVo = activity.hxpChemicalVo;
        // 化学品名
        String chemicalName = chemicalVo.getChemicalName();
        chemicalName = TextUtils.isEmpty(chemicalName) ? "" : chemicalName;
        activity.binding.chemicalSearchET.setText(chemicalName);
        // 规格
        double specNum = chemicalVo.getSpecNum();
        specNum = specNum < 0 ? 0 : specNum;
        activity.binding.chemicalSpecET.setText("" + specNum);
        String specUnit = chemicalVo.getSpecUnit();
        if ("ml".equals(specUnit)) {
            activity.binding.chemicalSpecRG.check(activity.binding.chemicalSpecMlRB.getId());
            activity.binding.netWtTV.setText("ml");
        } else if ("g".equals(specUnit)) {
            activity.binding.chemicalSpecRG.check(activity.binding.chemicalSpecGRB.getId());
            activity.binding.netWtTV.setText("g");
        }
        // cas
        String casNum = chemicalVo.getCasNum();
        casNum = TextUtils.isEmpty(casNum) ? "" : casNum;
        activity.binding.casET.setText(casNum);
        // 密度
        double density = chemicalVo.getChemicalDensity();
        density = density <= 0 ? 1 : density;
        activity.binding.chemicalDensityET.setText("" + density);
        // 净含量
        double netWt = chemicalVo.getNetContent();
        activity.binding.netWtET.setText("" + netWt);
        // 数量
        activity.binding.sizeET.setText("1");
        // 纯度
        String purity = chemicalVo.getChemicalPurity();
        purity = TextUtils.isEmpty(purity) ? "" : purity;
        activity.binding.purityET.setText(purity);
        // 管控
        if (chemicalVo.getChemicalLevel() == 1) {
            activity.binding.cmRG.check(activity.binding.controlledRB.getId());
        }
        // 非管控
        else {
            activity.binding.cmRG.check(activity.binding.uncontrolledRB.getId());
        }

        // 归属人
        if (2 == chemicalVo.getBelongType()) {
            activity.belongingPerson = new BelongingPersonBean(String.valueOf(chemicalVo.getBelongId()), chemicalVo.getBelongName(), chemicalVo.getBelongAccount(), "", "");
            String belongName = activity.belongingPerson.getUserName();
            String belongAccount = activity.belongingPerson.getAccount();
            belongName = TextUtils.isEmpty(belongName) ? "" : belongName;
            belongAccount = TextUtils.isEmpty(belongAccount) ? "" : belongAccount;
            activity.binding.belongET.setText(belongName + "-" + belongAccount);
            activity.binding.belongET.setTag(activity.belongingPerson.getUserId());
            activity.binding.belongET.setEnabled(false);
            activity.binding.belongET.setInputType(InputType.TYPE_NULL);
            activity.binding.belongBT.setEnabled(false);
            activity.binding.topicLL.setVisibility(View.VISIBLE);
            activity.binding.belongLL.setVisibility(View.GONE);
            activity.binding.belongRB.setChecked(true);
        }
        // 课题组
        else {
            activity.topicDataBean = new TopicDataBean(String.valueOf(chemicalVo.getBelongId()), chemicalVo.getBelongName());
            String topicName = activity.topicDataBean.getTopicName();
            topicName = TextUtils.isEmpty(topicName) ? "" : topicName;
            activity.binding.topicET.setText(topicName);
            activity.binding.topicET.setEnabled(false);
            activity.binding.topicET.setInputType(InputType.TYPE_NULL);
            activity.binding.topicET.setTag(activity.topicDataBean.getTopicId());
            activity.binding.topicBT.setEnabled(false);
            activity.binding.topicLL.setVisibility(View.VISIBLE);
            activity.binding.belongLL.setVisibility(View.GONE);
            activity.binding.topicRB.setChecked(true);
        }
        // 厂家
        String factory = chemicalVo.getFactory();
        factory = TextUtils.isEmpty(factory) ? "" : factory;
        activity.binding.factoryET.setText(factory);
        // 类别
        String chemicalCategory = chemicalVo.getChemicalCategory();
        activity.binding.chemicalCategoryTV.setTag(chemicalCategory);
        if (null != activity.chemicalTypeList && !activity.chemicalTypeList.isEmpty()) {
            for (int i = 0; i < activity.chemicalTypeList.size(); i++) {
                ChemicalTypeBean chemicalTypeBean = activity.chemicalTypeList.get(i);
                if (chemicalTypeBean.getValue().equals(chemicalCategory)) {
                    chemicalVo.setChemicalCategoryName(chemicalTypeBean.getLabel());
                    String chemicalCategoryName = chemicalVo.getChemicalCategoryName();
                    activity.binding.chemicalCategoryTV.setText(TextUtils.isEmpty(chemicalCategoryName) ? "" : chemicalCategoryName);
                    break;
                }
            }
        }
        {
            activity.binding.chemicalSearchET.setEnabled(false);
            activity.binding.chemicalSearchET.setInputType(InputType.TYPE_NULL);
            activity.binding.chemicalSpecET.setEnabled(false);
            activity.binding.chemicalSpecET.setInputType(InputType.TYPE_NULL);
            activity.binding.casET.setEnabled(false);
            activity.binding.casET.setInputType(InputType.TYPE_NULL);
            activity.binding.chemicalSpecET.setEnabled(false);
            activity.binding.chemicalSpecET.setInputType(InputType.TYPE_NULL);
            activity.binding.chemicalDensityET.setEnabled(false);
            activity.binding.chemicalDensityET.setInputType(InputType.TYPE_NULL);
            activity.binding.netWtET.setEnabled(false);
            activity.binding.netWtET.setInputType(InputType.TYPE_NULL);
            activity.binding.sizeET.setEnabled(false);
            activity.binding.sizeET.setInputType(InputType.TYPE_NULL);
            activity.binding.purityET.setEnabled(false);
            activity.binding.purityET.setInputType(InputType.TYPE_NULL);
            activity.binding.factoryET.setEnabled(false);
            activity.binding.factoryET.setInputType(InputType.TYPE_NULL);
            activity.binding.chemicalCategoryTV.setClickable(false);
            activity.binding.chemicalCategoryTV.setEnabled(false);

            activity.binding.chemicalSearchBT.setEnabled(false);
            activity.binding.casBT.setEnabled(false);
            activity.binding.resetBT.setVisibility(View.GONE);
            activity.binding.saveBT.setVisibility(View.VISIBLE);
            activity.binding.uncontrolledRB.setEnabled(false);
            activity.binding.controlledRB.setEnabled(false);
            activity.binding.chemicalSpecMlRB.setEnabled(false);
            activity.binding.chemicalSpecGRB.setEnabled(false);

            activity.binding.topicRB.setEnabled(false);
            activity.binding.belongRB.setEnabled(false);
        }

    }

    public void onDestroy() {
        if (null != printLabelDialog) {
            printLabelDialog.dismiss();
        }
        if (null != bluetoothWeighDialog) {
            bluetoothWeighDialog.dismiss();
        }
    }
}
