riku
2020-08-21 0328eab9276e57487eb2cfff31a945a01dd8c73a
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
38
39
package cn.flightfeather.thirdapp.common.net
 
import cn.flightfeather.thirdapp.CommonApplication
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import retrofit2.Response
import retrofit2.Retrofit
 
/**
 * @author riku
 * Date: 2019/7/22
 * 网络请求
 */
class RetrofitFactory constructor(application: CommonApplication){
 
    val retrofit: Retrofit = application.retrofit
 
    companion object {
 
        @Volatile
        lateinit var instance: RetrofitFactory
 
        @JvmStatic
        @Synchronized
        fun init(application: CommonApplication) {
            instance = RetrofitFactory(application)
        }
 
        /**
         * 执行请求返回结果
         */
        fun <T> executeResult(observable: Observable<Response<T>>, subscriber: ResultObserver<T>) {
            observable.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(subscriber)
        }
    }
}