// Path: SimpleWeatherForecast/src/main/java/fr/tvbarthel/apps/simpleweatherforcast/utils/SharedPreferenceUtils.java
// public class SharedPreferenceUtils {
// 
//     public static final long REFRESH_TIME_AUTO = 1000 * 60 * 60 * 2; // 2 hours in millis.
//     public static final long REFRESH_TIME_MANUAL = 1000 * 60 * 10; // 10 minutes.
// 
//     public static String KEY_LAST_UPDATE = "SharedPreferenceUtils.Key.LastUpdate";
//     public static String KEY_LAST_KNOWN_JSON_WEATHER = "SharedPreferenceUtils.Key.LastKnownJsonWeather";
//     public static String KEY_TEMPERATURE_UNIT_SYMBOL = "SharedPreferenceUtils.Key.TemperatureUnitSymbol";
// 
//     private static SharedPreferences getDefaultSharedPreferences(final Context context) {
//         return PreferenceManager.getDefaultSharedPreferences(context);
//     }
// 
//     public static String getLastKnownWeather(final Context context) {
//         return getDefaultSharedPreferences(context).getString(KEY_LAST_KNOWN_JSON_WEATHER, null);
//     }
// 
//     public static long getLastUpdate(final Context context) {
//         return getDefaultSharedPreferences(context).getLong(KEY_LAST_UPDATE, 0);
//     }
// 
//     public static void storeWeather(final Context context, final String jsonWeather) {
//         final Editor editor = getDefaultSharedPreferences(context).edit();
//         editor.putString(KEY_LAST_KNOWN_JSON_WEATHER, jsonWeather);
//         editor.putLong(KEY_LAST_UPDATE, System.currentTimeMillis());
//         editor.apply();
//     }
// 
//     public static void storeTemperatureUnitSymbol(final Context context, final String unitSymbol) {
//         final Editor editor = getDefaultSharedPreferences(context).edit();
//         editor.putString(KEY_TEMPERATURE_UNIT_SYMBOL, unitSymbol);
//         editor.apply();
//     }
// 
//     public static String getTemperatureUnitSymbol(final Context context) {
//         return getDefaultSharedPreferences(context).getString(KEY_TEMPERATURE_UNIT_SYMBOL,
//                 context.getString(R.string.temperature_unit_celsius_symbol));
//     }
// 
//     public static void registerOnSharedPreferenceChangeListener(final Context context, SharedPreferences.OnSharedPreferenceChangeListener listener) {
//         getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(listener);
//     }
// 
//     public static void unregisterOnSharedPreferenceChangeListener(final Context context, SharedPreferences.OnSharedPreferenceChangeListener listener) {
//         getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(listener);
//     }
// 
//     public static boolean isWeatherOutdated(Context context, boolean isManualRefresh) {
//         final long refreshTimeInMillis = isManualRefresh ? REFRESH_TIME_MANUAL : REFRESH_TIME_AUTO;
//         final long lastUpdate = SharedPreferenceUtils.getLastUpdate(context);
//         return System.currentTimeMillis() - lastUpdate > refreshTimeInMillis;
//     }
// 
// }


import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.ArrayAdapter;
import fr.tvbarthel.apps.simpleweatherforcast.R;
import fr.tvbarthel.apps.simpleweatherforcast.utils.SharedPreferenceUtils;
package fr.tvbarthel.apps.simpleweatherforcast.fragments;




public class TemperatureUnitPickerDialogFragment extends DialogFragment {

    private static final String BUNDLE_TEMPERATURE_UNIT_NAMES = "BundleTemperatureUnitNames";
    private static final String BUNDLE_TEMPERATURE_UNIT_SYMBOLS = "BundleTemperatureUnitSymbols";

    public static TemperatureUnitPickerDialogFragment newInstance(String[] temperatureUnitNames, String[] temperatureUnitSymbols) {
        final TemperatureUnitPickerDialogFragment instance = new TemperatureUnitPickerDialogFragment();
        final Bundle arguments = new Bundle();
        arguments.putStringArray(BUNDLE_TEMPERATURE_UNIT_NAMES, temperatureUnitNames);
        arguments.putStringArray(BUNDLE_TEMPERATURE_UNIT_SYMBOLS, temperatureUnitSymbols);
        instance.setArguments(arguments);
        return instance;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Bundle arguments = getArguments();

        final String[] temperatureUnitNames = arguments.getStringArray(BUNDLE_TEMPERATURE_UNIT_NAMES);
        final String[] temperatureUnitSymbols = arguments.getStringArray(BUNDLE_TEMPERATURE_UNIT_SYMBOLS);

        final ArrayAdapter<String> temperatureUnitNameAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_expandable_list_item_1, temperatureUnitNames);

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.dialog_temperature_unit_picker_title);
        builder.setAdapter(temperatureUnitNameAdapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
// Path: SimpleWeatherForecast/src/main/java/fr/tvbarthel/apps/simpleweatherforcast/utils/SharedPreferenceUtils.java
// public class SharedPreferenceUtils {
// 
//     public static final long REFRESH_TIME_AUTO = 1000 * 60 * 60 * 2; // 2 hours in millis.
//     public static final long REFRESH_TIME_MANUAL = 1000 * 60 * 10; // 10 minutes.
// 
//     public static String KEY_LAST_UPDATE = "SharedPreferenceUtils.Key.LastUpdate";
//     public static String KEY_LAST_KNOWN_JSON_WEATHER = "SharedPreferenceUtils.Key.LastKnownJsonWeather";
//     public static String KEY_TEMPERATURE_UNIT_SYMBOL = "SharedPreferenceUtils.Key.TemperatureUnitSymbol";
// 
//     private static SharedPreferences getDefaultSharedPreferences(final Context context) {
//         return PreferenceManager.getDefaultSharedPreferences(context);
//     }
// 
//     public static String getLastKnownWeather(final Context context) {
//         return getDefaultSharedPreferences(context).getString(KEY_LAST_KNOWN_JSON_WEATHER, null);
//     }
// 
//     public static long getLastUpdate(final Context context) {
//         return getDefaultSharedPreferences(context).getLong(KEY_LAST_UPDATE, 0);
//     }
// 
//     public static void storeWeather(final Context context, final String jsonWeather) {
//         final Editor editor = getDefaultSharedPreferences(context).edit();
//         editor.putString(KEY_LAST_KNOWN_JSON_WEATHER, jsonWeather);
//         editor.putLong(KEY_LAST_UPDATE, System.currentTimeMillis());
//         editor.apply();
//     }
// 
//     public static void storeTemperatureUnitSymbol(final Context context, final String unitSymbol) {
//         final Editor editor = getDefaultSharedPreferences(context).edit();
//         editor.putString(KEY_TEMPERATURE_UNIT_SYMBOL, unitSymbol);
//         editor.apply();
//     }
// 
//     public static String getTemperatureUnitSymbol(final Context context) {
//         return getDefaultSharedPreferences(context).getString(KEY_TEMPERATURE_UNIT_SYMBOL,
//                 context.getString(R.string.temperature_unit_celsius_symbol));
//     }
// 
//     public static void registerOnSharedPreferenceChangeListener(final Context context, SharedPreferences.OnSharedPreferenceChangeListener listener) {
//         getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(listener);
//     }
// 
//     public static void unregisterOnSharedPreferenceChangeListener(final Context context, SharedPreferences.OnSharedPreferenceChangeListener listener) {
//         getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(listener);
//     }
// 
//     public static boolean isWeatherOutdated(Context context, boolean isManualRefresh) {
//         final long refreshTimeInMillis = isManualRefresh ? REFRESH_TIME_MANUAL : REFRESH_TIME_AUTO;
//         final long lastUpdate = SharedPreferenceUtils.getLastUpdate(context);
//         return System.currentTimeMillis() - lastUpdate > refreshTimeInMillis;
//     }
// 
// }


// Path: SimpleWeatherForecast/src/main/java/fr/tvbarthel/apps/simpleweatherforcast/fragments/TemperatureUnitPickerDialogFragment.java
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.ArrayAdapter;
import fr.tvbarthel.apps.simpleweatherforcast.R;
import fr.tvbarthel.apps.simpleweatherforcast.utils.SharedPreferenceUtils;

package fr.tvbarthel.apps.simpleweatherforcast.fragments;




public class TemperatureUnitPickerDialogFragment extends DialogFragment {

    private static final String BUNDLE_TEMPERATURE_UNIT_NAMES = "BundleTemperatureUnitNames";
    private static final String BUNDLE_TEMPERATURE_UNIT_SYMBOLS = "BundleTemperatureUnitSymbols";

    public static TemperatureUnitPickerDialogFragment newInstance(String[] temperatureUnitNames, String[] temperatureUnitSymbols) {
        final TemperatureUnitPickerDialogFragment instance = new TemperatureUnitPickerDialogFragment();
        final Bundle arguments = new Bundle();
        arguments.putStringArray(BUNDLE_TEMPERATURE_UNIT_NAMES, temperatureUnitNames);
        arguments.putStringArray(BUNDLE_TEMPERATURE_UNIT_SYMBOLS, temperatureUnitSymbols);
        instance.setArguments(arguments);
        return instance;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Bundle arguments = getArguments();

        final String[] temperatureUnitNames = arguments.getStringArray(BUNDLE_TEMPERATURE_UNIT_NAMES);
        final String[] temperatureUnitSymbols = arguments.getStringArray(BUNDLE_TEMPERATURE_UNIT_SYMBOLS);

        final ArrayAdapter<String> temperatureUnitNameAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_expandable_list_item_1, temperatureUnitNames);

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.dialog_temperature_unit_picker_title);
        builder.setAdapter(temperatureUnitNameAdapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                SharedPreferenceUtils.storeTemperatureUnitSymbol(getActivity(), temperatureUnitSymbols[which]);