package com.github.apognu.otter.viewmodels import androidx.lifecycle.* import com.github.apognu.otter.Otter import com.github.apognu.otter.models.domain.Track class PlayerStateViewModel private constructor() : ViewModel() { companion object { private lateinit var instance: PlayerStateViewModel fun get(): PlayerStateViewModel { instance = if (::instance.isInitialized) instance else PlayerStateViewModel() return instance } } val isPlaying: MutableLiveData by lazy { MutableLiveData() } val isBuffering: MutableLiveData by lazy { MutableLiveData() } val position: MutableLiveData> by lazy { MutableLiveData>() } val _track: MutableLiveData by lazy { MutableLiveData() } val track: LiveData by lazy { Transformations.switchMap(_track) { if (it == null) { return@switchMap null } Otter.get().database.tracks().getDecorated(it.id).map { Track.fromDecoratedEntity(it) } } } }