mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 12:39:54 +00:00
Cleaned up PlaybackService interface to expose the currently playing
ITrack, instead of the awkward getPlayingString() and getPlayingLong() methods.
This commit is contained in:
parent
c62daae9d5
commit
5c71000bcc
@ -18,7 +18,7 @@ import android.widget.CompoundButton
|
|||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import io.casey.musikcube.remote.data.IDataProvider
|
import io.casey.musikcube.remote.data.IDataProvider
|
||||||
import io.casey.musikcube.remote.playback.PlaybackService
|
import io.casey.musikcube.remote.playback.IPlaybackService
|
||||||
import io.casey.musikcube.remote.playback.PlaybackState
|
import io.casey.musikcube.remote.playback.PlaybackState
|
||||||
import io.casey.musikcube.remote.playback.RepeatMode
|
import io.casey.musikcube.remote.playback.RepeatMode
|
||||||
import io.casey.musikcube.remote.ui.activity.*
|
import io.casey.musikcube.remote.ui.activity.*
|
||||||
@ -36,7 +36,7 @@ import io.casey.musikcube.remote.websocket.WebSocketService
|
|||||||
class MainActivity : WebSocketActivityBase() {
|
class MainActivity : WebSocketActivityBase() {
|
||||||
private val handler = Handler()
|
private val handler = Handler()
|
||||||
private lateinit var prefs: SharedPreferences
|
private lateinit var prefs: SharedPreferences
|
||||||
private var playback: PlaybackService? = null
|
private var playback: IPlaybackService? = null
|
||||||
|
|
||||||
private var updateCheck: UpdateCheck = UpdateCheck()
|
private var updateCheck: UpdateCheck = UpdateCheck()
|
||||||
private var seekbarValue = -1
|
private var seekbarValue = -1
|
||||||
|
@ -2,6 +2,6 @@ package io.casey.musikcube.remote.data
|
|||||||
|
|
||||||
interface ICategoryValue {
|
interface ICategoryValue {
|
||||||
val id: Long
|
val id: Long
|
||||||
val name: String
|
val value: String
|
||||||
val type: String
|
val type: String
|
||||||
}
|
}
|
@ -17,7 +17,6 @@ interface ITrack {
|
|||||||
val artist: String
|
val artist: String
|
||||||
val artistId: Long
|
val artistId: Long
|
||||||
|
|
||||||
fun getString(key: String, default: String): String
|
fun getCategoryId(categoryType: String): Long
|
||||||
fun getLong(key: String, default: Long): Long
|
|
||||||
fun toJson(): JSONObject
|
fun toJson(): JSONObject
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import org.json.JSONObject
|
|||||||
|
|
||||||
class RemoteAlbum(val json: JSONObject) : IAlbum {
|
class RemoteAlbum(val json: JSONObject) : IAlbum {
|
||||||
override val id: Long get() = json.optLong(Metadata.Album.ID, -1)
|
override val id: Long get() = json.optLong(Metadata.Album.ID, -1)
|
||||||
override val name: String get() = json.optString(Metadata.Album.TITLE, "<unknown>")
|
override val value: String get() = json.optString(Metadata.Album.TITLE, "")
|
||||||
override val albumArtist: String get() = json.optString(Metadata.Album.ALBUM_ARTIST, "<unknown>")
|
override val albumArtist: String get() = json.optString(Metadata.Album.ALBUM_ARTIST, "")
|
||||||
override val albumArtistId: Long get() = json.optLong(Metadata.Album.ALBUM_ARTIST_ID, -1)
|
override val albumArtistId: Long get() = json.optLong(Metadata.Album.ALBUM_ARTIST_ID, -1)
|
||||||
override val type: String get() = Messages.Category.ALBUM
|
override val type: String get() = Messages.Category.ALBUM
|
||||||
}
|
}
|
@ -6,8 +6,8 @@ import org.json.JSONObject
|
|||||||
|
|
||||||
class RemoteAlbumArtist(private val json: JSONObject) : IAlbumArtist {
|
class RemoteAlbumArtist(private val json: JSONObject) : IAlbumArtist {
|
||||||
override val id: Long
|
override val id: Long
|
||||||
get() = json.optLong(Messages.Key.ID)
|
get() = json.optLong(Messages.Key.ID, -1)
|
||||||
override val name: String
|
override val value: String
|
||||||
get() = json.optString(Messages.Key.VALUE, "")
|
get() = json.optString(Messages.Key.VALUE, "")
|
||||||
override val type: String
|
override val type: String
|
||||||
get() = Messages.Category.ALBUM_ARTIST
|
get() = Messages.Category.ALBUM_ARTIST
|
||||||
|
@ -8,8 +8,8 @@ class RemoteCategoryValue(private val categoryType: String,
|
|||||||
private val json: JSONObject) : ICategoryValue
|
private val json: JSONObject) : ICategoryValue
|
||||||
{
|
{
|
||||||
override val id: Long
|
override val id: Long
|
||||||
get() = json.optLong(Messages.Key.ID)
|
get() = json.optLong(Messages.Key.ID, -1)
|
||||||
override val name: String
|
override val value: String
|
||||||
get() = json.optString(Messages.Key.VALUE, "")
|
get() = json.optString(Messages.Key.VALUE, "")
|
||||||
override val type: String
|
override val type: String
|
||||||
get() = categoryType
|
get() = categoryType
|
||||||
|
@ -2,6 +2,7 @@ package io.casey.musikcube.remote.data.impl.remote
|
|||||||
|
|
||||||
import io.casey.musikcube.remote.data.ITrack
|
import io.casey.musikcube.remote.data.ITrack
|
||||||
import io.casey.musikcube.remote.playback.Metadata
|
import io.casey.musikcube.remote.playback.Metadata
|
||||||
|
import io.casey.musikcube.remote.websocket.Messages
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
class RemoteTrack(val json: JSONObject) : ITrack {
|
class RemoteTrack(val json: JSONObject) : ITrack {
|
||||||
@ -12,35 +13,44 @@ class RemoteTrack(val json: JSONObject) : ITrack {
|
|||||||
override val uri: String
|
override val uri: String
|
||||||
get() = json.optString(Metadata.Track.URI, "")
|
get() = json.optString(Metadata.Track.URI, "")
|
||||||
override val title: String
|
override val title: String
|
||||||
get() = json.optString(Metadata.Track.TITLE, "<no name>")
|
get() = json.optString(Metadata.Track.TITLE, "")
|
||||||
override val album: String
|
override val album: String
|
||||||
get() = json.optString(Metadata.Track.ALBUM, "<no album>")
|
get() = json.optString(Metadata.Track.ALBUM, "")
|
||||||
override val albumId: Long
|
override val albumId: Long
|
||||||
get() = json.optLong(Metadata.Track.ALBUM_ID, -1)
|
get() = json.optLong(Metadata.Track.ALBUM_ID, -1)
|
||||||
override val albumArtist: String
|
override val albumArtist: String
|
||||||
get() = json.optString(Metadata.Track.ALBUM_ARTIST, "<no album artist>")
|
get() = json.optString(Metadata.Track.ALBUM_ARTIST, "")
|
||||||
override val albumArtistId: Long
|
override val albumArtistId: Long
|
||||||
get() = json.optLong(Metadata.Track.ALBUM_ARTIST_ID, -1)
|
get() = json.optLong(Metadata.Track.ALBUM_ARTIST_ID, -1)
|
||||||
override val genre: String
|
override val genre: String
|
||||||
get() = json.optString(Metadata.Track.GENRE, "<no genre>")
|
get() = json.optString(Metadata.Track.GENRE, "")
|
||||||
override val trackNum: Int
|
override val trackNum: Int
|
||||||
get() = json.optInt(Metadata.Track.TRACK_NUM, 0)
|
get() = json.optInt(Metadata.Track.TRACK_NUM, 0)
|
||||||
override val genreId: Long
|
override val genreId: Long
|
||||||
get() = json.optLong(Metadata.Track.GENRE_ID, -1)
|
get() = json.optLong(Metadata.Track.GENRE_ID, -1)
|
||||||
override val artist: String
|
override val artist: String
|
||||||
get() = json.optString(Metadata.Track.ARTIST, "<no artist>")
|
get() = json.optString(Metadata.Track.ARTIST, "")
|
||||||
override val artistId: Long
|
override val artistId: Long
|
||||||
get() = json.optLong(Metadata.Track.ARTIST_ID, -1)
|
get() = json.optLong(Metadata.Track.ARTIST_ID, -1)
|
||||||
|
|
||||||
override fun getString(key: String, default: String): String {
|
override fun getCategoryId(categoryType: String): Long {
|
||||||
return json.optString(key, default)
|
val idKey = CATEGORY_NAME_TO_ID[categoryType]
|
||||||
}
|
if (idKey != null && idKey.isNotEmpty()) {
|
||||||
|
return json.optLong(idKey, -1L)
|
||||||
override fun getLong(key: String, default: Long): Long {
|
}
|
||||||
return json.optLong(key, default)
|
return -1L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toJson(): JSONObject {
|
override fun toJson(): JSONObject {
|
||||||
return JSONObject(json.toString())
|
return JSONObject(json.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val CATEGORY_NAME_TO_ID: Map<String, String> = mapOf(
|
||||||
|
Messages.Category.ALBUM_ARTIST to Metadata.Track.ALBUM_ARTIST_ID,
|
||||||
|
Messages.Category.GENRE to Metadata.Track.GENRE_ID,
|
||||||
|
Messages.Category.ARTIST to Metadata.Track.ARTIST_ID,
|
||||||
|
Messages.Category.ALBUM to Metadata.Track.ALBUM_ID,
|
||||||
|
Messages.Category.PLAYLISTS to Metadata.Track.ALBUM_ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package io.casey.musikcube.remote.playback
|
package io.casey.musikcube.remote.playback
|
||||||
|
|
||||||
|
import io.casey.musikcube.remote.data.ITrack
|
||||||
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
||||||
|
|
||||||
interface PlaybackService {
|
interface IPlaybackService {
|
||||||
fun connect(listener: () -> Unit)
|
fun connect(listener: () -> Unit)
|
||||||
fun disconnect(listener: () -> Unit)
|
fun disconnect(listener: () -> Unit)
|
||||||
|
|
||||||
@ -46,6 +47,5 @@ interface PlaybackService {
|
|||||||
|
|
||||||
val playlistQueryFactory: TrackListSlidingWindow.QueryFactory
|
val playlistQueryFactory: TrackListSlidingWindow.QueryFactory
|
||||||
|
|
||||||
fun getTrackString(key: String, defaultValue: String): String
|
val playingTrack: ITrack
|
||||||
fun getTrackLong(key: String, defaultValue: Long): Long
|
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ object PlaybackServiceFactory {
|
|||||||
private var remote: RemotePlaybackService? = null
|
private var remote: RemotePlaybackService? = null
|
||||||
private var prefs: SharedPreferences? = null
|
private var prefs: SharedPreferences? = null
|
||||||
|
|
||||||
@Synchronized fun instance(context: Context): PlaybackService {
|
@Synchronized fun instance(context: Context): IPlaybackService {
|
||||||
init(context)
|
init(context)
|
||||||
|
|
||||||
if (prefs!!.getBoolean(Prefs.Key.STREAMING_PLAYBACK, Prefs.Default.STREAMING_PLAYBACK)) {
|
if (prefs!!.getBoolean(Prefs.Key.STREAMING_PLAYBACK, Prefs.Default.STREAMING_PLAYBACK)) {
|
||||||
|
@ -4,6 +4,7 @@ import android.os.Handler
|
|||||||
import io.casey.musikcube.remote.Application
|
import io.casey.musikcube.remote.Application
|
||||||
import io.casey.musikcube.remote.data.IDataProvider
|
import io.casey.musikcube.remote.data.IDataProvider
|
||||||
import io.casey.musikcube.remote.data.ITrack
|
import io.casey.musikcube.remote.data.ITrack
|
||||||
|
import io.casey.musikcube.remote.data.impl.remote.RemoteTrack
|
||||||
import io.casey.musikcube.remote.injection.DaggerServiceComponent
|
import io.casey.musikcube.remote.injection.DaggerServiceComponent
|
||||||
import io.casey.musikcube.remote.injection.DataModule
|
import io.casey.musikcube.remote.injection.DataModule
|
||||||
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
||||||
@ -15,7 +16,7 @@ import org.json.JSONObject
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RemotePlaybackService : PlaybackService {
|
class RemotePlaybackService : IPlaybackService {
|
||||||
private interface Key {
|
private interface Key {
|
||||||
companion object {
|
companion object {
|
||||||
val STATE = "state"
|
val STATE = "state"
|
||||||
@ -288,19 +289,8 @@ class RemotePlaybackService : PlaybackService {
|
|||||||
override val bufferedTime: Double
|
override val bufferedTime: Double
|
||||||
get() = duration
|
get() = duration
|
||||||
|
|
||||||
override fun getTrackString(key: String, defaultValue: String): String {
|
override val playingTrack: ITrack
|
||||||
if (track.has(key)) {
|
get() = RemoteTrack(track)
|
||||||
return track.optString(key, defaultValue)
|
|
||||||
}
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTrackLong(key: String, defaultValue: Long): Long {
|
|
||||||
if (track.has(key)) {
|
|
||||||
return track.optLong(key, defaultValue)
|
|
||||||
}
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun reset() {
|
private fun reset() {
|
||||||
playbackState = PlaybackState.Stopped
|
playbackState = PlaybackState.Stopped
|
||||||
|
@ -12,6 +12,7 @@ import io.casey.musikcube.remote.Application
|
|||||||
import io.casey.musikcube.remote.R
|
import io.casey.musikcube.remote.R
|
||||||
import io.casey.musikcube.remote.data.IDataProvider
|
import io.casey.musikcube.remote.data.IDataProvider
|
||||||
import io.casey.musikcube.remote.data.ITrack
|
import io.casey.musikcube.remote.data.ITrack
|
||||||
|
import io.casey.musikcube.remote.data.impl.remote.RemoteTrack
|
||||||
import io.casey.musikcube.remote.injection.DaggerServiceComponent
|
import io.casey.musikcube.remote.injection.DaggerServiceComponent
|
||||||
import io.casey.musikcube.remote.injection.DataModule
|
import io.casey.musikcube.remote.injection.DataModule
|
||||||
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
||||||
@ -20,11 +21,12 @@ import io.casey.musikcube.remote.websocket.Messages
|
|||||||
import io.casey.musikcube.remote.websocket.Prefs
|
import io.casey.musikcube.remote.websocket.Prefs
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import org.json.JSONObject
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class StreamingPlaybackService(context: Context) : PlaybackService {
|
class StreamingPlaybackService(context: Context) : IPlaybackService {
|
||||||
@Inject lateinit var dataProvider: IDataProvider
|
@Inject lateinit var dataProvider: IDataProvider
|
||||||
|
|
||||||
private val prefs: SharedPreferences = context.getSharedPreferences(Prefs.NAME, Context.MODE_PRIVATE)
|
private val prefs: SharedPreferences = context.getSharedPreferences(Prefs.NAME, Context.MODE_PRIVATE)
|
||||||
@ -352,13 +354,11 @@ class StreamingPlaybackService(context: Context) : PlaybackService {
|
|||||||
notifyEventListeners()
|
notifyEventListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTrackString(key: String, defaultValue: String): String {
|
override val playingTrack: ITrack
|
||||||
return playContext.currentMetadata?.getString(key, defaultValue) ?: defaultValue
|
get() {
|
||||||
}
|
val playing: ITrack? = playContext.currentMetadata
|
||||||
|
return playing ?: RemoteTrack(JSONObject())
|
||||||
override fun getTrackLong(key: String, defaultValue: Long): Long {
|
}
|
||||||
return playContext.currentMetadata?.getLong(key, defaultValue) ?: defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
override val bufferedTime: Double /* ms -> sec */
|
override val bufferedTime: Double /* ms -> sec */
|
||||||
get() {
|
get() {
|
||||||
@ -567,11 +567,7 @@ class StreamingPlaybackService(context: Context) : PlaybackService {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (currentIndex + 1 >= count) {
|
if (currentIndex + 1 >= count) {
|
||||||
if (repeatMode === RepeatMode.List) {
|
return if (repeatMode === RepeatMode.List) 0 else -1
|
||||||
return 0
|
|
||||||
} else {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return currentIndex + 1
|
return currentIndex + 1
|
||||||
|
@ -23,6 +23,7 @@ import com.bumptech.glide.request.target.Target
|
|||||||
import io.casey.musikcube.remote.Application
|
import io.casey.musikcube.remote.Application
|
||||||
import io.casey.musikcube.remote.MainActivity
|
import io.casey.musikcube.remote.MainActivity
|
||||||
import io.casey.musikcube.remote.R
|
import io.casey.musikcube.remote.R
|
||||||
|
import io.casey.musikcube.remote.ui.extension.fallback
|
||||||
import io.casey.musikcube.remote.ui.model.AlbumArtModel
|
import io.casey.musikcube.remote.ui.model.AlbumArtModel
|
||||||
import io.casey.musikcube.remote.util.Debouncer
|
import io.casey.musikcube.remote.util.Debouncer
|
||||||
import io.casey.musikcube.remote.util.Strings
|
import io.casey.musikcube.remote.util.Strings
|
||||||
@ -188,9 +189,10 @@ class SystemService : Service() {
|
|||||||
else -> { }
|
else -> { }
|
||||||
}
|
}
|
||||||
|
|
||||||
title = playback?.getTrackString(Metadata.Track.TITLE, "-")!!
|
val playing = playback!!.playingTrack
|
||||||
album = playback?.getTrackString(Metadata.Track.ALBUM, "-")!!
|
title = fallback(playing.title, "-")
|
||||||
artist = playback?.getTrackString(Metadata.Track.ARTIST, "-")!!
|
album = fallback(playing.album, "-")
|
||||||
|
artist = fallback(playing.artist, "-")
|
||||||
duration = ((playback?.duration ?: 0.0) * 1000).toInt()
|
duration = ((playback?.duration ?: 0.0) * 1000).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class AlbumBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
val album = view.tag as IAlbum
|
val album = view.tag as IAlbum
|
||||||
|
|
||||||
val intent = TrackListActivity.getStartIntent(
|
val intent = TrackListActivity.getStartIntent(
|
||||||
this@AlbumBrowseActivity, Messages.Category.ALBUM, album.id, album.name)
|
this@AlbumBrowseActivity, Messages.Category.ALBUM, album.id, album.value)
|
||||||
|
|
||||||
startActivityForResult(intent, Navigation.RequestCode.ALBUM_TRACKS_ACTIVITY)
|
startActivityForResult(intent, Navigation.RequestCode.ALBUM_TRACKS_ACTIVITY)
|
||||||
}
|
}
|
||||||
@ -127,7 +127,8 @@ class AlbumBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
private val subtitle = itemView.findViewById<TextView>(R.id.subtitle)
|
private val subtitle = itemView.findViewById<TextView>(R.id.subtitle)
|
||||||
|
|
||||||
internal fun bind(album: IAlbum) {
|
internal fun bind(album: IAlbum) {
|
||||||
val playingId = transport.playbackService?.getTrackLong(Metadata.Track.ALBUM_ID, -1L) ?: -1L
|
val playing = transport.playbackService!!.playingTrack
|
||||||
|
val playingId = playing.albumId
|
||||||
|
|
||||||
var titleColor = R.color.theme_foreground
|
var titleColor = R.color.theme_foreground
|
||||||
var subtitleColor = R.color.theme_disabled_foreground
|
var subtitleColor = R.color.theme_disabled_foreground
|
||||||
@ -137,10 +138,10 @@ class AlbumBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
subtitleColor = R.color.theme_yellow
|
subtitleColor = R.color.theme_yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
title.text = album.name
|
title.text = fallback(album.value, "-")
|
||||||
title.setTextColor(getColorCompat(titleColor))
|
title.setTextColor(getColorCompat(titleColor))
|
||||||
|
|
||||||
subtitle.text = album.albumArtist
|
subtitle.text = fallback(album.albumArtist, "-")
|
||||||
subtitle.setTextColor(getColorCompat(subtitleColor))
|
subtitle.setTextColor(getColorCompat(subtitleColor))
|
||||||
itemView.tag = album
|
itemView.tag = album
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ class AlbumBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getStartIntent(context: Context, categoryName: String, categoryValue: ICategoryValue): Intent {
|
fun getStartIntent(context: Context, categoryName: String, categoryValue: ICategoryValue): Intent {
|
||||||
return getStartIntent(context, categoryName, categoryValue.id, categoryValue.name)
|
return getStartIntent(context, categoryName, categoryValue.id, categoryValue.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ class CategoryBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
|
|
||||||
private fun navigateToTracks(entry: ICategoryValue) {
|
private fun navigateToTracks(entry: ICategoryValue) {
|
||||||
val categoryId = entry.id
|
val categoryId = entry.id
|
||||||
val value = entry.name
|
val value = entry.value
|
||||||
val intent = TrackListActivity.getStartIntent(this, category, categoryId, value)
|
val intent = TrackListActivity.getStartIntent(this, category, categoryId, value)
|
||||||
startActivityForResult(intent, Navigation.RequestCode.CATEGORY_TRACKS_ACTIVITY)
|
startActivityForResult(intent, Navigation.RequestCode.CATEGORY_TRACKS_ACTIVITY)
|
||||||
}
|
}
|
||||||
@ -178,12 +178,8 @@ class CategoryBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun bind(entry: ICategoryValue) {
|
internal fun bind(entry: ICategoryValue) {
|
||||||
var playingId: Long = -1
|
val playing = transport.playbackService?.playingTrack
|
||||||
|
val playingId = playing?.getCategoryId(category) ?: -1
|
||||||
val idKey = CATEGORY_NAME_TO_ID[category]
|
|
||||||
if (idKey != null && idKey.isNotEmpty()) {
|
|
||||||
playingId = transport.playbackService?.getTrackLong(idKey, -1) ?: -1L
|
|
||||||
}
|
|
||||||
|
|
||||||
var titleColor = R.color.theme_foreground
|
var titleColor = R.color.theme_foreground
|
||||||
if (playingId != -1L && entry.id == playingId) {
|
if (playingId != -1L && entry.id == playingId) {
|
||||||
@ -191,7 +187,7 @@ class CategoryBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* note optString only does a null check! */
|
/* note optString only does a null check! */
|
||||||
var value = entry.name
|
var value = entry.value
|
||||||
value = if (Strings.empty(value)) getString(R.string.unknown_value) else value
|
value = if (Strings.empty(value)) getString(R.string.unknown_value) else value
|
||||||
|
|
||||||
title.text = value
|
title.text = value
|
||||||
@ -230,13 +226,6 @@ class CategoryBrowseActivity : WebSocketActivityBase(), Filterable {
|
|||||||
private val EXTRA_CATEGORY = "extra_category"
|
private val EXTRA_CATEGORY = "extra_category"
|
||||||
private val EXTRA_DEEP_LINK_TYPE = "extra_deep_link_type"
|
private val EXTRA_DEEP_LINK_TYPE = "extra_deep_link_type"
|
||||||
|
|
||||||
private val CATEGORY_NAME_TO_ID: Map<String, String> = mapOf(
|
|
||||||
Messages.Category.ALBUM_ARTIST to Metadata.Track.ALBUM_ARTIST_ID,
|
|
||||||
Messages.Category.GENRE to Metadata.Track.GENRE_ID,
|
|
||||||
Messages.Category.ARTIST to Metadata.Track.ARTIST_ID,
|
|
||||||
Messages.Category.ALBUM to Metadata.Track.ALBUM_ID,
|
|
||||||
Messages.Category.PLAYLISTS to Metadata.Track.ALBUM_ID)
|
|
||||||
|
|
||||||
private val CATEGORY_NAME_TO_TITLE: Map<String, Int> = mapOf(
|
private val CATEGORY_NAME_TO_TITLE: Map<String, Int> = mapOf(
|
||||||
Messages.Category.ALBUM_ARTIST to R.string.artists_title,
|
Messages.Category.ALBUM_ARTIST to R.string.artists_title,
|
||||||
Messages.Category.GENRE to R.string.genres_title,
|
Messages.Category.GENRE to R.string.genres_title,
|
||||||
|
@ -13,7 +13,7 @@ import io.casey.musikcube.remote.R
|
|||||||
import io.casey.musikcube.remote.data.IDataProvider
|
import io.casey.musikcube.remote.data.IDataProvider
|
||||||
import io.casey.musikcube.remote.data.ITrack
|
import io.casey.musikcube.remote.data.ITrack
|
||||||
import io.casey.musikcube.remote.playback.Metadata
|
import io.casey.musikcube.remote.playback.Metadata
|
||||||
import io.casey.musikcube.remote.playback.PlaybackService
|
import io.casey.musikcube.remote.playback.IPlaybackService
|
||||||
import io.casey.musikcube.remote.ui.extension.*
|
import io.casey.musikcube.remote.ui.extension.*
|
||||||
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
import io.casey.musikcube.remote.ui.model.TrackListSlidingWindow
|
||||||
import io.casey.musikcube.remote.ui.view.EmptyListView
|
import io.casey.musikcube.remote.ui.view.EmptyListView
|
||||||
@ -21,7 +21,7 @@ import io.casey.musikcube.remote.ui.view.EmptyListView
|
|||||||
class PlayQueueActivity : WebSocketActivityBase() {
|
class PlayQueueActivity : WebSocketActivityBase() {
|
||||||
private var adapter: Adapter = Adapter()
|
private var adapter: Adapter = Adapter()
|
||||||
private var offlineQueue: Boolean = false
|
private var offlineQueue: Boolean = false
|
||||||
private var playback: PlaybackService? = null
|
private var playback: IPlaybackService? = null
|
||||||
private lateinit var tracks: TrackListSlidingWindow
|
private lateinit var tracks: TrackListSlidingWindow
|
||||||
private lateinit var emptyView: EmptyListView
|
private lateinit var emptyView: EmptyListView
|
||||||
|
|
||||||
@ -113,16 +113,17 @@ class PlayQueueActivity : WebSocketActivityBase() {
|
|||||||
subtitle.text = "-"
|
subtitle.text = "-"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
val playing = playback!!.playingTrack
|
||||||
val entryExternalId = entry.externalId
|
val entryExternalId = entry.externalId
|
||||||
val playingExternalId = playback?.getTrackString(Metadata.Track.EXTERNAL_ID, "")
|
val playingExternalId = playing.externalId
|
||||||
|
|
||||||
if (entryExternalId == playingExternalId) {
|
if (entryExternalId == playingExternalId) {
|
||||||
titleColor = R.color.theme_green
|
titleColor = R.color.theme_green
|
||||||
subtitleColor = R.color.theme_yellow
|
subtitleColor = R.color.theme_yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
title.text = entry.title
|
title.text = fallback(entry.title, "-")
|
||||||
subtitle.text = entry.albumArtist
|
subtitle.text = fallback(entry.albumArtist, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
title.setTextColor(getColorCompat(titleColor))
|
title.setTextColor(getColorCompat(titleColor))
|
||||||
|
@ -150,16 +150,17 @@ class TrackListActivity : WebSocketActivityBase(), Filterable {
|
|||||||
var subtitleColor = R.color.theme_disabled_foreground
|
var subtitleColor = R.color.theme_disabled_foreground
|
||||||
|
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
|
val playing = transport.playbackService!!.playingTrack
|
||||||
val entryExternalId = track.externalId
|
val entryExternalId = track.externalId
|
||||||
val playingExternalId = transport.playbackService?.getTrackString(Metadata.Track.EXTERNAL_ID, "")
|
val playingExternalId = playing.externalId
|
||||||
|
|
||||||
if (entryExternalId == playingExternalId) {
|
if (entryExternalId == playingExternalId) {
|
||||||
titleColor = R.color.theme_green
|
titleColor = R.color.theme_green
|
||||||
subtitleColor = R.color.theme_yellow
|
subtitleColor = R.color.theme_yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
title.text = track.title
|
title.text = fallback(track.title, "-")
|
||||||
subtitle.text = track.albumArtist
|
subtitle.text = fallback(track.albumArtist, "-")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
title.text = "-"
|
title.text = "-"
|
||||||
|
@ -13,7 +13,7 @@ import com.uacf.taskrunner.Task
|
|||||||
import io.casey.musikcube.remote.Application
|
import io.casey.musikcube.remote.Application
|
||||||
import io.casey.musikcube.remote.data.IDataProvider
|
import io.casey.musikcube.remote.data.IDataProvider
|
||||||
import io.casey.musikcube.remote.injection.*
|
import io.casey.musikcube.remote.injection.*
|
||||||
import io.casey.musikcube.remote.playback.PlaybackService
|
import io.casey.musikcube.remote.playback.IPlaybackService
|
||||||
import io.casey.musikcube.remote.playback.PlaybackServiceFactory
|
import io.casey.musikcube.remote.playback.PlaybackServiceFactory
|
||||||
import io.casey.musikcube.remote.ui.extension.hideKeyboard
|
import io.casey.musikcube.remote.ui.extension.hideKeyboard
|
||||||
import io.casey.musikcube.remote.websocket.Prefs
|
import io.casey.musikcube.remote.websocket.Prefs
|
||||||
@ -137,7 +137,7 @@ abstract class WebSocketActivityBase : AppCompatActivity(), Runner.TaskCallbacks
|
|||||||
return wss
|
return wss
|
||||||
}
|
}
|
||||||
|
|
||||||
protected var playbackService: PlaybackService? = null
|
protected var playbackService: IPlaybackService? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
protected val runner: Runner
|
protected val runner: Runner
|
||||||
|
@ -189,4 +189,8 @@ fun AppCompatActivity.showSnackbar(view: View, stringId: Int) {
|
|||||||
|
|
||||||
fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int) {
|
fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int) {
|
||||||
this.showSnackbar(this.findViewById<View>(viewId), stringId)
|
this.showSnackbar(this.findViewById<View>(viewId), stringId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fallback(input: String?, fallback: String): String {
|
||||||
|
return if (input.isNullOrEmpty()) fallback else input!!
|
||||||
}
|
}
|
@ -11,10 +11,11 @@ import android.widget.TextView
|
|||||||
import io.casey.musikcube.remote.MainActivity
|
import io.casey.musikcube.remote.MainActivity
|
||||||
import io.casey.musikcube.remote.R
|
import io.casey.musikcube.remote.R
|
||||||
import io.casey.musikcube.remote.playback.Metadata
|
import io.casey.musikcube.remote.playback.Metadata
|
||||||
import io.casey.musikcube.remote.playback.PlaybackService
|
import io.casey.musikcube.remote.playback.IPlaybackService
|
||||||
import io.casey.musikcube.remote.playback.PlaybackServiceFactory
|
import io.casey.musikcube.remote.playback.PlaybackServiceFactory
|
||||||
import io.casey.musikcube.remote.playback.PlaybackState
|
import io.casey.musikcube.remote.playback.PlaybackState
|
||||||
import io.casey.musikcube.remote.ui.activity.PlayQueueActivity
|
import io.casey.musikcube.remote.ui.activity.PlayQueueActivity
|
||||||
|
import io.casey.musikcube.remote.ui.extension.fallback
|
||||||
import io.casey.musikcube.remote.ui.extension.getColorCompat
|
import io.casey.musikcube.remote.ui.extension.getColorCompat
|
||||||
|
|
||||||
class TransportFragment : Fragment() {
|
class TransportFragment : Fragment() {
|
||||||
@ -53,7 +54,7 @@ class TransportFragment : Fragment() {
|
|||||||
this.playbackService?.connect(playbackListener)
|
this.playbackService?.connect(playbackListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
var playbackService: PlaybackService? = null
|
var playbackService: IPlaybackService? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var modelChangedListener: OnModelChangedListener? = null
|
var modelChangedListener: OnModelChangedListener? = null
|
||||||
@ -112,10 +113,9 @@ class TransportFragment : Fragment() {
|
|||||||
title?.setText(R.string.transport_not_playing)
|
title?.setText(R.string.transport_not_playing)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
title?.setTextColor(getColorCompat(R.color.theme_green))
|
|
||||||
|
|
||||||
val defaultValue = getString(if (buffering) R.string.buffering else R.string.unknown_title)
|
val defaultValue = getString(if (buffering) R.string.buffering else R.string.unknown_title)
|
||||||
title?.text = playbackService?.getTrackString(Metadata.Track.TITLE, defaultValue)
|
title?.text = fallback(playbackService?.playingTrack?.title, defaultValue)
|
||||||
|
title?.setTextColor(getColorCompat(R.color.theme_green))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ import io.casey.musikcube.remote.Application
|
|||||||
import io.casey.musikcube.remote.R
|
import io.casey.musikcube.remote.R
|
||||||
import io.casey.musikcube.remote.injection.DaggerViewComponent
|
import io.casey.musikcube.remote.injection.DaggerViewComponent
|
||||||
import io.casey.musikcube.remote.injection.DataModule
|
import io.casey.musikcube.remote.injection.DataModule
|
||||||
import io.casey.musikcube.remote.injection.AppModule
|
|
||||||
import io.casey.musikcube.remote.playback.*
|
import io.casey.musikcube.remote.playback.*
|
||||||
import io.casey.musikcube.remote.ui.activity.AlbumBrowseActivity
|
import io.casey.musikcube.remote.ui.activity.AlbumBrowseActivity
|
||||||
import io.casey.musikcube.remote.ui.activity.TrackListActivity
|
import io.casey.musikcube.remote.ui.activity.TrackListActivity
|
||||||
|
import io.casey.musikcube.remote.ui.extension.fallback
|
||||||
import io.casey.musikcube.remote.ui.extension.getColorCompat
|
import io.casey.musikcube.remote.ui.extension.getColorCompat
|
||||||
import io.casey.musikcube.remote.ui.model.AlbumArtModel
|
import io.casey.musikcube.remote.ui.model.AlbumArtModel
|
||||||
import io.casey.musikcube.remote.util.Strings
|
import io.casey.musikcube.remote.util.Strings
|
||||||
@ -102,13 +102,14 @@ class MainMetadataView : FrameLayout {
|
|||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
|
|
||||||
val playback = playbackService
|
val playback = playbackService
|
||||||
|
val playing = playbackService.playingTrack
|
||||||
|
|
||||||
val buffering = playback.playbackState == PlaybackState.Buffering
|
val buffering = playback.playbackState == PlaybackState.Buffering
|
||||||
val streaming = playback is StreamingPlaybackService
|
val streaming = playback is StreamingPlaybackService
|
||||||
|
|
||||||
val artist = playback.getTrackString(Metadata.Track.ARTIST, "")
|
val artist = fallback(playing.artist, "")
|
||||||
val album = playback.getTrackString(Metadata.Track.ALBUM, "")
|
val album = fallback(playing.album, "")
|
||||||
val title = playback.getTrackString(Metadata.Track.TITLE, "")
|
val title = fallback(playing.title, "")
|
||||||
|
|
||||||
/* we don't display the volume amount when we're streaming -- the system has
|
/* we don't display the volume amount when we're streaming -- the system has
|
||||||
overlays for drawing volume. */
|
overlays for drawing volume. */
|
||||||
@ -151,7 +152,7 @@ class MainMetadataView : FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val playbackService: PlaybackService
|
private val playbackService: IPlaybackService
|
||||||
get() = PlaybackServiceFactory.instance(context)
|
get() = PlaybackServiceFactory.instance(context)
|
||||||
|
|
||||||
private fun getString(resId: Int): String {
|
private fun getString(resId: Int): String {
|
||||||
@ -181,14 +182,17 @@ class MainMetadataView : FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rebindAlbumArtistWithArtTextView(playback: PlaybackService) {
|
private fun rebindAlbumArtistWithArtTextView(playback: IPlaybackService) {
|
||||||
|
val playing = playback.playingTrack
|
||||||
val buffering = playback.playbackState == PlaybackState.Buffering
|
val buffering = playback.playbackState == PlaybackState.Buffering
|
||||||
|
|
||||||
val artist = playback.getTrackString(
|
val artist = fallback(
|
||||||
Metadata.Track.ARTIST, getString(if (buffering) R.string.buffering else R.string.unknown_artist))
|
playing.artist,
|
||||||
|
getString(if (buffering) R.string.buffering else R.string.unknown_artist))
|
||||||
|
|
||||||
val album = playback.getTrackString(
|
val album = fallback(
|
||||||
Metadata.Track.ALBUM, getString(if (buffering) R.string.buffering else R.string.unknown_album))
|
playing.album,
|
||||||
|
getString(if (buffering) R.string.buffering else R.string.unknown_album))
|
||||||
|
|
||||||
val albumColor = ForegroundColorSpan(getColorCompat(R.color.theme_orange))
|
val albumColor = ForegroundColorSpan(getColorCompat(R.color.theme_orange))
|
||||||
|
|
||||||
@ -338,11 +342,11 @@ class MainMetadataView : FrameLayout {
|
|||||||
|
|
||||||
private fun navigateToCurrentArtist() {
|
private fun navigateToCurrentArtist() {
|
||||||
val context = context
|
val context = context
|
||||||
val playback = playbackService
|
val playing = playbackService.playingTrack
|
||||||
|
|
||||||
val artistId = playback.getTrackLong(Metadata.Track.ARTIST_ID, -1)
|
val artistId = playing.artistId
|
||||||
if (artistId != -1L) {
|
if (artistId != -1L) {
|
||||||
val artistName = playback.getTrackString(Metadata.Track.ARTIST, "")
|
val artistName = fallback(playing.artist, "")
|
||||||
context.startActivity(AlbumBrowseActivity.getStartIntent(
|
context.startActivity(AlbumBrowseActivity.getStartIntent(
|
||||||
context, Messages.Category.ARTIST, artistId, artistName))
|
context, Messages.Category.ARTIST, artistId, artistName))
|
||||||
}
|
}
|
||||||
@ -350,11 +354,11 @@ class MainMetadataView : FrameLayout {
|
|||||||
|
|
||||||
private fun navigateToCurrentAlbum() {
|
private fun navigateToCurrentAlbum() {
|
||||||
val context = context
|
val context = context
|
||||||
val playback = playbackService
|
val playing = playbackService.playingTrack
|
||||||
|
|
||||||
val albumId = playback.getTrackLong(Metadata.Track.ALBUM_ID, -1)
|
val albumId = playing.albumId
|
||||||
if (albumId != -1L) {
|
if (albumId != -1L) {
|
||||||
val albumName = playback.getTrackString(Metadata.Track.ALBUM, "")
|
val albumName = fallback(playing.album, "")
|
||||||
context.startActivity(TrackListActivity.getStartIntent(
|
context.startActivity(TrackListActivity.getStartIntent(
|
||||||
context, Messages.Category.ALBUM, albumId, albumName))
|
context, Messages.Category.ALBUM, albumId, albumName))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user