aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-07-24 16:42:19 -0700
committerScott Jackson <daneren2005@gmail.com>2015-07-24 16:42:19 -0700
commit900caeea647200ae21f676f355d6fa87557954ce (patch)
treef443281617550924a0d848e97b26c225fd6c1ff1 /app
parentea38d28b79f40697615da5b0d00322d53eaf4d90 (diff)
downloaddsub-900caeea647200ae21f676f355d6fa87557954ce.tar.gz
dsub-900caeea647200ae21f676f355d6fa87557954ce.tar.bz2
dsub-900caeea647200ae21f676f355d6fa87557954ce.zip
#531 Add playlist cover art
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java17
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java12
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/FileUtil.java26
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java35
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java16
-rw-r--r--app/src/main/res/layout/playlist_cell_item.xml39
-rw-r--r--app/src/main/res/layout/playlist_list_item.xml34
9 files changed, 155 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
diff --git a/app/src/main/res/layout/playlist_cell_item.xml b/app/src/main/res/layout/playlist_cell_item.xml
new file mode 100644
index 00000000..7e6ab0cd
--- /dev/null
+++ b/app/src/main/res/layout/playlist_cell_item.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="?attr/selectableItemBackground">
+
+ <github.daneren2005.dsub.view.SquareImageView
+ android:id="@+id/playlist_coverart"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingTop="4dp"
+ android:paddingLeft="2dp">
+
+ <TextView
+ android:id="@+id/playlist_title"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:textColor="?android:textColorPrimary"/>
+
+ <ImageView
+ android:id="@+id/more_button"
+ android:src="?attr/download_none"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right|center_vertical"
+ android:paddingRight="2dp"
+ style="@style/BasicButton"/>
+ </LinearLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/playlist_list_item.xml b/app/src/main/res/layout/playlist_list_item.xml
new file mode 100644
index 00000000..c1cc7b3c
--- /dev/null
+++ b/app/src/main/res/layout/playlist_list_item.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="?attr/selectableItemBackground">
+
+ <github.daneren2005.dsub.view.RecyclingImageView
+ android:id="@+id/playlist_coverart"
+ android:layout_width="@dimen/AlbumArt.Small"
+ android:layout_height="@dimen/AlbumArt.Small"
+ android:layout_gravity="left|center_vertical"/>
+
+ <TextView
+ android:id="@+id/playlist_title"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="left|center_vertical"
+ android:paddingLeft="10dip"
+ android:paddingRight="3dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:textColor="?android:textColorPrimary"/>
+
+ <ImageView
+ android:id="@+id/more_button"
+ android:src="?attr/download_none"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="right|center_vertical"
+ style="@style/MoreButton"/>
+</LinearLayout>