2019-08-19 16:50:33 +02:00
|
|
|
package com.github.apognu.otter.utils
|
|
|
|
|
2019-10-22 20:03:52 +02:00
|
|
|
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
|
2020-06-14 14:59:50 +02:00
|
|
|
import com.google.android.exoplayer2.offline.Download
|
2020-06-20 22:10:13 +02:00
|
|
|
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 {
|
2020-07-09 23:01:35 +02:00
|
|
|
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()
|
2020-05-30 21:16:28 +02:00
|
|
|
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()
|
2020-09-01 21:06:00 +02:00
|
|
|
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
|
|
|
|
2020-05-29 23:42:03 +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()
|
2020-06-24 14:54:13 +02:00
|
|
|
|
|
|
|
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()
|
2020-06-01 16:31:58 +02:00
|
|
|
class TrackFinished(val track: Track?) : Event()
|
2020-06-02 18:50:46 +02:00
|
|
|
object RadioStarted : Event()
|
2020-06-13 19:34:57 +02:00
|
|
|
object ListingsChanged : Event()
|
2020-06-14 14:59:50 +02:00
|
|
|
class DownloadChanged(val download: Download) : Event()
|
2019-08-19 16:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
object EventBus {
|
|
|
|
fun send(event: Event) {
|
2020-06-20 22:10:13 +02:00
|
|
|
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) {
|
2020-06-25 01:26:15 +02:00
|
|
|
GlobalScope.launch(IO) {
|
2020-06-24 14:54:13 +02:00
|
|
|
Otter.get().commandBus.offer(command)
|
2019-08-19 16:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 14:54:13 +02:00
|
|
|
fun get() = Otter.get().commandBus.asFlow()
|
2019-08-19 16:50:33 +02:00
|
|
|
}
|
|
|
|
|