Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle Playlist option #364

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.afollestad.appthemeengine.customizers.ATEToolbarCustomizer;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.naman14.timber.MusicPlayer;
import com.naman14.timber.R;
import com.naman14.timber.adapters.SongsListAdapter;
import com.naman14.timber.dataloaders.LastAddedLoader;
Expand All @@ -61,6 +62,7 @@

import java.util.HashMap;
import java.util.List;
import java.util.Random;

public class PlaylistDetailActivity extends BaseActivity implements ATEActivityThemeCustomizer, ATEToolbarCustomizer {

Expand Down Expand Up @@ -317,6 +319,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.action_delete_playlist).setVisible(false);
menu.findItem(R.id.action_clear_auto_playlist).setTitle("Clear " + playlistname.getText().toString());
}
menu.findItem(R.id.action_shuffle).setVisible(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this id should be: shuffle_playlist, please check it


return super.onPrepareOptionsMenu(menu);
}
Expand All @@ -333,6 +336,16 @@ public boolean onOptionsItemSelected(final MenuItem item) {
case R.id.action_clear_auto_playlist:
clearAutoPlaylists();
break;
case R.id.shuffle_playlist:
List<Song> playlistsongs = PlaylistSongLoader.getSongsInPlaylist(mContext, playlistID);
long[] songIDs = new long[playlistsongs.size()];
for(int i = 0; i < playlistsongs.size();i++){
songIDs[i] = playlistsongs.get(i).id;
}
Random random = new Random();
int position = random.nextInt(playlistsongs.size() + 1);
MusicPlayer.playAll(mContext, songIDs, position, -1, TimberUtils.IdType.NA, true);
break;
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_playlist_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/shuffle_playlist"
android:orderInCategory="10"
android:title="Shuffle playlist"
app:showAsAction="never" />

<item
android:id="@+id/action_clear_auto_playlist"
android:orderInCategory="9"
Expand Down