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
......@@ -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>
......@@ -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();
......
......@@ -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}
*/
......
......@@ -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);
}
}
}
......
......@@ -115,17 +115,21 @@ public class HeaderBar extends LinearLayout {
return onPopupMenuItemClick(item);
}
});
}
final Menu menu = mPopupMenu.getMenu();
final MenuInflater inflater = mPopupMenu.getMenuInflater();
final Menu menu = mPopupMenu.getMenu();
final MenuInflater inflater = mPopupMenu.getMenuInflater();
menu.clear();
// Shuffle all
inflater.inflate(R.menu.shuffle_all, menu);
// 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);
}
// Settings
inflater.inflate(R.menu.activity_base, menu);
// show the popup
mPopupMenu.show();
......
......@@ -401,7 +401,7 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection {
int repeatMode = MusicUtils.getRepeatMode();
int targetSize = 0;
int targetIndex = 0;
int queueSize = MusicUtils.getQueue().length;
int queueSize = MusicUtils.getQueueSize();
if (repeatMode == MusicPlaybackService.REPEAT_CURRENT) {
targetSize = 1;
......@@ -423,9 +423,11 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection {
if(queueSize == 0) {
mAlbumArtViewPager.setVisibility(View.GONE);
mQueueEmpty.showNoResults();
mAddToPlaylistButton.setVisibility(View.GONE);
} else {
mAlbumArtViewPager.setVisibility(View.VISIBLE);
mQueueEmpty.hideAll();
mAddToPlaylistButton.setVisibility(View.VISIBLE);
}
}
......@@ -561,19 +563,22 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection {
return onPopupMenuItemClick(item);
}
});
}
final Menu menu = mPopupMenu.getMenu();
final MenuInflater inflater = mPopupMenu.getMenuInflater();
final Menu menu = mPopupMenu.getMenu();
final MenuInflater inflater = mPopupMenu.getMenuInflater();
menu.clear();
// Shuffle all
inflater.inflate(R.menu.shuffle_all, menu);
// Shuffle all
inflater.inflate(R.menu.shuffle_all, menu);
if (MusicUtils.getQueueSize() > 0) {
// ringtone, and equalizer
inflater.inflate(R.menu.audio_player, menu);
// save queue/clear queue
inflater.inflate(R.menu.queue, menu);
// Settings
inflater.inflate(R.menu.activity_base, menu);
}
// Settings
inflater.inflate(R.menu.activity_base, menu);
// show the popup
mPopupMenu.show();
......@@ -597,6 +602,9 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection {
// Settings
NavUtils.openSettings(getActivity());
return true;
case R.id.menu_audio_player_more_by_artist:
NavUtils.openArtistProfile(getActivity(), MusicUtils.getArtistName());
return true;
case R.id.menu_audio_player_delete:
// Delete current song
DeleteDialog.newInstance(MusicUtils.getTrackName(), new long[]{
......
......@@ -560,6 +560,35 @@ public final class MusicUtils {
return sEmptyList;
}
/**
* @param position
* @return the id of the track in the queue at the given position
*/
public static final long getQueueItemAtPosition(int position) {
try {
if (mService != null) {
return mService.getQueueItemAtPosition(position);
} else {
}
} catch (final RemoteException ignored) {
}
return -1;
}
/**
* @return the current queue size
*/
public static final int getQueueSize() {
try {
if (mService != null) {
return mService.getQueueSize();
} else {
}
} catch (final RemoteException ignored) {
}
return 0;
}
/**
* @return The position of the current track in the queue.
*/
......@@ -586,6 +615,19 @@ public final class MusicUtils {
return 0;
}
/**
* @return The queue history position at the position
*/
public static final int getQueueHistoryPosition(int position) {
if (mService != null) {
try {
return mService.getQueueHistoryPosition(position);
} catch (final RemoteException ignored) {
}
}
return -1;
}
/**
* @return The queue history
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment