diff options
Diffstat (limited to 'app/src/main/java')
7 files changed, 82 insertions, 32 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java index fa00c1dd..4221677e 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java @@ -16,29 +16,36 @@ package github.daneren2005.dsub.adapter; import android.content.Context; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; + import android.view.ViewGroup; import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.view.PlaylistView; import github.daneren2005.dsub.view.UpdateView; public class PlaylistAdapter extends SectionAdapter<Playlist> { public static int VIEW_TYPE_PLAYLIST = 1; - public PlaylistAdapter(Context context, List<Playlist> playlists, OnItemClickedListener listener) { + private ImageLoader imageLoader; + private boolean largeCell; + + public PlaylistAdapter(Context context, List<Playlist> playlists, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) { super(context, playlists); + this.imageLoader = imageLoader; + this.largeCell = largeCell; this.onItemClickedListener = listener; } - public PlaylistAdapter(Context context, List<String> headers, List<List<Playlist>> sections, OnItemClickedListener listener) { + public PlaylistAdapter(Context context, List<String> headers, List<List<Playlist>> sections, ImageLoader imageLoader, boolean largeCell, OnItemClickedListener listener) { super(context, headers, sections); + this.imageLoader = imageLoader; + this.largeCell = largeCell; this.onItemClickedListener = listener; } @Override public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) { - return new UpdateView.UpdateViewHolder(new PlaylistView(context)); + return new UpdateView.UpdateViewHolder(new PlaylistView(context, imageLoader, largeCell)); } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index c754f370..7b55c5c3 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -1300,7 +1300,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } } else { songTitleTextView.setText(null); - getImageLoader().loadImage(albumArtImageView, null, true, false); + getImageLoader().loadImage(albumArtImageView, (Entry) null, true, false); starButton.setImageResource(R.drawable.ic_toggle_star_outline_dark); setSubtitle(null); } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index b1587e24..a2f1aabd 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -42,6 +42,14 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_LARGE_ALBUM_ART, true)) { + largeAlbums = true; + } + } + + @Override public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Playlist> updateView, Playlist playlist) { if (Util.isOffline(context)) { menuInflater.inflate(R.menu.select_playlist_context_offline, menu); @@ -109,7 +117,7 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { } if(shared.isEmpty()) { - return new PlaylistAdapter(context, playlists, this); + return new PlaylistAdapter(context, playlists, getImageLoader(), largeAlbums, this); } else { Resources res = context.getResources(); List<String> headers = Arrays.asList(res.getString(R.string.playlist_mine), res.getString(R.string.playlist_shared)); @@ -118,7 +126,7 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { sections.add(mine); sections.add(shared); - return new PlaylistAdapter(context, headers, sections, this); + return new PlaylistAdapter(context, headers, sections, getImageLoader(), largeAlbums, this); } } diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java index 8ebf4c13..250d8566 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java @@ -380,8 +380,10 @@ public class OfflineMusicService implements MusicService { for(File file: fileList) { if(FileUtil.isPlaylistFile(file)) { String id = file.getName(); - String filename = server + ": " + FileUtil.getBaseName(id); - Playlist playlist = new Playlist(server, filename); + String filename = FileUtil.getBaseName(id); + String name = server + ": " + filename; + Playlist playlist = new Playlist(server, name); + playlist.setComment(filename); Reader reader = null; BufferedReader buffer = null; diff --git a/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java b/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java index 185a6b29..332f775c 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java +++ b/app/src/main/java/github/daneren2005/dsub/util/FileUtil.java @@ -182,19 +182,25 @@ public class FileUtil { } public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) { - File albumDir = getAlbumDirectory(context, entry); - File artFile; - File albumFile = getAlbumArtFile(albumDir); - File hexFile = getHexAlbumArtFile(context, albumDir); - if(albumDir.exists()) { - if(hexFile.exists()) { - hexFile.renameTo(albumFile); + if(entry.getId().indexOf("pl-") == -1) { + File albumDir = getAlbumDirectory(context, entry); + File artFile; + File albumFile = getAlbumArtFile(albumDir); + File hexFile = getHexAlbumArtFile(context, albumDir); + if (albumDir.exists()) { + if (hexFile.exists()) { + hexFile.renameTo(albumFile); + } + artFile = albumFile; + } else { + artFile = hexFile; } - artFile = albumFile; + return artFile; } else { - artFile = hexFile; + File playlistDir = getAlbumArtDirectory(context); + Log.d(TAG, entry.getTitle() + " => " + Util.md5Hex("pl-" + entry.getTitle())); + return new File(playlistDir, Util.md5Hex("pl-" + entry.getTitle()) + ".jpeg"); } - return artFile; } public static File getAlbumArtFile(File albumDir) { diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java index a770fbb1..7b3067ba 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java @@ -42,6 +42,7 @@ import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.ArtistInfo; import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; @@ -295,6 +296,24 @@ public class ImageLoader { return task; } + public SilentBackgroundTask loadImage(View view, Playlist playlist, boolean large, boolean crossfade) { + MusicDirectory.Entry entry = new MusicDirectory.Entry(); + String id; + if(Util.isOffline(context)) { + id = "pl-" + playlist.getName(); + entry.setTitle(playlist.getComment()); + } else { + id = "pl-" + playlist.getId(); + entry.setTitle(playlist.getName()); + } + entry.setId(id); + entry.setCoverArt(id); + // So this isn't treated as a artist + entry.setParent(""); + + return loadImage(view, entry, large, crossfade); + } + private String getKey(String coverArtId, int size) { return coverArtId + size; } @@ -388,12 +407,16 @@ public class ImageLoader { try { MusicService musicService = MusicServiceFactory.getMusicService(mContext); Bitmap bitmap = musicService.getCoverArt(mContext, mEntry, mSize, null, this); - String key = getKey(mEntry.getCoverArt(), mSize); - cache.put(key, bitmap); - // Make sure key is the most recently "used" - cache.get(key); - if(mIsNowPlaying) { - nowPlaying = bitmap; + if(bitmap != null) { + String key = getKey(mEntry.getCoverArt(), mSize); + cache.put(key, bitmap); + // Make sure key is the most recently "used" + cache.get(key); + if (mIsNowPlaying) { + nowPlaying = bitmap; + } + } else { + bitmap = getUnknownImage(mEntry, mSize); } mDrawable = Util.createDrawableFromBitmap(mContext, bitmap); diff --git a/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java b/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java index cb7bd186..2cd27b19 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java @@ -21,11 +21,11 @@ package github.daneren2005.dsub.view; import android.content.Context; import android.view.LayoutInflater; import android.view.View; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.SyncUtil; /** @@ -36,20 +36,24 @@ import github.daneren2005.dsub.util.SyncUtil; public class PlaylistView extends UpdateView<Playlist> { private static final String TAG = PlaylistView.class.getSimpleName(); + private View coverArtView; private TextView titleView; + private ImageLoader imageLoader; - public PlaylistView(Context context) { + public PlaylistView(Context context, ImageLoader imageLoader, boolean largeCell) { super(context); - LayoutInflater.from(context).inflate(R.layout.basic_list_item, this, true); + LayoutInflater.from(context).inflate(largeCell ? R.layout.playlist_cell_item : R.layout.playlist_list_item, this, true); - titleView = (TextView) findViewById(R.id.item_name); - starButton = (ImageButton) findViewById(R.id.item_star); - starButton.setFocusable(false); + coverArtView = findViewById(R.id.playlist_coverart); + titleView = (TextView) findViewById(R.id.playlist_title); moreButton = (ImageView) findViewById(R.id.item_more); + + this.imageLoader = imageLoader; } protected void setObjectImpl(Playlist playlist) { titleView.setText(playlist.getName()); + imageTask = imageLoader.loadImage(coverArtView, playlist, false, true); } @Override |