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
31
32
33
34
35
36
37
package cn.flightfeather.thirdapp.repository
 
import cn.flightfeather.thirdapp.common.net.ResultCallBack
import cn.flightfeather.thirdapp.common.net.RetrofitFactory
import cn.flightfeather.thirdapp.httpservice.CommonService
import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
 
/**
 * @author riku
 * Date: 2020/4/23
 */
class CommonRepository {
 
    fun upLoadCrashInfo(accountName: String, file: File, resultCallBack: ResultCallBack<Boolean>) {
        val builder = MultipartBody.Builder()
        val requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file)
        builder.addFormDataPart("files", file.name, requestBody)
        builder.setType(MultipartBody.FORM)
        val multipartBody = builder.build()
        val partList = mutableListOf<MultipartBody.Part>()
        partList.addAll(multipartBody.parts())
 
        val service = RetrofitFactory.instance.retrofit.create(CommonService::class.java)
            .upLoadCrashInfo(accountName, partList)
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.trampoline())
            .subscribe({
                resultCallBack.onSuccess(it.body())
            }, {
                resultCallBack.onFailure()
            })
    }
}