<commit_before>// Copyright (c) 2016, <NAME> <<EMAIL>>
// See LICENSE for licensing information

package cat.mvmike.minimalcalendarwidget.util;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.CalendarContract;

import cat.mvmike.minimalcalendarwidget.receiver.DateChangeReceiver;
import cat.mvmike.minimalcalendarwidget.receiver.InstanceChangeReceiver;

public class ReceiverUtil {

    private static final DateChangeReceiver DATE_CHANGE_RECEIVER = new DateChangeReceiver();

    private static final InstanceChangeReceiver INSTANCE_CHANGE_RECEIVER = new InstanceChangeReceiver();

    private static final IntentFilter DATE_CHANGE_INTENT_FILTER;

    private static final IntentFilter INSTANCE_CHANGE_INTENT_FILTER;

    static {

        DATE_CHANGE_INTENT_FILTER = new IntentFilter();
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);

        INSTANCE_CHANGE_INTENT_FILTER = new IntentFilter();
        INSTANCE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_PROVIDER_CHANGED);
        INSTANCE_CHANGE_INTENT_FILTER.addDataScheme(ContentResolver.SCHEME_CONTENT);
        INSTANCE_CHANGE_INTENT_FILTER.addDataAuthority(CalendarContract.AUTHORITY, null);
    }

    public static void registerReceivers(final Context context) {

        context.getApplicationContext().registerReceiver(DATE_CHANGE_RECEIVER, DATE_CHANGE_INTENT_FILTER);
        context.getApplicationContext().registerReceiver(INSTANCE_CHANGE_RECEIVER, INSTANCE_CHANGE_INTENT_FILTER);
    }

    public static void unregisterReceivers(final Context context) {

        context.getApplicationContext().unregisterReceiver(DATE_CHANGE_RECEIVER);
        context.getApplicationContext().unregisterReceiver(INSTANCE_CHANGE_RECEIVER);
    }
}
<commit_msg>avoid IllegalArgumentException in receiver when updating application<commit_after>// Copyright (c) 2016, <NAME> <<EMAIL>>
// See LICENSE for licensing information

package cat.mvmike.minimalcalendarwidget.util;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.CalendarContract;

import cat.mvmike.minimalcalendarwidget.receiver.DateChangeReceiver;
import cat.mvmike.minimalcalendarwidget.receiver.InstanceChangeReceiver;

public class ReceiverUtil {

    private static final DateChangeReceiver DATE_CHANGE_RECEIVER = new DateChangeReceiver();

    private static final InstanceChangeReceiver INSTANCE_CHANGE_RECEIVER = new InstanceChangeReceiver();

    private static final IntentFilter DATE_CHANGE_INTENT_FILTER;

    private static final IntentFilter INSTANCE_CHANGE_INTENT_FILTER;

    static {

        DATE_CHANGE_INTENT_FILTER = new IntentFilter();
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        DATE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);

        INSTANCE_CHANGE_INTENT_FILTER = new IntentFilter();
        INSTANCE_CHANGE_INTENT_FILTER.addAction(Intent.ACTION_PROVIDER_CHANGED);
        INSTANCE_CHANGE_INTENT_FILTER.addDataScheme(ContentResolver.SCHEME_CONTENT);
        INSTANCE_CHANGE_INTENT_FILTER.addDataAuthority(CalendarContract.AUTHORITY, null);
    }

    public static void registerReceivers(final Context context) {

        context.getApplicationContext().registerReceiver(DATE_CHANGE_RECEIVER, DATE_CHANGE_INTENT_FILTER);
        context.getApplicationContext().registerReceiver(INSTANCE_CHANGE_RECEIVER, INSTANCE_CHANGE_INTENT_FILTER);
    }

    public static void unregisterReceivers(final Context context) {

        try {
            context.getApplicationContext().unregisterReceiver(DATE_CHANGE_RECEIVER);
            context.getApplicationContext().unregisterReceiver(INSTANCE_CHANGE_RECEIVER);

        } catch (IllegalArgumentException iae) {

            // if coming from old version, receiver might have not been initialized
            iae.printStackTrace();
        }

    }
}

{'fraction_non_alphanumeric': 0.06683864915572232, 'fraction_numerical': 0.001876172607879925, 'mean_word_length': 5.272058823529412, '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': '5835526', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1173, 'n_words': 194}