use of com.kabouzeid.gramophone.model.AbsCustomPlaylist 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<Song>(), R.layout.item_list, false, this);
recyclerView.setAdapter(adapter);
} else {
recyclerViewDragDropManager = new RecyclerViewDragDropManager();
final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
adapter = new OrderablePlaylistSongAdapter(this, new ArrayList<PlaylistSong>(), 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.AbsCustomPlaylist in project Phonograph by kabouzeid.
the class M3UWriter method write.
public static File write(Context context, File dir, Playlist playlist) throws IOException {
if (// noinspection ResultOfMethodCallIgnored
!dir.exists())
dir.mkdirs();
File file = new File(dir, playlist.name.concat("." + EXTENSION));
ArrayList<? extends Song> songs;
if (playlist instanceof AbsCustomPlaylist) {
songs = ((AbsCustomPlaylist) playlist).getSongs(context);
} else {
songs = PlaylistSongLoader.getPlaylistSongList(context, playlist.id);
}
if (songs.size() > 0) {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(HEADER);
for (Song song : songs) {
bw.newLine();
bw.write(ENTRY + song.duration + DURATION_SEPARATOR + song.artistName + " - " + song.title);
bw.newLine();
bw.write(song.data);
}
bw.close();
}
return file;
}
use of com.kabouzeid.gramophone.model.AbsCustomPlaylist 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) {
ArrayList<Song> playlistSongs;
if (playlist instanceof AbsCustomPlaylist) {
playlistSongs = ((AbsCustomPlaylist) playlist).getSongs(getApplicationContext());
} else {
// noinspection unchecked
playlistSongs = (ArrayList<Song>) (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:
quit();
break;
}
}
}
return START_NOT_STICKY;
}
Aggregations