Squashed merge of favorites branch
No files matched your search
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 738 B |
|
Before Width: | Height: | Size: 947 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 908 B |
|
After Width: | Height: | Size: 647 B |
|
Before Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 965 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 875 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
@@ -69,6 +69,7 @@ THE SOFTWARE.
|
||||
<string name="save_as_playlist">Save as playlist…</string>
|
||||
<string name="add_to_playlist">Add to playlist…</string>
|
||||
<string name="add_to_favorites">Add to favorites</string>
|
||||
<string name="remove_from_favorites">Remove from favorites</string>
|
||||
<string name="playlist_favorites">Favorites</string>
|
||||
<string name="new_playlist">New playlist…</string>
|
||||
<string name="expand">Expand</string>
|
||||
@@ -94,6 +95,10 @@ THE SOFTWARE.
|
||||
<item quantity="one">1 song added to playlist %2$s.</item>
|
||||
<item quantity="other">%1$d songs added to playlist %2$s.</item>
|
||||
</plurals>
|
||||
<plurals name="removed_from_playlist">
|
||||
<item quantity="one">1 song removed from playlist %2$s.</item>
|
||||
<item quantity="other">%1$d songs removed from playlist %2$s.</item>
|
||||
</plurals>
|
||||
<plurals name="deleted">
|
||||
<item quantity="one">1 song deleted.</item>
|
||||
<item quantity="other">%d songs deleted.</item>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
|
||||
* Copyright (C) 2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -119,6 +120,7 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
private TextView mFormatView;
|
||||
private String mReplayGain;
|
||||
private TextView mReplayGainView;
|
||||
private MenuItem mFavorites;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle)
|
||||
@@ -298,8 +300,6 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
@Override
|
||||
protected void onSongChange(Song song)
|
||||
{
|
||||
super.onSongChange(song);
|
||||
|
||||
setDuration(song == null ? 0 : song.duration);
|
||||
|
||||
if (mTitle != null) {
|
||||
@@ -318,9 +318,14 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
mCurrentSong = song;
|
||||
updateElapsedTime();
|
||||
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_FAVOURITE_INFO);
|
||||
|
||||
// All quick UI updates are done: Time to update the cover
|
||||
// and parse additional info
|
||||
if (mExtraInfoVisible) {
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_EXTRA_INFO);
|
||||
}
|
||||
super.onSongChange(song);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,8 +372,11 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
menu.add(0, MENU_ENQUEUE_ALBUM, 0, R.string.enqueue_current_album).setIcon(R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_ENQUEUE_ARTIST, 0, R.string.enqueue_current_artist).setIcon(R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_ENQUEUE_GENRE, 0, R.string.enqueue_current_genre).setIcon(R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_SONG_FAVORITE, 0, R.string.add_to_favorites);
|
||||
mFavorites = menu.add(0, MENU_SONG_FAVORITE, 0, R.string.add_to_favorites).setIcon(R.drawable.btn_rating_star_off_mtrl_alpha).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
menu.add(0, MENU_SHOW_QUEUE, 0, R.string.show_queue);
|
||||
|
||||
// ensure that mFavorites is updated
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_FAVOURITE_INFO);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -390,15 +398,16 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
PlaybackService.get(this).enqueueFromCurrent(MediaUtils.TYPE_GENRE);
|
||||
break;
|
||||
case MENU_SONG_FAVORITE:
|
||||
String playlistName = getString(R.string.playlist_favorites);
|
||||
long playlistId = Playlist.getOrCreatePlaylist(getContentResolver(), playlistName);
|
||||
Song song = (PlaybackService.get(this)).getSong(0);
|
||||
long playlistId = Playlist.getFavoritesId(this, true);
|
||||
|
||||
if (song != null) {
|
||||
PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName);
|
||||
PlaylistTask playlistTask = new PlaylistTask(playlistId, getString(R.string.playlist_favorites));
|
||||
playlistTask.audioIds = new ArrayList<Long>();
|
||||
playlistTask.audioIds.add(song.id);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask));
|
||||
int action = Playlist.isInPlaylist(getContentResolver(), playlistId, song) ? MSG_REMOVE_FROM_PLAYLIST : MSG_ADD_TO_PLAYLIST;
|
||||
mHandler.sendMessage(mHandler.obtainMessage(action, playlistTask));
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_FAVOURITE_INFO);
|
||||
}
|
||||
break;
|
||||
case MENU_DELETE:
|
||||
@@ -645,6 +654,14 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
* Calls {@link PlaybackService#seekToProgress(int)}.
|
||||
*/
|
||||
private static final int MSG_SEEK_TO_PROGRESS = 18;
|
||||
/**
|
||||
* Check if passed song is a favorite
|
||||
*/
|
||||
private static final int MSG_LOAD_FAVOURITE_INFO = 19;
|
||||
/**
|
||||
* Updates the favorites state
|
||||
*/
|
||||
private static final int MSG_COMMIT_FAVOURITE_INFO = 20;
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message message)
|
||||
@@ -679,6 +696,19 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
PlaybackService.get(this).seekToProgress(message.arg1);
|
||||
updateElapsedTime();
|
||||
break;
|
||||
case MSG_LOAD_FAVOURITE_INFO:
|
||||
if (mCurrentSong != null) {
|
||||
boolean found = Playlist.isInPlaylist(getContentResolver(), Playlist.getFavoritesId(this, false), mCurrentSong);
|
||||
mUiHandler.sendMessage(mUiHandler.obtainMessage(MSG_COMMIT_FAVOURITE_INFO, found));
|
||||
}
|
||||
break;
|
||||
case MSG_COMMIT_FAVOURITE_INFO:
|
||||
if (mFavorites != null) {
|
||||
boolean found = (boolean)message.obj;
|
||||
mFavorites.setIcon(found ? R.drawable.btn_rating_star_on_mtrl_alpha: R.drawable.btn_rating_star_off_mtrl_alpha);
|
||||
mFavorites.setTitle(found ? R.string.remove_from_favorites : R.string.add_to_favorites);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return super.handleMessage(message);
|
||||
}
|
||||
|
||||
@@ -399,8 +399,14 @@ public abstract class PlaybackActivity extends Activity
|
||||
* Call addToPlaylist with data from the playlisttask object.
|
||||
*/
|
||||
protected static final int MSG_ADD_TO_PLAYLIST = 2;
|
||||
|
||||
protected static final int MSG_DELETE = 3;
|
||||
/**
|
||||
* Call removeFromPlaylist with data from the playlisttask object.
|
||||
*/
|
||||
protected static final int MSG_REMOVE_FROM_PLAYLIST = 3;
|
||||
/**
|
||||
* Removes a media object
|
||||
*/
|
||||
protected static final int MSG_DELETE = 4;
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message message)
|
||||
@@ -423,6 +429,11 @@ public abstract class PlaybackActivity extends Activity
|
||||
addToPlaylist(playlistTask);
|
||||
break;
|
||||
}
|
||||
case MSG_REMOVE_FROM_PLAYLIST: {
|
||||
PlaylistTask playlistTask = (PlaylistTask)message.obj;
|
||||
removeFromPlaylist(playlistTask);
|
||||
break;
|
||||
}
|
||||
case MSG_RENAME_PLAYLIST: {
|
||||
NewPlaylistDialog dialog = (NewPlaylistDialog)message.obj;
|
||||
if (dialog.isAccepted()) {
|
||||
@@ -462,6 +473,27 @@ public abstract class PlaybackActivity extends Activity
|
||||
showToast(message, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a set of songs represented by the playlistTask from a playlist. Displays a
|
||||
* Toast notifying of success.
|
||||
*
|
||||
* @param playlistTask The pending PlaylistTask to execute
|
||||
*/
|
||||
private void removeFromPlaylist(PlaylistTask playlistTask) {
|
||||
int count = 0;
|
||||
|
||||
if (playlistTask.query != null) {
|
||||
throw new IllegalArgumentException("Delete by query is not implemented yet");
|
||||
}
|
||||
|
||||
if (playlistTask.audioIds != null) {
|
||||
count += Playlist.removeFromPlaylist(getContentResolver(), playlistTask.playlistId, playlistTask.audioIds);
|
||||
}
|
||||
|
||||
String message = getResources().getQuantityString(R.plurals.removed_from_playlist, count, count, playlistTask.name);
|
||||
showToast(message, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the media represented by the given intent and show a Toast
|
||||
* informing the user of this.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
||||
* Copyright (C) 2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
* Copyright (C) 2014-2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -25,6 +25,7 @@ package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
@@ -50,23 +51,6 @@ public class Playlist {
|
||||
return MediaUtils.queryResolver(resolver, media, projection, null, null, sort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the id for a playlist with the given name.
|
||||
* A new playlist will be created if given name does not exist
|
||||
* @param resolver A ContentResolver to use.
|
||||
* @param name The name of the playlist.
|
||||
* @return The id of the playlist, or -1 if there is no playlist with the
|
||||
* given name.
|
||||
*/
|
||||
public static long getOrCreatePlaylist(ContentResolver resolver, String name)
|
||||
{
|
||||
long id = getPlaylist(resolver, name);
|
||||
if(id == -1) {
|
||||
id = createPlaylist(resolver, name);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the id for a playlist with the given name.
|
||||
*
|
||||
@@ -147,7 +131,7 @@ public class Playlist {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given query and add the results to the given playlist. Should be
|
||||
* Adds a set of audioIds to the given playlist. Should be
|
||||
* run on a background thread.
|
||||
*
|
||||
* @param resolver A ContentResolver to use.
|
||||
@@ -184,6 +168,29 @@ public class Playlist {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a set of audioIds from the given playlist. Should be
|
||||
* run on a background thread.
|
||||
*
|
||||
* @param resolver A ContentResolver to use.
|
||||
* @param playlistId The MediaStore.Audio.Playlist id of the playlist to
|
||||
* modify.
|
||||
* @param audioIds An ArrayList with all IDs to add
|
||||
* @return The number of songs that were added to the playlist.
|
||||
*/
|
||||
public static int removeFromPlaylist(ContentResolver resolver, long playlistId, ArrayList<Long> audioIds) {
|
||||
if (playlistId == -1)
|
||||
return 0;
|
||||
|
||||
int count = 0;
|
||||
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
|
||||
for (long id : audioIds) {
|
||||
String where = MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + id;
|
||||
count += resolver.delete(uri, where, null);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the playlist with the given id.
|
||||
*
|
||||
@@ -223,4 +230,44 @@ public class Playlist {
|
||||
deletePlaylist(resolver, id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the 'favorites' playlist.
|
||||
*
|
||||
* @param context The Context to use
|
||||
* @param create Create the playlist if it does not exist
|
||||
* @return the id of the playlist, -1 on error
|
||||
*/
|
||||
public static long getFavoritesId(Context context, boolean create) {
|
||||
String playlistName = context.getString(R.string.playlist_favorites);
|
||||
long playlistId = getPlaylist(context.getContentResolver(), playlistName);
|
||||
|
||||
if (playlistId == -1 && create == true)
|
||||
playlistId = createPlaylist(context.getContentResolver(), playlistName);
|
||||
|
||||
return playlistId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for given song in given playlist
|
||||
*
|
||||
* @param resolver A ContentResolver to use.
|
||||
* @param playlistId The ID of the Playlist to query
|
||||
* @param song The Song to search in given playlistId
|
||||
* @return true if `song' was found in `playlistId'
|
||||
*/
|
||||
public static boolean isInPlaylist(ContentResolver resolver, long playlistId, Song song) {
|
||||
if (playlistId == -1 || song == null)
|
||||
return false;
|
||||
|
||||
boolean found = false;
|
||||
String where = MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + song.id;
|
||||
QueryTask query = MediaUtils.buildPlaylistQuery(playlistId, Song.EMPTY_PLAYLIST_PROJECTION, where);
|
||||
Cursor cursor = query.runQuery(resolver);
|
||||
if (cursor != null) {
|
||||
found = cursor.getCount() != 0;
|
||||
cursor.close();
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||