<commit_before>package com.thebluealliance.androidclient.accounts;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.appspot.tba_dev_phil.tbaMobile.TbaMobile;
import com.appspot.tba_dev_phil.tbaMobile.model.ModelsMobileApiMessagesBaseResponse;
import com.appspot.tba_dev_phil.tbaMobile.model.ModelsMobileApiMessagesModelPreferenceMessage;
import com.thebluealliance.androidclient.Constants;
import com.thebluealliance.androidclient.datafeed.Database;
import com.thebluealliance.androidclient.gcm.GCMAuthHelper;
import com.thebluealliance.androidclient.helpers.ModelNotificationFavoriteSettings;
import com.thebluealliance.androidclient.helpers.MyTBAHelper;
import com.thebluealliance.androidclient.interfaces.ModelSettingsCallbacks;
import com.thebluealliance.androidclient.models.Favorite;
import com.thebluealliance.androidclient.models.Subscription;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * File created by phil on 8/2/14.
 */
public class UpdateUserModelSettings extends AsyncTask<String, Void, UpdateUserModelSettings.Result> {

    protected enum Result {
        SUCCESS, NOOP, ERROR
    }

    private Context context;
    private ModelNotificationFavoriteSettings settings;

    // We use a WeakReference so that the Activity can be garbage-collected if need be.
    private WeakReference<ModelSettingsCallbacks> callbacks;

    public UpdateUserModelSettings(Context context, ModelNotificationFavoriteSettings settings) {
        this.context = context;
        this.settings = settings;
    }

    public void setCallbacks(ModelSettingsCallbacks callbacks) {
        this.callbacks = new WeakReference<>(callbacks);
    }

    @Override
    protected Result doInBackground(String... params) {
        String modelKey = settings.modelKey;
        ArrayList<String> notifications = settings.enabledNotifications;
        boolean isFavorite = settings.isFavorite;

        Result notificationsResult, favoriteResult;

        // Save initial state so we can do a rollback
        Subscription initialSubscriptionState;
        Favorite initialFavorite;

        String user = AccountHelper.getSelectedAccount(context);
        String key = MyTBAHelper.createKey(user, modelKey);

        ModelsMobileApiMessagesModelPreferenceMessage request = new ModelsMobileApiMessagesModelPreferenceMessage();
        request.setModelKey(modelKey);
        request.setDeviceKey(GCMAuthHelper.getRegistrationId(context));
        request.setNotifications(notifications);
        request.setFavorite(isFavorite);

        Database.Subscriptions subscriptionsTable = Database.getInstance(context).getSubscriptionsTable();
        Database.Favorites favoritesTable = Database.getInstance(context).getFavoritesTable();

        // Determine if we have to do anything
        List<String> existingNotificationsList = new ArrayList<>();
        Subscription existingSubscription = subscriptionsTable.get(key);
        if(existingSubscription != null) {
            existingNotificationsList = existingSubscription.getNotificationList();
        }<commit_msg>Removed old stuff.<commit_after>package com.thebluealliance.androidclient.accounts;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.appspot.tba_dev_phil.tbaMobile.TbaMobile;
import com.appspot.tba_dev_phil.tbaMobile.model.ModelsMobileApiMessagesBaseResponse;
import com.appspot.tba_dev_phil.tbaMobile.model.ModelsMobileApiMessagesModelPreferenceMessage;
import com.thebluealliance.androidclient.Constants;
import com.thebluealliance.androidclient.datafeed.Database;
import com.thebluealliance.androidclient.gcm.GCMAuthHelper;
import com.thebluealliance.androidclient.helpers.ModelNotificationFavoriteSettings;
import com.thebluealliance.androidclient.helpers.MyTBAHelper;
import com.thebluealliance.androidclient.interfaces.ModelSettingsCallbacks;
import com.thebluealliance.androidclient.models.Favorite;
import com.thebluealliance.androidclient.models.Subscription;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * File created by phil on 8/2/14.
 */
public class UpdateUserModelSettings extends AsyncTask<String, Void, UpdateUserModelSettings.Result> {

    protected enum Result {
        SUCCESS, NOOP, ERROR
    }

    private Context context;
    private ModelNotificationFavoriteSettings settings;

    // We use a WeakReference so that the Activity can be garbage-collected if need be.
    private WeakReference<ModelSettingsCallbacks> callbacks;

    public UpdateUserModelSettings(Context context, ModelNotificationFavoriteSettings settings) {
        this.context = context;
        this.settings = settings;
    }

    public void setCallbacks(ModelSettingsCallbacks callbacks) {
        this.callbacks = new WeakReference<>(callbacks);
    }

    @Override
    protected Result doInBackground(String... params) {
        String modelKey = settings.modelKey;
        ArrayList<String> notifications = settings.enabledNotifications;
        boolean isFavorite = settings.isFavorite;

        String user = AccountHelper.getSelectedAccount(context);
        String key = MyTBAHelper.createKey(user, modelKey);

        ModelsMobileApiMessagesModelPreferenceMessage request = new ModelsMobileApiMessagesModelPreferenceMessage();
        request.setModelKey(modelKey);
        request.setDeviceKey(GCMAuthHelper.getRegistrationId(context));
        request.setNotifications(notifications);
        request.setFavorite(isFavorite);

        Database.Subscriptions subscriptionsTable = Database.getInstance(context).getSubscriptionsTable();
        Database.Favorites favoritesTable = Database.getInstance(context).getFavoritesTable();

        // Determine if we have to do anything
        List<String> existingNotificationsList = new ArrayList<>();
        Subscription existingSubscription = subscriptionsTable.get(key);
        if(existingSubscription != null) {
            existingNotificationsList = existingSubscription.getNotificationList();
        }
{'fraction_non_alphanumeric': 0.07647058823529412, 'fraction_numerical': 0.0012718600953895071, 'mean_word_length': 4.642152466367713, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6101795', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1611, 'n_words': 324}