puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.xw.common.utils
 
import android.content.Context
import android.net.Uri
import com.luck.picture.lib.engine.CompressFileEngine
import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener
import top.zibin.luban.Luban
import top.zibin.luban.OnNewCompressListener
import java.io.File
import java.util.ArrayList
 
class PictureCompressEngine : CompressFileEngine {
 
    override fun onStartCompress(context: Context?, source: ArrayList<Uri>?, call: OnKeyValueResultCallbackListener?) {
        Luban.with(context).load(source).ignoreBy(100)
            .setCompressListener(object : OnNewCompressListener {
                override fun onStart() {
                }
 
                override fun onSuccess(source: String?, compressFile: File?) {
                    call?.onCallback(source, compressFile?.absolutePath)
                }
 
                override fun onError(source: String?, e: Throwable?) {
                    call?.onCallback(source, null)
                }
 
            }).launch()
    }
}