<commit_before>package com.xlythe.sms.receiver;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;

import com.xlythe.sms.MainActivity;
import com.xlythe.sms.MessageActivity;
import com.xlythe.sms.R;
import com.xlythe.sms.drawable.ProfileDrawable;
import com.xlythe.textmanager.text.Attachment;
import com.xlythe.textmanager.text.Text;
import com.xlythe.textmanager.text.TextManager;
import com.xlythe.textmanager.text.Thread;
import com.xlythe.textmanager.text.util.Utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Notifications {
    private static final String TAG = "Notifications";
    private static final String EXTRA_INLINE_REPLY = "inline_reply";
    private static final String EXTRA_TEXT = "text";
    private static final String EXTRA_THREAD_ID = "thread_id";
    private static final String TEXTS_VISIBLE_IN_NOTIFICATION = "texts_visible_in_notification";
    private static final String NOTIFICATIONS = "notifications";
    private static final String NOTIFICATION_IDS = "notification_ids";
    private static final int GROUP_SUMMARY_ID = 12345;

    private static TextManager mManager;

    public static void buildNotification(Context context, Text text) {
        if (MessageActivity.isVisible(text.getThreadId())) {
            Log.w(TAG, "This thread is already visible to the user");
            return;
        }
        mManager = TextManager.getInstance(context);
        Set<Text> texts = getVisibleTexts(context, text);
        buildNotification(context, getTextsFromSameSender(text, texts), text.getThreadId().hashCode());
        buildGroupSummary(context, texts, GROUP_SUMMARY_ID);
    }

    private static void buildNotification(Context context, Set<Text> texts, int id) {
        Log.v(TAG, "Building a notification");
        context = context.getApplicationContext();
        addNotificationId(context, id);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fetch_icon_notif)
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setAutoCancel(true)
                .setDeleteIntent(buildOnDismissIntent(context, id, texts, false /*dismissAll*/))
                .setContentIntent(buildOnClickIntent(context, id, texts))
                .setLights(Color.WHITE, 500, 1500)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setPriority(Notification.PRIORITY_HIGH)
                .setCategory(Notification.CATEGORY_MESSAGE)
                .setGroup(TAG);

        if (sameSender(texts)) {
            Log.v(TAG, "All texts are from the same sender");
            Text randomText = texts.iterator().next();
            ProfileDrawable icon = new ProfileDrawable(context, mManager.getMembersExceptMe(randomText).get());
            builder.setLargeIcon(drawableToBitmap(icon))
                    .addAction(buildReplyAction(context, id, randomText));
        }

        if (texts.size() == 1) {
            Log.v(TAG, "There's only one text");
            buildDetailedNotification(context, texts.iterator().next(), builder);
        } else {
            buildSummaryNotification(context, texts, builder);
        }

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(id, builder.build());
    }

    private static void buildGroupSummary(Context context, Set<Text> texts, int id) {
        Log.v(TAG, "Building group summary");
        context = context.getApplicationContext();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fetch_icon_notif)
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setAutoCancel(true)
                .setDeleteIntent(buildOnDismissIntent(context, id, texts, true /*dismissAll*/))
                .setContentIntent(buildOnClickIntent(context, id, texts))
                .setLights(Color.WHITE, 500, 1500)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setPriority(Notification.PRIORITY_HIGH)
                .setCategory(Notification.CATEGORY_MESSAGE)
                .setGroup(TAG)<commit_msg>Update Notifications.java<commit_after>package com.xlythe.sms.receiver;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;

import com.xlythe.sms.MainActivity;
import com.xlythe.sms.MessageActivity;
import com.xlythe.sms.R;
import com.xlythe.sms.drawable.ProfileDrawable;
import com.xlythe.textmanager.text.Attachment;
import com.xlythe.textmanager.text.Text;
import com.xlythe.textmanager.text.TextManager;
import com.xlythe.textmanager.text.Thread;
import com.xlythe.textmanager.text.util.Utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Notifications {
    private static final String TAG = "Notifications";
    private static final String EXTRA_INLINE_REPLY = "inline_reply";
    private static final String EXTRA_TEXT = "text";
    private static final String EXTRA_THREAD_ID = "thread_id";
    private static final String TEXTS_VISIBLE_IN_NOTIFICATION = "texts_visible_in_notification";
    private static final String NOTIFICATIONS = "notifications";
    private static final String NOTIFICATION_IDS = "notification_ids";
    private static final int GROUP_SUMMARY_ID = 12345;

    private static TextManager mManager;

    public static void buildNotification(Context context, Text text) {
        if (MessageActivity.isVisible(text.getThreadId())) {
            Log.w(TAG, "This thread is already visible to the user");
            return;
        }
        mManager = TextManager.getInstance(context);
        Set<Text> texts = getVisibleTexts(context, text);
        buildNotification(context, getTextsFromSameSender(text, texts), text.getThreadId().hashCode());
        buildGroupSummary(context, texts, GROUP_SUMMARY_ID);
    }

    private static void buildNotification(Context context, Set<Text> texts, int id) {
        Log.v(TAG, "Building a notification");
        context = context.getApplicationContext();
        addNotificationId(context, id);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.fetch_icon_notif)
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setAutoCancel(true)
                .setDeleteIntent(buildOnDismissIntent(context, id, texts, false /*dismissAll*/))
                .setContentIntent(buildOnClickIntent(context, id, texts))
                .setLights(Color.WHITE, 500, 1500)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setPriority(Notification.PRIORITY_HIGH)
                .setCategory(Notification.CATEGORY_MESSAGE)
                .setGroup(TAG);

        if (sameSender(texts)) {
            Log.v(TAG, "All texts are from the same sender");
            Text randomText = texts.iterator().next();
            ProfileDrawable icon = new ProfileDrawable(context, mManager.getMembersExceptMe(randomText).get());
            builder.setLargeIcon(drawableToBitmap(icon))
                    .addAction(buildReplyAction(context, id, randomText));
        }

        if (texts.size() == 1) {
            Log.v(TAG, "There's only one text");
            buildDetailedNotification(context, texts.iterator().next(), builder);
        } else {
            buildSummaryNotification(context, texts, builder);
        }

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(id, builder.build());
    }

    private static void buildGroupSummary(Context context, Set<Text> texts, int id) {
        Log.v(TAG, "Building group summary");
        context = context.getApplicationContext();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.fetch_icon_notif)
                .setColor(context.getResources().getColor(R.color.colorPrimary))
                .setAutoCancel(true)
                .setDeleteIntent(buildOnDismissIntent(context, id, texts, true /*dismissAll*/))
                .setContentIntent(buildOnClickIntent(context, id, texts))
                .setLights(Color.WHITE, 500, 1500)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setPriority(Notification.PRIORITY_HIGH)
                .setCategory(Notification.CATEGORY_MESSAGE)
                .setGroup(TAG)
{'fraction_non_alphanumeric': 0.09720451201569397, 'fraction_numerical': 0.0047081902893575285, 'mean_word_length': 3.4719298245614034, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5627084', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2716, 'n_words': 559}