package com.philisense.rdgo.ui.validation;

import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.philisense.rdgo.R;
import com.philisense.rdgo.databinding.ActivityValidationBinding;
import com.philisense.rdgo.ui.replace.ReplaceOldActivity;
import com.scandecode.ScanDecode;
import com.scandecode.inf.ScanInterface;

public class ValidationActivity extends AppCompatActivity {

    ActivityValidationBinding mBinding;
    private ScanDecode scanDecode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_validation);

        Toolbar toolbar = mBinding.include.toolbar;
        toolbar.setTitle("市场稽查");
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                finish();
            }
        });

        // 初始化扫描
        try {
            scanDecode = new ScanDecode(this);
            scanDecode.initService("true");
        }catch (Exception e) {
            Snackbar.make(mBinding.validationLayout,"本机没有扫码功能",Snackbar.LENGTH_LONG).show();
        }

        scanDecode.getBarCode(new ScanInterface.OnScanListener() {
            @Override
            public void getBarcode(String s) {
                scanDecode.stopScan();
                // TODO:上传入库记录
            }
        });

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        try {
            scanDecode.onDestroy();
        }catch (Exception e) {
        }
    }


    public static void start(Activity context) {
        Intent intent = new Intent(context, ValidationActivity.class);
        ActivityCompat.startActivity(context, intent,null);
    }
}
