// 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;

        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)));
            } else {
                editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MIN)));
                editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MAX)));
            }
            editor.apply();
            refreshApplicationSettings(settings);
        }
        if (key.equals("pref_glucose_target_min") || key.equals("pref_glucose_target_max")) {
            refreshApplicationSettings(settings);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        PreferenceManager.getDefaultSharedPreferences(this)
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        PreferenceManager.getDefaultSharedPreferences(this)
// 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;


        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)));
            } else {
                editor.putString("pref_glucose_target_min", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MIN)));
                editor.putString("pref_glucose_target_max", Float.toString(convertGlucoseMMOLToMGDL(GLUCOSE_TARGET_MAX)));
            }
            editor.apply();
            refreshApplicationSettings(settings);
        }
        if (key.equals("pref_glucose_target_min") || key.equals("pref_glucose_target_max")) {
            refreshApplicationSettings(settings);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        PreferenceManager.getDefaultSharedPreferences(this)
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        PreferenceManager.getDefaultSharedPreferences(this)
                .unregisterOnSharedPreferenceChangeListener(this);