-
Notifications
You must be signed in to change notification settings - Fork 37
Dev: Favorites
Note: this is a work in progress while the code is being worked on. See the
favorites_now_playingbranch for implementation.
Squeezer has basic support for marking a playing song as a (non-) favorite and viewing the list of current favorites.
What works:
- Browsing the server's favorites and playing items from them.
- Adding / removing the playing song from favorites.
What doesn't work:
- Manipulating the favorites hierarchy (creating new levels, moving items between levels, etc).
Squeezer uses three server favorites commands.
favorites exists [url]favorites add url:[url] title:[title]favorites delete item_id:[item_id]
Critically, the server has no support for returning favorite information when querying a single song. I.e., the songinfo command does not tell you if a song is also a favorite. This means:
-
model/Songis not a great place to store information about a song's favorite status. - Favorite state is not a boolean, it's a tri-state (yes, no, don't know yet)
Further, although you can query for a song's favorite state by its ID or URL, to delete a favorite you need to pass in the "Favorite ID" of the item. I assume this is so that the server can manage multiple lists of favorites with the same song appearing in multiple lists -- deleting a song from one list should not delete it from the others.
In addition, the server might not support favorites at all. This information is included in the HandshakeCompleted event when it is posted.
To check for a favorite's state use SqueezeServer.favoritesExists(). This sends the appropriate command to the server. CliClient listens for the response and posts a FavoritesExists event with the details. If the song is a favorite then
the event includes the value of the item_id which can be used to remove the favorite later.
To add an item use SqueezeServer.favoritesAdd(). This sends the appropriate command to the server followed by a favorites exists query for the URL. UI components should not update the UI as soon as the user has toggled the favorite state, they need to wait for the FavoritesExists event to be posted which will contain the response that confirms the item was added.
To remove an item use SqueezeServer.favoritesDelete(). This sends the appropriate command to the server followed by a favorites exists query for the URL. UI components should not update the UI as soon as the user has toggled the favorite state, they need to wait for the FavoritesExists event to be posted which will contain the response that confirms the item was removed.
The logic to show a button to mark a thing as a favorite is in widget/FavoriteButton. See the comments in that file for details.
NowPlayingFragment instantiates a FavoriteButton and hosts callbacks that respond to user gestures by calling the service as appropriate.
On the server Favorites are interested as a plugin, so FavoriteListActivity is a simple subclass of PluginListActivity which does the heavy lifting.
- UI to manipulate favorites in more detail.
- Choose which favorites list is manipulated using the
NowPlayingFragment. - Add more than songs as favorites. I think it's possible to e.g. add whole albums at once.