Merge lp:~cmiller/ubuntuone-android-music/album-art-saved-to-disk into lp:ubuntuone-android-music

Proposed by Chad Miller
Status: Merged
Merged at revision: 509
Proposed branch: lp:~cmiller/ubuntuone-android-music/album-art-saved-to-disk
Merge into: lp:ubuntuone-android-music
Prerequisite: lp:~cmiller/ubuntuone-android-music/faster-load-use-cache
Diff against target: 175 lines (+29/-35)
6 files modified
src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java (+2/-2)
src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java (+1/-1)
src/net/sourceforge/subsonic/androidapp/service/MusicService.java (+1/-1)
src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java (+1/-1)
src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java (+21/-25)
src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java (+3/-5)
To merge this branch: bzr merge lp:~cmiller/ubuntuone-android-music/album-art-saved-to-disk
Reviewer Review Type Date Requested Status
Michał Karnicki (community) Approve
Review via email: mp+67061@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java'
2--- src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java 2011-07-06 16:07:41 +0000
3+++ src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java 2011-07-06 16:07:41 +0000
4@@ -150,8 +150,8 @@
5 }
6
7 @Override
8- public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
9- return musicService.getCoverArt(context, entry, size, saveToFile, progressListener);
10+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception {
11+ return musicService.getCoverArt(context, entry, size, progressListener);
12 }
13
14 @Override
15
16=== modified file 'src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java'
17--- src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java 2011-02-18 20:05:34 +0000
18+++ src/net/sourceforge/subsonic/androidapp/service/DownloadFile.java 2011-07-06 16:07:41 +0000
19@@ -259,7 +259,7 @@
20 if (song.getCoverArt() != null) {
21 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
22 int size = Math.min(metrics.widthPixels, metrics.heightPixels);
23- musicService.getCoverArt(context, song, size, true, null);
24+ musicService.getCoverArt(context, song, size, null);
25 }
26 } catch (Exception x) {
27 Log.e(TAG, "Failed to get cover art.", x);
28
29=== modified file 'src/net/sourceforge/subsonic/androidapp/service/MusicService.java'
30--- src/net/sourceforge/subsonic/androidapp/service/MusicService.java 2011-07-06 16:07:41 +0000
31+++ src/net/sourceforge/subsonic/androidapp/service/MusicService.java 2011-07-06 16:07:41 +0000
32@@ -62,7 +62,7 @@
33
34 MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception;
35
36- Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception;
37+ Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception;
38
39 HttpResponse getDownloadInputStream(Context context, MusicDirectory.Entry song, long offset, int maxBitrate, CancellableTask task) throws Exception;
40
41
42=== modified file 'src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java'
43--- src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java 2011-07-06 16:07:41 +0000
44+++ src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java 2011-07-06 16:07:41 +0000
45@@ -133,7 +133,7 @@
46 }
47
48 @Override
49- public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
50+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception {
51 InputStream in = new FileInputStream(entry.getCoverArt());
52 try {
53 byte[] bytes = Util.toByteArray(in);
54
55=== modified file 'src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java'
56--- src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java 2011-07-06 16:07:41 +0000
57+++ src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java 2011-07-06 16:07:41 +0000
58@@ -204,8 +204,8 @@
59 Reader reader = getReader(context, progressListener, "getIndexes", null, "ifModifiedSince", lastModified);
60 try {
61 Indexes indexes = new IndexesParser(context).parse(reader, progressListener);
62- writeCachedIndexes(context, indexes);
63- return indexes;
64+ writeCachedIndexes(context, indexes);
65+ return indexes;
66 } finally {
67 Util.close(reader);
68 }
69@@ -403,52 +403,48 @@
70 }
71
72 @Override
73- public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, boolean saveToFile, ProgressListener progressListener) throws Exception {
74-
75+ public Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, ProgressListener progressListener) throws Exception {
76 // Synchronize on the entry so that we don't download concurrently for the same song.
77 synchronized (entry) {
78
79 // Use cached file, if existing.
80 File albumArtFile = FileUtil.getAlbumArtFile(entry);
81 if (albumArtFile.exists()) {
82-
83- InputStream in = new FileInputStream(albumArtFile);
84- try {
85- byte[] bytes = Util.toByteArray(in);
86- Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
87- return Bitmap.createScaledBitmap(bitmap, size, size, true);
88- } finally {
89- Util.close(in);
90- }
91+ Log.d(TAG, "cover art file is " + albumArtFile);
92+
93+ // Prepare for poor-man's LRU.
94+ albumArtFile.setLastModified(System.currentTimeMillis());
95+
96+ //return BitmapFactory.decodeFile(albumArtFile.toString());
97+ Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.toString());
98+ return Bitmap.createScaledBitmap(bitmap, size, size, true);
99 }
100+ Log.d(TAG, "cover art file will be " + albumArtFile);
101
102 String url = Util.getRestUrl(context, "getCoverArt") + "&id=" + entry.getCoverArt() + "&size=" + size;
103
104 InputStream in = null;
105 try {
106 HttpEntity entity = getEntityForURL(context, url, null, progressListener);
107- in = entity.getContent();
108
109 // If content type is XML, an error occured. Get it.
110 String contentType = Util.getContentType(entity);
111 if (contentType != null && contentType.startsWith("text/xml")) {
112+ in = entity.getContent();
113 new ErrorParser(context).parse(new InputStreamReader(in, Constants.UTF_8));
114 return null; // Never reached.
115 }
116
117- byte[] bytes = Util.toByteArray(in);
118-
119- if (saveToFile) {
120- OutputStream out = null;
121- try {
122- out = new FileOutputStream(albumArtFile);
123- out.write(bytes);
124- } finally {
125- Util.close(out);
126- }
127+ OutputStream out = null;
128+ try {
129+ out = new FileOutputStream(albumArtFile);
130+ entity.writeTo(out);
131+ } finally {
132+ Util.close(out);
133 }
134
135- return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
136+ Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.toString());
137+ return Bitmap.createScaledBitmap(bitmap, size, size, true);
138
139 } finally {
140 Util.close(in);
141
142=== modified file 'src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java'
143--- src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java 2011-03-29 15:53:31 +0000
144+++ src/net/sourceforge/subsonic/androidapp/util/ImageLoader.java 2011-07-06 16:07:41 +0000
145@@ -79,7 +79,7 @@
146 }
147
148 setUnknownImage(view, large);
149- queue.offer(new Task(view, entry, size, large));
150+ queue.offer(new Task(view, entry, size));
151 }
152
153 private String getKey(String coverArtId, int size) {
154@@ -125,20 +125,18 @@
155 private final MusicDirectory.Entry entry;
156 private final Handler handler;
157 private final int size;
158- private final boolean saveToFile;
159
160- public Task(View view, MusicDirectory.Entry entry, int size, boolean saveToFile) {
161+ public Task(View view, MusicDirectory.Entry entry, int size) {
162 this.view = view;
163 this.entry = entry;
164 this.size = size;
165- this.saveToFile = saveToFile;
166 handler = new Handler();
167 }
168
169 public void execute() {
170 try {
171 MusicService musicService = MusicServiceFactory.getMusicService(view.getContext());
172- Bitmap bitmap = musicService.getCoverArt(view.getContext(), entry, size, saveToFile, null);
173+ Bitmap bitmap = musicService.getCoverArt(view.getContext(), entry, size, null);
174 final Drawable drawable = Util.createDrawableFromBitmap(view.getContext(), bitmap);
175 cache.put(getKey(entry.getCoverArt(), size), drawable);
176

Subscribers

People subscribed via source and target branches

to status/vote changes: