package com.zxhy.simplefilesmanager.simplegrid

import androidx.lifecycle.viewModelScope
import com.zxhy.simplefilesmanager.simpleCommon.SimpleCommonViewModel
import com.zxhy.simplefilesmanager.simpledata.JoGridFileJo
import com.zxhy.simplefilesmanager.simpledata.JoGridFileJo.Companion.joGridFileJo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File

class SimpleGridViewModel : SimpleCommonViewModel() {
    private fun isImage(file: File): Boolean {
        return file.name.contains(".jpg") or file.name.contains(".png") or file.name.contains(".gif")
    }

    private fun isVideo(file: File): Boolean {
        return file.name.contains(".mp4") or
                file.name.contains(".avi") or
                file.name.contains(".flv") or
                file.name.contains(".rmvb") or
                file.name.contains(".mkv")
    }

    fun loadImage(
        onDo: (list: List<JoGridFileJo>) -> Unit,
        onFinish: (list: List<JoGridFileJo>) -> Unit
    ) = loadFile(::isImage, ::joGridFileJo, onDo, onFinish)

    fun loadVideo(
        onDo: (list: List<JoGridFileJo>) -> Unit,
        onFinish: (list: List<JoGridFileJo>) -> Unit
    ) = loadFile(::isVideo, ::joGridFileJo, onDo, onFinish)
}