<commit_before>package sk.henrichg.phoneprofilesplus;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreferenceCompat;

class EventPreferencesActivatedProfile extends EventPreferences {

    long _startProfile;
    long _endProfile;

    int _running;

    static final String PREF_EVENT_ACTIVATED_PROFILE_ENABLED = "eventActivatedProfileEnabled";
    private static final String PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE = "eventActivatedProfileStartProfile";
    private static final String PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE = "eventActivatedProfileEndProfile";

    private static final String PREF_EVENT_ACTIVATED_PROFILE_CATEGORY = "eventActivatedProfileCategoryRoot";

    private static final int RUNNING_NOTSET = 0;
    private static final int RUNNING_RUNNING = 1;
    private static final int RUNNING_NOTRUNNING = 2;

    EventPreferencesActivatedProfile(Event event,
                                     boolean enabled,
                                     long startProfile,
                                     long endProfile)
    {
        super(event, enabled);

        this._startProfile = startProfile;
        this._endProfile = endProfile;

        this._running = RUNNING_NOTSET;
    }

    void copyPreferences(Event fromEvent)
    {
        this._enabled = fromEvent._eventPreferencesActivatedProfile._enabled;
        this._startProfile = fromEvent._eventPreferencesActivatedProfile._startProfile;
        this._endProfile = fromEvent._eventPreferencesActivatedProfile._endProfile;
        this.setSensorPassed(fromEvent._eventPreferencesActivatedProfile.getSensorPassed());

        this._running = RUNNING_NOTSET;
    }

    void loadSharedPreferences(SharedPreferences preferences)
    {
        Editor editor = preferences.edit();
        editor.putBoolean(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, _enabled);
        editor.putString(PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE, String.valueOf(this._startProfile));
        editor.putString(PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE, String.valueOf(this._endProfile));
        editor.apply();
    }

    void saveSharedPreferences(SharedPreferences preferences)
    {
        this._enabled = preferences.getBoolean(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, false);
        this._startProfile = Long.parseLong(preferences.getString(PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE, "0"));
        this._endProfile = Long.parseLong(preferences.getString(PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE, "0"));
    }

    String getPreferencesDescription(boolean addBullet, boolean addPassStatus, Context context)
    {
        String descr = "";

        if (!this._enabled) {
            if (!addBullet)
                descr = context.getString(R.string.event_preference_sensor_activated_profile_summary);
        } else {
            if (Event.isEventPreferenceAllowed(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) {
                if (addBullet) {
                    descr = descr + "<b>";
                    descr = descr + getPassStatusString(context.getString(R.string.event_type_activated_profile), addPassStatus, DatabaseHandler.ETYPE_ACTIVATED_PROFILE, context);
                    descr = descr + "</b> ";
                }

                descr = descr + context.getString(R.string.event_preferences_activated_profile_startProfile) + ": ";
                DataWrapper dataWrapper = new DataWrapper(context, false, 0, false, 0, 0, 0f);
                Profile profile = dataWrapper.getProfileById(this._startProfile, true, true, false);
                if (profile != null) {

                }

                descr = descr + context.getString(R.string.event_preferences_activated_profile_endProfile) + ": ";
                profile = dataWrapper.getProfileById(this._endProfile, true, true, false);
                if (profile != null) {

                }
            }
        }

        return descr;
    }

    private void setSummary(PreferenceManager prefMng, String key, String value, Context context)
    {
        SharedPreferences preferences = prefMng.getSharedPreferences();
        if (preferences == null)
            return;

        if (key.equals(PREF_EVENT_ACTIVATED_PROFILE_ENABLED)) {
            SwitchPreferenceCompat preference = prefMng.findPreference(key);
            if (preference != null) {
                GlobalGUIRoutines.setPreferenceTitleStyleX(preference, true, preferences.getBoolean(key, false), false, false, false);
            }
        }<commit_msg>Added: Save event id, which activates profile. Also for "Undo the profile" and "Restart events" from end of events. (24)<commit_after>package sk.henrichg.phoneprofilesplus;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreferenceCompat;

class EventPreferencesActivatedProfile extends EventPreferences {

    long _startProfile;
    long _endProfile;

    int _running;

    static final String PREF_EVENT_ACTIVATED_PROFILE_ENABLED = "eventActivatedProfileEnabled";
    private static final String PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE = "eventActivatedProfileStartProfile";
    private static final String PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE = "eventActivatedProfileEndProfile";

    private static final String PREF_EVENT_ACTIVATED_PROFILE_CATEGORY = "eventActivatedProfileCategoryRoot";

    private static final int RUNNING_NOTSET = 0;
    private static final int RUNNING_RUNNING = 1;
    private static final int RUNNING_NOTRUNNING = 2;

    EventPreferencesActivatedProfile(Event event,
                                     boolean enabled,
                                     long startProfile,
                                     long endProfile)
    {
        super(event, enabled);

        this._startProfile = startProfile;
        this._endProfile = endProfile;

        this._running = RUNNING_NOTSET;
    }

    void copyPreferences(Event fromEvent)
    {
        this._enabled = fromEvent._eventPreferencesActivatedProfile._enabled;
        this._startProfile = fromEvent._eventPreferencesActivatedProfile._startProfile;
        this._endProfile = fromEvent._eventPreferencesActivatedProfile._endProfile;
        this.setSensorPassed(fromEvent._eventPreferencesActivatedProfile.getSensorPassed());

        this._running = RUNNING_NOTSET;
    }

    void loadSharedPreferences(SharedPreferences preferences)
    {
        Editor editor = preferences.edit();
        editor.putBoolean(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, _enabled);
        editor.putString(PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE, String.valueOf(this._startProfile));
        editor.putString(PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE, String.valueOf(this._endProfile));
        editor.apply();
    }

    void saveSharedPreferences(SharedPreferences preferences)
    {
        this._enabled = preferences.getBoolean(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, false);
        this._startProfile = Long.parseLong(preferences.getString(PREF_EVENT_ACTIVATED_PROFILE_START_PROFILE, "0"));
        this._endProfile = Long.parseLong(preferences.getString(PREF_EVENT_ACTIVATED_PROFILE_END_PROFILE, "0"));
    }

    String getPreferencesDescription(boolean addBullet, boolean addPassStatus, Context context)
    {
        String descr = "";

        if (!this._enabled) {
            if (!addBullet)
                descr = context.getString(R.string.event_preference_sensor_activated_profile_summary);
        } else {
            if (Event.isEventPreferenceAllowed(PREF_EVENT_ACTIVATED_PROFILE_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) {
                if (addBullet) {
                    descr = descr + "<b>";
                    descr = descr + getPassStatusString(context.getString(R.string.event_type_activated_profile), addPassStatus, DatabaseHandler.ETYPE_ACTIVATED_PROFILE, context);
                    descr = descr + "</b> ";
                }

                descr = descr + context.getString(R.string.event_preferences_activated_profile_startProfile) + ": ";
                DataWrapper dataWrapper = new DataWrapper(context, false, 0, false, 0, 0, 0f);
                Profile profile = dataWrapper.getProfileById(this._startProfile, true, true, false);
                if (profile != null) {
                    descr = descr + "<b>" + profile._name + "</b>";
                } else {
                    descr = descr + "<b>" + context.getString(R.string.profile_preference_profile_not_set) + "</b>";
                }

                descr = descr + " • " + context.getString(R.string.event_preferences_activated_profile_endProfile) + ": ";
                profile = dataWrapper.getProfileById(this._endProfile, true, true, false);
                if (profile != null) {
                    descr = descr + "<b>" + profile._name + "</b>";
                } else {
                    descr = descr + "<b>" + context.getString(R.string.profile_preference_profile_not_set) + "</b>";
                }
            }
        }

        return descr;
    }

    private void setSummary(PreferenceManager prefMng, String key, String value, Context context)
    {
        SharedPreferences preferences = prefMng.getSharedPreferences();
        if (preferences == null)
            return;

        if (key.equals(PREF_EVENT_ACTIVATED_PROFILE_ENABLED)) {
            SwitchPreferenceCompat preference = prefMng.findPreference(key);
            if (preference != null) {
                GlobalGUIRoutines.setPreferenceTitleStyleX(preference, true, preferences.getBoolean(key, false), false, false, false);
            }
        }
{'fraction_non_alphanumeric': 0.08019102576858024, 'fraction_numerical': 0.0019898517560441747, 'mean_word_length': 2.954366640440598, 'pattern_counts': {'":': 4, '<': 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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3408589', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2669, 'n_words': 484}