Search in sources :

Example 1 with AbsCustomPlaylist

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();
        }
    });
}
Also used : MaterialCab(com.afollestad.materialcab.MaterialCab) Context(android.content.Context) Bundle(android.os.Bundle) ViewUtil(com.kabouzeid.gramophone.util.ViewUtil) ButterKnife(butterknife.ButterKnife) PlaylistSongLoader(com.kabouzeid.gramophone.loader.PlaylistSongLoader) PlaylistSong(com.kabouzeid.gramophone.model.PlaylistSong) MusicPlayerRemote(com.kabouzeid.gramophone.helper.MusicPlayerRemote) NonNull(android.support.annotation.NonNull) WrappedAsyncTaskLoader(com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BindView(butterknife.BindView) ThemeStore(com.kabouzeid.appthemehelper.ThemeStore) Playlist(com.kabouzeid.gramophone.model.Playlist) LoaderIds(com.kabouzeid.gramophone.interfaces.LoaderIds) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) PlaylistsUtil(com.kabouzeid.gramophone.util.PlaylistsUtil) PhonographColorUtil(com.kabouzeid.gramophone.util.PhonographColorUtil) PlaylistLoader(com.kabouzeid.gramophone.loader.PlaylistLoader) Menu(android.view.Menu) View(android.view.View) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) R(com.kabouzeid.gramophone.R) LoaderManager(android.support.v4.app.LoaderManager) WrapperAdapterUtils(com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) Loader(android.support.v4.content.Loader) SongAdapter(com.kabouzeid.gramophone.adapter.song.SongAdapter) Song(com.kabouzeid.gramophone.model.Song) PlaylistMenuHelper(com.kabouzeid.gramophone.helper.menu.PlaylistMenuHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) TextView(android.widget.TextView) AbsSlidingMusicPanelActivity(com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) Toolbar(android.support.v7.widget.Toolbar) CabHolder(com.kabouzeid.gramophone.interfaces.CabHolder) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) PlaylistSong(com.kabouzeid.gramophone.model.PlaylistSong) Song(com.kabouzeid.gramophone.model.Song) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager)

Example 2 with AbsCustomPlaylist

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;
}
Also used : Song(com.kabouzeid.gramophone.model.Song) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 3 with AbsCustomPlaylist

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;
}
Also used : AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) Playlist(com.kabouzeid.gramophone.model.Playlist) Song(com.kabouzeid.gramophone.model.Song) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) Random(java.util.Random) List(java.util.List) ArrayList(java.util.ArrayList) Point(android.graphics.Point)

Aggregations

AbsCustomPlaylist (com.kabouzeid.gramophone.model.AbsCustomPlaylist)3 Song (com.kabouzeid.gramophone.model.Song)3 Playlist (com.kabouzeid.gramophone.model.Playlist)2 Context (android.content.Context)1 Point (android.graphics.Point)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 LoaderManager (android.support.v4.app.LoaderManager)1 Loader (android.support.v4.content.Loader)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 MaterialCab (com.afollestad.materialcab.MaterialCab)1 GeneralItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator)1