Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Playlist already added song prevention & AndroidSlidingUpPanel repo U… #671

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -5,6 +5,7 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;

import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.loader.PlaylistLoader;
Expand Down Expand Up @@ -57,9 +58,32 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
CreatePlaylistDialog.create(songs).show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
} else {
materialDialog.dismiss();
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlists.get(i - 1).id, true);
ArrayList<Song> updatedSongs = getNotExistingSongs(songs, playlists.get(i - 1).id);
if (updatedSongs.size() > 0 ){
PlaylistsUtil.addToPlaylist(getActivity(), updatedSongs, playlists.get(i - 1).id, true);
}else {
Toast.makeText(getActivity(), " Inserted "+updatedSongs.size()+" songs ins to the Playlist", Toast.LENGTH_SHORT).show();
}
}
})
.build();
}

/**
* getNotExistingSongs helps get rid of songs that already exxist in a playlist,
* returns a list of songs
* @param songs list of songs to be added to playlist
* @param playlistId playlist Id
*/
private ArrayList<Song> getNotExistingSongs(ArrayList<Song> songs, int playlistId ){
ArrayList<Song> newSongsList = new ArrayList<>();
if (songs.size()>0){
for (Song song : songs){
if (!PlaylistsUtil.doPlaylistContains(getActivity(), playlistId, song.id)){
newSongsList.add(song);
}
}
}
return newSongsList;
}
}