package com.example.patrice.rerservation01;

import android.content.Context;
import android.content.SharedPreferences;

class sharedPreference
{

    public static final String PREFS_NAME = "AOP_PREFS";
    public static final String PREFS_KEY = "AOP_PREFS_String";

    public sharedPreference()
    {
        super();
    }


    public boolean exists(Context context, String KEY)
    {
        SharedPreferences settings;
        SharedPreferences.Editor editor;

        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); //1
        boolean result = settings.contains(KEY);

        return result;
    }


    public void save(Context context, String KEY, String valeur)
    {
        SharedPreferences settings;
        SharedPreferences.Editor editor;

        //settings = PreferenceManager.getDefaultSharedPreferences(context);
        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); //1
        editor = settings.edit(); //2

        //editor.putString(PREFS_KEY, text); //3
        editor.putString(KEY, valeur); //3

        editor.commit(); //4
    }

    public String getValue(Context context, String KEY)
    {
        SharedPreferences settings;
        String valeur;

        //settings = PreferenceManager.getDefaultSharedPreferences(context);
        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        //text = settings.getString(PREFS_KEY, null);
        valeur = settings.getString(KEY, null);

        return valeur;
    }

    public void clearSharedPreference(Context context)
    {
        SharedPreferences settings;
        SharedPreferences.Editor editor;

        //settings = PreferenceManager.getDefaultSharedPreferences(context);
        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        editor = settings.edit();

        editor.clear();
        editor.commit();
    }

    public void removeValue(Context context)
    {
        SharedPreferences settings;
        SharedPreferences.Editor editor;

        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        editor = settings.edit();

        editor.remove(PREFS_KEY);
        editor.commit();
    }
}