package com.google.firebase.quickstart.firebasestorage;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

/**
 * Base class for Services that keep track of the number of active jobs and self-stop when the
 * count is zero.
 */
public abstract class MyBaseTaskService extends Service {

    static final int PROGRESS_NOTIFICATION_ID = 0;
    static final int FINISHED_NOTIFICATION_ID = 1;

    private static final String TAG = "MyBaseTaskService";
    private int mNumTasks = 0;

    public void taskStarted() {
        changeNumberOfTasks(1);
    }

    public void taskCompleted() {
        changeNumberOfTasks(-1);
    }

    private synchronized void changeNumberOfTasks(int delta) {
        Log.d(TAG, "changeNumberOfTasks:" + mNumTasks + ":" + delta);
        mNumTasks += delta;

        // If there are no tasks left, stop the service
        if (mNumTasks <= 0) {
            Log.d(TAG, "stopping");
            stopSelf();
        }
    }

    /**
     * Show notification with a progress bar.
     */
    protected void showProgressNotification(String caption, long completedUnits, long totalUnits) {
        int percentComplete = 0;
        if (totalUnits > 0) {
            percentComplete = (int) (100 * completedUnits / totalUnits);
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_file_upload_white_24dp)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(caption)
                .setProgress(100, percentComplete, false)
                .setOngoing(true)
                .setAutoCancel(false);

        NotificationManager manager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        manager.notify(PROGRESS_NOTIFICATION_ID, builder.build());
    }

    /**
     * Show notification that the activity finished.
     */
    protected void showFinishedNotification(String caption, Intent intent, boolean success) {
        // Make PendingIntent for notification
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* requestCode */, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        int icon = success ? R.drawable.ic_check_white_24 : R.drawable.ic_error_white_24dp;

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(icon)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(caption)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent);

        NotificationManager manager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        manager.notify(FINISHED_NOTIFICATION_ID, builder.build());
    }

    /**
     * Dismiss the progress notification.
     */
    protected void dismissProgressNotification() {
        NotificationManager manager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        manager.cancel(PROGRESS_NOTIFICATION_ID);
    }
}

@@ -50,16 +50,56 @@
 orage;%0A%0A
+import android.app.NotificationChannel;%0A
 import a
@@ -130,16 +130,16 @@
 anager;%0A
-
 import a
@@ -247,32 +247,57 @@
 content.Intent;%0A
+import android.os.Build;%0A
 import android.s
@@ -536,16 +536,81 @@
 vice %7B%0A%0A
+    private static final String CHANNEL_ID_DEFAULT = %22default%22;%0A%0A
     stat
@@ -1257,32 +1257,544 @@
        %7D%0A    %7D%0A%0A
+    private void createDefaultChannel() %7B%0A        // Since android Oreo notification channel is needed.%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.O) %7B%0A            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);%0A%0A            NotificationChannel channel = new NotificationChannel(CHANNEL_ID_DEFAULT,%0A                    %22Default%22,%0A                    NotificationManager.IMPORTANCE_DEFAULT);%0A            nm.createNotificationChannel(channel);%0A        %7D%0A    %7D%0A%0A
     /**%0A     * S
@@ -2082,24 +2082,56 @@
 %0A        %7D%0A%0A
+        createDefaultChannel();%0A
         Noti
@@ -2190,32 +2190,52 @@
 pat.Builder(this
+, CHANNEL_ID_DEFAULT
 )%0A              
@@ -3178,16 +3178,48 @@
 _24dp;%0A%0A
+        createDefaultChannel();%0A
         
@@ -3290,16 +3290,36 @@
 der(this
+, CHANNEL_ID_DEFAULT
 )%0A      

Make notifications use channels