wuchangfeng / EventBusKotlin

A Simple EventBus

Home Page:https://t.me/android_with_kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EventBusKotlin

用 Kotlin 简单实现了一个 EventBus

如何自己实现一个 EventBus

Download

Dependency

compile 'com.werb.eventbuskotlin:eventbuskotlin:0.2.0'

or

implementation 'com.werb.eventbuskotlin:eventbuskotlin:0.2.0'

注册和取消注册

EventBus.register(this)
EventBus.unRegister(this)

实现事件 Event 实体类(实现 IEvent 接口)

class XXXXEvent: IEvent

发送事件

EventBus.post(XXXEvent())

利用注解实现事件订阅执行方法

  • tag 用于细化区分事件
  • mode 方法执行线程
@Subscriber(tag = DEFAULT_TAG, mode = ThreadMode.MAIN)
    private fun change2(event: XXXEvent){
        textView2.text = "今天星期五"
        textView2.setTextColor(resources.getColor(R.color.colorAccent))

        println("myActivity - 200")
    }

About

A Simple EventBus

https://t.me/android_with_kotlin


Languages

Language:Kotlin 96.1%Language:Java 3.9%