<commit_before>package com.pastcustoms.cq;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

public class SmsStatusReceiver extends BroadcastReceiver {

    private SharedPreferences mSharedPrefs;

    // Check if ComposeMessageActivity is running. If so, show error dialog; if not,
    // send notification.

    @Override
    public void onReceive(Context context, Intent intent){

        // Check if ComposeMessageActivity is running in foreground.
        // Do this by checking Shared Preferences.
        mSharedPrefs = context.getSharedPreferences(
                context.getString(R.string.shared_prefs_file_key), Context.MODE_PRIVATE);
        boolean cqIsForeground = mSharedPrefs.getBoolean(
                context.getString(R.string.prefs_is_foreground_app), false);

        String actionName = intent.getAction();

        Bundle extras = intent.getExtras();
        String phoneNumOrName = extras.getString("PHONE_OR_NAME");

        int messageId = intent.getIntExtra("MSG_ID", 0);
        String errorMessage;

        if (actionName.equals("com.pastcustoms.cq.SMS_SENT")){
            switch(getResultCode()) {
                case Activity.RESULT_OK:
                    // Only display "SMS sent" toast if CQ is in foreground.
                    if (cqIsForeground) {
                        Toast.makeText(context, context.getString(R.string.toast_sms_sent_to_)
                                + phoneNumOrName, Toast.LENGTH_LONG).show();
                    }

                    if (DevOptions.LOG) {
                        Log.d("CQ SMS Status Receiver",
                                "phoneNumOrName: " + phoneNumOrName);
                        Log.d("CQ SMS Status Receiver",
                                "messageId: " + Integer.toString(messageId));
                    }

                    // FOR DEBUGGING: display fake notification that SMS was not sent
                    if (DevOptions.DEBUG) {
                        String debugErrorMessage = context.getString(R.string.toast_sms_to_)
                                + phoneNumOrName
                                + context.getString(R.string.toast__was_not_sent);
                        errorNotification(context, debugErrorMessage, messageId);
                    }
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    // Display error dialog if CQ is in foreground. If not, create a notification.
                    errorMessage = context.getString(R.string.toast_sms_to_)
                            + phoneNumOrName
                            + context.getString(R.string.toast__was_not_sent);
                    if (cqIsForeground) {
                        errorDialog(context, errorMessage);
                    } else {
                        errorNotification(context, errorMessage, messageId);
                    }
                    break;
                default:
                    errorMessage = context.getString(R.string.toast_sms_to_)
                            + phoneNumOrName
                            + context.getString(R.string.toast__was_not_sent);
                    if (cqIsForeground) {
                        errorDialog(context, errorMessage);
                    } else {
                        errorNotification(context, errorMessage, messageId);
                    }
            }
        }

        if (actionName.equals("com.pastcustoms.cq.SMS_DELIVERED")) {
            switch(getResultCode()) {
                case Activity.RESULT_OK:
                    if (cqIsForeground) {
                        Toast.makeText(context, context.getString(R.string.toast_sms_delivered_to_)
                                + phoneNumOrName, Toast.LENGTH_LONG).show();
                    }
                    break;
                default:
                    errorMessage = context.getString(R.string.toast_sms_to_)
                            + phoneNumOrName
                            + context.getString(R.string.toast__was_not_delivered);
                    if (cqIsForeground) {
                        errorDialog(context, errorMessage);
                    } else {<commit_msg>remove redundant error code handling in SmsStatusReceiver<commit_after>package com.pastcustoms.cq;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

public class SmsStatusReceiver extends BroadcastReceiver {

    private SharedPreferences mSharedPrefs;

    // Check if ComposeMessageActivity is running. If so, show error dialog; if not,
    // send notification.

    @Override
    public void onReceive(Context context, Intent intent){

        // Check if ComposeMessageActivity is running in foreground.
        // Do this by checking Shared Preferences.
        mSharedPrefs = context.getSharedPreferences(
                context.getString(R.string.shared_prefs_file_key), Context.MODE_PRIVATE);
        boolean cqIsForeground = mSharedPrefs.getBoolean(
                context.getString(R.string.prefs_is_foreground_app), false);

        String actionName = intent.getAction();

        Bundle extras = intent.getExtras();
        String phoneNumOrName = extras.getString("PHONE_OR_NAME");

        int messageId = intent.getIntExtra("MSG_ID", 0);
        String errorMessage;

        if (actionName.equals("com.pastcustoms.cq.SMS_SENT")){
            switch(getResultCode()) {
                case Activity.RESULT_OK:
                    // Only display "SMS sent" toast if CQ is in foreground.
                    if (cqIsForeground) {
                        Toast.makeText(context, context.getString(R.string.toast_sms_sent_to_)
                                + phoneNumOrName, Toast.LENGTH_LONG).show();
                    }

                    if (DevOptions.LOG) {
                        Log.d("CQ SMS Status Receiver",
                                "phoneNumOrName: " + phoneNumOrName);
                        Log.d("CQ SMS Status Receiver",
                                "messageId: " + Integer.toString(messageId));
                    }

                    // FOR DEBUGGING: display fake notification that SMS was not sent
                    if (DevOptions.DEBUG) {
                        String debugErrorMessage = context.getString(R.string.toast_sms_to_)
                                + phoneNumOrName
                                + context.getString(R.string.toast__was_not_sent);
                        errorNotification(context, debugErrorMessage, messageId);
                    }
                    break;
                default:
                    errorMessage = context.getString(R.string.toast_sms_to_)
                            + phoneNumOrName
                            + context.getString(R.string.toast__was_not_sent);
                    if (cqIsForeground) {
                        errorDialog(context, errorMessage);
                    } else {
                        errorNotification(context, errorMessage, messageId);
                    }
            }
        }

        if (actionName.equals("com.pastcustoms.cq.SMS_DELIVERED")) {
            switch(getResultCode()) {
                case Activity.RESULT_OK:
                    if (cqIsForeground) {
                        Toast.makeText(context, context.getString(R.string.toast_sms_delivered_to_)
                                + phoneNumOrName, Toast.LENGTH_LONG).show();
                    }
                    break;
                default:
                    errorMessage = context.getString(R.string.toast_sms_to_)
                            + phoneNumOrName
                            + context.getString(R.string.toast__was_not_delivered);
                    if (cqIsForeground) {
                        errorDialog(context, errorMessage);
                    } else {
{'fraction_non_alphanumeric': 0.07724768491384362, 'fraction_numerical': 0.00046887820888524205, 'mean_word_length': 1.59963436928702, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3017265', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2039, 'n_words': 400}