Replaced UIL with Picasso

Huge replacement
Hopefully better performance
This commit is contained in:
Karim Abou Zeid 2015-03-11 13:33:06 +01:00
commit cfce92535b
27 changed files with 398 additions and 457 deletions

View file

@ -12,6 +12,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;
@ -20,7 +21,9 @@ import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.service.MusicService;
import com.kabouzeid.gramophone.ui.activities.MusicControllerActivity;
import com.kabouzeid.gramophone.util.MusicUtil;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
public class PlayingNotificationHelper {
public static final String TAG = PlayingNotificationHelper.class.getSimpleName();
@ -40,17 +43,12 @@ public class PlayingNotificationHelper {
.getSystemService(Context.NOTIFICATION_SERVICE);
}
public void buildNotification(Song song, final boolean isPlaying) {
public void buildNotification(final Song song, final boolean isPlaying) {
notificationLayout = new RemoteViews(service.getPackageName(),
R.layout.notification_playing);
notificationLayoutExpanded = new RemoteViews(service.getPackageName(),
R.layout.notification_playing_expanded);
setUpCollapsedLayout(song);
setUpExpandedLayout(song);
setUpPlaybackActions(isPlaying);
setUpExpandedPlaybackActions(isPlaying);
notification = new NotificationCompat.Builder(service)
.setSmallIcon(R.drawable.notification_icon)
.setContentIntent(getOpenMusicControllerPendingIntent())
@ -61,6 +59,12 @@ public class PlayingNotificationHelper {
.build();
notification.bigContentView = notificationLayoutExpanded;
setUpCollapsedLayout(song);
setUpExpandedLayout(song);
loadAlbumArt(song);
setUpPlaybackActions(isPlaying);
setUpExpandedPlaybackActions(isPlaying);
service.startForeground(NOTIFICATION_ID, notification);
}
@ -134,28 +138,35 @@ public class PlayingNotificationHelper {
return null;
}
private void setUpCollapsedLayout(Song song) {
loadAlbumArt(notificationLayout, MusicUtil.getAlbumArtUri(song.albumId).toString());
private void setUpCollapsedLayout(final Song song) {
notificationLayout.setTextViewText(R.id.song_title, song.title);
notificationLayout.setTextViewText(R.id.song_artist, song.title);
}
private static void loadAlbumArt(RemoteViews notificationView, String albumArtUri) {
Bitmap albumArtBitmap = ImageLoader.getInstance().loadImageSync(albumArtUri);
if (albumArtBitmap == null) {
notificationView.setImageViewResource(R.id.album_art, R.drawable.default_album_art);
} else {
notificationView.setImageViewBitmap(R.id.album_art, albumArtBitmap);
}
}
private void setUpExpandedLayout(Song song) {
loadAlbumArt(notificationLayoutExpanded, MusicUtil.getAlbumArtUri(song.albumId).toString());
private void setUpExpandedLayout(final Song song) {
notificationLayoutExpanded.setTextViewText(R.id.song_title, song.title);
notificationLayoutExpanded.setTextViewText(R.id.song_artist, song.artistName);
notificationLayoutExpanded.setTextViewText(R.id.album_title, song.albumName);
}
private void loadAlbumArt(final Song song) {
resetAlbumArt();
Picasso.with(service)
.load(MusicUtil.getAlbumArtUri(song.albumId))
.error(R.drawable.default_album_art)
.into(notificationLayoutExpanded, R.id.album_art, NOTIFICATION_ID, notification);
Picasso.with(service)
.load(MusicUtil.getAlbumArtUri(song.albumId))
.error(R.drawable.default_album_art)
.into(notificationLayout, R.id.album_art, NOTIFICATION_ID, notification);
}
private void resetAlbumArt() {
notificationLayout.setImageViewResource(R.id.album_art, R.drawable.default_album_art);
notificationLayoutExpanded.setImageViewResource(R.id.album_art, R.drawable.default_album_art);
notificationManager.notify(NOTIFICATION_ID, notification);
};
public void killNotification() {
service.stopForeground(true);
notification = null;