package com.ux.video.file.filerecovery.main

import android.content.Intent
import android.view.LayoutInflater
import com.ux.video.file.filerecovery.R
import com.ux.video.file.filerecovery.base.BaseActivity
import com.ux.video.file.filerecovery.databinding.ActivityScanSelectTypeBinding
import com.ux.video.file.filerecovery.result.ScanningActivity
import com.ux.video.file.filerecovery.utils.Common
import com.ux.video.file.filerecovery.utils.FileType
import com.ux.video.file.filerecovery.utils.ScanType
import kotlin.properties.Delegates


/**
 * 选择扫描所有文件还是扫描删除过的文件
 */
class ScanSelectTypeActivity : BaseActivity<ActivityScanSelectTypeBinding>() {

    private var allType by Delegates.notNull<Int>()
    private var deletedType by Delegates.notNull<Int>()
    override fun inflateBinding(inflater: LayoutInflater): ActivityScanSelectTypeBinding =
        ActivityScanSelectTypeBinding.inflate(inflater)


    override fun initView() {
        super.initView()
        val intExtra = intent.getIntExtra(Common.KEY_FILE_TYPE, FileType.PHOTO.value)
        val fileType = FileType.from(intExtra)
        fileType?.let { setSelectType(it) }


    }

    override fun initData() {
        super.initData()
        binding.imageBack.setOnClickListener { finish() }
        binding.scanAllFile.setOnClickListener {

            startActivity(Intent(this@ScanSelectTypeActivity, ScanningActivity::class.java).apply {
                putExtra(Common.KEY_SCAN_TYPE, allType)
            })

        }
        binding.scanDeletedFile.setOnClickListener {
            startActivity(Intent(this@ScanSelectTypeActivity, ScanningActivity::class.java).apply {
                putExtra(Common.KEY_SCAN_TYPE, deletedType)
            })
        }
    }

    private fun setSelectType(fileType: FileType) {
        when (fileType) {
            FileType.PHOTO -> {
                allType = ScanType.ALL_PHOTO.value
                deletedType = ScanType.DELETED_PHOTO.value
                binding.title.text = getString(R.string.photo_title)
            }

            FileType.VIDEO -> {
                allType = ScanType.ALL_VIDEO.value
                deletedType = ScanType.DELETED_VIDEO.value
                binding.title.text = getString(R.string.video_title)
            }

            FileType.AUDIO -> {
                allType = ScanType.ALL_AUDIO.value
                deletedType = ScanType.DELETED_AUDIO.value
                binding.title.text = getString(R.string.audio_title)
            }

            FileType.DOCUMENT -> {
                allType = ScanType.ALL_DOCUMENT.value
                deletedType = ScanType.DELETED_DOCUMENT.value
                binding.title.text = getString(R.string.document_title)
            }
        }

    }
}