use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.
the class FanartActivity method onDisconnected.
@Override
protected void onDisconnected() {
updateMPDStatus(new MPDCurrentStatus());
updateMPDCurrentTrack(new MPDTrack(""));
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.
the class FanartActivity method syncFanart.
/**
* Checks if new fanart is available for the given artist. This ensures that the user
* gets new images from time to time if they have old images in cache.
*
* @param track Track to check for new fanart for.
*/
private void syncFanart(final MPDTrack track) {
// Get a list of fanart urls for the current artist
if (!downloadAllowed()) {
return;
}
FanartTVManager.getInstance(getApplicationContext()).getArtistFanartURLs(track.getTrackArtistMBID(), response -> {
for (final String url : response) {
// Check if the given image is in the cache already.
if (mFanartCache.inCache(track.getTrackArtistMBID(), String.valueOf(url.hashCode()))) {
continue;
}
// If not try to download the image.
FanartTVManager.getInstance(getApplicationContext()).getFanartImage(track, url, response1 -> {
mFanartCache.addFanart(track.getTrackArtistMBID(), String.valueOf(response1.url.hashCode()), response1.image);
int fanartCount = mFanartCache.getFanartCount(response1.track.getTrackArtistMBID());
if (fanartCount == 1) {
updateFanartViews();
}
if (mCurrentFanart == (fanartCount - 2)) {
mNextFanart = (mCurrentFanart + 1) % fanartCount;
}
}, error -> {
});
}
}, new FanartFetchError() {
@Override
public void imageListFetchError() {
}
@Override
public void fanartFetchError(MPDTrack track) {
}
});
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.
the class ArtworkManager method fetchNextBulkTrackAlbum.
/**
* Iterates over the list of artists and downloads images for them.
*/
private void fetchNextBulkTrackAlbum() {
Log.v(TAG, "fetchNextBulkTrackAlbum");
boolean isEmpty;
synchronized (mTrackList) {
isEmpty = mTrackList.isEmpty();
}
while (!isEmpty) {
Log.v(TAG, "Next track album");
MPDTrack track;
synchronized (mTrackList) {
track = mTrackList.remove(0);
mBulkProgressCallback.albumsRemaining(mTrackList.size());
}
mCurrentBulkTrack = track;
// Check if image already there
try {
getAlbumImageForTrack(track, -1, -1, true);
// If this does not throw the exception it already has an image.
} catch (ImageNotFoundException e) {
fetchAlbumImage(track);
return;
}
synchronized (mTrackList) {
isEmpty = mTrackList.isEmpty();
}
}
if (mAlbumList.isEmpty()) {
mBulkProgressCallback.finishedLoading();
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.
the class ArtworkManager method fetchAlbumImage.
/**
* Starts an asynchronous fetch for the image of the given album
*
* @param track Track to be used for image fetching
*/
public void fetchAlbumImage(final MPDTrack track) {
// Create a dummy album
MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
album.setMBID(track.getTrackAlbumMBID());
album.setArtistName(track.getTrackAlbumArtist());
// Check if user-specified HTTP cover download is activated
if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
HTTPAlbumImageProvider.getInstance(mContext).fetchAlbumImage(track, response -> new InsertTrackAlbumImageTask().execute(response), new TrackAlbumFetchError() {
@Override
public void fetchJSONException(MPDTrack track, JSONException exception) {
}
@Override
public void fetchVolleyError(MPDTrack track, VolleyError error) {
Log.v(TAG, "Local HTTP download failed, try user-selected download provider");
MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
album.setMBID(track.getTrackAlbumMBID());
album.setArtistName(track.getTrackAlbumArtist());
fetchAlbumImage(album);
synchronized (mTrackList) {
if (!mTrackList.isEmpty()) {
fetchNextBulkTrackAlbum();
}
}
}
});
} else {
// Use the dummy album to fetch the image
fetchAlbumImage(album);
}
}
use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.
the class CurrentPlaylistAdapter method getView.
/**
* Create the actual listview items if no reusable object is provided.
*
* @param position Index of the item to create.
* @param convertView If != null this view can be reused to optimize performance.
* @param parent Parent of the view
* @return
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get MPDTrack at the given index used for this item.
MPDTrack track = getTrack(position);
// Check if the track was available in local data set already (or is currently fetching)
if (track != null) {
String trackAlbum = track.getTrackAlbum();
VIEW_TYPES type = VIEW_TYPES.values()[getItemViewType(position)];
// Normal track item type
if (type == VIEW_TYPES.TYPE_TRACK_ITEM) {
if (convertView == null) {
// If not create a new Listitem
convertView = new FileListItem(mContext, false);
}
FileListItem tracksListViewItem = (FileListItem) convertView;
tracksListViewItem.setTrack(track, true, mContext);
tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
} else if (type == VIEW_TYPES.TYPE_SECTION_TRACK_ITEM) {
// Section track type.
if (convertView == null) {
// If not create a new Listitem
convertView = new FileListItem(mContext, trackAlbum, false, this);
}
FileListItem tracksListViewItem = (FileListItem) convertView;
tracksListViewItem.setSectionHeader(trackAlbum);
tracksListViewItem.setTrack(track, true, mContext);
tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
// This will prepare the view for fetching the image from the internet if not already saved in local database.
((FileListItem) convertView).prepareArtworkFetching(mArtworkManager, track);
// starts the loading.
if (mScrollSpeed == 0) {
((FileListItem) convertView).startCoverImageTask();
}
}
if (null != mLastStatus && mLastStatus.getCurrentSongIndex() == position) {
((FileListItem) convertView).setPlaying(true);
} else {
((FileListItem) convertView).setPlaying(false);
}
} else {
// the running fetch.
if (convertView == null) {
// If not create a new Listitem
convertView = new FileListItem(mContext, false);
} else {
FileListItem tracksListViewItem = (FileListItem) convertView;
tracksListViewItem.setTrack(null, true, mContext);
}
}
// The view that is used for the position in the list
return convertView;
}
Aggregations