Search in sources :

Example 1 with Playlist

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();
        }
    });
}
Also used : MaterialCab(com.afollestad.materialcab.MaterialCab) Context(android.content.Context) Bundle(android.os.Bundle) ViewUtil(com.kabouzeid.gramophone.util.ViewUtil) ButterKnife(butterknife.ButterKnife) NonNull(androidx.annotation.NonNull) PlaylistSongLoader(com.kabouzeid.gramophone.loader.PlaylistSongLoader) MusicPlayerRemote(com.kabouzeid.gramophone.helper.MusicPlayerRemote) LoaderManager(androidx.loader.app.LoaderManager) 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) RecyclerView(androidx.recyclerview.widget.RecyclerView) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) R(com.kabouzeid.gramophone.R) Loader(androidx.loader.content.Loader) WrapperAdapterUtils(com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) SongAdapter(com.kabouzeid.gramophone.adapter.song.SongAdapter) Song(com.kabouzeid.gramophone.model.Song) PlaylistMenuHelper(com.kabouzeid.gramophone.helper.menu.PlaylistMenuHelper) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) List(java.util.List) TextView(android.widget.TextView) AbsSlidingMusicPanelActivity(com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) CabHolder(com.kabouzeid.gramophone.interfaces.CabHolder) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) Toolbar(androidx.appcompat.widget.Toolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) Song(com.kabouzeid.gramophone.model.Song) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) RecyclerView(androidx.recyclerview.widget.RecyclerView) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) 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 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 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;
    }
}
Also used : LastAddedPlaylist(com.kabouzeid.gramophone.model.smartplaylist.LastAddedPlaylist) Playlist(com.kabouzeid.gramophone.model.Playlist) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist)

Example 3 with Playlist

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;
}
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) Point(android.graphics.Point)

Example 4 with Playlist

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));
    }
}
Also used : LastAddedPlaylist(com.kabouzeid.gramophone.model.smartplaylist.LastAddedPlaylist) Playlist(com.kabouzeid.gramophone.model.Playlist) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist)

Example 5 with 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;
    }
}
Also used : LastAddedPlaylist(com.kabouzeid.gramophone.model.smartplaylist.LastAddedPlaylist) Playlist(com.kabouzeid.gramophone.model.Playlist) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist) AbsSmartPlaylist(com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist)

Aggregations

AbsCustomPlaylist (com.kabouzeid.gramophone.model.AbsCustomPlaylist)5 Playlist (com.kabouzeid.gramophone.model.Playlist)5 AbsSmartPlaylist (com.kabouzeid.gramophone.model.smartplaylist.AbsSmartPlaylist)3 LastAddedPlaylist (com.kabouzeid.gramophone.model.smartplaylist.LastAddedPlaylist)3 Song (com.kabouzeid.gramophone.model.Song)2 Context (android.content.Context)1 Point (android.graphics.Point)1 Bundle (android.os.Bundle)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Toolbar (androidx.appcompat.widget.Toolbar)1 LoaderManager (androidx.loader.app.LoaderManager)1 Loader (androidx.loader.content.Loader)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1