package com.zxhy.hfilemanagermaster.image

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.hfilemanagermaster.R
import com.example.hfilemanagermaster.databinding.ActivityImageShowBinding
import com.zxhy.hfilemanagermaster.glide.loadIntoImageView
import java.io.File

class ImageShowActivity : AppCompatActivity() {
    private lateinit var binding: ActivityImageShowBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityImageShowBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        window.statusBarColor = ContextCompat.getColor(this, R.color.color_FF000000)
        binding.clTop.setBackgroundColor(ContextCompat.getColor(this, R.color.color_FF000000))
        binding.ivArrow.setOnClickListener {
            finish()
        }
        val path = intent.extras?.getString("Path") ?: ""
        val file = File(path)
        if (file.exists()) {
            loadIntoImageView(this, file, binding.iv)
            binding.tvDelete.setOnClickListener {
                file.delete()
                finish()
            }
        }
        binding.ivArrow.setOnClickListener {
            finish()
        }

    }
}