// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
//     // read settings values
//     NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
//     GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
//     GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
//     GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
//     return mgdl / 18f;
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
//     return mmol * 18f;
// }


import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;
package de.dorianscholz.openlibre.ui;




public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

        // Display the fragment as the main content.
        getFragmentManager().beginTransaction()
                .replace(android.R.id.content, new SettingsFragment())
                .commit();
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
        // when username or server changes update the key for the sync progress
        if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
            // trim spaces off of email address
            String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("pref_tidepool_username", tidepoolUsername);
            editor.apply();

            String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);

            SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
            preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
            preferencesEditor.apply();

        }

        if (key.equals("pref_glucose_unit_is_mmol")) {
            GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
            SharedPreferences.Editor editor = settings.edit();
            if (GLUCOSE_UNIT_IS_MMOL) {
                editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MAX = 140;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static float GLUCOSE_TARGET_MIN = 80;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static boolean GLUCOSE_UNIT_IS_MMOL = false;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static void refreshApplicationSettings(SharedPreferences settings) {
//     // read settings values
//     NFC_USE_MULTI_BLOCK_READ = settings.getBoolean("pref_nfc_use_multi_block_read", NFC_USE_MULTI_BLOCK_READ);
//     GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
//     GLUCOSE_TARGET_MIN = Float.parseFloat(settings.getString("pref_glucose_target_min", Float.toString(GLUCOSE_TARGET_MIN)));
//     GLUCOSE_TARGET_MAX = Float.parseFloat(settings.getString("pref_glucose_target_max", Float.toString(GLUCOSE_TARGET_MAX)));
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMGDLToMMOL(float mgdl) {
//     return mgdl / 18f;
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/GlucoseData.java
// public static float convertGlucoseMMOLToMGDL(float mmol) {
//     return mmol * 18f;
// }


// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SettingsActivity.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.renderscript.Float2;
import io.tidepool.api.APIClient;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MAX;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_TARGET_MIN;
import static de.dorianscholz.openlibre.OpenLibre.GLUCOSE_UNIT_IS_MMOL;
import static de.dorianscholz.openlibre.OpenLibre.refreshApplicationSettings;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMGDLToMMOL;
import static de.dorianscholz.openlibre.model.GlucoseData.convertGlucoseMMOLToMGDL;

package de.dorianscholz.openlibre.ui;




public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

        // Display the fragment as the main content.
        getFragmentManager().beginTransaction()
                .replace(android.R.id.content, new SettingsFragment())
                .commit();
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
        // when username or server changes update the key for the sync progress
        if (key.equals("pref_tidepool_username") || key.equals("pref_tidepool_server")) {
            // trim spaces off of email address
            String tidepoolUsername = settings.getString("pref_tidepool_username", "").trim();
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("pref_tidepool_username", tidepoolUsername);
            editor.apply();

            String tidepoolServer = settings.getString("pref_tidepool_server", APIClient.PRODUCTION);

            SharedPreferences.Editor preferencesEditor = getApplicationContext().getSharedPreferences("tidepool", MODE_PRIVATE).edit();
            preferencesEditor.putString("upload_timestamp_key", "upload_timestamp_for_" + tidepoolUsername.toLowerCase() + "_at_" + tidepoolServer);
            preferencesEditor.apply();

        }

        if (key.equals("pref_glucose_unit_is_mmol")) {
            GLUCOSE_UNIT_IS_MMOL = settings.getBoolean("pref_glucose_unit_is_mmol", GLUCOSE_UNIT_IS_MMOL);
            SharedPreferences.Editor editor = settings.edit();
            if (GLUCOSE_UNIT_IS_MMOL) {
                editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MIN)));
                editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMGDLToMMOL(GLUCOSE_TARGET_MAX)));