package com.zxhy.fastfilemanagerpro.kokomanager

import android.content.Context
import androidx.lifecycle.viewModelScope
import com.zxhy.fastfilemanagerpro.CommonViewModel
import com.zxhy.fastfilemanagerpro.kokodata.KoFileDatako
import com.zxhy.fastfilemanagerpro.kokotools.MediaStoreEx.recentImage
import com.zxhy.fastfilemanagerpro.kokotools.MediaStoreEx.recentVideo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class KoManagerkoViewModel : CommonViewModel() {
    fun loadRecentImageVideo(
        context: Context,
        result: (list: ArrayList<KoFileDatako>) -> Unit
    ) = viewModelScope.launch(Dispatchers.IO) {
        val imageList = recentImage(context).map { KoFileDatako(uri = it) }
        val videoList = recentVideo(context).map { KoFileDatako(uri = it) }
        val list= arrayListOf<KoFileDatako>()
        list.addAll(imageList)
        list.addAll(videoList)
        result.invoke(list)
    }
}