Otter-App-Android-Funkwhale/app/src/main/java/com/github/apognu/otter/utils/Bus.kt

72 lines
2.0 KiB
Kotlin
Raw Normal View History

2019-08-19 16:50:33 +02:00
package com.github.apognu.otter.utils
import com.github.apognu.otter.Otter
2020-07-13 23:32:42 +02:00
import com.github.apognu.otter.models.dao.RadioEntity
import com.github.apognu.otter.models.domain.Track
import com.google.android.exoplayer2.offline.Download
import kotlinx.coroutines.Dispatchers.IO
2019-08-19 16:50:33 +02:00
import kotlinx.coroutines.GlobalScope
2019-10-31 16:17:37 +01:00
import kotlinx.coroutines.flow.asFlow
2019-08-19 16:50:33 +02:00
import kotlinx.coroutines.launch
sealed class Command {
class StartService(val command: Command) : Command()
2019-08-19 16:50:33 +02:00
object RefreshService : Command()
object ToggleState : Command()
class SetState(val state: Boolean) : Command()
object NextTrack : Command()
object PreviousTrack : Command()
class Seek(val progress: Int) : Command()
class AddToQueue(val tracks: List<Track>) : Command()
class PlayNext(val track: Track) : Command()
class ReplaceQueue(val queue: List<Track>, val fromRadio: Boolean = false) : Command()
2019-08-19 16:50:33 +02:00
class RemoveFromQueue(val track: Track) : Command()
class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command()
2019-10-30 22:06:57 +01:00
object ClearQueue : Command()
object ShuffleQueue : Command()
2020-07-13 23:32:42 +02:00
class PlayRadio(val radio: RadioEntity) : Command()
2019-08-19 16:50:33 +02:00
class SetRepeatMode(val mode: Int) : Command()
2019-08-19 16:50:33 +02:00
class PlayTrack(val index: Int) : Command()
2020-06-10 16:25:20 +02:00
class PinTrack(val track: Track) : Command()
2020-06-13 16:45:58 +02:00
class PinTracks(val tracks: List<Track>) : Command()
class RefreshTrack(val track: Track?) : Command()
2019-08-19 16:50:33 +02:00
}
sealed class Event {
object LogOut : Event()
class PlaybackError(val message: String) : Event()
object PlaybackStopped : Event()
class TrackFinished(val track: Track?) : Event()
object RadioStarted : Event()
object ListingsChanged : Event()
class DownloadChanged(val download: Download) : Event()
2019-08-19 16:50:33 +02:00
}
object EventBus {
fun send(event: Event) {
GlobalScope.launch(IO) {
Otter.get().eventBus.offer(event)
2019-08-19 16:50:33 +02:00
}
}
2019-10-31 16:17:37 +01:00
fun get() = Otter.get().eventBus.asFlow()
2019-08-19 16:50:33 +02:00
}
object CommandBus {
fun send(command: Command) {
GlobalScope.launch(IO) {
Otter.get().commandBus.offer(command)
2019-08-19 16:50:33 +02:00
}
}
fun get() = Otter.get().commandBus.asFlow()
2019-08-19 16:50:33 +02:00
}