package com.yatatsu.debugmenu;

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

import java.util.ArrayList;
import java.util.List;

public final class AndroidDebugMenu {

  private static volatile AndroidDebugMenu instance;
  private final AndroidDebugMenu.Configuration configuration;

  public static void initialize(AndroidDebugMenu.Configuration configuration) {
    if (instance == null) {
      synchronized (AndroidDebugMenu.class) {
        if (instance == null) {
          instance = new AndroidDebugMenu(configuration);
          instance.startDebugMenu();
        }
      }
    }
  }

  static AndroidDebugMenu getInstance() {
    return instance;
  }

  private AndroidDebugMenu(AndroidDebugMenu.Configuration configuration) {
    this.configuration = configuration;
  }

  List<DebugMenuItem> getDebugMenuItems() {
    return configuration.debugMenuItems;
  }

  private void startDebugMenu() {
    Context context = configuration.context;
    String appName = context.getApplicationInfo().loadLabel(context.getPackageManager()).toString();
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context).setContentTitle("AndroidDebugMenu")
            .setSmallIcon(R.drawable.ic_settings_black_24dp)
            .setContentText("Click to see debug menu for " + appName)
            .setAutoCancel(false);

    Intent resultIntent = new Intent(context, MenuActivity.class);
    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(configuration.notificationId, notificationBuilder.build());
  }

  public final static class Configuration {
    private final Context context;
    private final List<DebugMenuItem> debugMenuItems;
    private final int notificationId;

    private Configuration(AndroidDebugMenu.ConfigurationBuilder builder) {
      this.context = builder.context;
      this.debugMenuItems = builder.debugMenuItems;
      this.notificationId = builder.notificationId;
    }
  }

  public final static class ConfigurationBuilder {

    private final Context context;
    private List<DebugMenuItem> debugMenuItems;
    private int notificationId;

    public ConfigurationBuilder(Context context) {
      this.context = context;
      this.debugMenuItems = new ArrayList<>();
    }

    public AndroidDebugMenu.ConfigurationBuilder addDebugMenuItem(DebugMenuItem debugMenuItem) {
      debugMenuItems.add(debugMenuItem);
      return this;
    }

    public AndroidDebugMenu.ConfigurationBuilder notificationId(int notificationId) {
      this.notificationId = notificationId;
      return this;
    }

    public AndroidDebugMenu.Configuration build() {
      return new AndroidDebugMenu.Configuration(this);
    }
  }
}

@@ -25,16 +25,56 @@
 gmenu;%0A%0A
+import android.app.NotificationChannel;%0A
 import a
@@ -194,32 +194,57 @@
 content.Intent;%0A
+import android.os.Build;%0A
 import android.s
@@ -277,17 +277,16 @@
 Compat;%0A
-%0A
 import j
@@ -482,16 +482,82 @@
 uration;
+%0A  private static final String DEFAULT_CHANNEL_NAME = %22DebugMenu%22;
 %0A%0A  publ
@@ -1314,24 +1314,581 @@
 toString();%0A
+    NotificationManager notificationManager =%0A        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);%0A%0A    // create channel (for Android O+ target)%0A    if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.O) %7B%0A      NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL_NAME,%0A          %22Debug Menu%22, NotificationManager.IMPORTANCE_MIN);%0A      channel.setShowBadge(false);%0A      channel.enableLights(false);%0A      channel.enableVibration(false);%0A      notificationManager.createNotificationChannel(channel);%0A    %7D%0A%0A
     Notifica
@@ -1974,17 +1974,52 @@
 (context
-)
+, DEFAULT_CHANNEL_NAME)%0A            
 .setCont
@@ -2484,140 +2484,8 @@
 t);%0A
-    NotificationManager notificationManager =%0A        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);%0A
     

Add NotificationChannel for O