/*
 * Copyright (C) 2015 8tory, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package json2notification;

import android.app.Notification;
import android.content.Context;

import org.json.JSONObject;
import org.json.JSONException;

import json2notification.model.AndroidNotification;
import android.app.NotificationManager;

public class Json2Notification {
    private static final String TAG = "json2notification";
    private Context context;
    private JSONObject jsonObject;

    public static Json2Notification from(Context context) {
        return new Json2Notification(context);
    }

    private Json2Notification(Context context) {
        this.context = context;
    }

    public Json2Notification with(String json) {
        try {
            return with(new JSONObject(json));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return this;
    }

    public Json2Notification with(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
        return this;
    }

    public Notification notification() {
        Notification notification = null;

        try {
            AndroidNotification androidNotification = AndroidNotification.parse(context, jsonObject.toString());
            notification = androidNotification.android.notification;
        } catch (Exception e) {
        }

        return notification;
    }

    public void notifying() {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notification());
    }
}

@@ -1533,32 +1533,109 @@
 rn this;%0A    %7D%0A%0A
+    Notification notification;%0A    AndroidNotification androidNotification;%0A%0A
     public Notif
@@ -1659,33 +1659,39 @@
 ion() %7B%0A        
-N
+//if (n
 otification noti
@@ -1678,33 +1678,63 @@
 f (notification 
-n
+== null) %7B%0A        if (androidN
 otification = nu
@@ -1734,16 +1734,22 @@
 on =
+=
  null
-;%0A%0A
+) %7B%0A    
     
@@ -1770,35 +1770,19 @@
         
-AndroidNotification
+   
  android
@@ -1851,24 +1851,28 @@
 oString());%0A
+    
             
@@ -1928,32 +1928,36 @@
 cation;%0A        
+    
 %7D catch (Excepti
@@ -1956,32 +1956,46 @@
 (Exception e) %7B%0A
+            %7D%0A
         %7D%0A%0A     
@@ -2033,29 +2033,100 @@
     
-public void notifying
+NotificationManager notificationManager;%0A%0A    public NotificationManager notificationManager
 () %7B
@@ -2130,25 +2130,29 @@
 ) %7B%0A        
-N
+if (n
 otificationM
@@ -2150,32 +2150,55 @@
 ficationManager 
+== null) %7B%0A            
 notificationMana
@@ -2281,16 +2281,102 @@
 RVICE);%0A
+        %7D%0A        return notificationManager;%0A    %7D%0A%0A    public void notify(int id) %7B%0A
         
@@ -2398,16 +2398,18 @@
 ager
+()
 .notify(
 1, n
@@ -2404,17 +2404,133 @@
 .notify(
-1
+id, notification());%0A    %7D%0A%0A    public void notify(String tag, int id) %7B%0A        notificationManager().notify(tag, id
 , notifi

Add notify(id) and notify(tag, id)