mirror of https://github.com/tasks/tasks
Add MainActivity and TaskList event buses
parent
51609e54a9
commit
ce191d3325
@ -0,0 +1,28 @@
|
|||||||
|
package org.tasks.injection
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.components.ActivityRetainedComponent
|
||||||
|
import dagger.hilt.android.scopes.ActivityRetainedScoped
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import org.tasks.ui.MainActivityEventBus
|
||||||
|
import org.tasks.ui.TaskListEventBus
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(ActivityRetainedComponent::class)
|
||||||
|
class ActivityRetainedModule {
|
||||||
|
@Provides
|
||||||
|
@ActivityRetainedScoped
|
||||||
|
fun getTaskListBus(): TaskListEventBus = makeFlow()
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@ActivityRetainedScoped
|
||||||
|
fun getMainActivityBus(): MainActivityEventBus = makeFlow()
|
||||||
|
|
||||||
|
private fun <T> makeFlow() = MutableSharedFlow<T>(
|
||||||
|
extraBufferCapacity = 1,
|
||||||
|
onBufferOverflow = BufferOverflow.DROP_OLDEST
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package org.tasks.ui
|
||||||
|
|
||||||
|
import com.todoroo.astrid.data.Task
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
|
||||||
|
typealias MainActivityEventBus = MutableSharedFlow<MainActivityEvent>
|
||||||
|
|
||||||
|
sealed interface MainActivityEvent {
|
||||||
|
data class OpenTask(val task: Task) : MainActivityEvent
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
package org.tasks.ui
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
|
||||||
|
typealias TaskListEventBus = MutableSharedFlow<TaskListEvent>
|
||||||
|
|
||||||
|
sealed interface TaskListEvent {
|
||||||
|
data class TaskCreated(val uuid: String) : TaskListEvent
|
||||||
|
data class CalendarEventCreated(val title: String?, val uri: String) : TaskListEvent
|
||||||
|
}
|
Loading…
Reference in New Issue