diff --git a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt index 81a34dcdd..473d65eb8 100644 --- a/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt +++ b/base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt @@ -32,7 +32,6 @@ import androidx.core.os.bundleOf import androidx.core.text.parseAsHtml import androidx.core.text.toSpannable import androidx.databinding.DataBindingUtil -import androidx.databinding.ObservableField import androidx.databinding.ViewDataBinding import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity @@ -91,10 +90,6 @@ typealias MutableStringLiveData = MutableLiveData typealias MutableListLiveData = MutableLiveData> -typealias ObservableString = ObservableField - -typealias ObservableList = ObservableField> - typealias ParamMap = HashMap // ---------------------Any-------------------------------// @@ -107,7 +102,8 @@ inline val currentThreadName: String get() = Thread.currentThread().name inline val isMainThread: Boolean get() = Looper.getMainLooper() == Looper.myLooper() -fun unsafeLazy(initializer: () -> T): Lazy = lazy(LazyThreadSafetyMode.NONE, initializer) +fun unsafeLazy(initializer: () -> T): Lazy = + lazy(LazyThreadSafetyMode.NONE, initializer) fun MutableLiveData.asLiveData(): LiveData = this diff --git a/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonExtensions.kt b/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonExtensions.kt index 2961e6ec9..f99c561bd 100644 --- a/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonExtensions.kt +++ b/common/src/main/kotlin/io/goooler/demoapp/common/util/CommonExtensions.kt @@ -183,19 +183,19 @@ fun Number.formatMoney(isYuan: Boolean = false, trans2W: Boolean = false, scale: // ---------------------Rx-------------------------------// -fun Single.subscribeOnIoThread(): Single = subscribeOn(Schedulers.io()) +fun Single.subscribeOnIoThread(): Single = subscribeOn(Schedulers.io()) -fun Single.observeOnMainThread(): Single = observeOn(AndroidSchedulers.mainThread()) +fun Single.observeOnMainThread(): Single = observeOn(AndroidSchedulers.mainThread()) -fun Single.subscribeAndObserve(): Single = +fun Single.subscribeAndObserve(): Single = subscribeOnIoThread().observeOnMainThread() -fun Observable.subscribeOnIoThread(): Observable = subscribeOn(Schedulers.io()) +fun Observable.subscribeOnIoThread(): Observable = subscribeOn(Schedulers.io()) -fun Observable.observeOnMainThread(): Observable = +fun Observable.observeOnMainThread(): Observable = observeOn(AndroidSchedulers.mainThread()) -fun Observable.subscribeAndObserve(): Observable = +fun Observable.subscribeAndObserve(): Observable = subscribeOnIoThread().observeOnMainThread() // ---------------------Res-------------------------------// diff --git a/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservableObserver.kt b/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservableObserver.kt deleted file mode 100644 index 7de05ff24..000000000 --- a/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservableObserver.kt +++ /dev/null @@ -1,22 +0,0 @@ -package io.goooler.demoapp.test.network.exception - -import io.goooler.demoapp.common.network.BaseResponse -import io.reactivex.rxjava3.observers.DisposableObserver - -abstract class CustomObservableObserver : - DisposableObserver(), - CustomObserver { - - override fun onNext(t: T) { - if (t.code == 200) - onCustomSuccess(t) - else - onCustomError((t.message ?: t.code.toString()).toResponseException()) - } - - override fun onError(e: Throwable?) { - onCustomError(e.toResponseException()) - } - - override fun onComplete() {} -} diff --git a/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomSingleObserver.kt b/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservers.kt similarity index 55% rename from test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomSingleObserver.kt rename to test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservers.kt index eaade112c..ab14d0d85 100644 --- a/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomSingleObserver.kt +++ b/test/src/main/kotlin/io/goooler/demoapp/test/network/exception/CustomObservers.kt @@ -1,13 +1,21 @@ package io.goooler.demoapp.test.network.exception import io.goooler.demoapp.common.network.BaseResponse +import io.reactivex.rxjava3.observers.DisposableObserver import io.reactivex.rxjava3.observers.DisposableSingleObserver -abstract class CustomSingleObserver : - DisposableSingleObserver(), +sealed interface CustomObserver { + + fun onCustomSuccess(t: T) + + fun onCustomError(e: ResponseException) +} + +abstract class CustomObservableObserver : + DisposableObserver(), CustomObserver { - override fun onSuccess(t: T) { + override fun onNext(t: T) { if (t.code == 200) onCustomSuccess(t) else @@ -17,11 +25,22 @@ abstract class CustomSingleObserver : override fun onError(e: Throwable) { onCustomError(e.toResponseException()) } + + override fun onComplete() {} } -sealed interface CustomObserver { +abstract class CustomSingleObserver : + DisposableSingleObserver(), + CustomObserver { - fun onCustomSuccess(t: T) + override fun onSuccess(t: T) { + if (t.code == 200) + onCustomSuccess(t) + else + onCustomError((t.message ?: t.code.toString()).toResponseException()) + } - fun onCustomError(e: ResponseException) + override fun onError(e: Throwable) { + onCustomError(e.toResponseException()) + } }