package com.erpdevelopment.vbvm;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v7.app.NotificationCompat;

/**
 * Helper APIs for constructing MediaStyle notifications
 */
public class MediaStyleHelper {
    /**
     * Build a notification using the information from the given media session. Makes heavy use
     * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
     * @param context Context used to construct the notification.
     * @param mediaSession Media session to get information.
     * @return A pre-built notification with information from the given media session.
     */
    public static NotificationCompat.Builder from(
            Context context, MediaSessionCompat mediaSession) {
        MediaControllerCompat controller = mediaSession.getController();
        MediaMetadataCompat mediaMetadata = controller.getMetadata();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

        if (mediaMetadata != null) {
            MediaDescriptionCompat description = mediaMetadata.getDescription();
            builder
                    .setContentTitle(description.getTitle())
                    .setContentText(description.getSubtitle())
                    .setSubText(description.getDescription())
                    .setLargeIcon(description.getIconBitmap());
        }

        builder.setContentIntent(controller.getSessionActivity())
                .setDeleteIntent(
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        return builder;
    }
}

@@ -1318,229 +1318,324 @@
     
-NotificationCompat.Builder builder = new NotificationCompat.Builder(context);%0A%0A        if (mediaMetadata != null) %7B%0A            MediaDescriptionCompat description = mediaMetadata.getDescription();%0A            builder%0A    
+if (mediaMetadata == null) %7B%0A            return null;%0A        %7D%0A%0A        MediaDescriptionCompat description = mediaMetadata.getDescription();%0A        if (description == null) %7B%0A            return null;%0A        %7D%0A%0A        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);%0A%0A        builder%0A
     
@@ -1695,36 +1695,32 @@
                 
-    
 .setContentText(
@@ -1758,28 +1758,24 @@
             
-  
-  
 .setSubText(
@@ -1816,28 +1816,24 @@
             
-   
- 
 .setLargeIco
@@ -1862,17 +1862,16 @@
 itmap())
-;
 %0A       
@@ -1871,27 +1871,24 @@
         
-%7D%0A%0A
         
 builder.
@@ -1879,23 +1879,16 @@
         
-builder
 .setCont

fix null pointer bug