[6.8.0]
[fix] [handle 改 Rxjava]
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
package com.mogo.och.common.module.manager.loop
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.util.Log
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.common.module.utils.RxUtils
|
||||
@@ -30,16 +26,9 @@ object BizLoopManager {
|
||||
|
||||
val frequentThread = HandlerThread("och_biz")
|
||||
|
||||
var handler:Handler
|
||||
|
||||
init {
|
||||
frequentThread.start()
|
||||
handler = object : Handler(frequentThread.looper) {
|
||||
override fun handleMessage(msg: Message) {
|
||||
super.handleMessage(msg)
|
||||
CallerLogger.d(SceneConstant.M_BUS_P + TAG, "2分钟没有触摸屏幕导致锁屏")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const val LOOP_LINE_2S = 2 * 1000L
|
||||
@@ -123,15 +112,6 @@ object BizLoopManager {
|
||||
}
|
||||
|
||||
|
||||
fun postDelayed(function:Runnable,delayMillis:Long){
|
||||
handler.postDelayed(function,delayMillis)
|
||||
|
||||
}
|
||||
|
||||
fun removeCallback(function:Runnable){
|
||||
handler.removeCallbacks(function)
|
||||
}
|
||||
|
||||
fun runInMainThread(function: Runnable){
|
||||
if (ThreadUtils.isMainThread()) {
|
||||
function.run()
|
||||
|
||||
@@ -6,17 +6,16 @@ import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.utils.RxUtils
|
||||
import com.mogo.och.weaknet.bean.request.ShuttleEventRequest
|
||||
import com.mogo.och.weaknet.bean.WaitUploadLine
|
||||
import com.mogo.och.weaknet.bean.WaitUploadTask
|
||||
import com.mogo.och.weaknet.repository.db.bean.EventDataBean
|
||||
import com.mogo.och.weaknet.repository.db.repository.EventDb
|
||||
import com.mogo.och.weaknet.repository.RepositoryManager
|
||||
import com.mogo.och.weaknet.repository.db.repository.SiteDb
|
||||
import com.mogo.och.weaknet.repository.db.repository.WriteOffDb
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@@ -26,20 +25,24 @@ object EventModel {
|
||||
|
||||
private val createDefault = BehaviorSubject.createDefault(isUpdating.get())
|
||||
|
||||
private var eventUpdateInfo: Disposable? = null
|
||||
|
||||
|
||||
fun load(){
|
||||
if (RepositoryManager.supportDb() || RepositoryManager.supportWriteOffDb()) {
|
||||
BizLoopManager.postDelayed(loopUpdateInfo,2*60*1000)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
eventUpdateInfo = RxUtils.createSubscribe(2*60*1000) {
|
||||
updateEvent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun release(){
|
||||
BizLoopManager.removeCallback(loopUpdateInfo)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
}
|
||||
|
||||
private val loopUpdateInfo = Runnable { updateEvent() }
|
||||
|
||||
fun notifySyn() {
|
||||
BizLoopManager.removeCallback(loopUpdateInfo)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
updateEvent()
|
||||
checkDbData()
|
||||
}
|
||||
@@ -65,7 +68,10 @@ object EventModel {
|
||||
OchChainLogManager.writeChainLogDb("上报event","没有数据需要上报${Thread.currentThread().name}")
|
||||
isUpdating.set(false)
|
||||
createDefault.onNext(isUpdating.get())
|
||||
BizLoopManager.postDelayed(loopUpdateInfo,2*60*1000)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
eventUpdateInfo = RxUtils.createSubscribe(2*60*1000) {
|
||||
updateEvent()
|
||||
}
|
||||
return@submit
|
||||
}
|
||||
OchChainLogManager.writeChainLogDb("上报event","开始上报:${Thread.currentThread().name}")
|
||||
@@ -104,21 +110,30 @@ object EventModel {
|
||||
return
|
||||
}
|
||||
|
||||
BizLoopManager.postDelayed(loopUpdateInfo,2*60*1000)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
eventUpdateInfo = RxUtils.createSubscribe(2*60*1000) {
|
||||
updateEvent()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, msg: String?) {
|
||||
isUpdating.set(false)
|
||||
createDefault.onNext(isUpdating.get())
|
||||
OchChainLogManager.writeChainLogDb("上报event失败","$transformDb2Net ${Thread.currentThread().name}")
|
||||
BizLoopManager.postDelayed(loopUpdateInfo,10*1000)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
eventUpdateInfo = RxUtils.createSubscribe(10*1000) {
|
||||
updateEvent()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
isUpdating.set(false)
|
||||
createDefault.onNext(isUpdating.get())
|
||||
OchChainLogManager.writeChainLogDb("上报event失败","$transformDb2Net ${Thread.currentThread().name}")
|
||||
BizLoopManager.postDelayed(loopUpdateInfo,10*1000)
|
||||
RxUtils.disposeSubscribe(eventUpdateInfo)
|
||||
eventUpdateInfo = RxUtils.createSubscribe(10*1000) {
|
||||
updateEvent()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -73,9 +73,10 @@ object LineModel {
|
||||
|
||||
|
||||
private val isRequesting = AtomicBoolean(false)
|
||||
private val loopQueryInfo = Runnable { queryCarExecutableTaskList(true) }
|
||||
private var startTaskDisposable:Disposable?=null
|
||||
|
||||
private var queryCarInfo: Disposable? = null
|
||||
|
||||
// 当前站点
|
||||
@JvmStatic
|
||||
var startStationIndex: Int = 0 //A->B 此处值是A站点索引
|
||||
@@ -85,7 +86,7 @@ object LineModel {
|
||||
CallerLogger.d(TAG,"init")
|
||||
mContext = AbsMogoApplication.getApp()
|
||||
EventModel.load()
|
||||
loopQueryInfo.run()
|
||||
queryCarExecutableTaskList(true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -95,7 +96,7 @@ object LineModel {
|
||||
mContext = null
|
||||
EventModel.release()
|
||||
mBusLinesCallbackMap.clear()
|
||||
BizLoopManager.removeCallback(loopQueryInfo)
|
||||
RxUtils.disposeSubscribe(queryCarInfo)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -109,7 +110,7 @@ object LineModel {
|
||||
}
|
||||
|
||||
fun refreshTask() {
|
||||
BizLoopManager.removeCallback(loopQueryInfo)
|
||||
RxUtils.disposeSubscribe(queryCarInfo)
|
||||
queryCarExecutableTaskList(false)
|
||||
}
|
||||
|
||||
@@ -132,7 +133,10 @@ object LineModel {
|
||||
override fun onSuccess(data: CarExecutableTaskResponse) {
|
||||
isRequesting.set(false)
|
||||
CallerLogger.d(TAG,"同步数据成功")
|
||||
BizLoopManager.postDelayed(loopQueryInfo, 60_000)
|
||||
RxUtils.disposeSubscribe(queryCarInfo)
|
||||
queryCarInfo = RxUtils.createSubscribe(60_000) {
|
||||
queryCarExecutableTaskList(true)
|
||||
}
|
||||
// 第一次过滤 请求返回值的md5
|
||||
val currentRequest = DigestUtils.md5Hex(data.data.toString())
|
||||
val lastChangeMd5 = SharedPrefsMgr.getInstance().getString(EXECUTABLECHANGEMD5)
|
||||
@@ -168,7 +172,10 @@ object LineModel {
|
||||
override fun onError() {
|
||||
isRequesting.set(false)
|
||||
CallerLogger.d(TAG,"同步数据失败 onError")
|
||||
BizLoopManager.postDelayed(loopQueryInfo, 60_000)
|
||||
RxUtils.disposeSubscribe(queryCarInfo)
|
||||
queryCarInfo = RxUtils.createSubscribe(60_000) {
|
||||
queryCarExecutableTaskList(true)
|
||||
}
|
||||
if (!isBackground) {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(ResourcesUtils.getString(R.string.network_error_tip))
|
||||
@@ -181,7 +188,10 @@ object LineModel {
|
||||
override fun onFail(code: Int, failMsg: String) {
|
||||
isRequesting.set(false)
|
||||
CallerLogger.d(TAG,"同步数据失败 onFail")
|
||||
BizLoopManager.postDelayed(loopQueryInfo, 60_000)
|
||||
RxUtils.disposeSubscribe(queryCarInfo)
|
||||
queryCarInfo = RxUtils.createSubscribe(60_000) {
|
||||
queryCarExecutableTaskList(true)
|
||||
}
|
||||
if (!isBackground) {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort("网络异常,请稍后重试")
|
||||
|
||||
Reference in New Issue
Block a user