<commit_before>package com.kluehspies.marian.unlockmanager.trigger;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.kluehspies.marian.unlockmanager.manager.IRewardManager;
import com.kluehspies.marian.unlockmanager.persistence.PersistenceHandler;
import com.kluehspies.marian.unlockmanager.trigger.AndroidAchievementUnlocker;
import com.kluehspies.marian.unlockmanager.trigger.Trigger;

/**
 * Created by <NAME> on 21.01.2015.
 *
 * Default implementation of PersistenceHandler
 */

public class SharedPreferencesHandler<M> extends PersistenceHandler<M> {

    private String sharedPreferencesKey;
    private SharedPreferences preferences;

    public SharedPreferencesHandler(Class<M> clazz,Context context, String sharedPreferencesKey) {
        super(clazz);
        this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
        this.sharedPreferencesKey = sharedPreferencesKey;
    }

    @Override
    public void unlockFailed(M item, Trigger<M> trigger) {
        setUnlockState(item, false);
    }

    public void unlockSucceeded(M item, Trigger<M> trigger) {
        setUnlockState(item, true);
    }


    private void setUnlockState(M item, boolean state) {
        preferences.edit().putBoolean(sharedPreferencesKey + "_" + item, state).apply();
    }<commit_msg>Refactoring<commit_after>package com.kluehspies.marian.unlockmanager.trigger;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.kluehspies.marian.unlockmanager.persistence.PersistenceHandler;

/**
 * Created by <NAME> on 21.01.2015.
 *
 * Default implementation of PersistenceHandler
 */
public class SharedPreferencesHandler<M> extends PersistenceHandler<M> {

    private String sharedPreferencesKey;
    private SharedPreferences preferences;

    public SharedPreferencesHandler(Class<M> clazz, Context context, String sharedPreferencesKey) {
        super(clazz);
        this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
        this.sharedPreferencesKey = sharedPreferencesKey;
    }

    @Override
    public void unlockFailed(M item, Trigger<M> trigger) {
        setUnlockState(item, false);
    }

    public void unlockSucceeded(M item, Trigger<M> trigger) {
        setUnlockState(item, true);
    }


    private void setUnlockState(M item, boolean state) {
        preferences.edit().putBoolean(sharedPreferencesKey + "_" + item, state).apply();
    }
{'fraction_non_alphanumeric': 0.09009009009009009, 'fraction_numerical': 0.00626713670191931, 'mean_word_length': 4.613186813186813, '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': '3528063', 'n_tokens_mistral': 718, 'n_tokens_neox': 691, 'n_words': 141}