package app.furmeet.events.system.schedule

import android.graphics.Point
import android.os.Bundle
import android.view.WindowManager
import app.furmeet.events.system.TranslatableAppCompatActivityWithScheduleServiceWrapped
import app.furmeet.events.system.helper.resourcesAliased
import app.furmeet.events.bff.databinding.ActivityAssetImageViewerBinding
import kotlin.math.max
import android.graphics.Bitmap
import com.google.zxing.BarcodeFormat
import com.journeyapps.barcodescanner.BarcodeEncoder


class QRCodeViewerActivity : TranslatableAppCompatActivityWithScheduleServiceWrapped() {

    lateinit var binding: ActivityAssetImageViewerBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
        binding = ActivityAssetImageViewerBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        resourcesAliased = this.resources
        resources.displayMetrics
        val display = windowManager.defaultDisplay
        val size = Point()
        display.getSize(size)
        val maxDimen = max(size.x, size.y)
        val data = intent.getStringExtra("data")
        val barcodeEncoder = BarcodeEncoder()
        val bitmap: Bitmap = barcodeEncoder.encodeBitmap(data, BarcodeFormat.QR_CODE, maxDimen, maxDimen)
        binding.myZoomageView.setImageBitmap(bitmap)
    }
}