use of com.sdsmdg.harjot.MusicDNA.adapters.playlistdialogadapter.AddToPlaylistAdapter in project MusicDNA by harjot-oberai.
the class HomeActivity method showAddToPlaylistDialog.
public void showAddToPlaylistDialog(final UnifiedTrack track) {
final Dialog dialog = new Dialog(ctx);
dialog.setContentView(R.layout.add_to_playlist_dialog);
dialog.setTitle("Add to Playlist");
ListView lv = (ListView) dialog.findViewById(R.id.playlist_list);
AddToPlaylistAdapter adapter;
if (allPlaylists.getPlaylists() != null && allPlaylists.getPlaylists().size() != 0) {
adapter = new AddToPlaylistAdapter(allPlaylists.getPlaylists(), ctx);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Playlist temp = allPlaylists.getPlaylists().get(position);
boolean isRepeat = false;
for (UnifiedTrack ut : temp.getSongList()) {
if (track.getType() && ut.getType() && track.getLocalTrack().getTitle().equals(ut.getLocalTrack().getTitle())) {
isRepeat = true;
break;
} else if (!track.getType() && !ut.getType() && track.getStreamTrack().getTitle().equals(ut.getStreamTrack().getTitle())) {
isRepeat = true;
break;
}
}
if (!isRepeat) {
temp.addSong(track);
playlistsRecycler.setVisibility(View.VISIBLE);
playlistNothingText.setVisibility(View.INVISIBLE);
pAdapter.notifyDataSetChanged();
Toast.makeText(ctx, "Added to Playlist : " + temp.getPlaylistName(), Toast.LENGTH_SHORT).show();
new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
} else {
Toast.makeText(ctx, "Song already present in Playlist", Toast.LENGTH_SHORT).show();
}
}
});
} else {
lv.setVisibility(GONE);
}
// set the custom dialog components - text, image and button
final EditText text = (EditText) dialog.findViewById(R.id.new_playlist_name);
ImageView image = (ImageView) dialog.findViewById(R.id.confirm_button);
// if button is clicked, close the custom dialog
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isNameRepeat = false;
if (text.getText().toString().trim().equals("")) {
text.setError("Enter Playlist Name!");
} else {
for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
if (text.getText().toString().equals(allPlaylists.getPlaylists().get(i).getPlaylistName())) {
isNameRepeat = true;
text.setError("Playlist with same name exists!");
break;
}
}
if (!isNameRepeat) {
List<UnifiedTrack> l = new ArrayList<UnifiedTrack>();
l.add(track);
Playlist pl = new Playlist(l, text.getText().toString().trim());
allPlaylists.addPlaylist(pl);
playlistsRecycler.setVisibility(View.VISIBLE);
playlistNothingText.setVisibility(View.INVISIBLE);
pAdapter.notifyDataSetChanged();
dialog.dismiss();
new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
});
dialog.show();
}
Aggregations