From fa23d1de24f4b8ece586e4e486535ef1c7110b76 Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Thu, 1 Aug 2019 11:31:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/BookshelfFragment.kt | 5 +- .../app/ui/sourcedebug/SourceDebugActivity.kt | 2 +- .../java/io/legado/app/utils/EventBusKt.kt | 54 ++++++++++++++++--- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index fece79af1..ec4b22c5c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -16,7 +16,10 @@ import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup -import io.legado.app.lib.dialogs.* +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.bookshelf.BookshelfActivity diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt index 644843369..a6345fe13 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt @@ -65,7 +65,7 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s } override fun observeLiveBus() { - observeEvent(Bus.SOURCE_DEBUG_LOG){ + observeEvent(Bus.SOURCE_DEBUG_LOG) { adapter.addItem(it.obj as String) if (it.what == -1 || it.what == 1000) { rotate_loading.hide() 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 116540e75..fa6904ea3 100644 --- a/app/src/main/java/io/legado/app/utils/EventBusKt.kt +++ b/app/src/main/java/io/legado/app/utils/EventBusKt.kt @@ -10,29 +10,71 @@ inline fun eventObservable(tag: String): LiveEventBus.Observable } inline fun postEvent(tag: String, event: EVENT) { - return LiveEventBus.get().with(tag, EVENT::class.java).post(event) + LiveEventBus.get().with(tag, EVENT::class.java).post(event) } inline fun AppCompatActivity.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { - return eventObservable(tag).observe(this, Observer { + eventObservable(tag).observe(this, Observer { observer(it) }) } +/** + * 只能观察相同类型的事件,可用EventMessage + */ +inline fun AppCompatActivity.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) { + val o = Observer { + observer(it) + } + tags.forEach { + eventObservable(it).observe(this, o) + } +} + inline fun AppCompatActivity.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { - return eventObservable(tag).observeSticky(this, Observer { + eventObservable(tag).observeSticky(this, Observer { observer(it) }) } +inline fun AppCompatActivity.observeEventsSticky( + vararg tags: String, + crossinline observer: (EVENT) -> Unit +) { + val o = Observer { + observer(it) + } + tags.forEach { + eventObservable(it).observeSticky(this, o) + } +} + inline fun Fragment.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { - return eventObservable(tag).observe(this, Observer { + eventObservable(tag).observe(this, Observer { observer(it) }) } +inline fun Fragment.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) { + val o = Observer { + observer(it) + } + tags.forEach { + eventObservable(it).observe(this, o) + } +} + inline fun Fragment.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { - return eventObservable(tag).observeSticky(this, Observer { + eventObservable(tag).observeSticky(this, Observer { observer(it) }) -} \ No newline at end of file +} + +inline fun Fragment.observeEventsSticky(vararg tags: String, crossinline observer: (EVENT) -> Unit) { + val o = Observer { + observer(it) + } + tags.forEach { + eventObservable(it).observeSticky(this, o) + } +}