[抽出启动自驾、代码整理]
This commit is contained in:
yangyakun
2023-07-14 17:14:20 +08:00
parent 1e192b633a
commit 2b3d24b2b6
23 changed files with 614 additions and 1862 deletions

View File

@@ -1,11 +1,19 @@
package com.mogo.och.common.module.utils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import java.io.IOException
import java.util.concurrent.TimeUnit
import io.reactivex.functions.Consumer
object RxUtils {
private const val TAG = "RxUtils"
fun disposeSubscribe(subscribe: Disposable?) {
subscribe?.let {
if (!it.isDisposed) {
@@ -29,4 +37,41 @@ object RxUtils {
return false
}
// 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃
// The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the excTeption has nowhere to go to begin with
fun errCatch(){
RxJavaPlugins.setErrorHandler(Consumer { e ->
if (e is UndeliverableException) {
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "UndeliverableException")
return@Consumer
}
if (e is IOException) { //
// fine, irrelevant network problem or API that throws on cancellation
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "IOException")
return@Consumer
}
if (e is InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "InterruptedException")
return@Consumer
}
if (e is NullPointerException || e is IllegalArgumentException) {
// that's likely a bug in the application
CallerLogger.d(
SceneConstant.M_OCHCOMMON + TAG,
"NullPointerException or IllegalArgumentException"
)
Thread.currentThread().uncaughtExceptionHandler?.uncaughtException(Thread.currentThread(), e)
return@Consumer
}
if (e is IllegalStateException) {
// that's a bug in RxJava or in a custom operator
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "IllegalStateException")
Thread.currentThread().uncaughtExceptionHandler?.uncaughtException(Thread.currentThread(), e)
return@Consumer
}
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "Undeliverable exception")
})
}
}