Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb9f4f57 authored by linus_lee's avatar linus_lee
Browse files

Eleven: Remove irrelevant options when queue is empty

https://cyanogen.atlassian.net/browse/MUSIC-182

Change-Id: Ie6aace33c27009bd93c512a4bc1b5ccbe49b68f1
parent 8f8e5591
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -27,9 +27,14 @@
        android:orderInCategory="42"
        android:title="@string/context_menu_use_as_ringtone"/>
    <item
        android:id="@+id/menu_audio_player_delete"
        android:id="@+id/menu_audio_player_more_by_artist"
        android:showAsAction="never"
        android:orderInCategory="43"
        android:title="@string/context_menu_more_by_artist"/>
    <item
        android:id="@+id/menu_audio_player_delete"
        android:showAsAction="never"
        android:orderInCategory="44"
        android:title="@string/context_menu_delete"/>

</menu>
+3 −0
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@ interface IElevenService
    void playlistChanged();
    boolean isPlaying();
    long [] getQueue();
    long getQueueItemAtPosition(int position);
    int getQueueSize();
    int getQueuePosition();
    int getQueueHistoryPosition(int position);
    int getQueueHistorySize();
    int[] getQueueHistoryList();
    long duration();
+61 −0
Original line number Diff line number Diff line
@@ -1812,6 +1812,19 @@ public class MusicPlaybackService extends Service {
        }
    }

    /**
     * @return the position in the history
     */
    public int getQueueHistoryPosition(int position) {
        synchronized (this) {
            if (position >= 0 && position < mHistory.size()) {
                return mHistory.get(position);
            }
        }

        return -1;
    }

    /**
     * @return the queue of history positions
     */
@@ -2074,6 +2087,30 @@ public class MusicPlaybackService extends Service {
        }
    }

    /**
     * Gets the track id at a given position in the queue
     * @param position
     * @return track id in the queue position
     */
    public long getQueueItemAtPosition(int position) {
        synchronized (this) {
            if (position >= 0 && position < mPlaylist.size()) {
                return mPlaylist.get(position).mId;
            }
        }

        return -1;
    }

    /**
     * @return the size of the queue
     */
    public int getQueueSize() {
        synchronized (this) {
            return mPlaylist.size();
        }
    }

    /**
     * @return True if music is playing, false otherwise
     */
@@ -3109,6 +3146,30 @@ public class MusicPlaybackService extends Service {
            return mService.get().getQueue();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public long getQueueItemAtPosition(int position) throws RemoteException {
            return mService.get().getQueueItemAtPosition(position);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public int getQueueSize() throws RemoteException {
            return mService.get().getQueueSize();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public int getQueueHistoryPosition(int position) throws RemoteException {
            return mService.get().getQueueHistoryPosition(position);
        }

        /**
         * {@inheritDoc}
         */
+4 −11
Original line number Diff line number Diff line
@@ -108,9 +108,7 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
        } else if (MusicUtils.getShuffleMode() == MusicPlaybackService.SHUFFLE_NONE) {
            // if we aren't shuffling, just return based on the queue position
            // add a check for empty queue
            long[] songQueue = MusicUtils.getQueue();
            return (position >= 0 && position < songQueue.length)
                    ? songQueue[position] : NO_TRACK_ID;
            return MusicUtils.getQueueItemAtPosition(position);
        } else {
            // if we are shuffling, there is no 'queue' going forward per say
            // because it is dynamically generated.  In that case we can only look
@@ -126,14 +124,9 @@ public class AlbumArtPagerAdapter extends FragmentStatePagerAdapter {
            } else if (position - positionOffset == 1) { // next track
                return MusicUtils.getNextAudioId();
            } else if (position < positionOffset) {
                // historical track - look up the historical position
                long[] audioIds = MusicUtils.getQueue();
                int[] historyPositions = MusicUtils.getQueueHistoryList();
                if (position < historyPositions.length) {
                    int queuePosition = historyPositions[position];
                    if (queuePosition < audioIds.length) {
                        return audioIds[queuePosition];
                    }
                int queuePosition = MusicUtils.getQueueHistoryPosition(position);
                if (position >= 0) {
                    return MusicUtils.getQueueItemAtPosition(queuePosition);
                }
            }
        }
+10 −6
Original line number Diff line number Diff line
@@ -115,17 +115,21 @@ public class HeaderBar extends LinearLayout {
                    return onPopupMenuItemClick(item);
                }
            });
        }

        final Menu menu = mPopupMenu.getMenu();
        final MenuInflater inflater = mPopupMenu.getMenuInflater();

        menu.clear();

        // Shuffle all
        inflater.inflate(R.menu.shuffle_all, menu);
        if (MusicUtils.getQueueSize() > 0) {
            // save queue/clear queue
            inflater.inflate(R.menu.queue, menu);
        }
        // Settings
        inflater.inflate(R.menu.activity_base, menu);
        }

        // show the popup
        mPopupMenu.show();
Loading