package com.base.filerecoveryrecyclebin.activity.recyclebin

import android.content.Intent
import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import com.base.filerecoveryrecyclebin.activity.ResultActivity
import com.base.filerecoveryrecyclebin.activity.recyclebin.MyFileObserver.Companion.findRecycleBinFile
import com.base.filerecoveryrecyclebin.activity.recyclebin.MyFileObserver.Companion.findRecycleBinJsonFile
import com.base.filerecoveryrecyclebin.bean.ConstObject.RECYCLE_BIN
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import com.base.filerecoveryrecyclebin.databinding.ActivityRecycleBinDetailBinding
import com.base.filerecoveryrecyclebin.help.BaseActivity
import com.base.filerecoveryrecyclebin.utils.BarUtils
import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.view.DialogViews.showRecycleBinDetailDialog
import com.bumptech.glide.Glide
import com.google.gson.Gson
import java.io.File

class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>() {

    private val TAG = "RecycleBinDetailActivity"
    override val binding: ActivityRecycleBinDetailBinding by lazy {
        ActivityRecycleBinDetailBinding.inflate(layoutInflater)
    }

    @RequiresApi(Build.VERSION_CODES.Q)
    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)

        val json = intent.extras?.getString("Json") ?: ""
        LogEx.logDebug(TAG, "json=$json")
        val bean = Gson().fromJson(json, RecycleBinBean::class.java)
        if (bean.mimeType == "image/jpeg") {
            val file = File(bean.path)
            val binFile = findRecycleBinFile(file.name)
            val binJsonFile = findRecycleBinJsonFile(file.name)
            if (binFile != null && binJsonFile != null) {
                Glide.with(this).load(binFile.absoluteFile).centerCrop().into(binding.iv)
                showRecycleBinDetailDialog(bean, binFile, binJsonFile) {
                    startActivity(Intent(this, ResultActivity::class.java).apply {
                        putExtra("from", RECYCLE_BIN)
                    })
                    finish()
                }
            }
        }
        if (bean.mimeType == "") {

        }
    }

    override fun initListener() {
        super.initListener()
    }

}