package com.audio.record.screen.test.activity

import android.net.Uri
import android.os.Build
import androidx.core.view.isVisible
import com.audio.record.screen.test.base.BaseActivity
import com.audio.record.screen.test.databinding.ActivityImageViewBinding
import com.audio.record.screen.test.tool.Common
import com.bumptech.glide.Glide

/**
 * 图片预览页面
 */
class ImageViewActivity : BaseActivity<ActivityImageViewBinding>() {

    companion object {
        val KEY_URI = "uri_key"
        val KEY_name = "name"
    }


    private var mUri: Uri? = null
    private var displayName: String? = null
    override fun initBinding(): ActivityImageViewBinding =
        ActivityImageViewBinding.inflate(layoutInflater)

    override fun getFullColor(): Boolean? = null
    override fun onInitPadding(): Boolean = false
    override fun onSetViewBefore() {
    }

    override fun onCreateInit() {
        Common.enableImmersiveMode(this)
        mUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            intent.getParcelableExtra(KEY_URI, Uri::class.java)
        } else {
            intent.getParcelableExtra(KEY_URI)
        }
        displayName = intent.getStringExtra(KEY_name)
        initView()

    }


    private fun initView() {
        binding.run {
            back.setOnClickListener {
                finish()
            }
            textName.text = displayName
            Glide.with(this@ImageViewActivity)
                .load(mUri)
                .into(imgView)
            imgView.setOnClickListener {
                layoutName.isVisible = !layoutName.isVisible
            }
        }

    }
}