<commit_before>package org.stepic.droid.preferences;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.base.MainApplication;
import org.stepic.droid.model.EmailAddress;
import org.stepic.droid.model.Profile;
import org.stepic.droid.model.comments.DiscussionOrder;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.RWLocks;
import org.stepic.droid.web.AuthenticationStepicResponse;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class SharedPreferenceHelper {
    private static final String NOTIFICATION_SOUND_DISABLED = "notification_sound";
    private static final String TEMP_UPDATE_LINK = "temp_update_link";
    private Context mContext;
    private Analytic analytic;

    @Inject
    public SharedPreferenceHelper(Analytic analytic) {
        this.analytic = analytic;
        mContext = MainApplication.getAppContext();
    }

    public boolean isSDChosen() {
        //default is not. false -> sd is not chosen
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, SD_CHOSEN);
    }

    public void setSDChosen(boolean isSdChosen) {
        put(PreferenceType.DEVICE_SPECIFIC, SD_CHOSEN, isSdChosen);
    }

    public boolean isNotificationVibrationDisabled() {
        //default is enabled
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_VIBRATION_DISABLED);
    }

    public void setNotificationVibrationDisabled(boolean isNotificationVibrationDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_VIBRATION_DISABLED, isNotificationVibrationDisabled);
    }

    public boolean isNotificationDisabled() {
        //default is enabled
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_DISABLED);
    }

    public void setNotificationDisabled(boolean isNotificationDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_DISABLED, isNotificationDisabled);
    }

    public boolean isNotificationSoundDisabled() {
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_SOUND_DISABLED);
    }

    public void setNotificationSoundDisabled(boolean isDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_SOUND_DISABLED, isDisabled);
    }

    public boolean isFirstTime() {
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, FIRST_TIME_LAUNCH, true);
    }

    public void afterFirstTime() {
        put(PreferenceType.DEVICE_SPECIFIC, FIRST_TIME_LAUNCH, false);
    }

//    public enum CommentsOrder {
//        DISCUSSION_NEW_FIRST("discussion"),
//        DISCUSSION_MOST_LIKED("discussions_most_liked"),
//        DISCUSSION_MOST_ACTIVE("discussions_most_active"),
//        DISCUSSION_RECENT_ACTIVITY("discussions_recent_activity");
//
//        private String description;
//
//        CommentsOrder(String description) {
//            this.description = description;
//        }
//
//        private String getStoreName() {
//            return description;
//        }
//    }

    public enum PreferenceType {
        LOGIN("login preference"),
        WIFI("wifi_preference"),
        VIDEO_QUALITY("video_quality_preference"),
        TEMP("temporary"),
        VIDEO_SETTINGS("video_settings"),
        DEVICE_SPECIFIC("device_specific");

        private String description;

        PreferenceType(String description) {
            this.description = description;
        }

        private String getStoreName() {
            return description;
        }
    }

    public DiscussionOrder getDiscussionOrder() {
        int orderId = getInt(PreferenceType.LOGIN, DISCUSSION_ORDER);
        return DiscussionOrder.Companion.getById(orderId);
    }

    public void setDiscussionOrder(DiscussionOrder disscussionOrder){
        put(PreferenceType.LOGIN, DISCUSSION_ORDER, disscussionOrder.getId());
    }

    public void setIsGcmTokenOk(boolean isGcmTokenOk) {
        put(PreferenceType.LOGIN, GCM_TOKEN_ACTUAL, isGcmTokenOk);
    }

    public boolean isGcmTokenOk() {
        return getBoolean(PreferenceType.LOGIN, GCM_TOKEN_ACTUAL);
    }

    public void storeVideoPlaybackRate(@NotNull VideoPlaybackRate videoPlaybackRate) {
        int videoIndex = videoPlaybackRate.getIndex();
        put(PreferenceType.VIDEO_SETTINGS, VIDEO_RATE_PREF_KEY, videoIndex);
    }

    @NotNull
    public VideoPlaybackRate getVideoPlaybackRate() {
        int index = getInt(PreferenceType.VIDEO_SETTINGS, VIDEO_RATE_PREF_KEY);<commit_msg>Add trend of order comments<commit_after>package org.stepic.droid.preferences;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.base.MainApplication;
import org.stepic.droid.model.EmailAddress;
import org.stepic.droid.model.Profile;
import org.stepic.droid.model.comments.DiscussionOrder;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.RWLocks;
import org.stepic.droid.web.AuthenticationStepicResponse;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class SharedPreferenceHelper {
    private static final String NOTIFICATION_SOUND_DISABLED = "notification_sound";
    private static final String TEMP_UPDATE_LINK = "temp_update_link";
    private Context mContext;
    private Analytic analytic;

    @Inject
    public SharedPreferenceHelper(Analytic analytic) {
        this.analytic = analytic;
        mContext = MainApplication.getAppContext();
    }

    public boolean isSDChosen() {
        //default is not. false -> sd is not chosen
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, SD_CHOSEN);
    }

    public void setSDChosen(boolean isSdChosen) {
        put(PreferenceType.DEVICE_SPECIFIC, SD_CHOSEN, isSdChosen);
    }

    public boolean isNotificationVibrationDisabled() {
        //default is enabled
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_VIBRATION_DISABLED);
    }

    public void setNotificationVibrationDisabled(boolean isNotificationVibrationDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_VIBRATION_DISABLED, isNotificationVibrationDisabled);
    }

    public boolean isNotificationDisabled() {
        //default is enabled
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_DISABLED);
    }

    public void setNotificationDisabled(boolean isNotificationDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_DISABLED, isNotificationDisabled);
    }

    public boolean isNotificationSoundDisabled() {
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_SOUND_DISABLED);
    }

    public void setNotificationSoundDisabled(boolean isDisabled) {
        put(PreferenceType.DEVICE_SPECIFIC, NOTIFICATION_SOUND_DISABLED, isDisabled);
    }

    public boolean isFirstTime() {
        return getBoolean(PreferenceType.DEVICE_SPECIFIC, FIRST_TIME_LAUNCH, true);
    }

    public void afterFirstTime() {
        put(PreferenceType.DEVICE_SPECIFIC, FIRST_TIME_LAUNCH, false);
    }

//    public enum CommentsOrder {
//        DISCUSSION_NEW_FIRST("discussion"),
//        DISCUSSION_MOST_LIKED("discussions_most_liked"),
//        DISCUSSION_MOST_ACTIVE("discussions_most_active"),
//        DISCUSSION_RECENT_ACTIVITY("discussions_recent_activity");
//
//        private String description;
//
//        CommentsOrder(String description) {
//            this.description = description;
//        }
//
//        private String getStoreName() {
//            return description;
//        }
//    }

    public enum PreferenceType {
        LOGIN("login preference"),
        WIFI("wifi_preference"),
        VIDEO_QUALITY("video_quality_preference"),
        TEMP("temporary"),
        VIDEO_SETTINGS("video_settings"),
        DEVICE_SPECIFIC("device_specific");

        private String description;

        PreferenceType(String description) {
            this.description = description;
        }

        private String getStoreName() {
            return description;
        }
    }

    public DiscussionOrder getDiscussionOrder() {
        int orderId = getInt(PreferenceType.LOGIN, DISCUSSION_ORDER);
        DiscussionOrder order = DiscussionOrder.Companion.getById(orderId);
        analytic.reportEvent(Analytic.Comments.ORDER_TREND, order.toString());
        return order;
    }

    public void setDiscussionOrder(DiscussionOrder disscussionOrder){
        put(PreferenceType.LOGIN, DISCUSSION_ORDER, disscussionOrder.getId());
    }

    public void setIsGcmTokenOk(boolean isGcmTokenOk) {
        put(PreferenceType.LOGIN, GCM_TOKEN_ACTUAL, isGcmTokenOk);
    }

    public boolean isGcmTokenOk() {
        return getBoolean(PreferenceType.LOGIN, GCM_TOKEN_ACTUAL);
    }

    public void storeVideoPlaybackRate(@NotNull VideoPlaybackRate videoPlaybackRate) {
        int videoIndex = videoPlaybackRate.getIndex();
        put(PreferenceType.VIDEO_SETTINGS, VIDEO_RATE_PREF_KEY, videoIndex);
    }

    @NotNull
    public VideoPlaybackRate getVideoPlaybackRate() {
        int index = getInt(PreferenceType.VIDEO_SETTINGS, VIDEO_RATE_PREF_KEY);
{'fraction_non_alphanumeric': 0.08480492813141684, 'fraction_numerical': 0.0, 'mean_word_length': 3.698986975397974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2655633', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2759, 'n_words': 488}