package com.baoshi.swms.util;

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

import com.baoshi.swms.App;

/**
 * 全局存储器
 *
 * @author Zhendong Zhou
 * @date   2021/12/3 15:42
 */
public class GlobalStorage {
    public static String MODEL = "Global";
    private static SharedPreferences share;
    private static GlobalStorage storage;

    public static GlobalStorage getGlobalStorage() {
        if (storage==null) {
            share = App.getAppContext().getSharedPreferences(MODEL,Context.MODE_PRIVATE);
            storage = new GlobalStorage();
        }
        return storage;
    }
    public GlobalStorage(){
    }
    public GlobalStorage(String key){
        MODEL = key;
        share = App.getAppContext().getSharedPreferences(MODEL,Context.MODE_PRIVATE);
    }

    //存数据
    public void put(String key, String val) {
        SharedPreferences.Editor editor= share.edit();
        editor.putString(key,val);
        editor.commit();
    }
    //读数据
    public String get(String key) {
        return share.getString(key, null);
    }

    public void remove(String key)
    {
        SharedPreferences.Editor editor= share.edit();
        editor.remove(key);
        editor.commit();
    }
}
