<commit_before>package com.iterable.iterableapi;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;

/**
 * An extension of {@link android.support.v7.app.NotificationCompat.Builder}
 * In addition to the builder in v7, this builder also includes a factory for creating
 * IterableNotification objects.
 *
 * IterableNotification takes care of ghostPushes which are sent to determine whether an
 * application is currently installed or uninstalled.
 *
 * Created by davidtruong on 4/29/16.
 */
public class IterableNotification extends NotificationCompat.Builder {

    //TODO: update notificationID to use a bitwise timestamp so it doesn't overwrite old notifications
    public static final int NOTIFICATION_ID = 1;

    private boolean isGhostPush;

    protected IterableNotification(Context context) {
        super(context);
    }

    //TODO: create public notification to be modified
//    public static IterableNotification createNotification(Context context, Class classToOpen, int icon, String defaultMessageBody) {
//        return createNotification(context, null, classToOpen, icon, defaultMessageBody);
//    }

    protected static IterableNotification createNotification(Context context, Intent intent, Class classToOpen, int icon) {
        return createNotification(context, intent, classToOpen, icon, null);
    }

        /**
         * Creates and returns an instance of IterableNotification.
         * If the notification is a ghostPush, then the function returns null.
         * @param context
         * @param intent
         * @param classToOpen
         * @param icon
         * @param defaultMessageBody
         * @return Returns null if the intent comes from an Iterable ghostPush
         */
    private static IterableNotification createNotification(Context context, Intent intent, Class classToOpen, int icon, String defaultMessageBody) {
        Bundle extras = intent.getExtras();

        String notificationBody = (defaultMessageBody == null) ? defaultMessageBody : "";
        if (intent.hasExtra("itbl")) {
            notificationBody = extras.getString("body");
        }

        Intent mainIntentWithExtras = new Intent(IterableConstants.ACTION_NOTIF_OPENED);
        mainIntentWithExtras.setClass(context, classToOpen);
        mainIntentWithExtras.putExtras(extras);
        mainIntentWithExtras.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent notificationClickedIntent = PendingIntent.getActivity(context, 0,
                mainIntentWithExtras, 0);

        //TODO: allow for a custom title to be passed in
        int stringId = context.getApplicationInfo().labelRes;
        String applicationName  = context.getString(stringId);

        IterableNotification notificationBuilder = new IterableNotification(context);
        notificationBuilder.setSmallIcon(icon)
                .setContentTitle(applicationName)
                .setContentText(notificationBody)
                .setAutoCancel(true);<commit_msg>Updates the extra data passed to the new intent from the notification clicked.<commit_after>package com.iterable.iterableapi;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.NotificationCompat;

/**
 * An extension of {@link android.support.v7.app.NotificationCompat.Builder}
 * In addition to the builder in v7, this builder also includes a factory for creating
 * IterableNotification objects.
 *
 * IterableNotification takes care of ghostPushes which are sent to determine whether an
 * application is currently installed or uninstalled.
 *
 * Created by davidtruong on 4/29/16.
 */
public class IterableNotification extends NotificationCompat.Builder {

    //TODO: update notificationID to use a bitwise timestamp so it doesn't overwrite old notifications
    public static final int NOTIFICATION_ID = 1;

    private boolean isGhostPush;

    protected IterableNotification(Context context) {
        super(context);
    }

    //TODO: create public notification to be modified
//    public static IterableNotification createNotification(Context context, Class classToOpen, int icon, String defaultMessageBody) {
//        return createNotification(context, null, classToOpen, icon, defaultMessageBody);
//    }

    protected static IterableNotification createNotification(Context context, Intent intent, Class classToOpen, int icon) {
        return createNotification(context, intent, classToOpen, icon, null);
    }

        /**
         * Creates and returns an instance of IterableNotification.
         * If the notification is a ghostPush, then the function returns null.
         * @param context
         * @param intent
         * @param classToOpen
         * @param icon
         * @param defaultMessageBody
         * @return Returns null if the intent comes from an Iterable ghostPush
         */
    private static IterableNotification createNotification(Context context, Intent intent, Class classToOpen, int icon, String defaultMessageBody) {
        Bundle extras = intent.getExtras();

        String notificationBody = (defaultMessageBody == null) ? defaultMessageBody : "";
        if (intent.hasExtra("itbl")) {
            notificationBody = extras.getString("body");
        }

        Intent mainIntentWithExtras = new Intent(IterableConstants.ACTION_NOTIF_OPENED);
        mainIntentWithExtras.setClass(context, classToOpen);
        mainIntentWithExtras.putExtras(extras);
        mainIntentWithExtras.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


        PendingIntent notificationClickedIntent = PendingIntent.getActivity(context, 0,
                mainIntentWithExtras, PendingIntent.FLAG_UPDATE_CURRENT);

        //TODO: allow for a custom title to be passed in
        int stringId = context.getApplicationInfo().labelRes;
        String applicationName  = context.getString(stringId);

        IterableNotification notificationBuilder = new IterableNotification(context);
        notificationBuilder.setSmallIcon(icon)
                .setContentTitle(applicationName)
                .setContentText(notificationBody)
                .setAutoCancel(true);
{'fraction_non_alphanumeric': 0.0704445835942392, 'fraction_numerical': 0.003287413901064496, 'mean_word_length': 3.4803646563814867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '261300', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1517, 'n_words': 479}