[6.6.0]
[fea] [线路和任务]
This commit is contained in:
@@ -141,4 +141,12 @@ object BizLoopManager {
|
||||
}
|
||||
}
|
||||
|
||||
fun runInIoThread(runable:Runnable){
|
||||
if(ThreadUtils.isMainThread()){
|
||||
ThreadUtils.getIoPool().submit(runable)
|
||||
}else{
|
||||
runable.run()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.mogo.och.common.module.network
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.utils.CallerLoggerUtils.flavorTag
|
||||
import com.mogo.och.weaknet.repository.db.exception.NetDataException
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableSource
|
||||
import io.reactivex.functions.Function
|
||||
|
||||
|
||||
class OchCommonNet<T:BaseData>(val apiName:String, val writeLog:Boolean) : Function<T?, ObservableSource<T?>> {
|
||||
|
||||
companion object {
|
||||
const val TAG = "CommonNet"
|
||||
}
|
||||
|
||||
private var tag:Long = System.currentTimeMillis()
|
||||
|
||||
|
||||
init {
|
||||
CallerLogger.e("$flavorTag${OchCommonSubscribeImpl.TAG}", "$apiName: 去请求()")
|
||||
if(writeLog) {
|
||||
OchChainLogManager.writeChainLogNet(false,"接口:${apiName}", "去请求_${tag}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun apply(baseData: T): ObservableSource<T?> {
|
||||
if (baseData.code != 0 && baseData.code != 200) {
|
||||
onError(baseData.msg,baseData.code)
|
||||
return Observable.error(NetDataException(baseData.code,baseData.msg))
|
||||
} else {
|
||||
onSuccess(baseData)
|
||||
return Observable.just(baseData)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSuccess(o: T) {
|
||||
CallerLogger.d("$flavorTag${TAG}", "$apiName: onSuccess() ${o.msg}")
|
||||
if(writeLog) {
|
||||
OchChainLogManager.writeChainLogNet(false,"接口:${apiName}", "请求成功:${o}_${tag}")
|
||||
}
|
||||
}
|
||||
|
||||
fun onError(message: String, code: Int) {
|
||||
CallerLogger.e("$flavorTag${TAG}", "$apiName: onError() code = $code; message = $message")
|
||||
if(writeLog) {
|
||||
OchChainLogManager.writeChainLogNet(
|
||||
true,
|
||||
"接口:${apiName}",
|
||||
"请求失败: onError() code = $code; message = $message\" _${tag}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mogo.och.weaknet.repository.db.transform
|
||||
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableSource
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.Function
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
fun <T,V> Observable<T>.transform4DataBase(transfor:Function<T, ObservableSource<V>>): Observable<V> {
|
||||
return flatMap(transfor)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mogo.och.weaknet.repository.db.exception
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.common.module.R
|
||||
import com.mogo.och.common.module.utils.ResourcesUtils
|
||||
|
||||
class NetDataException: RuntimeException {
|
||||
constructor() : super()
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(code:Int,message: String?):super("${code}_${message}"){
|
||||
if (!NetworkUtils.isConnected(AbsMogoApplication.getApp())) {
|
||||
ToastUtils.showShort(ResourcesUtils.getString(R.string.network_error_tip));
|
||||
} else {
|
||||
ToastUtils.showShort(ResourcesUtils.getString(R.string.request_error_tip));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user