34
34
import com .atomjack .vcfp .model .PlexClient ;
35
35
import com .atomjack .vcfp .model .PlexMedia ;
36
36
import com .atomjack .vcfp .model .PlexServer ;
37
+ import com .atomjack .vcfp .model .PlexTrack ;
37
38
import com .atomjack .vcfp .services .PlexControlService ;
38
39
import com .google .gson .Gson ;
39
40
import com .google .gson .GsonBuilder ;
@@ -89,6 +90,7 @@ public static enum NOTIFICATION_STATUS {
89
90
90
91
private NotificationManager mNotifyMgr ;
91
92
private Bitmap notificationBitmap = null ;
93
+ private Bitmap notificationBitmapBig = null ;
92
94
93
95
public final static class Intent {
94
96
public final static String GDMRECEIVE = "com.atomjack.vcfp.intent.gdmreceive" ;
@@ -354,40 +356,42 @@ public void setNotification(final PlexClient client, final PlayerState currentSt
354
356
setNotification (client , currentState , media , false );
355
357
}
356
358
357
- public void setNotification (final PlexClient client , final PlayerState currentState , final PlexMedia media , boolean skipThumb ) {
358
- Logger .d ("Setting notification, client: %s, media: %s" , client , media );
359
- if (notificationStatus == NOTIFICATION_STATUS .off ) {
360
- notificationStatus = NOTIFICATION_STATUS .initializing ;
361
- notificationBitmap = null ;
362
- }
359
+ private Bitmap getCachedBitmap (String key ) {
360
+ if (key == null )
361
+ return null ;
363
362
363
+ Bitmap bitmap = null ;
364
364
try {
365
- Logger .d ("Trying to get cached thumb: %s" , media . getImageKey ( PlexMedia . IMAGE_KEY . NOTIFICATION_THUMB ) );
366
- SimpleDiskCache .BitmapEntry bitmapEntry = mSimpleDiskCache .getBitmap (media . getImageKey ( PlexMedia . IMAGE_KEY . NOTIFICATION_THUMB ) );
365
+ Logger .d ("Trying to get cached thumb: %s" , key );
366
+ SimpleDiskCache .BitmapEntry bitmapEntry = mSimpleDiskCache .getBitmap (key );
367
367
Logger .d ("bitmapEntry: %s" , bitmapEntry );
368
368
if (bitmapEntry != null ) {
369
- notificationBitmap = bitmapEntry .getBitmap ();
369
+ bitmap = bitmapEntry .getBitmap ();
370
370
}
371
371
} catch (Exception ex ) {
372
372
ex .printStackTrace ();
373
373
}
374
374
375
- if (notificationBitmap == null && notificationStatus == NOTIFICATION_STATUS .initializing && !skipThumb ) {
376
- Logger .d ("Thumb not found in cache. Downloading." );
375
+ return bitmap ;
376
+
377
+
378
+ }
379
+
380
+ // Fetch the notification bitmap for the given key. Once it's been downloaded, we'll save the bitmap to the image cache, then set the
381
+ // notification again.
382
+ private void fetchNotificationBitmap (final PlexMedia .IMAGE_KEY key , final PlexClient client , final PlexMedia media , final PlayerState currentState ) {
383
+ Logger .d ("Thumb not found in cache. Downloading %s." , key );
377
384
new AsyncTask () {
378
385
@ Override
379
386
protected Object doInBackground (Object [] objects ) {
380
387
if (client != null && media != null ) {
381
- InputStream inputStream = media .getNotificationThumb ();
382
- Logger .d ("Got input stream: %s" , inputStream );
383
- notificationBitmap = BitmapFactory .decodeStream (inputStream );
388
+ InputStream inputStream = media .getNotificationThumb (media instanceof PlexTrack ? PlexMedia .IMAGE_KEY .NOTIFICATION_THUMB_MUSIC : key );
384
389
try {
385
390
inputStream .reset ();
386
391
} catch (IOException e ) {}
387
- Logger .d ("notificationBitmap: %s" , notificationBitmap );
388
392
try {
389
- Logger .d ("image key: %s" , media .getImageKey (PlexMedia . IMAGE_KEY . NOTIFICATION_THUMB ));
390
- mSimpleDiskCache .put (media .getImageKey (PlexMedia . IMAGE_KEY . NOTIFICATION_THUMB ), inputStream );
393
+ Logger .d ("image key: %s" , media .getImageKey (key ));
394
+ mSimpleDiskCache .put (media .getImageKey (key ), inputStream );
391
395
inputStream .close ();
392
396
Logger .d ("Downloaded thumb. Redoing notification." );
393
397
setNotification (client , currentState , media , true );
@@ -396,10 +400,29 @@ protected Object doInBackground(Object[] objects) {
396
400
return null ;
397
401
}
398
402
}.execute ();
403
+ }
404
+
405
+ public void setNotification (final PlexClient client , final PlayerState currentState , final PlexMedia media , boolean skipThumb ) {
406
+ Logger .d ("Setting notification, client: %s, media: %s" , client , media );
407
+ if (client == null ) {
408
+ Logger .d ("Client is null for some reason" );
409
+ return ;
410
+ }
411
+ if (notificationStatus == NOTIFICATION_STATUS .off ) {
412
+ notificationStatus = NOTIFICATION_STATUS .initializing ;
413
+ notificationBitmap = null ;
414
+ notificationBitmapBig = null ;
399
415
}
400
416
417
+ notificationBitmap = getCachedBitmap (media .getImageKey (PlexMedia .IMAGE_KEY .NOTIFICATION_THUMB ));
418
+ if (notificationBitmap == null && notificationStatus == NOTIFICATION_STATUS .initializing && !skipThumb )
419
+ fetchNotificationBitmap (PlexMedia .IMAGE_KEY .NOTIFICATION_THUMB , client , media , currentState );
420
+ notificationBitmapBig = getCachedBitmap (media .getImageKey (PlexMedia .IMAGE_KEY .NOTIFICATION_THUMB_BIG ));
421
+ if (notificationBitmapBig == null && notificationStatus == NOTIFICATION_STATUS .initializing && !skipThumb )
422
+ fetchNotificationBitmap (PlexMedia .IMAGE_KEY .NOTIFICATION_THUMB_BIG , client , media , currentState );
423
+
424
+
401
425
Logger .d ("Setting up notification" );
402
- // notificationBitmap
403
426
android .content .Intent rewindIntent = new android .content .Intent (VoiceControlForPlexApplication .this , PlexControlService .class );
404
427
rewindIntent .setAction (PlexControlService .ACTION_REWIND );
405
428
rewindIntent .putExtra (PlexControlService .CLIENT , client );
@@ -421,7 +444,6 @@ protected Object doInBackground(Object[] objects) {
421
444
android .content .Intent nowPlayingIntent ;
422
445
if (client .isCastClient ) {
423
446
nowPlayingIntent = new android .content .Intent (VoiceControlForPlexApplication .this , CastActivity .class );
424
- // nowPlayingIntent.setAction(Intent.CAST_MEDIA);
425
447
} else
426
448
nowPlayingIntent = new android .content .Intent (VoiceControlForPlexApplication .this , NowPlayingActivity .class );
427
449
nowPlayingIntent .setFlags (android .content .Intent .FLAG_ACTIVITY_NEW_TASK |
@@ -438,11 +460,11 @@ protected Object doInBackground(Object[] objects) {
438
460
.setOngoing (true )
439
461
.setOnlyAlertOnce (true )
440
462
.setContentIntent (piNowPlaying )
441
- .setContent (getNotificationView (R .layout .now_playing_notification , notificationBitmap , media , client , playPendingIntent , pausePendingIntent , piRewind , currentState == PlayerState .PLAYING ))
463
+ .setContent (getNotificationView (media . isMusic () ? R . layout . now_playing_notification_music : R .layout .now_playing_notification , notificationBitmap , media , client , playPendingIntent , pausePendingIntent , piRewind , currentState == PlayerState .PLAYING ))
442
464
.setDefaults (Notification .DEFAULT_ALL );
443
465
Notification n = mBuilder .build ();
444
466
if (Build .VERSION .SDK_INT >= 16 )
445
- n .bigContentView = getNotificationView (media .isMusic () ? R .layout .now_playing_notification_big_music : R .layout .now_playing_notification_big , notificationBitmap , media , client , playPendingIntent , pausePendingIntent , piRewind , currentState == PlayerState .PLAYING );
467
+ n .bigContentView = getNotificationView (media .isMusic () ? R .layout .now_playing_notification_big_music : R .layout .now_playing_notification_big , notificationBitmapBig , media , client , playPendingIntent , pausePendingIntent , piRewind , currentState == PlayerState .PLAYING );
446
468
447
469
// Disable notification sound
448
470
n .defaults = 0 ;
@@ -474,7 +496,8 @@ private RemoteViews getNotificationView(int layoutId, Bitmap thumb, PlexMedia me
474
496
title = String .format ("%s - %s" , media .grandparentTitle , media .title );
475
497
else if (media .isShow ())
476
498
title = String .format ("%s - %s" , media .grandparentTitle , media .title );
477
-
499
+ // else if(media.isShow())
500
+ // title = String.format("%s - %s", media.grandparentTitle, media.title);
478
501
remoteViews .setTextViewText (R .id .title , title );
479
502
remoteViews .setTextViewText (R .id .playingOn , String .format (getString (R .string .playing_on ), client .name ));
480
503
0 commit comments