content: package barreto.alessandro.feedlist.util;
  
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.preference.PreferenceManager;
  
  /**
   * Created by Alessandro on 04/03/2017.
   */
  
  public class SharedPrefsUtils {
  
      /**
       * Helper method to retrieve a boolean value from {@link SharedPreferences}.
       *
       * @param context a {@link Context} object.
       * @param key
       * @param defaultValue A default to return if the value could not be read.
       * @return The value from shared preferences, or the provided default.
       */
      public static boolean getBooleanPreference(Context context, String key, boolean defaultValue) {
          boolean value = defaultValue;
          SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
          if (preferences != null) {
              value = preferences.getBoolean(key, defaultValue);
          }
          return value;
      }
  
      /**
       * Helper method to write a boolean value to {@link SharedPreferences}.
       *
       * @param context a {@link Context} object.
       * @param key
       * @param value
       * @return true if the new value was successfully written to persistent storage.
       */
      public static boolean setBooleanPreference(Context context, String key, boolean value) {
          SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
          if (preferences != null) {
              SharedPreferences.Editor editor = preferences.edit();
              editor.putBoolean(key, value);
              return editor.commit();
          }
          return false;
      }
  
  }
  