https://github.com/werbhelius/EventBusKotlin
A Simple EventBus
https://github.com/werbhelius/EventBusKotlin
Last synced: 3 months ago
JSON representation
A Simple EventBus
- Host: GitHub
- URL: https://github.com/werbhelius/EventBusKotlin
- Owner: werbhelius
- Created: 2017-08-29T06:53:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-25T02:21:54.000Z (over 8 years ago)
- Last Synced: 2025-04-09T21:47:16.690Z (over 1 year ago)
- Language: Kotlin
- Homepage: https://t.me/android_with_kotlin
- Size: 225 KB
- Stars: 44
- Watchers: 1
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-java - EventBusKotlin
README
# EventBusKotlin
用 Kotlin 简单实现了一个 EventBus
[如何自己实现一个 EventBus](https://github.com/Werb/EventBusKotlin/wiki/%E5%A6%82%E4%BD%95%E8%87%AA%E5%B7%B1%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA-EventBus)
[ ](https://bintray.com/werbhelius/maven/eventbuskotlin/_latestVersion)
## Dependency
```gradle
compile 'com.werb.eventbuskotlin:eventbuskotlin:0.2.0'
```
or
```gradle
implementation 'com.werb.eventbuskotlin:eventbuskotlin:0.2.0'
```
#### 注册和取消注册
```kotlin
EventBus.register(this)
EventBus.unRegister(this)
```
#### 实现事件 Event 实体类(实现 IEvent 接口)
```kotlin
class XXXXEvent: IEvent
```
#### 发送事件
```kotlin
EventBus.post(XXXEvent())
```
#### 利用注解实现事件订阅执行方法
* tag 用于细化区分事件
* mode 方法执行线程
```kotlin
@Subscriber(tag = DEFAULT_TAG, mode = ThreadMode.MAIN)
private fun change2(event: XXXEvent){
textView2.text = "今天星期五"
textView2.setTextColor(resources.getColor(R.color.colorAccent))
println("myActivity - 200")
}
```