<commit_before>package com.nutomic.syncthingandroid.fragments;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v4.app.NavUtils;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.preferences.WifiSsidPreference;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import eu.chainfire.libsuperuser.Shell;

public class SettingsFragment extends PreferenceFragment
        implements SyncthingActivity.OnServiceConnectedListener,
        SyncthingService.OnApiChangeListener, Preference.OnPreferenceChangeListener,
        Preference.OnPreferenceClickListener {

    private static final String TAG = "SettingsFragment";

    private static final String SYNCTHING_OPTIONS_KEY = "syncthing_options";
    private static final String SYNCTHING_GUI_KEY     = "syncthing_gui";
    private static final String DEVICE_NAME_KEY       = "deviceName";
    private static final String USAGE_REPORT_ACCEPTED = "urAccepted";
    private static final String ADDRESS               = "address";
    private static final String GUI_USER              = "gui_user";
    private static final String GUI_PASSWORD          = "<PASSWORD>";
    private static final String EXPORT_CONFIG         = "export_config";
    private static final String IMPORT_CONFIG         = "import_config";
    private static final String STTRACE               = "sttrace";
    private static final String SYNCTHING_RESET       = "streset";
    private static final String SYNCTHING_VERSION_KEY = "syncthing_version";
    private static final String APP_VERSION_KEY       = "app_version";

    private CheckBoxPreference mAlwaysRunInBackground;
    private CheckBoxPreference mSyncOnlyCharging;
    private CheckBoxPreference mSyncOnlyWifi;
    private WifiSsidPreference mSyncOnlyOnSSIDs;
    private CheckBoxPreference mUseRoot;
    private CheckBoxPreference mKeepWakelock;
    private PreferenceScreen mOptionsScreen;
    private PreferenceScreen mGuiScreen;
    private SyncthingService mSyncthingService;

    @Override
    public void onApiChange(SyncthingService.State currentState) {
        boolean enabled = currentState == SyncthingService.State.ACTIVE;
        mOptionsScreen.setEnabled(enabled);
        mGuiScreen.setEnabled(enabled);
        mUseRoot.setEnabled(enabled);

        if (currentState == SyncthingService.State.ACTIVE) {
            Preference syncthingVersion = getPreferenceScreen().findPreference(SYNCTHING_VERSION_KEY);
            syncthingVersion.setSummary(mSyncthingService.getApi().getVersion());
            RestApi api = mSyncthingService.getApi();
            for (int i = 0; i < mOptionsScreen.getPreferenceCount(); i++) {
                final Preference pref = mOptionsScreen.getPreference(i);
                pref.setOnPreferenceChangeListener(SettingsFragment.this);
                String value;
                switch (pref.getKey()) {
                    case DEVICE_NAME_KEY:
                        value = api.getLocalDevice().name;
                        break;
                    case USAGE_REPORT_ACCEPTED:
                        RestApi.UsageReportSetting setting = api.getUsageReportAccepted();
                        value = Boolean.toString(setting  == RestApi.UsageReportSetting.ACCEPTED);<commit_msg>Disable keep wakelock setting on restart.<commit_after>package com.nutomic.syncthingandroid.fragments;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v4.app.NavUtils;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.preferences.WifiSsidPreference;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import eu.chainfire.libsuperuser.Shell;

public class SettingsFragment extends PreferenceFragment
        implements SyncthingActivity.OnServiceConnectedListener,
        SyncthingService.OnApiChangeListener, Preference.OnPreferenceChangeListener,
        Preference.OnPreferenceClickListener {

    private static final String TAG = "SettingsFragment";

    private static final String SYNCTHING_OPTIONS_KEY = "syncthing_options";
    private static final String SYNCTHING_GUI_KEY     = "syncthing_gui";
    private static final String DEVICE_NAME_KEY       = "deviceName";
    private static final String USAGE_REPORT_ACCEPTED = "urAccepted";
    private static final String ADDRESS               = "address";
    private static final String GUI_USER              = "gui_user";
    private static final String GUI_PASSWORD          = "<PASSWORD>";
    private static final String EXPORT_CONFIG         = "export_config";
    private static final String IMPORT_CONFIG         = "import_config";
    private static final String STTRACE               = "sttrace";
    private static final String SYNCTHING_RESET       = "streset";
    private static final String SYNCTHING_VERSION_KEY = "syncthing_version";
    private static final String APP_VERSION_KEY       = "app_version";

    private CheckBoxPreference mAlwaysRunInBackground;
    private CheckBoxPreference mSyncOnlyCharging;
    private CheckBoxPreference mSyncOnlyWifi;
    private WifiSsidPreference mSyncOnlyOnSSIDs;
    private CheckBoxPreference mUseRoot;
    private CheckBoxPreference mKeepWakelock;
    private PreferenceScreen mOptionsScreen;
    private PreferenceScreen mGuiScreen;
    private SyncthingService mSyncthingService;

    @Override
    public void onApiChange(SyncthingService.State currentState) {
        boolean enabled = currentState == SyncthingService.State.ACTIVE;
        mOptionsScreen.setEnabled(enabled);
        mGuiScreen.setEnabled(enabled);
        mUseRoot.setEnabled(enabled);
        mKeepWakelock.setEnabled(enabled);

        if (currentState == SyncthingService.State.ACTIVE) {
            Preference syncthingVersion = getPreferenceScreen().findPreference(SYNCTHING_VERSION_KEY);
            syncthingVersion.setSummary(mSyncthingService.getApi().getVersion());
            RestApi api = mSyncthingService.getApi();
            for (int i = 0; i < mOptionsScreen.getPreferenceCount(); i++) {
                final Preference pref = mOptionsScreen.getPreference(i);
                pref.setOnPreferenceChangeListener(SettingsFragment.this);
                String value;
                switch (pref.getKey()) {
                    case DEVICE_NAME_KEY:
                        value = api.getLocalDevice().name;
                        break;
                    case USAGE_REPORT_ACCEPTED:
                        RestApi.UsageReportSetting setting = api.getUsageReportAccepted();
                        value = Boolean.toString(setting  == RestApi.UsageReportSetting.ACCEPTED);
{'fraction_non_alphanumeric': 0.06966565349544072, 'fraction_numerical': 0.00048632218844984804, 'mean_word_length': 3.6712095400340714, 'pattern_counts': {'":': 0, '<': 7, '<?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': '141529', 'n_tokens_mistral': 2217, 'n_tokens_neox': 2176, 'n_words': 465}