package com.gh.common.util

import android.content.Context
import com.zhihu.matisse.MimeType
import com.zhihu.matisse.filter.Filter
import com.zhihu.matisse.internal.entity.IncapableCause
import com.zhihu.matisse.internal.entity.Item

class GhMatisseVideoFilter : Filter() {

    override fun constraintTypes(): MutableSet<MimeType> {
        return MimeType.ofVideo()
    }

    override fun filter(context: Context, item: Item): IncapableCause? {
        if (!needFiltering(context, item)) return null
        if (item.mimeType != MimeType.MP4.toString()) {
            return IncapableCause(IncapableCause.TOAST, "请把视频格式转换为MP4后再上传")
        }

        if (item.size > 500 * 1024 * 1024) {
            return IncapableCause(IncapableCause.TOAST, "视频大小限制为500M")
        }
        return null
    }

}