mirror of
https://github.com/playmusicexporter/playmusicexporter
synced 2024-05-14 14:46:42 +00:00
Create a subclass for artwork properties
This commit is contained in:
parent
c36675f639
commit
ea84b5f685
|
@ -90,12 +90,8 @@ public class MusicContainerListAdapter extends ArrayAdapter<MusicTrackList> {
|
|||
// Final for the callback
|
||||
imageView = (ImageView)view.findViewById(R.id.image_music_track_artwork);
|
||||
|
||||
// Gets the artwork
|
||||
String artworkPath = musicTrackList.getArtworkPath();
|
||||
String artworkLocation = musicTrackList.getArtworkLocation();
|
||||
|
||||
// Loads the artwork
|
||||
ArtworkViewLoader.loadImage(imageView, artworkPath, artworkLocation, R.drawable.cd_case);
|
||||
ArtworkViewLoader.loadImage(musicTrackList, imageView, R.drawable.cd_case);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -134,10 +134,7 @@ public class MusicTrackListAdapter extends ArrayAdapter<MusicTrack> {
|
|||
if (mShowArtworks) {
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.image_music_track_artwork);
|
||||
|
||||
String artworkPath = musicTrack.getArtworkPath();
|
||||
String artworkLocation = musicTrack.getArtworkLocation();
|
||||
|
||||
ArtworkViewLoader.loadImage(imageView, artworkPath, artworkLocation, R.drawable.cd_case);
|
||||
ArtworkViewLoader.loadImage(musicTrack, imageView, R.drawable.cd_case);
|
||||
}
|
||||
|
||||
// Sets the title
|
||||
|
|
|
@ -130,11 +130,8 @@ public class MusicTrackListFragment extends Fragment {
|
|||
// Sets the artwork image
|
||||
imageView = (ImageView)headerView.findViewById(R.id.image_music_track_artwork);
|
||||
|
||||
String artworkPath = mMusicTrackList.getArtworkPath();
|
||||
String artworkLocation = mMusicTrackList.getArtworkLocation();
|
||||
|
||||
// Loads the artwork
|
||||
ArtworkViewLoader.loadImage(imageView, artworkPath, artworkLocation, R.drawable.cd_case);
|
||||
ArtworkViewLoader.loadImage(mMusicTrackList, imageView, R.drawable.cd_case);
|
||||
|
||||
// Sets the title
|
||||
textView = (TextView)headerView.findViewById(R.id.text_music_track_list_title);
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.lang.ref.WeakReference;
|
|||
|
||||
import de.arcus.playmusiclib.ArtworkLoader;
|
||||
import de.arcus.playmusiclib.ArtworkLoaderCallback;
|
||||
import de.arcus.playmusiclib.items.ArtworkEntry;
|
||||
|
||||
/**
|
||||
* Class to load artworks
|
||||
|
@ -52,47 +53,32 @@ public class ArtworkViewLoader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Path of the image
|
||||
* The artwork entry
|
||||
*/
|
||||
private String mImagePath;
|
||||
|
||||
/**
|
||||
* Url of the image
|
||||
*/
|
||||
private String mImageUrl;
|
||||
private ArtworkEntry mArtworkEntry;
|
||||
|
||||
/**
|
||||
* Path of the new image which will be loaded after the current loading is completed
|
||||
*/
|
||||
private String mNewImagePath;
|
||||
private String mNewImageUrl;
|
||||
private ArtworkEntry mNewArtworkEntry;
|
||||
|
||||
/**
|
||||
* The default image of the image view
|
||||
*/
|
||||
private int mDefaultImage;
|
||||
|
||||
/**
|
||||
* @return Gets the path of the image we want to load
|
||||
*/
|
||||
public String getImagePath() {
|
||||
return mImagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an image loader
|
||||
* @param artworkEntry The artwork entry
|
||||
* @param imageView The image view
|
||||
* @param path The file path
|
||||
* @param defaultImage The default image in case the image could not be loaded
|
||||
*/
|
||||
public static void loadImage(ImageView imageView, String path, String url, int defaultImage) {
|
||||
public static void loadImage(ArtworkEntry artworkEntry, ImageView imageView, int defaultImage) {
|
||||
// Checks for an old artwork loader on this image view
|
||||
ArtworkViewLoader imageViewLoader = (ArtworkViewLoader)imageView.getTag();
|
||||
|
||||
if (path == null) path = "";
|
||||
|
||||
if (imageViewLoader == null) {
|
||||
imageViewLoader = new ArtworkViewLoader(imageView, path, url, defaultImage);
|
||||
imageViewLoader = new ArtworkViewLoader(artworkEntry, imageView, defaultImage);
|
||||
|
||||
// Save the loader in the tag
|
||||
// If someone wants to load another artwork to this view
|
||||
|
@ -101,19 +87,19 @@ public class ArtworkViewLoader {
|
|||
imageViewLoader.loadImage();
|
||||
} else {
|
||||
// Updates the old loader
|
||||
imageViewLoader.updateImage(path, url);
|
||||
imageViewLoader.updateImage(artworkEntry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a image to an image view
|
||||
* @param imageView The image view we want to set
|
||||
* @param path The path to load
|
||||
* @param artworkEntry The artwork entry
|
||||
* @param imageView The image view
|
||||
* @param defaultImage The default image in case the image could not be loaded
|
||||
*/
|
||||
private ArtworkViewLoader(ImageView imageView, String path, String url, int defaultImage) {
|
||||
private ArtworkViewLoader(ArtworkEntry artworkEntry, ImageView imageView, int defaultImage) {
|
||||
mImageView = new WeakReference<>(imageView);
|
||||
mImagePath = path;
|
||||
mImageUrl = url;
|
||||
mArtworkEntry = artworkEntry;
|
||||
mDefaultImage = defaultImage;
|
||||
}
|
||||
|
||||
|
@ -144,7 +130,7 @@ public class ArtworkViewLoader {
|
|||
mIsLoading = true;
|
||||
|
||||
// Load the artwork
|
||||
ArtworkLoader.loadArtworkAsync(mImagePath, mImageUrl, maximalArtworkSize, new ArtworkLoaderCallback() {
|
||||
ArtworkLoader.loadArtworkAsync(mArtworkEntry, maximalArtworkSize, new ArtworkLoaderCallback() {
|
||||
@Override
|
||||
public void onFinished(final Bitmap bitmap) {
|
||||
final ImageView imageView = mImageView.get();
|
||||
|
@ -168,11 +154,9 @@ public class ArtworkViewLoader {
|
|||
mIsLoading = false;
|
||||
|
||||
// Loads the next image
|
||||
if (mNewImagePath != null) {
|
||||
mImagePath = mNewImagePath;
|
||||
mImageUrl = mNewImageUrl;
|
||||
mNewImagePath = null;
|
||||
mNewImageUrl = null;
|
||||
if (mNewArtworkEntry != null) {
|
||||
mArtworkEntry = mNewArtworkEntry;
|
||||
mNewArtworkEntry = null;
|
||||
|
||||
loadImage();
|
||||
}
|
||||
|
@ -182,20 +166,18 @@ public class ArtworkViewLoader {
|
|||
|
||||
/**
|
||||
* Loads a new artwork
|
||||
* @param path New artwork path
|
||||
* @param artworkEntry New artwork entry
|
||||
*/
|
||||
private void updateImage(String path, String url) {
|
||||
private void updateImage(ArtworkEntry artworkEntry) {
|
||||
// The same artwork; nothing to do
|
||||
if (path.equals(mImagePath)) {
|
||||
if (artworkEntry.getArtworkLocation().equals(mArtworkEntry.getArtworkLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsLoading) {
|
||||
mNewImagePath = path;
|
||||
mNewImageUrl = url;
|
||||
mNewArtworkEntry = artworkEntry;
|
||||
} else {
|
||||
mImagePath = path;
|
||||
mImageUrl = url;
|
||||
mArtworkEntry = artworkEntry;
|
||||
loadImage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.URL;
|
|||
import de.arcus.framework.logger.Logger;
|
||||
import de.arcus.framework.superuser.SuperUserTools;
|
||||
import de.arcus.framework.utils.ImageTools;
|
||||
import de.arcus.playmusiclib.items.ArtworkEntry;
|
||||
|
||||
/**
|
||||
* This class contains methods to load the artworks from the Play Music cache or from the internet
|
||||
|
@ -39,13 +40,14 @@ import de.arcus.framework.utils.ImageTools;
|
|||
public class ArtworkLoader {
|
||||
/**
|
||||
* Loads an artwork
|
||||
* @param artworkPath The local filepath
|
||||
* @param artworkUrl The remote url
|
||||
* @param artworkEntry The artwork entry
|
||||
* @param artworkSize The size
|
||||
* @return The loaded bitmap or null if it failed
|
||||
*/
|
||||
public static Bitmap loadArtwork(String artworkPath, String artworkUrl, int artworkSize) {
|
||||
public static Bitmap loadArtwork(ArtworkEntry artworkEntry, int artworkSize) {
|
||||
Bitmap bitmap = null;
|
||||
String artworkPath = artworkEntry.getArtworkPath();
|
||||
String artworkUrl = artworkEntry.getArtworkLocation();
|
||||
|
||||
// The local path is set
|
||||
if (!TextUtils.isEmpty(artworkPath)) {
|
||||
|
@ -81,12 +83,11 @@ public class ArtworkLoader {
|
|||
|
||||
/**
|
||||
* Loads an artwork
|
||||
* @param artworkPath The local filepath
|
||||
* @param artworkUrl The remote url
|
||||
* @param artworkEntry The artwork entry
|
||||
* @param artworkSize The size
|
||||
* @param callback The callback
|
||||
*/
|
||||
public static void loadArtworkAsync(final String artworkPath, final String artworkUrl, final int artworkSize, final ArtworkLoaderCallback callback) {
|
||||
public static void loadArtworkAsync(final ArtworkEntry artworkEntry, final int artworkSize, final ArtworkLoaderCallback callback) {
|
||||
// The main handler
|
||||
final Handler handler = new Handler();
|
||||
|
||||
|
@ -94,7 +95,7 @@ public class ArtworkLoader {
|
|||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Bitmap bitmap = loadArtwork(artworkPath, artworkUrl, artworkSize);
|
||||
final Bitmap bitmap = loadArtwork(artworkEntry, artworkSize);
|
||||
|
||||
// Call the callback event in the main thread
|
||||
handler.post(new Runnable() {
|
||||
|
|
|
@ -602,11 +602,8 @@ public class PlayMusicManager {
|
|||
|
||||
// Add the artwork to the meta data
|
||||
if (mID3EnableArtwork) {
|
||||
String artworkPath = musicTrack.getArtworkPath();
|
||||
String artworkLocation = musicTrack.getArtworkLocation();
|
||||
|
||||
// Load the artwork
|
||||
Bitmap bitmap = ArtworkLoader.loadArtwork(artworkPath, artworkLocation, mID3ArtworkMaximumSize);
|
||||
Bitmap bitmap = ArtworkLoader.loadArtwork(musicTrack, mID3ArtworkMaximumSize);
|
||||
|
||||
if (bitmap != null) {
|
||||
// JPEG is default
|
||||
|
|
|
@ -22,8 +22,76 @@
|
|||
|
||||
package de.arcus.playmusiclib.items;
|
||||
|
||||
import de.arcus.playmusiclib.PlayMusicManager;
|
||||
|
||||
/**
|
||||
* Created by david on 14.05.15.
|
||||
*/
|
||||
public interface ArtworkEntry {
|
||||
public class ArtworkEntry {
|
||||
/**
|
||||
* The manager
|
||||
*/
|
||||
protected PlayMusicManager mPlayMusicManager;
|
||||
|
||||
/**
|
||||
* Creates a data item
|
||||
* @param playMusicManager The manager
|
||||
*/
|
||||
public ArtworkEntry(PlayMusicManager playMusicManager) {
|
||||
mPlayMusicManager = playMusicManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* The filename of the artwork
|
||||
*/
|
||||
protected String mArtworkFile;
|
||||
|
||||
/**
|
||||
* The url of the artwork
|
||||
*/
|
||||
protected String mArtworkLocation;
|
||||
|
||||
/**
|
||||
* The complete path of the artwork
|
||||
*/
|
||||
protected String mArtworkPath;
|
||||
|
||||
/**
|
||||
* Gets the artwork filename
|
||||
*/
|
||||
public String getArtworkFile() {
|
||||
return mArtworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param artworkFile Sets the artwork filename
|
||||
*/
|
||||
public void setArtworkFile(String artworkFile) {
|
||||
mArtworkFile = artworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the artwork url
|
||||
*/
|
||||
public String getArtworkLocation() {
|
||||
return mArtworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the artwork url
|
||||
*/
|
||||
public void setArtworkLocation(String artworkLocation) {
|
||||
mArtworkLocation = artworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the artwork path
|
||||
* @return Path to the artwork
|
||||
*/
|
||||
public String getArtworkPath() {
|
||||
// Search for the artwork path
|
||||
if (mArtworkPath == null)
|
||||
mArtworkPath = mPlayMusicManager.getArtworkPath(mArtworkFile);
|
||||
return mArtworkPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,27 +29,20 @@ import de.arcus.playmusiclib.PlayMusicManager;
|
|||
/**
|
||||
* A single music track from Play Music
|
||||
*/
|
||||
public class MusicTrack {
|
||||
public class MusicTrack extends ArtworkEntry {
|
||||
// Variables
|
||||
private long mId, mSize, mTrackNumber, mDiscNumber, mAlbumId, mArtistId, mLocalCopyType, mLocalCopyStorageType, mDuration, mRating;
|
||||
private String mTitle, mArtist, mAlbum, mAlbumArtist, mLocalCopyPath, mGenre, mYear, mClientId, mSourceId, mArtworkFile;
|
||||
private String mTitle, mArtist, mAlbum, mAlbumArtist, mLocalCopyPath, mGenre, mYear, mClientId, mSourceId;
|
||||
private byte[] mCpData;
|
||||
|
||||
private String mSourceFile;
|
||||
private String mArtworkPath;
|
||||
private String mArtworkLocation;
|
||||
|
||||
/**
|
||||
* The manager
|
||||
*/
|
||||
private PlayMusicManager mPlayMusicManager;
|
||||
|
||||
/**
|
||||
* Creates a data item
|
||||
* @param playMusicManager The manager
|
||||
*/
|
||||
public MusicTrack(PlayMusicManager playMusicManager) {
|
||||
mPlayMusicManager = playMusicManager;
|
||||
super(playMusicManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -331,21 +324,6 @@ public class MusicTrack {
|
|||
public void setCpData(byte[] cpData) {
|
||||
this.mCpData = cpData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the artwork file name
|
||||
*/
|
||||
public String getArtworkFile() {
|
||||
return mArtworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param artworkFile Sets the artwork file name
|
||||
*/
|
||||
public void setArtworkFile(String artworkFile) {
|
||||
this.mArtworkFile = artworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the container (eg. a playlist or an artist)
|
||||
*/
|
||||
|
@ -370,20 +348,6 @@ public class MusicTrack {
|
|||
*/
|
||||
private long mContainerPosition;
|
||||
|
||||
/**
|
||||
* Gets the artwork url
|
||||
*/
|
||||
public String getArtworkLocation() {
|
||||
return mArtworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the artwork url
|
||||
*/
|
||||
public void setArtworkLocation(String artworkLocation) {
|
||||
mArtworkLocation = artworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the position in the container
|
||||
*/
|
||||
|
@ -408,16 +372,6 @@ public class MusicTrack {
|
|||
return mSourceFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the full album artwork path
|
||||
*/
|
||||
public String getArtworkPath() {
|
||||
// Search for the artwork path
|
||||
if (mArtworkPath == null)
|
||||
mArtworkPath = mPlayMusicManager.getArtworkPath(mArtworkFile);
|
||||
return mArtworkPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns if this file is encoded from AllAccess
|
||||
*/
|
||||
|
|
|
@ -33,18 +33,13 @@ import de.arcus.playmusiclib.datasources.PlaylistDataSource;
|
|||
* List of {@link de.arcus.playmusiclib.items.MusicTrack MusicTracks}.
|
||||
* Eg. albums, playlists, etc...
|
||||
*/
|
||||
public abstract class MusicTrackList {
|
||||
/**
|
||||
* The manager
|
||||
*/
|
||||
protected PlayMusicManager mPlayMusicManager;
|
||||
|
||||
public abstract class MusicTrackList extends ArtworkEntry {
|
||||
/**
|
||||
* Creates a data item
|
||||
* @param playMusicManager The manager
|
||||
*/
|
||||
public MusicTrackList(PlayMusicManager playMusicManager) {
|
||||
mPlayMusicManager = playMusicManager;
|
||||
super(playMusicManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,22 +48,10 @@ public abstract class MusicTrackList {
|
|||
*/
|
||||
protected List<MusicTrack> mMusicTrackList;
|
||||
|
||||
/**
|
||||
* The filename of the artwork
|
||||
*/
|
||||
protected String mArtworkFile;
|
||||
|
||||
/**
|
||||
* The url of the artwork
|
||||
* @return Returns the music track list
|
||||
*/
|
||||
protected String mArtworkLocation;
|
||||
|
||||
/**
|
||||
* The complete path of the artwork
|
||||
*/
|
||||
protected String mArtworkPath;
|
||||
|
||||
|
||||
public List<MusicTrack> getMusicTrackList() {
|
||||
// List is requested for the fist time
|
||||
if (mMusicTrackList == null)
|
||||
|
@ -79,35 +62,6 @@ public abstract class MusicTrackList {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the artwork filename
|
||||
*/
|
||||
public String getArtworkFile() {
|
||||
return mArtworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param artworkFile Sets the artwork filename
|
||||
*/
|
||||
public void setArtworkFile(String artworkFile) {
|
||||
mArtworkFile = artworkFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the artwork url
|
||||
*/
|
||||
public String getArtworkLocation() {
|
||||
return mArtworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the artwork url
|
||||
*/
|
||||
public void setArtworkLocation(String artworkLocation) {
|
||||
mArtworkLocation = artworkLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all tracks from this list.
|
||||
* Must be overwritten in all extended classes
|
||||
|
@ -146,17 +100,6 @@ public abstract class MusicTrackList {
|
|||
*/
|
||||
public abstract boolean getShowArtworkInTrack();
|
||||
|
||||
/**
|
||||
* Gets the artwork path
|
||||
* @return Path to the artwork
|
||||
*/
|
||||
public String getArtworkPath() {
|
||||
// Search for the artwork path
|
||||
if (mArtworkPath == null)
|
||||
mArtworkPath = mPlayMusicManager.getArtworkPath(mArtworkFile);
|
||||
return mArtworkPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a music track list by type and id
|
||||
* @param playMusicManager The PlayMusicManager
|
||||
|
|
Loading…
Reference in a new issue