From 64dc125897c8fc676ae32cd0c113de1ba40f07ca Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Fri, 2 Aug 2019 09:36:49 +0800 Subject: [PATCH] update --- .../java/io/legado/app/utils/EventBusKt.kt | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/EventBusKt.kt b/app/src/main/java/io/legado/app/utils/EventBusKt.kt index fa6904ea3..82c3f0f30 100644 --- a/app/src/main/java/io/legado/app/utils/EventBusKt.kt +++ b/app/src/main/java/io/legado/app/utils/EventBusKt.kt @@ -13,16 +13,10 @@ inline fun postEvent(tag: String, event: EVENT) { LiveEventBus.get().with(tag, EVENT::class.java).post(event) } -inline fun AppCompatActivity.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { - eventObservable(tag).observe(this, Observer { - observer(it) - }) -} - -/** - * 只能观察相同类型的事件,可用EventMessage - */ -inline fun AppCompatActivity.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) { +inline fun AppCompatActivity.observeEvent( + vararg tags: String, + noinline observer: (EVENT) -> Unit +) { val o = Observer { observer(it) } @@ -31,15 +25,10 @@ inline fun AppCompatActivity.observeEvents(vararg tags: String, } } -inline fun AppCompatActivity.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { - eventObservable(tag).observeSticky(this, Observer { - observer(it) - }) -} -inline fun AppCompatActivity.observeEventsSticky( +inline fun AppCompatActivity.observeEventSticky( vararg tags: String, - crossinline observer: (EVENT) -> Unit + noinline observer: (EVENT) -> Unit ) { val o = Observer { observer(it) @@ -49,13 +38,10 @@ inline fun AppCompatActivity.observeEventsSticky( } } -inline fun Fragment.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { - eventObservable(tag).observe(this, Observer { - observer(it) - }) -} - -inline fun Fragment.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) { +inline fun Fragment.observeEvent( + vararg tags: String, + noinline observer: (EVENT) -> Unit +) { val o = Observer { observer(it) } @@ -64,13 +50,10 @@ inline fun Fragment.observeEvents(vararg tags: String, crossinli } } -inline fun Fragment.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { - eventObservable(tag).observeSticky(this, Observer { - observer(it) - }) -} - -inline fun Fragment.observeEventsSticky(vararg tags: String, crossinline observer: (EVENT) -> Unit) { +inline fun Fragment.observeEventSticky( + vararg tags: String, + noinline observer: (EVENT) -> Unit +) { val o = Observer { observer(it) } @@ -78,3 +61,4 @@ inline fun Fragment.observeEventsSticky(vararg tags: String, cro eventObservable(it).observeSticky(this, o) } } +