package com.itant.shiwushu.manager;

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

import com.itant.shiwushu.LAFApplication;

/**
 * Created by Jason on 2018/9/18.
 */

public class ThemeManager {
    public static final String NAME_THEME = "file_theme";
    // 主题
    public static final String KEY_THEME_MODE = "theme_mode";
    public static final int THEME_MODE_DEFAULT = 0;
    public static final int THEME_MODE_RED = 1;
    public static final int THEME_MODE_BLUE = 2;

    private static ThemeManager manager;
    private SharedPreferences themePreference;
    private ThemeManager() {
        themePreference = LAFApplication.instance.getSharedPreferences(NAME_THEME, Context.MODE_PRIVATE);
    }

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

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

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

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

    public int getInt(String key, int defaultValue) {
        if (UserManager.getInstance().getUser() == null) {
            return defaultValue;
        }
        return themePreference.getInt(key + UserManager.getInstance().getUser().getUserId(), defaultValue);
    }

    public void putInt(String key, int value) {
        if (UserManager.getInstance().getUser() != null) {
            themePreference.edit().putInt(key + UserManager.getInstance().getUser().getUserId(), value).commit();
        }
    }

    public void clear() {
        SharedPreferences.Editor editor = themePreference.edit();
        editor.clear();
        editor.commit();
    }
}
