package com.kozen.printerhelper.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.kozen.printerhelper.R;
import com.kozen.printerhelper.helper.KozenPrintHelper;
import com.kozen.printerhelper.utils.BluetoothUtil;
import com.kozen.printerhelper.utils.BytesUtil;
import com.kozen.printerhelper.utils.ESCUtil;

public class BlackLabelActivity extends BaseActivity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blacklabel);
        setMyTitle(R.string.blackline_title);
        setBack();
        initView();
    }

    private void initView() {
        findViewById(R.id.bl_setting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(BlackLabelActivity.this, R.string.toast_11, Toast.LENGTH_LONG).show();
            }
        });

        findViewById(R.id.bl_check).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(KozenPrintHelper.getInstance().isBlackLabelMode()){
                    if(!BluetoothUtil.isBlueToothPrinter){
                        KozenPrintHelper.getInstance().sendRawData(ESCUtil.gogogo());
                    }else{
                        BluetoothUtil.sendData(ESCUtil.gogogo());
                    }
                }else{
                    Toast.makeText(BlackLabelActivity.this, R.string.toast_10, Toast.LENGTH_LONG).show();
                }
            }
        });

        findViewById(R.id.bl_sample).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!KozenPrintHelper.getInstance().isBlackLabelMode()){
                    Toast.makeText(BlackLabelActivity.this, R.string.toast_10, Toast.LENGTH_LONG).show();
                }else{
                    if(!BluetoothUtil.isBlueToothPrinter){
                        KozenPrintHelper.getInstance().printQr("www.baidu.com", 4, 3);
                        KozenPrintHelper.getInstance().feedPaper();
                        KozenPrintHelper.getInstance().sendRawData(ESCUtil.gogogo());
                        KozenPrintHelper.getInstance().cutpaper(BlackLabelActivity.this);
                    }else{
                        byte[] rv = ESCUtil.getPrintQRCode("www.baidu.com", 6, 3);
                        rv = BytesUtil.byteMerger(rv, new byte[]{0xa, 0xa,0xa});
                        BluetoothUtil.sendData(rv);
                        BluetoothUtil.sendData(ESCUtil.gogogo());
                        BluetoothUtil.sendData(ESCUtil.cutter());
                    }
                }
            }
        });
    }
}
