Search in sources :

Example 6 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class AlbumsFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    String libraryView = sharedPref.getString(getString(R.string.pref_library_view_key), getString(R.string.pref_library_view_default));
    if (libraryView.equals(getString(R.string.pref_library_view_list_key))) {
        mUseList = true;
    }
    View rootView;
    // get gridview
    if (mUseList) {
        rootView = inflater.inflate(R.layout.listview_layout_refreshable, container, false);
        mAdapterView = (ListView) rootView.findViewById(R.id.main_listview);
    } else {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_gridview, container, false);
        mAdapterView = (GridView) rootView.findViewById(R.id.grid_refresh_gridview);
    }
    mSortOrder = PreferenceHelper.getMPDAlbumSortOrder(sharedPref, getContext());
    mUseArtistSort = sharedPref.getBoolean(getString(R.string.pref_use_artist_sort_key), getResources().getBoolean(R.bool.pref_use_artist_sort_default));
    mAlbumsAdapter = new AlbumsAdapter(getActivity(), mAdapterView, mUseList);
    /* Check if an artistname was given in the extras */
    Bundle args = getArguments();
    if (null != args) {
        mAlbumsPath = args.getString(BUNDLE_STRING_EXTRA_PATH);
        mArtist = args.getParcelable(BUNDLE_STRING_EXTRA_ARTIST);
        mBitmap = args.getParcelable(BUNDLE_STRING_EXTRA_BITMAP);
    } else {
        mAlbumsPath = "";
        // Create dummy album
        mArtist = new MPDArtist("");
    }
    mAdapterView.setAdapter(mAlbumsAdapter);
    mAdapterView.setOnItemClickListener(this);
    mAdapterView.setOnScrollListener(new ScrollSpeedListener(mAlbumsAdapter, mAdapterView));
    // register for context menu
    registerForContextMenu(mAdapterView);
    setHasOptionsMenu(true);
    // get swipe layout
    mSwipeRefreshLayout = rootView.findViewById(R.id.refresh_layout);
    // set swipe colors
    mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent), ThemeUtils.getThemeColor(getContext(), R.attr.colorPrimary));
    // set swipe refresh listener
    mSwipeRefreshLayout.setOnRefreshListener(this::refreshContent);
    mBitmapLoader = new CoverBitmapLoader(getContext(), this);
    return rootView;
}
Also used : CoverBitmapLoader(org.gateshipone.malp.application.utils.CoverBitmapLoader) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ScrollSpeedListener(org.gateshipone.malp.application.utils.ScrollSpeedListener) AlbumsAdapter(org.gateshipone.malp.application.adapters.AlbumsAdapter) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 7 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class MPDInterface method getAlbumArtists.

/**
 * Get a list of all album artists available in MPDs database
 *
 * @return List of MPDArtist objects
 */
public List<MPDArtist> getAlbumArtists() throws MPDException {
    // Get list of artists for MBID correction
    List<MPDArtist> normalArtists = getArtists();
    MPDCapabilities capabilities = mConnection.getServerCapabilities();
    List<MPDArtist> artists;
    synchronized (this) {
        // Get a list of artists. If server is new enough this will contain MBIDs for artists, that are tagged correctly.
        mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMARTISTS(capabilities.hasListGroup() && capabilities.hasMusicBrainzTags()));
        artists = MPDResponseParser.parseMPDArtists(mConnection, capabilities.hasMusicBrainzTags(), capabilities.hasListGroup());
    }
    // If MusicBrainz support is present, try to correct the MBIDs
    if (capabilities.hasMusicBrainzTags()) {
        // Merge normalArtists MBIDs with album artists MBIDs
        HashMap<String, MPDArtist> normalArtistsHashed = new HashMap<>();
        for (MPDArtist artist : normalArtists) {
            normalArtistsHashed.put(artist.getArtistName(), artist);
        }
        // For every albumartist try to get normal artistMBID
        for (MPDArtist artist : artists) {
            MPDArtist hashedArtist = normalArtistsHashed.get(artist.getArtistName());
            if (hashedArtist != null && hashedArtist.getMBIDCount() > 0) {
                artist.setMBID(hashedArtist.getMBID(0));
            }
        }
    }
    // Remove first empty artist if present.
    if (artists.size() > 0 && artists.get(0).getArtistName().isEmpty()) {
        artists.remove(0);
    }
    return artists;
}
Also used : HashMap(java.util.HashMap) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 8 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class MPDInterface method getAlbumArtistsSort.

/**
 * Get a list of all album artists available in MPDs database
 *
 * @return List of MPDArtist objects
 */
public List<MPDArtist> getAlbumArtistsSort() throws MPDException {
    MPDCapabilities capabilities = mConnection.getServerCapabilities();
    // Check if tag is supported
    if (!capabilities.hasTagAlbumArtistSort()) {
        return getAlbumArtists();
    }
    // Get list of artists for MBID correction
    List<MPDArtist> normalArtists = getArtistsSort();
    List<MPDArtist> artists;
    synchronized (this) {
        // Get a list of artists. If server is new enough this will contain MBIDs for artists, that are tagged correctly.
        mConnection.sendMPDCommand(MPDCommands.MPD_COMMAND_REQUEST_ALBUMARTISTS_SORT(capabilities.hasListGroup() && capabilities.hasMusicBrainzTags()));
        artists = MPDResponseParser.parseMPDArtists(mConnection, capabilities.hasMusicBrainzTags(), capabilities.hasListGroup());
    }
    // If MusicBrainz support is present, try to correct the MBIDs
    if (capabilities.hasMusicBrainzTags()) {
        // Merge normalArtists MBIDs with album artists MBIDs
        HashMap<String, MPDArtist> normalArtistsHashed = new HashMap<>();
        for (MPDArtist artist : normalArtists) {
            normalArtistsHashed.put(artist.getArtistName(), artist);
        }
        // For every albumartist try to get normal artistMBID
        for (MPDArtist artist : artists) {
            MPDArtist hashedArtist = normalArtistsHashed.get(artist.getArtistName());
            if (hashedArtist != null && hashedArtist.getMBIDCount() > 0) {
                artist.setMBID(hashedArtist.getMBID(0));
            }
        }
    }
    // Remove first empty artist if present.
    if (artists.size() > 0 && artists.get(0).getArtistName().isEmpty()) {
        artists.remove(0);
    }
    return artists;
}
Also used : HashMap(java.util.HashMap) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 9 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class MainActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (info == null) {
        return super.onContextItemSelected(item);
    }
    CurrentPlaylistView currentPlaylistView = findViewById(R.id.now_playing_playlist);
    if (currentPlaylistView != null && mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP) {
        MPDTrack track = (MPDTrack) currentPlaylistView.getItem(info.position);
        switch(item.getItemId()) {
            case R.id.action_song_play_next:
                MPDQueryHandler.playIndexAsNext(info.position);
                return true;
            case R.id.action_add_to_saved_playlist:
                // open dialog in order to save the current playlist as a playlist in the mediastore
                ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
                Bundle args = new Bundle();
                args.putBoolean(ChoosePlaylistDialog.EXTRA_SHOW_NEW_ENTRY, true);
                choosePlaylistDialog.setCallback(new AddPathToPlaylist(track, this));
                choosePlaylistDialog.setArguments(args);
                choosePlaylistDialog.show(getSupportFragmentManager(), "ChoosePlaylistDialog");
                return true;
            case R.id.action_remove_song:
                MPDQueryHandler.removeSongFromCurrentPlaylist(info.position);
                return true;
            case R.id.action_remove_album:
                currentPlaylistView.removeAlbumFrom(info.position);
                return true;
            case R.id.action_show_artist:
                if (mUseArtistSort) {
                    onArtistSelected(new MPDArtist(track.getTrackArtistSort()), null);
                } else {
                    onArtistSelected(new MPDArtist(track.getTrackArtist()), null);
                }
                return true;
            case R.id.action_show_album:
                MPDAlbum tmpAlbum = new MPDAlbum(track.getTrackAlbum());
                // Set album artist
                if (!track.getTrackAlbumArtist().isEmpty()) {
                    tmpAlbum.setArtistName(track.getTrackAlbumArtist());
                } else {
                    tmpAlbum.setArtistName(track.getTrackArtist());
                }
                // Set albumartistsort
                if (!track.getTrackAlbumArtistSort().isEmpty()) {
                    tmpAlbum.setArtistSortName(track.getTrackAlbumArtistSort());
                } else {
                    tmpAlbum.setArtistSortName(track.getTrackArtistSort());
                }
                tmpAlbum.setMBID(track.getTrackAlbumMBID());
                onAlbumSelected(tmpAlbum, null);
                return true;
            case R.id.action_show_details:
                // Open song details dialog
                SongDetailsDialog songDetailsDialog = new SongDetailsDialog();
                Bundle songArgs = new Bundle();
                songArgs.putParcelable(SongDetailsDialog.EXTRA_FILE, track);
                songDetailsDialog.setArguments(songArgs);
                songDetailsDialog.show(getSupportFragmentManager(), "SongDetails");
                return true;
        }
    }
    return false;
}
Also used : AddPathToPlaylist(org.gateshipone.malp.application.callbacks.AddPathToPlaylist) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) Bundle(android.os.Bundle) ChoosePlaylistDialog(org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog) AdapterView(android.widget.AdapterView) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) CurrentPlaylistView(org.gateshipone.malp.application.views.CurrentPlaylistView) SongDetailsDialog(org.gateshipone.malp.application.fragments.serverfragments.SongDetailsDialog)

Example 10 with MPDArtist

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist in project malp by gateship-one.

the class ArtistsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MPDArtist artist = (MPDArtist) getItem(position);
    String label = artist.getArtistName();
    if (label.isEmpty()) {
        label = mContext.getResources().getString(R.string.no_artist_tag);
    }
    if (mUseList) {
        // Check if a view can be recycled
        ImageListItem listItem;
        if (convertView != null) {
            listItem = (ImageListItem) convertView;
            // Make sure to reset the layoutParams in case of change (rotation for example)
            listItem.setText(label);
        } else {
            // Create new view if no reusable is available
            listItem = new ImageListItem(mContext, label, null, this);
        }
        // This will prepare the view for fetching the image from the internet if not already saved in local database.
        listItem.prepareArtworkFetching(mArtworkManager, artist);
        // Check if the scroll speed currently is already 0, then start the image task right away.
        if (mScrollSpeed == 0) {
            listItem.setImageDimension(mListItemHeight, mListItemHeight);
            listItem.startCoverImageTask();
        }
        return listItem;
    } else {
        GenericGridItem gridItem;
        ViewGroup.LayoutParams layoutParams;
        int width = ((GridView) mListView).getColumnWidth();
        // Check if a view can be recycled
        if (convertView == null) {
            // Create new view if no reusable is available
            gridItem = new GenericGridItem(mContext, label, this);
            layoutParams = new android.widget.AbsListView.LayoutParams(width, width);
        } else {
            gridItem = (GenericGridItem) convertView;
            gridItem.setTitle(label);
            layoutParams = gridItem.getLayoutParams();
            layoutParams.height = width;
            layoutParams.width = width;
        }
        // Make sure to reset the layoutParams in case of change (rotation for example)
        gridItem.setLayoutParams(layoutParams);
        // This will prepare the view for fetching the image from the internet if not already saved in local database.
        gridItem.prepareArtworkFetching(mArtworkManager, artist);
        // Check if the scroll speed currently is already 0, then start the image task right away.
        if (mScrollSpeed == 0) {
            gridItem.setImageDimension(width, width);
            gridItem.startCoverImageTask();
        }
        return gridItem;
    }
}
Also used : ImageListItem(org.gateshipone.malp.application.listviewitems.ImageListItem) GenericGridItem(org.gateshipone.malp.application.listviewitems.GenericGridItem) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist) GridView(android.widget.GridView)

Aggregations

MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)15 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)5 Bitmap (android.graphics.Bitmap)3 HashMap (java.util.HashMap)3 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)2 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)2 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)2 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1