use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack 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();
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method onShuffleDisabled.
@Override
public void onShuffleDisabled() {
UnifiedTrack ut1 = queue.getQueue().get(queueCurrentIndex);
for (int i = 0; i < queue.getQueue().size(); i++) {
UnifiedTrack ut = queue.getQueue().get(i);
if (!originalQueue.getQueue().contains(ut)) {
originalQueue.getQueue().add(ut);
}
}
queue.getQueue().clear();
for (UnifiedTrack ut : originalQueue.getQueue()) {
queue.addToQueue(ut);
}
for (int i = 0; i < queue.getQueue().size(); i++) {
if (ut1.equals(queue.getQueue().get(i))) {
queueCurrentIndex = i;
break;
}
}
new SaveQueue().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method addFavToQueue.
@Override
public void addFavToQueue() {
for (UnifiedTrack ut : favouriteTracks.getFavourite()) {
queue.addToQueue(ut);
}
if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
playerFragment.snappyRecyclerView.setTransparency();
}
Toast.makeText(ctx, "Added " + favouriteTracks.getFavourite().size() + " song(s) to queue", Toast.LENGTH_SHORT).show();
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method onFavouriteItemClicked.
// //////////////////////////////////////////////////////////////////////////////////////////////
/*
* FavouriteFragment callbacks START
* onFavouriteItemClicked() -> when a song is selected from favourites.
* onFavouritePlayAll() -> when favourite play all fab is selected.
* addFavToQueue() -> when `add favourite to queue` is selected.
*/
@Override
public void onFavouriteItemClicked(int position) {
UnifiedTrack ut = favouriteTracks.getFavourite().get(position);
if (ut.getType()) {
LocalTrack track = ut.getLocalTrack();
if (queue.getQueue().size() == 0) {
queueCurrentIndex = 0;
queue.getQueue().add(new UnifiedTrack(true, track, null));
} else if (queueCurrentIndex == queue.getQueue().size() - 1) {
queueCurrentIndex++;
queue.getQueue().add(new UnifiedTrack(true, track, null));
} else if (isReloaded) {
isReloaded = false;
queueCurrentIndex = queue.getQueue().size();
queue.getQueue().add(new UnifiedTrack(true, track, null));
} else {
queue.getQueue().add(++queueCurrentIndex, new UnifiedTrack(true, track, null));
}
localSelectedTrack = track;
streamSelected = false;
localSelected = true;
queueCall = false;
isReloaded = false;
onLocalTrackSelected(position);
} else {
Track track = ut.getStreamTrack();
if (queue.getQueue().size() == 0) {
queueCurrentIndex = 0;
queue.getQueue().add(new UnifiedTrack(false, null, track));
} else if (queueCurrentIndex == queue.getQueue().size() - 1) {
queueCurrentIndex++;
queue.getQueue().add(new UnifiedTrack(false, null, track));
} else if (isReloaded) {
isReloaded = false;
queueCurrentIndex = queue.getQueue().size();
queue.getQueue().add(new UnifiedTrack(false, null, track));
} else {
queue.getQueue().add(++queueCurrentIndex, new UnifiedTrack(false, null, track));
}
selectedTrack = track;
streamSelected = true;
localSelected = false;
queueCall = false;
isReloaded = false;
onTrackSelected(position);
}
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method onQueueItemClicked2.
public void onQueueItemClicked2(int position) {
if (position <= (queue.getQueue().size() - 1)) {
queueCurrentIndex = position;
UnifiedTrack ut = queue.getQueue().get(position);
if (ut.getType()) {
LocalTrack track = ut.getLocalTrack();
localSelectedTrack = track;
streamSelected = false;
localSelected = true;
queueCall = true;
isReloaded = false;
onLocalTrackSelected(position);
} else {
Track track = ut.getStreamTrack();
selectedTrack = track;
streamSelected = true;
localSelected = false;
queueCall = true;
isReloaded = false;
onTrackSelected(position);
}
}
}
Aggregations