Search in sources :

Example 1 with Song

use of com.andrew.apollo.model.Song in project frostwire by frostwire.

the class SongAdapter method buildCache.

/**
 * Method used to cache the data used to populate the list or grid. The idea
 * is to cache everything before {@code #getView(int, View, ViewGroup)} is
 * called.
 */
public void buildCache() {
    mData = new DataHolder[getCount()];
    for (int i = 0; i < getCount(); i++) {
        // Build the song
        final Song song = getItem(i);
        if (song == null) {
            continue;
        }
        // Build the data holder
        mData[i] = new DataHolder();
        // Song Id
        mData[i].mItemId = song.mSongId;
        // Song names (line one)
        mData[i].mLineOne = song.mSongName;
        // Song duration (line one, right)
        mData[i].mLineOneRight = MusicUtils.makeTimeString(getContext(), song.mDuration);
        // Artist name (line two)
        mData[i].mLineTwo = song.mArtistName;
    }
}
Also used : Song(com.andrew.apollo.model.Song) DataHolder(com.andrew.apollo.ui.MusicViewHolder.DataHolder)

Example 2 with Song

use of com.andrew.apollo.model.Song in project frostwire by frostwire.

the class SearchLoader method loadInBackground.

/**
 * {@inheritDoc}
 */
@Override
public List<Song> loadInBackground() {
    ArrayList<Song> mSongList = new ArrayList<>();
    Cursor mCursor;
    try {
        mCursor = makeCursor(getContext());
    } catch (Throwable ignored) {
        return Collections.emptyList();
    }
    // Gather the data
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            // Copy the song Id
            long id = -1;
            // Copy the song name
            final String songName = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
            // Check for a song Id
            if (!TextUtils.isEmpty(songName)) {
                id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
            }
            // Copy the album name
            final String album = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
            // Check for a album Id
            if (id < 0 && !TextUtils.isEmpty(album)) {
                id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
            }
            // Copy the artist name
            final String artist = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
            // Check for a artist Id
            if (id < 0 && !TextUtils.isEmpty(artist)) {
                id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID));
            }
            // Create a new song
            final Song song = new Song(id, songName, artist, album, -1);
            // Add everything up
            mSongList.add(song);
        } while (mCursor.moveToNext());
    }
    // Close the cursor
    if (mCursor != null) {
        mCursor.close();
    }
    return mSongList;
}
Also used : Song(com.andrew.apollo.model.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 3 with Song

use of com.andrew.apollo.model.Song in project frostwire by frostwire.

the class ApolloFragment method onCreateContextMenu.

@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    int mSelectedPosition = info.position - mAdapter.getOffset();
    // Create a new song
    mItem = mAdapter.getItem(mSelectedPosition);
    // TODO: Remove these mutable properties, parametrize the onMenuEvent handlers.
    if (mItem instanceof Song) {
        Song mSong = (Song) mItem;
        mSelectedId = mSong.mSongId;
        mSongName = mSong.mSongName;
        mAlbumName = mSong.mAlbumName;
        mArtistName = mSong.mArtistName;
        mSongList = null;
    } else if (mItem instanceof Album) {
        Album mAlbum = (Album) mItem;
        mSelectedId = mAlbum.mAlbumId;
        mSongName = null;
        mAlbumName = mAlbum.mAlbumName;
        mArtistName = mAlbum.mArtistName;
        mSongList = MusicUtils.getSongListForAlbum(getActivity(), mAlbum.mAlbumId);
    } else if (mItem instanceof Artist) {
        Artist mArtist = (Artist) mItem;
        mSelectedId = mArtist.mArtistId;
        mSongName = null;
        mArtistName = mArtist.mArtistName;
        mSongList = MusicUtils.getSongListForArtist(getActivity(), mArtist.mArtistId);
    } else if (mItem instanceof Genre) {
        Genre mGenre = (Genre) mItem;
        mSelectedId = mGenre.mGenreId;
        mSongList = MusicUtils.getSongListForGenre(getActivity(), mGenre.mGenreId);
    } else if (mItem instanceof Playlist) {
        Playlist mPlaylist = (Playlist) mItem;
        mSelectedId = mPlaylist.mPlaylistId;
        if (mSelectedId == PlaylistLoader.FAVORITE_PLAYLIST_ID) {
            mSongList = MusicUtils.getSongListForFavorites(getActivity());
        } else if (mSelectedId == PlaylistLoader.LAST_ADDED_PLAYLIST_ID) {
            mSongList = MusicUtils.getSongListForLastAdded(getActivity());
        } else {
            mSongList = MusicUtils.getSongListForPlaylist(getActivity(), mPlaylist.mPlaylistId);
        }
    }
    // Play the selected songs
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE, getString(R.string.context_menu_play_selection)).setIcon(R.drawable.contextmenu_icon_play);
    // Play the next song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next)).setIcon(R.drawable.contextmenu_icon_next);
    // Add the song/album to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue)).setIcon(R.drawable.contextmenu_icon_queue_add);
    // Add the song to favorite's playlist
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_FAVORITES, Menu.NONE, R.string.add_to_favorites).setIcon(R.drawable.contextmenu_icon_favorite);
    // Add the song/album to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE, R.string.add_to_playlist).setIcon(R.drawable.contextmenu_icon_add_to_existing_playlist_dark);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);
    if (mItem instanceof Song) {
        menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE, getString(R.string.context_menu_use_as_ringtone)).setIcon(R.drawable.contextmenu_icon_ringtone);
    }
    // More by artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE, getString(R.string.context_menu_more_by_artist)).setIcon(R.drawable.contextmenu_icon_artist);
    // Delete the album
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete)).setIcon(R.drawable.contextmenu_icon_trash);
}
Also used : Artist(com.andrew.apollo.model.Artist) Song(com.andrew.apollo.model.Song) Playlist(com.andrew.apollo.model.Playlist) CreateNewPlaylist(com.andrew.apollo.menu.CreateNewPlaylist) Album(com.andrew.apollo.model.Album) AdapterView(android.widget.AdapterView) SubMenu(android.view.SubMenu) Genre(com.andrew.apollo.model.Genre)

Example 4 with Song

use of com.andrew.apollo.model.Song in project frostwire by frostwire.

the class ProfileSongAdapter method getView.

/**
 * {@inheritDoc}
 */
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    // Return a faux header at position 0
    if (position == 0) {
        return mHeader;
    }
    // Recycle MusicHolder's items
    MusicViewHolder holder;
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(mLayoutId, parent, false);
        holder = new MusicViewHolder(convertView);
        // Hide the third line of text
        holder.mLineThree.get().setVisibility(View.GONE);
        convertView.setTag(holder);
    } else {
        holder = (MusicViewHolder) convertView.getTag();
    }
    // Retrieve the album
    // getOffset());
    final Song song = getItem(position - 1);
    // Set each track name (line one)
    holder.mLineOne.get().setText(song.mSongName);
    // Set the line two
    switch(mDisplaySetting) {
        // show duration if on album fragment
        case DISPLAY_ALBUM_SETTING:
            holder.mLineOneRight.get().setVisibility(View.GONE);
            holder.mLineTwo.get().setText(MusicUtils.makeTimeString(getContext(), song.mDuration));
            break;
        case DISPLAY_PLAYLIST_SETTING:
            if (song.mDuration == -1) {
                holder.mLineOneRight.get().setVisibility(View.GONE);
            } else {
                holder.mLineOneRight.get().setVisibility(View.VISIBLE);
                holder.mLineOneRight.get().setText(MusicUtils.makeTimeString(getContext(), song.mDuration));
            }
            final StringBuilder sb = new StringBuilder(song.mArtistName);
            sb.append(SEPARATOR_STRING);
            sb.append(song.mAlbumName);
            holder.mLineTwo.get().setText(sb.toString());
            break;
        case DISPLAY_DEFAULT_SETTING:
        default:
            holder.mLineOneRight.get().setVisibility(View.VISIBLE);
            holder.mLineOneRight.get().setText(MusicUtils.makeTimeString(getContext(), song.mDuration));
            holder.mLineTwo.get().setText(song.mAlbumName);
            break;
    }
    return convertView;
}
Also used : Song(com.andrew.apollo.model.Song) MusicViewHolder(com.andrew.apollo.ui.MusicViewHolder)

Example 5 with Song

use of com.andrew.apollo.model.Song in project frostwire by frostwire.

the class MusicUtils method getSong.

public static Song getSong(Context context, final long songId) {
    final StringBuilder mSelection = new StringBuilder(BaseColumns._ID + "=?");
    mSelection.append(" AND " + AudioColumns.IS_MUSIC + "=1");
    // $NON-NLS-2$
    mSelection.append(" AND " + AudioColumns.TITLE + " != ''");
    final Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { /* 0 */
    BaseColumns._ID, /* 1 */
    AudioColumns.TITLE, /* 2 */
    AudioColumns.ARTIST, /* 3 */
    AudioColumns.ALBUM, /* 4 */
    AudioColumns.DURATION }, mSelection.toString(), new String[] { String.valueOf(songId) }, PreferenceUtils.getInstance().getSongSortOrder());
    if (cursor != null && cursor.getCount() == 1) {
        cursor.moveToFirst();
        return new Song(songId, cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4));
    } else {
        return null;
    }
}
Also used : Song(com.andrew.apollo.model.Song) Cursor(android.database.Cursor)

Aggregations

Song (com.andrew.apollo.model.Song)10 Cursor (android.database.Cursor)5 ArrayList (java.util.ArrayList)4 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1 CreateNewPlaylist (com.andrew.apollo.menu.CreateNewPlaylist)1 Album (com.andrew.apollo.model.Album)1 Artist (com.andrew.apollo.model.Artist)1 Genre (com.andrew.apollo.model.Genre)1 Playlist (com.andrew.apollo.model.Playlist)1 MusicViewHolder (com.andrew.apollo.ui.MusicViewHolder)1 DataHolder (com.andrew.apollo.ui.MusicViewHolder.DataHolder)1