|
|
|
@ -2,6 +2,7 @@ package com.common.commonlib.net
|
|
|
|
|
|
|
|
|
|
import android.net.ParseException
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import com.common.commonlib.log.Logger
|
|
|
|
|
import com.common.commonlib.net.callback.RequestCallBack
|
|
|
|
|
import com.google.gson.JsonParseException
|
|
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|
|
|
@ -24,6 +25,16 @@ import javax.net.ssl.SSLHandshakeException
|
|
|
|
|
* @since 2021/7/28
|
|
|
|
|
*/
|
|
|
|
|
open class BaseObserve<T> {
|
|
|
|
|
var api: T? = null
|
|
|
|
|
|
|
|
|
|
constructor(clazz: Class<T>) {
|
|
|
|
|
api = RequestManager.create(clazz)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(clazz: Class<T>, interceptors: List<Interceptor>) {
|
|
|
|
|
api = RequestManager.create(clazz, interceptors)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化服务类
|
|
|
|
|
*/
|
|
|
|
@ -31,6 +42,9 @@ open class BaseObserve<T> {
|
|
|
|
|
return RequestManager.create(clazz)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化服务类
|
|
|
|
|
*/
|
|
|
|
|
fun initService(clazz: Class<T>, interceptors: List<Interceptor>): T {
|
|
|
|
|
return RequestManager.create(clazz, interceptors)
|
|
|
|
|
}
|
|
|
|
@ -40,7 +54,11 @@ open class BaseObserve<T> {
|
|
|
|
|
* @param observable 可订阅
|
|
|
|
|
* @param callBack 请求回调
|
|
|
|
|
*/
|
|
|
|
|
fun <R> observe(observable: Observable<R>, callBack: RequestCallBack<R>?) {
|
|
|
|
|
fun <R> observe(observable: Observable<R>?, callBack: RequestCallBack<R>?) {
|
|
|
|
|
if (observable == null) {
|
|
|
|
|
Logger.e("BaseObserve", "observe observable is null")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
observable
|
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
|
.unsubscribeOn(Schedulers.io())
|
|
|
|
|