Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

240 lines
8.6 KiB

  1. import 'dart:convert';
  2. import 'package:amap_location/amap_location.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/utils/HttpUtil.dart';
  5. import 'package:crclib/crclib.dart';
  6. import 'package:shared_preferences/shared_preferences.dart';
  7. import '../models/UserInfo.dart';
  8. class UserData {
  9. //私有构造函数
  10. UserData._internal();
  11. //保存单例
  12. static UserData _singleton = new UserData._internal();
  13. //工厂构造函数
  14. factory UserData() => _singleton;
  15. int language = 0;
  16. int deviceLanguage = 0;
  17. double latitude = 10.7517368433358;
  18. double longitude = 106.600798525456;
  19. UserInfo basicInfo = new UserInfo();
  20. int totalMoney = 0; //用户总金额
  21. String bindCardId = '';
  22. bool isCanProgram = true; //用户能否发约会节目
  23. int picNum = 0; //用户相册的数量
  24. int incomeMoney = 0; //用户收入金额
  25. int frozenMoney = 0; //用户冻结金额
  26. bool isFirstTip = false; //第一次进来提示完善资料
  27. int mobile = 0; //是否绑定手机号
  28. int freeNum = 0; //免费次数
  29. int usedNum = 0; //使用的次数
  30. bool haveReview = false; //有照片在审核
  31. String memberEndTime = ''; //会员到期时间
  32. bool hasLocationPermission = false; //是否有定位权限
  33. bool isBannerStatus = false; //是否支付状态
  34. int agentId = 0; //代理id
  35. int redPacketSW = 0; //红包开关
  36. int giftSwitch = 0; //打赏礼物开关
  37. int bannerZF = 0; //苹果内购开关
  38. int sign = 0; //签到开关
  39. int groupQRCode = 0; //群二维码开关
  40. int addFdDistanceSwitch = 0; //二维码加好友距离判断开关
  41. int inviteCodePrice = 0; //绑定邀请码奖励
  42. int accountPrice = 0; //解锁账号金额
  43. int redPhotoPrice = 0; //红包照片金额
  44. int addProgramPrice = 120; //发布节目金额
  45. double keyboardHeight = 0; //缓存键盘高度
  46. bool privatyMsgPushSwitch = true; //私人消息推送开关
  47. bool needRequestPushPermission = false; //是否需要推送权限
  48. bool newDateSwitch = false; //有新约会提醒开关
  49. bool applyCheckSwitch = false; //查看资料提醒开关
  50. bool acceptCheckSwitch = false; //通过查看资料提醒开关
  51. bool checkPhotoSwitch = false; //查看红包照片提醒开关
  52. bool codeSucessSwitch = false; //邀请码申请成功提醒开关
  53. bool stationOpenSwitch = true; //开启电台开关
  54. bool myProgramOpenSwitch = true; //我的节目开关
  55. bool nearbyOpenSwitch = true; //附近的人开关
  56. bool isTranslateUser = false ;
  57. List contactList = [];
  58. bool isInChina = false;
  59. int homemainIndex = 0;
  60. String currentCity = '';
  61. String deviceLanguageCode;
  62. Map<String, dynamic> toJson() {
  63. Map<String, dynamic> json = new Map<String, dynamic>();
  64. json['language'] = language;
  65. json['deviceLanguage'] = deviceLanguage;
  66. json['latitude'] = latitude;
  67. json['longitude'] = longitude;
  68. json['basicInfo'] = jsonEncode(basicInfo).toString();
  69. json['totalMoney'] = totalMoney;
  70. json['bindCardId'] = bindCardId;
  71. json['isCanProgram'] = isCanProgram;
  72. json['picNum'] = picNum;
  73. json['incomeMoney'] = incomeMoney;
  74. json['frozenMoney'] = frozenMoney;
  75. json['isFirstTip'] = isFirstTip;
  76. json['mobile'] = mobile;
  77. json['freeNum'] = freeNum;
  78. json['usedNum'] = usedNum;
  79. json['haveReview'] = haveReview;
  80. json['memberEndTime'] = memberEndTime;
  81. json['isBannerStatus'] = isBannerStatus;
  82. json['agentId'] = agentId;
  83. json['redPacketSW'] = redPacketSW;
  84. json['giftSwitch'] = giftSwitch;
  85. json['bannerZF'] = bannerZF;
  86. json['sign'] = sign;
  87. json['groupQRCode'] = groupQRCode;
  88. json['addFdDistanceSwitch'] = addFdDistanceSwitch;
  89. json['inviteCodePrice'] = inviteCodePrice;
  90. json['accountPrice'] = accountPrice;
  91. json['redPhotoPrice'] = redPhotoPrice;
  92. json['addProgramPrice'] = addProgramPrice;
  93. json['keyboardHeight'] = keyboardHeight;
  94. json['privatyMsgPushSwitch'] = privatyMsgPushSwitch;
  95. json['needRequestPushPermission'] = needRequestPushPermission;
  96. json['newDateSwitch'] = newDateSwitch;
  97. json['applyCheckSwitch'] = applyCheckSwitch;
  98. json['acceptCheckSwitch'] = acceptCheckSwitch;
  99. json['checkPhotoSwitch'] = checkPhotoSwitch;
  100. json['codeSucessSwitch'] = codeSucessSwitch;
  101. json['stationOpenSwitch'] = stationOpenSwitch;
  102. json['myProgramOpenSwitch'] = myProgramOpenSwitch;
  103. json['nearbyOpenSwitch'] = nearbyOpenSwitch;
  104. json['isInChina'] = isInChina;
  105. return json;
  106. }
  107. fromLocalJson(Map<String, dynamic> data) {
  108. language = data['language'];
  109. deviceLanguage = data['deviceLanguage'];
  110. latitude = data['latitude'];
  111. longitude = data['longitude'];
  112. basicInfo = UserInfo.fromLocalJson(json.decode(data['basicInfo']));
  113. totalMoney = data['totalMoney'];
  114. bindCardId = data['bindCardId'];
  115. isCanProgram = data['isCanProgram'];
  116. picNum = data['picNum'];
  117. incomeMoney = data['incomeMoney'];
  118. frozenMoney = data['frozenMoney'];
  119. isFirstTip = data['isFirstTip'];
  120. mobile = data['mobile'];
  121. freeNum = data['freeNum'];
  122. usedNum = data['usedNum'];
  123. haveReview = data['haveReview'];
  124. memberEndTime = data['memberEndTime'];
  125. isBannerStatus = data['isBannerStatus'];
  126. agentId = data['agentId'];
  127. redPacketSW = data['redPacketSW'];
  128. giftSwitch = data['giftSwitch'];
  129. bannerZF = data['bannerZF'];
  130. sign = data['sign'];
  131. groupQRCode = data['groupQRCode'];
  132. addFdDistanceSwitch = data['addFdDistanceSwitch'];
  133. inviteCodePrice = data['inviteCodePrice'];
  134. accountPrice = data['accountPrice'];
  135. redPhotoPrice = data['redPhotoPrice'];
  136. addProgramPrice = data['addProgramPrice'];
  137. keyboardHeight = data['keyboardHeight'];
  138. privatyMsgPushSwitch = data['privatyMsgPushSwitch'];
  139. needRequestPushPermission = data['needRequestPushPermission'];
  140. newDateSwitch = data['newDateSwitch'];
  141. applyCheckSwitch = data['applyCheckSwitch'];
  142. acceptCheckSwitch = data['acceptCheckSwitch'];
  143. checkPhotoSwitch = data['checkPhotoSwitch'];
  144. codeSucessSwitch = data['codeSucessSwitch'];
  145. stationOpenSwitch = data['stationOpenSwitch'];
  146. myProgramOpenSwitch = data['myProgramOpenSwitch'];
  147. nearbyOpenSwitch = data['nearbyOpenSwitch'];
  148. isInChina = data['isInChina'];
  149. }
  150. bool isMan() {
  151. return UserData().basicInfo.sex == 1;
  152. }
  153. setKeyboardHeight(double newHeight) async {
  154. SharedPreferences prefs = await SharedPreferences.getInstance();
  155. var oldHeight = prefs.getDouble(Constants.KeyboardHeight);
  156. if (oldHeight != newHeight) {
  157. prefs.setDouble(Constants.KeyboardHeight, newHeight);
  158. }
  159. }
  160. getValidHCoin() {
  161. return incomeMoney - frozenMoney;
  162. }
  163. bool get isSuperVip {
  164. return basicInfo.isMember == 2;
  165. }
  166. bool get isVip {
  167. return basicInfo.isMember > 0;
  168. }
  169. int getSessionId(int friendId) {
  170. var myId = basicInfo.userId;
  171. var idStr = myId > friendId
  172. ? friendId.toString() + myId.toString()
  173. : myId.toString() + friendId.toString();
  174. return Crc32Zlib().convert(utf8.encode(idStr));
  175. }
  176. reset() {
  177. basicInfo = new UserInfo();
  178. bindCardId = '';
  179. isCanProgram = true; //用户能否发约会节目
  180. picNum = 0; //用户相册的数量
  181. incomeMoney = 0; //用户收入金额
  182. frozenMoney = 0;
  183. isFirstTip = false; //第一次进来提示完善资料
  184. mobile = 0; //是否绑定手机号
  185. freeNum = 0; //免费次数
  186. usedNum = 0; //使用的次数
  187. haveReview = false; //有照片在审核
  188. memberEndTime = '';
  189. agentId = 0;
  190. isBannerStatus = false;
  191. homemainIndex = 0;
  192. }
  193. getCurrentPosition({callback}) async {
  194. //使用高德定位
  195. var loc = await AMapLocationClient.getLocation(false);
  196. if (loc != null && loc.latitude != null && loc.longitude != null) {
  197. UserData().latitude = loc.latitude;
  198. UserData().longitude = loc.longitude;
  199. SharedPreferences prefs = await SharedPreferences.getInstance();
  200. await prefs.setDouble(Constants.Latitude, UserData().latitude);
  201. await prefs.setDouble(Constants.Longitude, UserData().longitude);
  202. HttpUtil().getAddress(loc.longitude, loc.latitude);
  203. //HttpUtil().getAddress(106.600798525456, 10.7517368433358);
  204. if (callback != null) callback(loc);
  205. }
  206. }
  207. getCurrentCityKey() {
  208. if (UserData().basicInfo.meetPlace == null ||
  209. UserData().basicInfo.meetPlace == "") return 'HoChiMinhCIty';
  210. var list = UserData().basicInfo.meetPlace.split('-');
  211. if (list.length == 2) {
  212. return list[1];
  213. } else {
  214. return 'HoChiMinhCIty';
  215. }
  216. }
  217. }