package com.genlot.ninglottery.toolkit;

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

/**
 * 共享参数的工具类
 */
public class SharedUtil {

    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;

    public static void init(Context context){
        sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }

    public static void putString(String key, String value){
        editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static void putInt(String key, int value){
        editor = sharedPreferences.edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public static void putLong(String key, long value){
        editor = sharedPreferences.edit();
        editor.putLong(key, value);
        editor.apply();
    }

    public static void putBoolean(String key, boolean value) {
        editor = sharedPreferences.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static String getString(String key, String defValue){
        return sharedPreferences.getString(key, defValue);
    }

    public static int getInt(String key, int defValue){
        return sharedPreferences.getInt(key, defValue);
    }
    public static long getLong(String key, long defValue){
        return sharedPreferences.getLong(key, defValue);
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return sharedPreferences.getBoolean(key, defValue);
    }
}
