2018-05-27 10:22:12 +02:00
|
|
|
package com.keylesspalace.tusky.appstore
|
|
|
|
|
2023-09-09 21:11:23 +02:00
|
|
|
import io.reactivex.rxjava3.core.Observable
|
|
|
|
import io.reactivex.rxjava3.subjects.PublishSubject
|
2023-03-18 10:11:47 +01:00
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
2022-01-23 20:24:55 +01:00
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Singleton
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
interface Event
|
|
|
|
|
2022-01-23 20:24:55 +01:00
|
|
|
@Singleton
|
|
|
|
class EventHub @Inject constructor() {
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2023-03-18 10:11:47 +01:00
|
|
|
private val sharedEventFlow: MutableSharedFlow<Event> = MutableSharedFlow()
|
|
|
|
val events: Flow<Event> = sharedEventFlow
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2023-09-09 21:11:23 +02:00
|
|
|
// TODO remove this old stuff as soon as NotificationsFragment is Kotlin
|
|
|
|
private val eventsSubject = PublishSubject.create<Event>()
|
|
|
|
val eventsObservable: Observable<Event> = eventsSubject
|
|
|
|
|
2023-03-18 10:11:47 +01:00
|
|
|
suspend fun dispatch(event: Event) {
|
|
|
|
sharedEventFlow.emit(event)
|
2023-09-09 21:11:23 +02:00
|
|
|
eventsSubject.onNext(event)
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
2023-09-11 22:19:34 +02:00
|
|
|
|
|
|
|
fun dispatchOld(event: Event) {
|
|
|
|
eventsSubject.onNext(event)
|
|
|
|
}
|
2021-06-28 21:13:24 +02:00
|
|
|
}
|