package net.alteridem.feedme;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Binder;
import android.os.IBinder;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat;

import java.util.ArrayList;

public class MenuService extends Service {
    private NotificationManagerCompat mNotificationManager;
    private Binder mBinder = new LocalBinder();

    public class LocalBinder extends Binder {
        MenuService getService() {
            return MenuService.this;
        }
    }

    @Override
    public void onCreate() {
        mNotificationManager = NotificationManagerCompat.from(this);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null && intent.getAction().equals(Constants.ACTION_START_MENU)) {
            createNotification(intent);
            return START_STICKY;
        }
        return START_NOT_STICKY;
    }

    private void createNotification(Intent intent) {
        Menu menu = Menu.fromBundle(intent.getBundleExtra(Constants.EXTRA_RESTAURANT));

        // Create an intent to launch back to the menu on the phone
        Intent viewIntent = new Intent(this, RestaurantActivity.class);
        viewIntent.putExtra(Constants.RESTAURANT_TO_LOAD, menu.json);  // This is the restaurant name
        PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);

        // Add a button to purchase a beer
        Intent beerIntent = new Intent(this, BeerActivity.class);
        PendingIntent beerPendingIntent = PendingIntent.getActivity(this, 0, beerIntent, 0);

        // Create the notification
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(menu.titleText)
            .setContentText(getString(R.string.notification_order))
            .setSmallIcon(R.mipmap.ic_notification)
            .setContentIntent(viewPendingIntent)
            .addAction(R.mipmap.ic_notification, getString(R.string.order_beer), beerPendingIntent);

        // If we have a restaurant image, add it as the background image to the notification
        if (menu.image != null) {
            Bitmap image = Bitmap.createScaledBitmap(
                    AssetUtils.loadBitmapAsset(this, menu.image),
                    Constants.NOTIFICATION_IMAGE_WIDTH, Constants.NOTIFICATION_IMAGE_HEIGHT, false);
            builder.setLargeIcon(image);
        }

        // Send the notification
        Notification notification = builder.build();
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(Constants.NOTIFICATION_ID, notification);
    }
}

@@ -273,31 +273,24 @@
 Notification
-Manager
 Compat;%0Aimpo
@@ -319,32 +319,39 @@
 app.Notification
+Manager
 Compat;%0A%0Aimport 
@@ -347,37 +347,8 @@
 t;%0A%0A
-import java.util.ArrayList;%0A%0A
 publ
@@ -390,68 +390,8 @@
 e %7B%0A
-    private NotificationManagerCompat mNotificationManager;%0A
     
@@ -617,77 +617,8 @@
 ) %7B%0A
-        mNotificationManager = NotificationManagerCompat.from(this);%0A
     
@@ -2037,30 +2037,32 @@
 addAction(R.
-mipmap
+drawable
 .ic_notifica
@@ -2065,16 +2065,21 @@
 fication
+_full
 , getStr

Use the higher resolution versions of the notification icons