/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.common.gcm.support;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * <pre>
 * 1. ClassName :   BaseDefaultSharedPreferences
 * 2. FileName  :   BaseDefaultSharedPreferences.java
 * 3. Package   :   com.ntels.kneet.v3.common.gcm.support
 * 4. Date      :   2016-12-05
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class BaseDefaultSharedPreferences {

    private SharedPreferences mSharedPreferences;

    /**
     * 생성자.
     *
     * @param $context 컨텍스트
     */
    protected BaseDefaultSharedPreferences(Context $context) {
        super();
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences($context);
    }

	/*
     * protected void clear() {
	 * SharedPreferences.Editor editor = mSharedPreferences.edit();
	 * editor.clear();
	 * editor.commit();
	 * }
	 */

    /**
     * SharedPreferences remove item.
     *
     * @param $key Item key
     */
    protected void remove(String $key) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.remove($key);
        editor.commit();
    }

    /**
     * SharedPreferences insert string item.
     *
     * @param $key   Item key
     * @param $value Item value
     */
    protected void put(String $key, String $value) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString($key, $value);
        editor.commit();
    }

    /**
     * SharedPreferences get string item.
     *
     * @param $key Item key
     * @return Item value
     */
    protected String get(String $key) {
        return mSharedPreferences.getString($key, null);
    }

    /**
     * SharedPreferences insert boolean item.
     *
     * @param $key   Item key
     * @param $value Item value
     */
    protected void put(String $key, boolean $value) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putBoolean($key, $value);
        editor.commit();
    }

    /**
     * SharedPreferences get boolean item.
     *
     * @param $key     Item key
     * @param $default Item default value
     * @return Item value
     */
    protected boolean get(String $key, boolean $default) {
        return mSharedPreferences.getBoolean($key, $default);
    }

    /**
     * SharedPreferences insert int item.
     *
     * @param $key   Item key
     * @param $value Item value
     */
    protected void put(String $key, int $value) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putInt($key, $value);
        editor.commit();
    }

    /**
     * SharedPreferences get int item.
     *
     * @param $key     Item key
     * @param $default Item default value
     * @return Item value
     */
    protected int get(String $key, int $default) {
        return mSharedPreferences.getInt($key, $default);
    }

}
