<commit_before>
package fi.iki.murgo.irssinotifier;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.apache.http.auth.AuthenticationException;
import yuku.ambilwarna.AmbilWarnaDialog;

import java.io.IOException;


@SuppressWarnings("deprecation")
public class SettingsActivity extends PreferenceActivity {
    private static final String TAG = SettingsActivity.class.getSimpleName();
    protected static final int ICB_HOST_REQUEST_CODE = 666;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "Opened settings");
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preference_screen);

        final Context ctx = this;

        CheckBoxPreference enabled = (CheckBoxPreference) findPreference("NotificationsEnabled");
        enabled.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String s = "Disabling notifications...";
                if ((Boolean)newValue) {
                    s = "Enabling notifications...";
                }

                SettingsSendingTask task = new SettingsSendingTask(SettingsActivity.this, "Sending settings", s);
                task.setCallback(new Callback<ServerResponse>() {
                    @Override
                    public void doStuff(ServerResponse result) {
                        if (result.getException() != null) {
                            if (result.getException() instanceof IOException) {
                                MessageBox.Show(ctx, "Network error", "Ensure your internet connection works and try again.", null);
                            } else if (result.getException() instanceof AuthenticationException) {
                                MessageBox.Show(ctx, "Authentication error", "Unable to authenticate to server.", null);
                            } else if (result.getException() instanceof ServerException) {
                                MessageBox.Show(ctx, "Server error", "Mystical server error, check if updates are available", null);
                            } else {
                                MessageBox.Show(ctx, null, "Unable to send settings to the server! Please try again later!", null);
                            }
                        }
                    }<commit_msg>Notification enabled no longer incorrectly switch state if no internet connection is available<commit_after>
package fi.iki.murgo.irssinotifier;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.apache.http.auth.AuthenticationException;
import yuku.ambilwarna.AmbilWarnaDialog;

import java.io.IOException;


@SuppressWarnings("deprecation")
public class SettingsActivity extends PreferenceActivity {
    private static final String TAG = SettingsActivity.class.getSimpleName();
    protected static final int ICB_HOST_REQUEST_CODE = 666;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "Opened settings");
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preference_screen);

        final Context ctx = this;

        final CheckBoxPreference enabled = (CheckBoxPreference) findPreference("NotificationsEnabled");
        enabled.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final boolean checked = (Boolean)newValue;
                String s = "Disabling notifications...";
                if (checked) {
                    s = "Enabling notifications...";
                }

                SettingsSendingTask task = new SettingsSendingTask(SettingsActivity.this, "Sending settings", s);
                task.setCallback(new Callback<ServerResponse>() {
                    @Override
                    public void doStuff(ServerResponse result) {
                        if (result.getException() != null) {
                            if (result.getException() instanceof IOException) {
                                MessageBox.Show(ctx, "Network error", "Ensure your internet connection works and try again.", null);
                            } else if (result.getException() instanceof AuthenticationException) {
                                MessageBox.Show(ctx, "Authentication error", "Unable to authenticate to server.", null);
                            } else if (result.getException() instanceof ServerException) {
                                MessageBox.Show(ctx, "Server error", "Mystical server error, check if updates are available", null);
                            } else {
                                MessageBox.Show(ctx, null, "Unable to send settings to the server! Please try again later!", null);
                            }
                            enabled.setChecked(!checked);
                        }
                    }
{'fraction_non_alphanumeric': 0.07960117685518144, 'fraction_numerical': 0.0013076168682576005, 'mean_word_length': 2.5554909936083674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6543147', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1383, 'n_words': 360}