use of com.kabouzeid.gramophone.model.Playlist in project Phonograph by kabouzeid.
the class PlaylistDetailActivity method setUpRecyclerView.
private void setUpRecyclerView() {
ViewUtil.setUpFastScrollRecyclerViewColor(this, ((FastScrollRecyclerView) recyclerView), ThemeStore.accentColor(this));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
if (playlist instanceof AbsCustomPlaylist) {
adapter = new PlaylistSongAdapter(this, new ArrayList<>(), R.layout.item_list, false, this);
recyclerView.setAdapter(adapter);
} else {
recyclerViewDragDropManager = new RecyclerViewDragDropManager();
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
adapter = new OrderablePlaylistSongAdapter(this, new ArrayList<>(), R.layout.item_list, false, this, (fromPosition, toPosition) -> {
if (PlaylistsUtil.moveItem(PlaylistDetailActivity.this, playlist.id, fromPosition, toPosition)) {
Song song = adapter.getDataSet().remove(fromPosition);
adapter.getDataSet().add(toPosition, song);
adapter.notifyItemMoved(fromPosition, toPosition);
}
});
wrappedAdapter = recyclerViewDragDropManager.createWrappedAdapter(adapter);
recyclerView.setAdapter(wrappedAdapter);
recyclerView.setItemAnimator(animator);
recyclerViewDragDropManager.attachRecyclerView(recyclerView);
}
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
checkIsEmpty();
}
});
}
use of com.kabouzeid.gramophone.model.Playlist in project Phonograph by kabouzeid.
the class PlaylistAdapter method onMultipleItemAction.
@Override
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull ArrayList<Playlist> selection) {
switch(menuItem.getItemId()) {
case R.id.action_delete_playlist:
for (int i = 0; i < selection.size(); i++) {
Playlist playlist = selection.get(i);
if (playlist instanceof AbsSmartPlaylist) {
AbsSmartPlaylist absSmartPlaylist = (AbsSmartPlaylist) playlist;
ClearSmartPlaylistDialog.create(absSmartPlaylist).show(activity.getSupportFragmentManager(), "CLEAR_PLAYLIST_" + absSmartPlaylist.name);
selection.remove(playlist);
i--;
}
}
if (selection.size() > 0) {
DeletePlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_PLAYLIST");
}
break;
default:
SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.getItemId());
break;
}
}
use of com.kabouzeid.gramophone.model.Playlist in project Phonograph by kabouzeid.
the class MusicService method onStartCommand.
@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
if (intent != null) {
if (intent.getAction() != null) {
restoreQueuesAndPositionIfNecessary();
String action = intent.getAction();
switch(action) {
case ACTION_TOGGLE_PAUSE:
if (isPlaying()) {
pause();
} else {
play();
}
break;
case ACTION_PAUSE:
pause();
break;
case ACTION_PLAY:
play();
break;
case ACTION_PLAY_PLAYLIST:
Playlist playlist = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST);
int shuffleMode = intent.getIntExtra(INTENT_EXTRA_SHUFFLE_MODE, getShuffleMode());
if (playlist != null) {
List<Song> playlistSongs;
if (playlist instanceof AbsCustomPlaylist) {
playlistSongs = ((AbsCustomPlaylist) playlist).getSongs(getApplicationContext());
} else {
// noinspection unchecked
playlistSongs = (List) PlaylistSongLoader.getPlaylistSongList(getApplicationContext(), playlist.id);
}
if (!playlistSongs.isEmpty()) {
if (shuffleMode == SHUFFLE_MODE_SHUFFLE) {
int startPosition = 0;
if (!playlistSongs.isEmpty()) {
startPosition = new Random().nextInt(playlistSongs.size());
}
openQueue(playlistSongs, startPosition, true);
setShuffleMode(shuffleMode);
} else {
openQueue(playlistSongs, 0, true);
}
} else {
Toast.makeText(getApplicationContext(), R.string.playlist_is_empty, Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), R.string.playlist_is_empty, Toast.LENGTH_LONG).show();
}
break;
case ACTION_REWIND:
back(true);
break;
case ACTION_SKIP:
playNextSong(true);
break;
case ACTION_STOP:
case ACTION_QUIT:
pendingQuit = false;
quit();
break;
case ACTION_PENDING_QUIT:
pendingQuit = true;
break;
}
}
}
return START_NOT_STICKY;
}
use of com.kabouzeid.gramophone.model.Playlist in project Phonograph by kabouzeid.
the class PlaylistAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final Playlist playlist = dataSet.get(position);
holder.itemView.setActivated(isChecked(playlist));
if (holder.title != null) {
holder.title.setText(playlist.name);
}
if (holder.getAdapterPosition() == getItemCount() - 1) {
if (holder.shortSeparator != null) {
holder.shortSeparator.setVisibility(View.GONE);
}
} else {
if (holder.shortSeparator != null && !(dataSet.get(position) instanceof AbsSmartPlaylist)) {
holder.shortSeparator.setVisibility(View.VISIBLE);
}
}
if (holder.image != null) {
holder.image.setImageResource(getIconRes(playlist));
}
}
use of com.kabouzeid.gramophone.model.Playlist in project Phonograph by kabouzeid.
the class PlaylistAdapter method onMultipleItemAction.
@Override
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull List<Playlist> selection) {
switch(menuItem.getItemId()) {
case R.id.action_delete_playlist:
for (int i = 0; i < selection.size(); i++) {
Playlist playlist = selection.get(i);
if (playlist instanceof AbsSmartPlaylist) {
AbsSmartPlaylist absSmartPlaylist = (AbsSmartPlaylist) playlist;
ClearSmartPlaylistDialog.create(absSmartPlaylist).show(activity.getSupportFragmentManager(), "CLEAR_PLAYLIST_" + absSmartPlaylist.name);
selection.remove(playlist);
i--;
}
}
if (selection.size() > 0) {
DeletePlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_PLAYLIST");
}
break;
case R.id.action_save_playlist:
if (selection.size() == 1) {
PlaylistMenuHelper.handleMenuClick(activity, selection.get(0), menuItem);
} else {
new SavePlaylistsAsyncTask(activity).execute(selection);
}
break;
default:
SongsMenuHelper.handleMenuClick(activity, getSongList(selection), menuItem.getItemId());
break;
}
}
Aggregations