package com.hdl.photovoltaic.config;
|
|
|
import android.text.TextUtils;
|
|
import com.google.gson.Gson;
|
import com.hdl.photovoltaic.HDLApp;
|
import com.hdl.photovoltaic.other.HdlFileLogic;
|
import com.hdl.photovoltaic.other.HdlLogLogic;
|
import com.hdl.photovoltaic.other.HdlResidenceLogic;
|
import com.hdl.photovoltaic.ui.bean.HouseInfoBean;
|
import com.hdl.photovoltaic.utils.LocalManageUtil;
|
import com.hdl.photovoltaic.utils.SharedPreUtils;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 用户信息类
|
*/
|
public class UserConfigManage {
|
|
|
private static UserConfigManage sUserConfigManage = null;
|
|
/**
|
* 获取当前对象
|
*
|
* @return UserConfigManage
|
*/
|
public static UserConfigManage getInstance() {
|
if (sUserConfigManage == null) {
|
sUserConfigManage = new UserConfigManage();
|
sUserConfigManage.reFresh();
|
}
|
return sUserConfigManage;
|
}
|
|
//当前账号:刷新Token用的token(不用记录什么有效期,如果刷新失败,就踢人即可)
|
private String refreshToken;
|
//账户登录成功时的时间
|
private long loginDateTime;
|
//当前登录的帐号
|
private String account;
|
//添加到Token头部的东西(不要理它,只给底层使用)
|
private String headerPrefix;
|
//登陆账号的Guid,也是账号的userId
|
private String userId;
|
//当前的住宅ID
|
private String homeId;
|
|
|
private String homeName;
|
//是否登录状态
|
private boolean isLogin;
|
//本地通讯秘钥
|
private String localSecret;
|
|
//是否是B端账号登录(true=B端)
|
private boolean isB_account;
|
|
|
//是否是用户体验账号登录
|
private boolean isUserExperience;
|
//住宅文件列表
|
public List<String> homeFilePathList = new ArrayList<>();
|
|
//判断当前时间点是否能够自动登录
|
public boolean isAutoLogin() {
|
//7天内自动登录
|
return ((System.currentTimeMillis() - loginDateTime) < (7 * 24 * 60 * 60 * 1000));
|
}
|
|
//是否同意隐私政策
|
private boolean acceiptPolicy;
|
//当前帐号的Token(这个东西不用存了)
|
private String token;
|
//远程连接的Mqtt的客户端ID
|
public String connEmqClientId;
|
//当前登录的账号是不是之前的账号
|
private boolean theSameLoginAccount;
|
|
//绑定手机号
|
private String bingPhone;
|
//绑定邮箱
|
private String bingEmail;
|
|
//温度单位(C摄氏度;F=华氏度)
|
private String temperature_unit = "℃";
|
|
//app当前的语言
|
private String currentAppLanguage;
|
|
|
/// <summary>
|
/// 注册极光ID
|
/// </summary>
|
public String registrationID;
|
/// <summary>
|
/// 添加极光ID到云端成功时返回的
|
/// </summary>
|
public String pushId;
|
|
|
public String getRegistrationID() {
|
return registrationID == null ? "" : registrationID;
|
}
|
|
public void setRegistrationID(String registrationID) {
|
this.registrationID = registrationID;
|
}
|
|
public String getPushId() {
|
return pushId == null ? "" : pushId;
|
}
|
|
public void setPushId(String pushId) {
|
this.pushId = pushId;
|
}
|
|
public String getCurrentAppLanguage() {
|
return currentAppLanguage;
|
}
|
|
public void setCurrentAppLanguage(String currentAppLanguage) {
|
this.currentAppLanguage = currentAppLanguage;
|
}
|
|
public String getTemperature_unit() {
|
return temperature_unit;
|
}
|
|
public void setTemperature_unit(String temperature_unit) {
|
this.temperature_unit = temperature_unit;
|
}
|
|
public String getBingPhone() {
|
return bingPhone == null ? "" : bingPhone;
|
}
|
|
public void setBingPhone(String bingPhone) {
|
this.bingPhone = bingPhone;
|
}
|
|
|
public String getBingEmail() {
|
return bingEmail == null ? "" : bingEmail;
|
}
|
|
public void setBingEmail(String bingEmail) {
|
this.bingEmail = bingEmail;
|
}
|
|
/**
|
* 用户名称
|
*
|
* @return -
|
*/
|
public String getUserName() {
|
|
return TextUtils.isEmpty(userName) ? account : userName;
|
}
|
|
public void setUserName(String userName) {
|
this.userName = userName;
|
}
|
|
private String userName;//用户名称
|
|
public String getRefreshToken() {
|
return refreshToken == null ? "" : refreshToken;
|
}
|
|
public void setRefreshToken(String refreshToken) {
|
this.refreshToken = refreshToken;
|
}
|
|
public long getLoginDateTime() {
|
return loginDateTime;
|
}
|
|
public void setLoginDateTime(long loginDateTime) {
|
this.loginDateTime = loginDateTime;
|
}
|
|
public String getAccount() {
|
return account == null ? "" : account;
|
}
|
|
public void setAccount(String account) {
|
this.account = account;
|
}
|
|
public String getHeaderPrefix() {
|
return headerPrefix == null ? "" : headerPrefix;
|
}
|
|
public void setHeaderPrefix(String headerPrefix) {
|
this.headerPrefix = headerPrefix;
|
}
|
|
public String getUserId() {
|
return userId == null ? "" : userId;
|
}
|
|
public void setUserId(String userId) {
|
this.userId = userId;
|
}
|
|
public String getHomeId() {
|
return homeId == null ? "" : homeId;
|
}
|
|
public void setHomeId(String homeId) {
|
this.homeId = homeId;
|
}
|
|
public String getHomeName() {
|
return homeName == null ? "" : homeName;
|
}
|
|
public void setHomeName(String homeName) {
|
this.homeName = homeName;
|
}
|
|
public boolean isAcceiptPolicy() {
|
return acceiptPolicy;
|
}
|
|
public void setAcceiptPolicy(boolean acceiptPolicy) {
|
this.acceiptPolicy = acceiptPolicy;
|
}
|
|
public String getToken() {
|
return token == null ? "" : token;
|
}
|
|
public void setToken(String token) {
|
this.token = token;
|
}
|
|
public boolean isLogin() {
|
return isLogin;
|
}
|
|
public void setLogin(boolean login) {
|
isLogin = login;
|
}
|
|
public boolean isTheSameLoginAccount() {
|
return theSameLoginAccount;
|
}
|
|
public void setTheSameLoginAccount(boolean theSameLoginAccount) {
|
this.theSameLoginAccount = theSameLoginAccount;
|
}
|
|
/**
|
* 是否是B端账号登录(true=B端)
|
*
|
* @return -
|
*/
|
public boolean isBAccount() {
|
return isB_account;
|
}
|
|
public void setBAccount(boolean b) {
|
isB_account = b;
|
}
|
|
public boolean isUserExperience() {
|
return isUserExperience;
|
}
|
|
public void setUserExperience(boolean userExperience) {
|
isUserExperience = userExperience;
|
}
|
|
public String getLocalSecret() {
|
return localSecret == null ? "" : localSecret;
|
}
|
|
public void setLocalSecret(String localSecret) {
|
this.localSecret = localSecret;
|
}
|
|
/**
|
* 当前住宅
|
*/
|
private HouseInfoBean m_Home = null;
|
|
/**
|
* 当前住宅
|
*/
|
public HouseInfoBean home() {
|
if (m_Home != null) {
|
return m_Home;
|
}
|
m_Home = HdlResidenceLogic.getInstance().getHouse(homeId);
|
if (m_Home == null) {
|
m_Home = new HouseInfoBean();
|
}
|
return m_Home;
|
}
|
|
|
/**
|
* 刷新
|
*/
|
private void reFresh() {
|
String str = HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getUserFilePath());
|
// String str =SharedPreUtils.getSharedPreferencesKey("UserConfigManage.json",HDLApp.getInstance());
|
if (!TextUtils.isEmpty(str) && str.length() > 0) {
|
//读取保存的数据
|
Gson gson = new Gson();
|
sUserConfigManage = gson.fromJson(str, UserConfigManage.class);
|
if (sUserConfigManage == null) {
|
sUserConfigManage = new UserConfigManage();
|
}
|
}
|
}
|
|
|
/**
|
* 保存
|
*/
|
public void Save() {
|
if (sUserConfigManage == null) {
|
HdlLogLogic.print("UserConfigManage保存用户信息文件失败", false);
|
return;
|
}
|
Gson gson = new Gson();
|
String json = gson.toJson(sUserConfigManage);
|
HdlFileLogic.getInstance().writeFile(HdlFileLogic.getInstance().getUserFilePath(), json);
|
// SharedPreUtils.saveMyDataInfo("UserConfigManage.json", json, HDLApp.getInstance());
|
}
|
|
/**
|
* true表示是中文
|
*
|
* @return true表示是中文
|
*/
|
public boolean isZh() {
|
return currentAppLanguage.equals(LocalManageUtil.zh);
|
}
|
|
|
}
|