package com.base.appzxhy.ui.recovery

import android.annotation.SuppressLint
import android.os.Bundle
import android.os.Environment
import androidx.activity.addCallback
import com.base.appzxhy.R
import com.base.appzxhy.base.BaseActivity
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.databinding.ActivityFileRecoveredBinding
import com.base.appzxhy.ui.recovery.FileScanResultActivity.Companion.SCAN_AUDIOS
import com.base.appzxhy.ui.recovery.FileScanResultActivity.Companion.SCAN_DOCUMENTS
import com.base.appzxhy.ui.recovery.FileScanResultActivity.Companion.SCAN_PHOTOS
import com.base.appzxhy.ui.recovery.FileScanResultActivity.Companion.SCAN_VIDEOS
import java.io.File

class FileRecoveredActivity : BaseActivity<ActivityFileRecoveredBinding>(ActivityFileRecoveredBinding::inflate) {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
        initListener()
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        super.initView()

        val number = intent.extras?.getInt("Number") ?: 0
        val scanType = intent.extras?.getInt("ScanType")
        val path: String? = intent.extras?.getString("Path")

        binding.tvNumber.text = number.toString()
        val type = when (scanType) {
            SCAN_PHOTOS -> if (number == 1) "Photo" else "Photos"
            SCAN_VIDEOS -> if (number == 1) "Video" else "Videos"
            SCAN_DOCUMENTS -> if (number == 1) "Document" else "Documents"
            SCAN_AUDIOS -> if (number == 1) "Audio" else "Audios"
            else -> ""
        }
        binding.tvType.text = type

        val appName = getString(R.string.app_name).replace("/", " ")
        val appDir = File(Environment.getExternalStorageDirectory(), appName)
        binding.tvDir.text = "Recovered in $appDir"
    }

    override fun initListener() {

        binding.ivBack.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        onBackPressedDispatcher.addCallback {
            AdsMgr.showInsert(this@FileRecoveredActivity, showCallBack = object : AdsShowCallBack() {
                override fun next() {
                    finishToMainTop()
                }
            })
        }
        binding.tvContinue.setOnClickListener {
            AdsMgr.showInsert(this@FileRecoveredActivity, showCallBack = object : AdsShowCallBack() {
                override fun next() {
                    finish()
                }
            })
        }
        binding.tvFinish.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
    }


}