package com.tcl.ah.tvcontrol.utils;

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


public class SharedPrefHelper {
    /**
     * SharedPreferences的名字
     */
    private static final String SP_FILE_NAME = "APPLICATION_SP";
    private static final String KEY_CLIENT_INVALID = "client_invalid";
    private static final String KEY_MQTT_IP = "mqtt_ip";
    private static final String KEY_MQTT_PORT = "mqtt_port";
    private static final String KEY_MQTT_USER = "mqtt_user";
    private static final String KEY_MQTT_PWD = "mqtt_pwd";
    private static final String KEY_HOTEL_ID = "hotel_id";
    private static final String KEY_HOTEL_ROOM = "hotel_room";

    private static SharedPrefHelper sharedPrefHelper = null;
    private static SharedPreferences sharedPreferences;


    public static synchronized SharedPrefHelper getInstance(Context c) {
        if (null == sharedPrefHelper) {
            synchronized (SharedPrefHelper.class) {
                if (null == sharedPrefHelper) {
                    sharedPrefHelper = new SharedPrefHelper(c);
                }
            }
        }
        return sharedPrefHelper;
    }

    private SharedPrefHelper(Context c) {
        sharedPreferences = c.getSharedPreferences(SP_FILE_NAME,
                Context.MODE_PRIVATE);
    }

    public static SharedPreferences sp(Context c) {
        return c.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
    }


    public void setKeyMqttIp(String mqttIp) {
        sharedPreferences.edit().putString(KEY_MQTT_IP, mqttIp).commit();
    }

    public String getKeyMqttIp() {
        return sharedPreferences.getString(KEY_MQTT_IP, "ip");
    }
    public void setKeyMqttPort(String mqttPort) {
        sharedPreferences.edit().putString(KEY_MQTT_PORT, mqttPort).commit();
    }

    public String getKeyMqttPort() {
        return sharedPreferences.getString(KEY_MQTT_PORT, "");
    }

    public void setKeyMqttUser(String mqttUser) {
        sharedPreferences.edit().putString(KEY_MQTT_USER, mqttUser).commit();
    }

    public String getKeyMqttUser() {
        return sharedPreferences.getString(KEY_MQTT_USER, "user");
    }

    public void setKeyMqttPwd(String mqttPwd) {
        sharedPreferences.edit().putString(KEY_MQTT_PWD, mqttPwd).commit();
    }

    public String getKeyMqttPwd() {
        return sharedPreferences.getString(KEY_MQTT_PWD, "pwd");
    }

    public void setKeyHotelId(String hotelId) {
        sharedPreferences.edit().putString(KEY_HOTEL_ID, hotelId).commit();
    }

    public String getKeyHotelId() {
        return sharedPreferences.getString(KEY_HOTEL_ID, "");
    }

    public void setKeyHotelRoom(String hotelRoom) {
        sharedPreferences.edit().putString(KEY_HOTEL_ROOM, hotelRoom).commit();
    }

    public String getKeyHotelRoom() {
        return sharedPreferences.getString(KEY_HOTEL_ROOM, "");
    }


}
