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

import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.NonNull;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableEntryException;
import java.util.HashMap;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import tomas_vycital.eet.android_app.VAT;
import tomas_vycital.eet.android_app.error.UnreadableKeyPassword;
import tomas_vycital.eet.android_app.error.UnsupportedImportItemsVersion;
import tomas_vycital.eet.android_app.items.Items;

/**
 * Allows settings to be retrieved from anywhere in the app and saved from this package, items and last printer MAC can be saved from anywhere. has to be initialized with setup() before use.
 */
public class Settings {
    static final FilenameFilter keyFilter;
    static final FilenameFilter backupFilter;
    static final String keysDir = Environment.getExternalStorageDirectory().toString() + "/TV EET/Keys";
    static final String backupsDir = Environment.getExternalStorageDirectory().toString() + "/TV EET/Backups";
    static final HashMap<String, Object> defaults;
    static SharedPreferences prefs;
    static Encryption encryption;

    static {
        defaults = new HashMap<>();
        defaults.put("address", "");
        defaults.put("charset", Charset.ascii.getStr());
        defaults.put("codepage", 0);
        defaults.put("DIC", "→NUTNO ZADAT←");
        defaults.put("VAT0", 0);
        defaults.put("VAT1", 21);
        defaults.put("VAT2", 15);
        defaults.put("VAT3", 10);
        defaults.put("footing", "");
        defaults.put("heading", "");
        defaults.put("ICO", "");
        defaults.put("itemsImportURL", "https://pastebin.com/raw/L0EkXrPf");
        defaults.put("keyFileName", null);
        defaults.put("name", "");
        defaults.put("receiptWidth", 32);
        defaults.put("server", Server.play.getID());
        defaults.put("verifying", true);

        keyFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.matches("^.*\\.p12$");
            }
        };
        backupFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.matches("^.*\\.json$");
            }
        };
    }

    public static void setup(SharedPreferences prefs) {
        Settings.prefs = prefs;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Settings.encryption = new Encryption23();
        } else {
            Settings.encryption = new EncryptionNone();
        }
    }

    private static String getString(String id) {<commit_msg>Změň výchozí adresu pro import zboží<commit_after>package tomas_vycital.eet.android_app.settings;

import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.NonNull;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableEntryException;
import java.util.HashMap;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import tomas_vycital.eet.android_app.VAT;
import tomas_vycital.eet.android_app.error.UnreadableKeyPassword;
import tomas_vycital.eet.android_app.error.UnsupportedImportItemsVersion;
import tomas_vycital.eet.android_app.items.Items;

/**
 * Allows settings to be retrieved from anywhere in the app and saved from this package, items and last printer MAC can be saved from anywhere. has to be initialized with setup() before use.
 */
public class Settings {
    static final FilenameFilter keyFilter;
    static final FilenameFilter backupFilter;
    static final String keysDir = Environment.getExternalStorageDirectory().toString() + "/TV EET/Keys";
    static final String backupsDir = Environment.getExternalStorageDirectory().toString() + "/TV EET/Backups";
    static final HashMap<String, Object> defaults;
    static SharedPreferences prefs;
    static Encryption encryption;

    static {
        defaults = new HashMap<>();
        defaults.put("address", "");
        defaults.put("charset", Charset.ascii.getStr());
        defaults.put("codepage", 0);
        defaults.put("DIC", "→NUTNO ZADAT←");
        defaults.put("VAT0", 0);
        defaults.put("VAT1", 21);
        defaults.put("VAT2", 15);
        defaults.put("VAT3", 10);
        defaults.put("footing", "");
        defaults.put("heading", "");
        defaults.put("ICO", "");
        defaults.put("itemsImportURL", "https://pastebin.com/raw/eUZbZjTt");
        defaults.put("keyFileName", null);
        defaults.put("name", "");
        defaults.put("receiptWidth", 32);
        defaults.put("server", Server.play.getID());
        defaults.put("verifying", true);

        keyFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.matches("^.*\\.p12$");
            }
        };
        backupFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.matches("^.*\\.json$");
            }
        };
    }

    public static void setup(SharedPreferences prefs) {
        Settings.prefs = prefs;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Settings.encryption = new Encryption23();
        } else {
            Settings.encryption = new EncryptionNone();
        }
    }

    private static String getString(String id) {
{'fraction_non_alphanumeric': 0.11389521640091116, 'fraction_numerical': 0.005618830675778284, 'mean_word_length': 3.3789893617021276, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2277753', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1819, 'n_words': 407}