Search in sources :

Example 1 with Playlist

use of com.sdsmdg.harjot.MusicDNA.models.Playlist in project MusicDNA by harjot-oberai.

the class PlayListsHorizontalAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Playlist pl = playlists.get(position);
    List<UnifiedTrack> list = pl.getSongList();
    for (int i = 0; i < 4; i++) {
        holder.img[i].setImageBitmap(null);
    }
    if (list.size() >= 4) {
        for (int i = 0; i < 4; i++) {
            if (list.get(i).getType()) {
                imgLoader.DisplayImage(list.get(i).getLocalTrack().getPath(), holder.img[i]);
            } else {
                imgLoader.DisplayImage(list.get(i).getStreamTrack().getArtworkURL(), holder.img[i]);
            }
        }
    } else {
        int sz = list.size();
        for (int i = 0; i < sz; i++) {
            if (list.get(i).getType()) {
                imgLoader.DisplayImage(list.get(i).getLocalTrack().getPath(), holder.img[i]);
            } else {
                imgLoader.DisplayImage(list.get(i).getStreamTrack().getArtworkURL(), holder.img[i]);
            }
        }
    }
    holder.playlistName.setText(pl.getPlaylistName());
    if (pl.getSongList().size() > 1)
        holder.playlistSize.setText(String.valueOf(pl.getSongList().size()) + " Songs");
    else
        holder.playlistSize.setText(String.valueOf(pl.getSongList().size()) + " Song");
}
Also used : Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)

Example 2 with Playlist

use of com.sdsmdg.harjot.MusicDNA.models.Playlist in project MusicDNA by harjot-oberai.

the class ViewAllPlaylistsRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Playlist p = playlists.get(position);
    List<UnifiedTrack> list = p.getSongList();
    if (SplashActivity.tf3 != null)
        holder.playListName.setTypeface(SplashActivity.tf3);
    holder.playListName.setText(p.getPlaylistName());
    if (list.size() >= 3) {
        String[] names = new String[3];
        for (int i = 0; i < 3; i++) {
            if (list.get(i).getType()) {
                names[i] = list.get(i).getLocalTrack().getTitle();
                imgLoader.DisplayImage(list.get(i).getLocalTrack().getPath(), holder.img[i]);
            } else {
                names[i] = list.get(i).getStreamTrack().getTitle();
                imgLoader.DisplayImage(list.get(i).getStreamTrack().getArtworkURL(), holder.img[i]);
            }
            holder.name[i].setText(names[i]);
        }
        holder.continuedSymbol.setVisibility(View.VISIBLE);
    } else {
        int sz = list.size();
        String[] names = new String[3];
        for (int i = 0; i < sz; i++) {
            if (list.get(i).getType()) {
                names[i] = list.get(i).getLocalTrack().getTitle();
                imgLoader.DisplayImage(list.get(i).getLocalTrack().getPath(), holder.img[i]);
            } else {
                names[i] = list.get(i).getStreamTrack().getTitle();
                imgLoader.DisplayImage(list.get(i).getStreamTrack().getArtworkURL(), holder.img[i]);
            }
            holder.name[i].setText(names[i]);
        }
    }
}
Also used : Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)

Example 3 with Playlist

use of com.sdsmdg.harjot.MusicDNA.models.Playlist 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();
}
Also used : EditText(android.widget.EditText) AddToPlaylistAdapter(com.sdsmdg.harjot.MusicDNA.adapters.playlistdialogadapter.AddToPlaylistAdapter) ImageView(android.widget.ImageView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WheelView(com.lantouzi.wheelview.WheelView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) ListView(android.widget.ListView) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) AdapterView(android.widget.AdapterView) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView)

Example 4 with Playlist

use of com.sdsmdg.harjot.MusicDNA.models.Playlist in project MusicDNA by harjot-oberai.

the class HomeActivity method showSaveQueueDialog.

public void showSaveQueueDialog() {
    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.add_to_playlist_dialog);
    dialog.setTitle("Save Queue");
    ListView lv = (ListView) dialog.findViewById(R.id.playlist_list);
    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) {
                    Playlist pl = new Playlist(text.getText().toString());
                    for (int i = 0; i < queue.getQueue().size(); i++) {
                        pl.getSongList().add(queue.getQueue().get(i));
                    }
                    allPlaylists.addPlaylist(pl);
                    playlistsRecycler.setVisibility(View.VISIBLE);
                    playlistNothingText.setVisibility(View.INVISIBLE);
                    pAdapter.notifyDataSetChanged();
                    new SavePlaylists().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    Toast.makeText(HomeActivity.this, "Queue saved!", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }
            }
        }
    });
    dialog.show();
}
Also used : EditText(android.widget.EditText) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) ListView(android.widget.ListView) Dialog(android.app.Dialog) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ImageView(android.widget.ImageView) VisualizerView(com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WheelView(com.lantouzi.wheelview.WheelView) ListView(android.widget.ListView)

Example 5 with Playlist

use of com.sdsmdg.harjot.MusicDNA.models.Playlist in project MusicDNA by harjot-oberai.

the class HomeActivity method getLocalSongs.

private void getLocalSongs() {
    localTrackList.clear();
    recentlyAddedTrackList.clear();
    finalLocalSearchResultList.clear();
    finalRecentlyAddedTrackSearchResultList.clear();
    albums.clear();
    finalAlbums.clear();
    artists.clear();
    finalArtists.clear();
    ContentResolver musicResolver = this.getContentResolver();
    Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor musicCursor = musicResolver.query(musicUri, null, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
    if (musicCursor != null && musicCursor.moveToFirst()) {
        // get columns
        int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
        int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
        int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
        int albumColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
        int pathColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
        int durationColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
        // add songs to list
        do {
            long thisId = musicCursor.getLong(idColumn);
            String thisTitle = musicCursor.getString(titleColumn);
            String thisArtist = musicCursor.getString(artistColumn);
            String thisAlbum = musicCursor.getString(albumColumn);
            String path = musicCursor.getString(pathColumn);
            long duration = musicCursor.getLong(durationColumn);
            if (duration > 10000) {
                LocalTrack lt = new LocalTrack(thisId, thisTitle, thisArtist, thisAlbum, path, duration);
                localTrackList.add(lt);
                finalLocalSearchResultList.add(lt);
                if (recentlyAddedTrackList.size() <= 50) {
                    recentlyAddedTrackList.add(lt);
                    finalRecentlyAddedTrackSearchResultList.add(lt);
                }
                int pos;
                if (thisAlbum != null) {
                    pos = checkAlbum(thisAlbum);
                    if (pos != -1) {
                        albums.get(pos).getAlbumSongs().add(lt);
                    } else {
                        List<LocalTrack> llt = new ArrayList<>();
                        llt.add(lt);
                        Album ab = new Album(thisAlbum, llt);
                        albums.add(ab);
                    }
                    if (pos != -1) {
                        finalAlbums.get(pos).getAlbumSongs().add(lt);
                    } else {
                        List<LocalTrack> llt = new ArrayList<>();
                        llt.add(lt);
                        Album ab = new Album(thisAlbum, llt);
                        finalAlbums.add(ab);
                    }
                }
                if (thisArtist != null) {
                    pos = checkArtist(thisArtist);
                    if (pos != -1) {
                        artists.get(pos).getArtistSongs().add(lt);
                    } else {
                        List<LocalTrack> llt = new ArrayList<>();
                        llt.add(lt);
                        Artist ab = new Artist(thisArtist, llt);
                        artists.add(ab);
                    }
                    if (pos != -1) {
                        finalArtists.get(pos).getArtistSongs().add(lt);
                    } else {
                        List<LocalTrack> llt = new ArrayList<>();
                        llt.add(lt);
                        Artist ab = new Artist(thisArtist, llt);
                        finalArtists.add(ab);
                    }
                }
                File f = new File(path);
                String dirName = f.getParentFile().getName();
                if (getFolder(dirName) == null) {
                    MusicFolder mf = new MusicFolder(dirName);
                    mf.getLocalTracks().add(lt);
                    allMusicFolders.getMusicFolders().add(mf);
                } else {
                    getFolder(dirName).getLocalTracks().add(lt);
                }
            }
        } while (musicCursor.moveToNext());
    }
    if (musicCursor != null)
        musicCursor.close();
    System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
    try {
        if (localTrackList.size() > 0) {
            Collections.sort(localTrackList, new LocalMusicComparator());
            Collections.sort(finalLocalSearchResultList, new LocalMusicComparator());
        }
        if (albums.size() > 0) {
            Collections.sort(albums, new AlbumComparator());
            Collections.sort(finalAlbums, new AlbumComparator());
        }
        if (artists.size() > 0) {
            Collections.sort(artists, new ArtistComparator());
            Collections.sort(finalArtists, new ArtistComparator());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<UnifiedTrack> tmp = new ArrayList<>();
    boolean queueCurrentIndexCollision = false;
    int indexCorrection = 0;
    for (int i = 0; i < queue.getQueue().size(); i++) {
        UnifiedTrack ut = queue.getQueue().get(i);
        if (ut.getType()) {
            if (!checkTrack(ut.getLocalTrack())) {
                if (i == queueCurrentIndex) {
                    queueCurrentIndexCollision = true;
                } else if (i < queueCurrentIndex) {
                    indexCorrection++;
                }
                tmp.add(ut);
            }
        }
    }
    for (int i = 0; i < tmp.size(); i++) {
        queue.getQueue().remove(tmp.get(i));
    }
    if (queueCurrentIndexCollision) {
        if (queue.getQueue().size() > 0) {
            queueCurrentIndex = 0;
        } else {
            queue = new Queue();
        }
    } else {
        queueCurrentIndex -= indexCorrection;
    }
    tmp.clear();
    for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
        UnifiedTrack ut = recentlyPlayed.getRecentlyPlayed().get(i);
        if (ut.getType()) {
            if (!checkTrack(ut.getLocalTrack())) {
                tmp.add(ut);
            }
        }
    }
    for (int i = 0; i < tmp.size(); i++) {
        recentlyPlayed.getRecentlyPlayed().remove(tmp.get(i));
    }
    List<UnifiedTrack> temp = new ArrayList<>();
    List<Playlist> tmpPL = new ArrayList<>();
    for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
        Playlist pl = allPlaylists.getPlaylists().get(i);
        for (int j = 0; j < pl.getSongList().size(); j++) {
            UnifiedTrack ut = pl.getSongList().get(j);
            if (ut.getType()) {
                if (!checkTrack(ut.getLocalTrack())) {
                    temp.add(ut);
                }
            }
        }
        for (int j = 0; j < temp.size(); j++) {
            pl.getSongList().remove(temp.get(j));
        }
        temp.clear();
        if (pl.getSongList().size() == 0) {
            tmpPL.add(pl);
        }
    }
    for (int i = 0; i < tmpPL.size(); i++) {
        allPlaylists.getPlaylists().remove(tmpPL.get(i));
    }
    tmpPL.clear();
}
Also used : Artist(com.sdsmdg.harjot.MusicDNA.models.Artist) ArrayList(java.util.ArrayList) Album(com.sdsmdg.harjot.MusicDNA.models.Album) LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) Cursor(android.database.Cursor) LocalMusicComparator(com.sdsmdg.harjot.MusicDNA.utilities.comparators.LocalMusicComparator) Uri(android.net.Uri) MusicFolder(com.sdsmdg.harjot.MusicDNA.models.MusicFolder) TextPaint(android.text.TextPaint) FileNotFoundException(java.io.FileNotFoundException) ContentResolver(android.content.ContentResolver) Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) AlbumComparator(com.sdsmdg.harjot.MusicDNA.utilities.comparators.AlbumComparator) File(java.io.File) Queue(com.sdsmdg.harjot.MusicDNA.models.Queue) ArtistComparator(com.sdsmdg.harjot.MusicDNA.utilities.comparators.ArtistComparator)

Aggregations

Playlist (com.sdsmdg.harjot.MusicDNA.models.Playlist)10 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)8 View (android.view.View)5 TextView (android.widget.TextView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 ImageView (android.widget.ImageView)4 Dialog (android.app.Dialog)3 NavigationView (android.support.design.widget.NavigationView)3 SearchView (android.support.v7.widget.SearchView)3 AdapterView (android.widget.AdapterView)3 EditText (android.widget.EditText)3 ListView (android.widget.ListView)3 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)3 WheelView (com.lantouzi.wheelview.WheelView)3 CustomGeneralBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog)3 CustomLocalBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog)3 VisualizerView (com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView)3 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)3 TextPaint (android.text.TextPaint)2 ArrayList (java.util.ArrayList)2