package com.itant.shiwushu.manager;

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

import com.itant.shiwushu.LAFApplication;

/**
 * Created by Jason on 2018/8/31.
 */

public class SharedPreferenceManager {
    public static final String NAME_MAIN_PREFERENCE = "temp";
    public static final String KEY_USER = "user";

    // 反馈
    public static final String KEY_FEEDBACK = "feedback";


    private static SharedPreferenceManager manager;
    private final SharedPreferences preferences;

    private SharedPreferenceManager() {
        preferences = LAFApplication.instance.getSharedPreferences(NAME_MAIN_PREFERENCE, Context.MODE_PRIVATE);
    }

    public static SharedPreferenceManager getInstance() {
        if (manager == null) {
            init();
        }
        return manager;
    }

    private static synchronized void init() {
        if (manager == null) {
            manager = new SharedPreferenceManager();
        }
    }

    public void putString(String key, String value) {
        preferences.edit().putString(key, value).commit();
    }

    public void putInt(String key, int value) {
        preferences.edit().putInt(key, value).commit();
    }

    public String getString(String key) {
        return preferences.getString(key, "");
    }

    public String getString(String key, String defaultValue) {
        return preferences.getString(key, defaultValue);
    }

    public int getInt(String key) {
        return preferences.getInt(key, 0);
    }

    public int getInt(String key, int defaultValue) {
        return preferences.getInt(key, defaultValue);
    }

    public void clear() {
        SharedPreferences.Editor editor = preferences.edit();
        editor.clear();
        editor.commit();
        // 如果是自定义的皮肤，那么就不支持重新保存了
        //ThemeManager.getInstance().putInt(ThemeManager.KEY_THEME_MODE, CommonConstant.THEME_DEFAULT);
    }
}
