<commit_before>package tomas_vycital.eet.android_app.settings;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.design.widget.Snackbar;
import android.util.JsonReader;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;

import org.json.JSONObject;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.Writer;
import java.util.Calendar;
import java.util.TimeZone;

import tomas_vycital.eet.android_app.R;
import tomas_vycital.eet.android_app.printer.BTPrinter;

/**
 * Created by tom on 3.3.17.
 */

public class SettingsGUI implements View.OnClickListener {
    private final Context context;
    private final View layout;
    private final BTPrinter printer;

    public SettingsGUI(Context context, Button settingsButton, LinearLayout settings, BTPrinter printer) {
        this.context = context;
        this.layout = settings;
        this.printer = printer;

        this.refresh();

        // Onclick listeners
        settingsButton.setOnClickListener(this);
        this.layout.findViewById(R.id.settings_codepage_test).setOnClickListener(this);
        this.layout.findViewById(R.id.settings_backup).setOnClickListener(this);
        this.layout.findViewById(R.id.settings_restore).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        SharedPreferences.Editor editor;

        switch (v.getId()) {
            case R.id.settings_save:
                Snackbar.make(this.layout, "Ukládá se…", Snackbar.LENGTH_LONG).setAction("Action", null).show();

                editor = Settings.prefs.edit();
                this.saveString(editor, R.id.setting_dic, "DIC");
                this.saveString(editor, R.id.setting_heading, "heading");
                this.saveString(editor, R.id.setting_footing, "footing");
                this.saveInteger(editor, R.id.settings_receipt_width, "receiptWidth");
                this.saveString(editor, R.id.settings_id_pokl, "idPokl");
                this.saveString(editor, R.id.settings_id_provoz, "idProvoz");
                switch (((RadioGroup) this.layout.findViewById(R.id.settings_server)).getCheckedRadioButtonId()) {
                    case R.id.settings_server_play:
                        editor.putInt("server", Server.play.getID());
                        break;
                    case R.id.settings_server_prod:
                        editor.putInt("server", Server.prod.getID());
                        break;
                }
                this.saveBoolean(editor, R.id.settings_verifying, "verifying");
                editor.putInt("codepage", this.getUnsavedCodepage());
                editor.putString("charset", this.getUnsavedCharset().getStr());
                editor.putString("keyFileName", this.getRadioGroupValue(R.id.settings_keys));
                editor.apply();

                Snackbar.make(this.layout, "Uloženo", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                break;
            case R.id.settings_codepage_test:
                try {
                    this.printer.testCP(this.getUnsavedCodepage(), this.getUnsavedCharset());
                } catch (IOException ignored) {
                }
                break;
            case R.id.settings_backup:
                try {
                    (new File(Settings.backupsDir)).mkdirs();
                    File file = new File(Settings.backupsDir + "/" + String.format("%tFT%<tR%<tZ", Calendar.getInstance(TimeZone.getDefault())) + ".json");
                    Writer writer = new BufferedWriter(new FileWriter(file));
                    writer.write(
                            (new JSONObject(
                                    Settings.prefs.getAll()
                            )).toString()
                    );
                    writer.close();

                    Snackbar.make(this.layout, "Zazálohováno", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                } catch (Exception e) {
                    Snackbar.make(this.layout, "Záloha se nezdařilo", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                }
                break;
            case R.id.settings_restore:
                try {
                    String fileName = ((RadioButton) this.layout.findViewById(((RadioGroup) this.layout.findViewById(R.id.settings_backups)).getCheckedRadioButtonId())).getText().toString();
                    JsonReader reader = new JsonReader(new FileReader(Settings.backupsDir + "/" + fileName));

                    editor = Settings.prefs.edit();
                    reader.beginObject();
                    while (reader.hasNext()) {
                        String name = reader.nextName();
                        Object defaultValue = Settings.defaults.get(name);
                        if (defaultValue instanceof Integer) {
                            editor.putInt(name, reader.nextInt());
                        } else if (defaultValue instanceof Boolean) {
                            editor.putBoolean(name, reader.nextBoolean());
                        } else { // String
                            editor.putString(name, reader.nextString());
                        }
                    }
                    reader.endObject();
                    editor.commit();

                    Snackbar.make(this.layout, "Obnoveno", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                } catch (Exception e) {
                    Snackbar.make(this.layout, "Obnovení se nezdařilo", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                }
                break;
        }

        this.refresh();
    }
<commit_msg>Neobnovuj nastavení po testu kódování<commit_after>package tomas_vycital.eet.android_app.settings;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.design.widget.Snackbar;
import android.util.JsonReader;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;

import org.json.JSONObject;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.Writer;
import java.util.Calendar;
import java.util.TimeZone;

import tomas_vycital.eet.android_app.R;
import tomas_vycital.eet.android_app.printer.BTPrinter;

/**
 * Created by tom on 3.3.17.
 */

public class SettingsGUI implements View.OnClickListener {
    private final Context context;
    private final View layout;
    private final BTPrinter printer;

    public SettingsGUI(Context context, Button settingsButton, LinearLayout settings, BTPrinter printer) {
        this.context = context;
        this.layout = settings;
        this.printer = printer;

        this.refresh();

        // Onclick listeners
        settingsButton.setOnClickListener(this);
        this.layout.findViewById(R.id.settings_codepage_test).setOnClickListener(this);
        this.layout.findViewById(R.id.settings_backup).setOnClickListener(this);
        this.layout.findViewById(R.id.settings_restore).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        SharedPreferences.Editor editor;

        switch (v.getId()) {
            case R.id.settings_save:
                Snackbar.make(this.layout, "Ukládá se…", Snackbar.LENGTH_LONG).setAction("Action", null).show();

                editor = Settings.prefs.edit();
                this.saveString(editor, R.id.setting_dic, "DIC");
                this.saveString(editor, R.id.setting_heading, "heading");
                this.saveString(editor, R.id.setting_footing, "footing");
                this.saveInteger(editor, R.id.settings_receipt_width, "receiptWidth");
                this.saveString(editor, R.id.settings_id_pokl, "idPokl");
                this.saveString(editor, R.id.settings_id_provoz, "idProvoz");
                switch (((RadioGroup) this.layout.findViewById(R.id.settings_server)).getCheckedRadioButtonId()) {
                    case R.id.settings_server_play:
                        editor.putInt("server", Server.play.getID());
                        break;
                    case R.id.settings_server_prod:
                        editor.putInt("server", Server.prod.getID());
                        break;
                }
                this.saveBoolean(editor, R.id.settings_verifying, "verifying");
                editor.putInt("codepage", this.getUnsavedCodepage());
                editor.putString("charset", this.getUnsavedCharset().getStr());
                editor.putString("keyFileName", this.getRadioGroupValue(R.id.settings_keys));
                editor.apply();

                Snackbar.make(this.layout, "Uloženo", Snackbar.LENGTH_LONG).setAction("Action", null).show();

                this.refresh();
                break;
            case R.id.settings_codepage_test:
                try {
                    this.printer.testCP(this.getUnsavedCodepage(), this.getUnsavedCharset());
                } catch (IOException ignored) {
                }
                break;
            case R.id.settings_backup:
                try {
                    (new File(Settings.backupsDir)).mkdirs();
                    File file = new File(Settings.backupsDir + "/" + String.format("%tFT%<tR%<tZ", Calendar.getInstance(TimeZone.getDefault())) + ".json");
                    Writer writer = new BufferedWriter(new FileWriter(file));
                    writer.write(
                            (new JSONObject(
                                    Settings.prefs.getAll()
                            )).toString()
                    );
                    writer.close();

                    Snackbar.make(this.layout, "Zazálohováno", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                } catch (Exception e) {
                    Snackbar.make(this.layout, "Záloha se nezdařilo", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                }

                this.refresh();
                break;
            case R.id.settings_restore:
                try {
                    String fileName = ((RadioButton) this.layout.findViewById(((RadioGroup) this.layout.findViewById(R.id.settings_backups)).getCheckedRadioButtonId())).getText().toString();
                    JsonReader reader = new JsonReader(new FileReader(Settings.backupsDir + "/" + fileName));

                    editor = Settings.prefs.edit();
                    reader.beginObject();
                    while (reader.hasNext()) {
                        String name = reader.nextName();
                        Object defaultValue = Settings.defaults.get(name);
                        if (defaultValue instanceof Integer) {
                            editor.putInt(name, reader.nextInt());
                        } else if (defaultValue instanceof Boolean) {
                            editor.putBoolean(name, reader.nextBoolean());
                        } else { // String
                            editor.putString(name, reader.nextString());
                        }
                    }
                    reader.endObject();
                    editor.commit();

                    Snackbar.make(this.layout, "Obnoveno", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                } catch (Exception e) {
                    Snackbar.make(this.layout, "Obnovení se nezdařilo", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                }

                this.refresh();
                break;
        }
    }

{'fraction_non_alphanumeric': 0.11175592770684795, 'fraction_numerical': 0.000663239927043608, 'mean_word_length': 1.930046150109303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '831341', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3100, 'n_words': 528}