package com.zxhy.fastfilemanagerpro.kokogridfile

import android.content.Context
import com.zxhy.fastfilemanagerpro.CommonViewModel
import com.zxhy.fastfilemanagerpro.kokodata.KoFileDatako
import java.io.File

class KoGridFilekoViewModel : CommonViewModel() {


    fun isImageFilter(file: File): Boolean {
        return file.name.contains(".jpg") or
                file.name.contains(".png") or
                file.name.contains(".gif")
    }

    fun isVideoFilter(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 loadImageFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isImageFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }

    fun loadVideoFile(
        context: Context,
        onDo: (list: List<KoFileDatako>) -> Unit,
        onFinish: (list: List<KoFileDatako>) -> Unit
    ) {
        loadFile(context, filter = (::isVideoFilter),
            onDo = { list ->
                onDo.invoke(list)
            },
            onFinish = { list ->
                onFinish.invoke(list)
            }
        )
    }


}