package com.xty.common

import android.content.Context
import android.text.TextUtils
import com.bumptech.glide.util.Util
import top.zibin.luban.CompressionPredicate
import top.zibin.luban.Luban
import top.zibin.luban.OnCompressListener
import java.io.File
import java.io.FileInputStream

class ImageCompressUtils(var success: () -> Unit) {

    fun compress(context: Context,file:File){

        var fileThumb=FileUtils.getCacheFile(context)+File.separator+"${System.currentTimeMillis()}_wxThumb.png"
        Luban.with(context)
            .load(file)
            .ignoreBy(100)
            .setTargetDir(fileThumb)
            .filter(object : CompressionPredicate{
                override fun apply(path: String): Boolean {
                    return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
                }
            })
            .setCompressListener(object : OnCompressListener {
                override fun onStart() {
                }

                override fun onSuccess(file: File?) {
                    if(FileInputStream(file).available()>0){

                    }
                }

                override fun onError(e: Throwable?) {

                }
            }).launch();

    }


}