package com.test.mydemo3.activity

import android.os.Bundle
import com.kongzue.dialogx.dialogs.WaitDialog
import com.test.mydemo3.R
import com.test.mydemo3.base.BaseActivity
import com.test.mydemo3.model.FileBean
import com.test.mydemo3.util.FileUtil

class FileManagerActivity : BaseActivity() {
    private var mFileBeanList = ArrayList<FileBean>()
    private lateinit var mFileTypeBeanList : ArrayList<FileBean>
    private lateinit var mFileType: String


    override fun getLayout(): Int {
        return R.layout.activity_file_manager
    }
    companion object{
        val fileTypes = arrayOf(
            arrayOf("png","jpg"),
            arrayOf("mp4","3gp", "avi"),
            arrayOf("mp3","aac", "wav"),
            arrayOf("zip"),
            arrayOf("apk"),
            arrayOf("log"),
            arrayOf("png","jpg","doc","docm","docx","xlsx","xlsm","xlsb","xltx","ppt","pdf","txt"),
            arrayOf("doc","docm","docx"),
            arrayOf("xlsx","xlsm","xlsb","xltx",),
            arrayOf("ppt"),
            arrayOf("pdf"),
            arrayOf("txt"),
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        isNewShow(false)
        mFileType = intent.getStringExtra("fileType").toString()
        setTitle(mFileType)
        isCurrantTvShow(false)
        initData()
        setOnClickBtn()


    }

    private fun initData() {
        WaitDialog.show("please wait..")
        Thread(Runnable {
            if (mFileType.contains("audio")) {
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.MP3_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.WAV_MIME_TYPE, this))
            } else if (mFileType.contains("zip")) {
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.ZIP_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.ZIP_7Z_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.RAR_MIME_TYPE, this))
            } else if (mFileType.contains("all")) {
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.ZIP_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.ZIP_7Z_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.RAR_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.TEXT_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.WORD_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.EXCEL_MIME_TYPE, this))
                mFileBeanList.addAll(FileUtil.getFileType(FileUtil.PPT_MIME_TYPE, this))
            } else {
                mFileBeanList = when (mFileType) {
                    "apk" -> {
                        FileUtil.getFileType(FileUtil.APK_MIME_TYPE, this)
                    }

                    "log" -> {
                        FileUtil.getFileType(FileUtil.TEXT_MIME_TYPE, this)
                    }

                    "word" -> {
                        FileUtil.getFileType(FileUtil.WORD_MIME_TYPE, this)
                    }

                    "excel" -> {
                        FileUtil.getFileType(FileUtil.EXCEL_MIME_TYPE, this)
                    }

                    "ppt" -> {
                        FileUtil.getFileType(FileUtil.PPT_MIME_TYPE, this)
                    }

                    "pdf" -> {
                        FileUtil.getFileType(FileUtil.PDF_MIME_TYPE, this)
                    }

                    "txt" -> {
                        FileUtil.getFileType(FileUtil.TEXT_MIME_TYPE, this)
                    }

                    else -> {
                        mFileBeanList
                    }
                }
            }
            runOnUiThread(Runnable {
                setAdapter(findViewById(R.id.files_item_listview), mFileBeanList)
                WaitDialog.dismiss()
            })
        }).start()
    }

}