package com.lemonhc.mplus.mcare_plus.activity

import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity

import com.lemonhc.mplus.mcare_plus.R
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentResult
import com.lemonhc.mplus.framework.util.kotlinExtension.isCaptureFlag

/**
 * 바코드 스캔 화면
 */
class BarcodeActivity: AppCompatActivity() {
    companion object {
        lateinit var callBack: (String?) -> Unit
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!isCaptureFlag) {
            window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
        }
        setContentView(R.layout.activity_)
        MainActivity.isVisibleQrcode = true
        IntentIntegrator(this@BarcodeActivity).initiateScan()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
        val result: IntentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent)
        if (result != null) {
            if (result.contents == null) {
                finish()
            } else {
                callBack(result.contents)
                finish()
            }
        } else {
            super.onActivityResult(requestCode, resultCode, intent)
        }
    }

}
