use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class AbsPlayerFragment method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem item) {
final Song song = MusicPlayerRemote.getCurrentSong();
switch(item.getItemId()) {
case R.id.action_sleep_timer:
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
return true;
case R.id.action_toggle_favorite:
toggleFavorite(song);
return true;
case R.id.action_share:
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
return true;
case R.id.action_equalizer:
NavigationUtil.openEqualizer(getActivity());
return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
return true;
case R.id.action_clear_playing_queue:
MusicPlayerRemote.clearQueue();
return true;
case R.id.action_save_playing_queue:
CreatePlaylistDialog.create(MusicPlayerRemote.getPlayingQueue()).show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
return true;
case R.id.action_tag_editor:
Intent intent = new Intent(getActivity(), SongTagEditorActivity.class);
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
startActivity(intent);
return true;
case R.id.action_details:
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
return true;
case R.id.action_go_to_album:
NavigationUtil.goToAlbum(getActivity(), song.albumId);
return true;
case R.id.action_go_to_artist:
NavigationUtil.goToArtist(getActivity(), song.artistId);
return true;
}
return false;
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class FlatPlayerFragment method updateLyrics.
private void updateLyrics() {
if (updateLyricsAsyncTask != null)
updateLyricsAsyncTask.cancel(false);
final Song song = MusicPlayerRemote.getCurrentSong();
updateLyricsAsyncTask = new AsyncTask<Void, Void, Lyrics>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
lyrics = null;
playerAlbumCoverFragment.setLyrics(null);
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
}
@Override
protected Lyrics doInBackground(Void... params) {
String data = MusicUtil.getLyrics(song);
if (TextUtils.isEmpty(data)) {
return null;
}
return Lyrics.parse(song, data);
}
@Override
protected void onPostExecute(Lyrics l) {
lyrics = l;
playerAlbumCoverFragment.setLyrics(lyrics);
if (lyrics == null) {
if (toolbar != null) {
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
}
} else {
Activity activity = getActivity();
if (toolbar != null && activity != null)
if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
int color = ToolbarContentTintHelper.toolbarContentColor(activity, Color.TRANSPARENT);
Drawable drawable = ImageUtil.getTintedVectorDrawable(activity, R.drawable.ic_comment_text_outline_white_24dp, color);
toolbar.getMenu().add(Menu.NONE, R.id.action_show_lyrics, Menu.NONE, R.string.action_show_lyrics).setIcon(drawable).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
}
@Override
protected void onCancelled(Lyrics s) {
onPostExecute(null);
}
}.execute();
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class FlatPlayerFragment method updateIsFavorite.
private void updateIsFavorite() {
if (updateIsFavoriteTask != null)
updateIsFavoriteTask.cancel(false);
updateIsFavoriteTask = new AsyncTask<Song, Void, Boolean>() {
@Override
protected Boolean doInBackground(Song... params) {
Activity activity = getActivity();
if (activity != null) {
return MusicUtil.isFavorite(getActivity(), params[0]);
} else {
cancel(false);
return null;
}
}
@Override
protected void onPostExecute(Boolean isFavorite) {
Activity activity = getActivity();
if (activity != null) {
int res = isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_border_white_24dp;
int color = ToolbarContentTintHelper.toolbarContentColor(activity, Color.TRANSPARENT);
Drawable drawable = ImageUtil.getTintedVectorDrawable(activity, res, color);
toolbar.getMenu().findItem(R.id.action_toggle_favorite).setIcon(drawable).setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
}
}
}.execute(MusicPlayerRemote.getCurrentSong());
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicPlaybackQueueStore method saveQueue.
/**
* Clears the existing database and saves the queue into the db so that when the
* app is restarted, the tracks you were listening to is restored
*
* @param queue the queue to save
*/
private synchronized void saveQueue(final String tableName, @NonNull final List<Song> queue) {
final SQLiteDatabase database = getWritableDatabase();
database.beginTransaction();
try {
database.delete(tableName, null, null);
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
final int NUM_PROCESS = 20;
int position = 0;
while (position < queue.size()) {
database.beginTransaction();
try {
for (int i = position; i < queue.size() && i < position + NUM_PROCESS; i++) {
Song song = queue.get(i);
ContentValues values = new ContentValues(4);
values.put(BaseColumns._ID, song.id);
values.put(AudioColumns.TITLE, song.title);
values.put(AudioColumns.TRACK, song.trackNumber);
values.put(AudioColumns.YEAR, song.year);
values.put(AudioColumns.DURATION, song.duration);
values.put(AudioColumns.DATA, song.data);
values.put(AudioColumns.DATE_MODIFIED, song.dateModified);
values.put(AudioColumns.ALBUM_ID, song.albumId);
values.put(AudioColumns.ALBUM, song.albumName);
values.put(AudioColumns.ARTIST_ID, song.artistId);
values.put(AudioColumns.ARTIST, song.artistName);
database.insert(tableName, null, values);
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
position += NUM_PROCESS;
}
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicService method moveSong.
public void moveSong(int from, int to) {
if (from == to)
return;
final int currentPosition = getPosition();
Song songToMove = playingQueue.remove(from);
playingQueue.add(to, songToMove);
if (getShuffleMode() == SHUFFLE_MODE_NONE) {
Song tmpSong = originalPlayingQueue.remove(from);
originalPlayingQueue.add(to, tmpSong);
}
if (from > currentPosition && to <= currentPosition) {
position = currentPosition + 1;
} else if (from < currentPosition && to >= currentPosition) {
position = currentPosition - 1;
} else if (from == currentPosition) {
position = to;
}
notifyChange(QUEUE_CHANGED);
}
Aggregations