Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

239 wiersze
8.5 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. List contactList = [];
  57. bool isInChina = false;
  58. int homemainIndex = 0;
  59. String currentCity = '';
  60. String deviceLanguageCode;
  61. Map<String, dynamic> toJson() {
  62. Map<String, dynamic> json = new Map<String, dynamic>();
  63. json['language'] = language;
  64. json['deviceLanguage'] = deviceLanguage;
  65. json['latitude'] = latitude;
  66. json['longitude'] = longitude;
  67. json['basicInfo'] = jsonEncode(basicInfo).toString();
  68. json['totalMoney'] = totalMoney;
  69. json['bindCardId'] = bindCardId;
  70. json['isCanProgram'] = isCanProgram;
  71. json['picNum'] = picNum;
  72. json['incomeMoney'] = incomeMoney;
  73. json['frozenMoney'] = frozenMoney;
  74. json['isFirstTip'] = isFirstTip;
  75. json['mobile'] = mobile;
  76. json['freeNum'] = freeNum;
  77. json['usedNum'] = usedNum;
  78. json['haveReview'] = haveReview;
  79. json['memberEndTime'] = memberEndTime;
  80. json['isBannerStatus'] = isBannerStatus;
  81. json['agentId'] = agentId;
  82. json['redPacketSW'] = redPacketSW;
  83. json['giftSwitch'] = giftSwitch;
  84. json['bannerZF'] = bannerZF;
  85. json['sign'] = sign;
  86. json['groupQRCode'] = groupQRCode;
  87. json['addFdDistanceSwitch'] = addFdDistanceSwitch;
  88. json['inviteCodePrice'] = inviteCodePrice;
  89. json['accountPrice'] = accountPrice;
  90. json['redPhotoPrice'] = redPhotoPrice;
  91. json['addProgramPrice'] = addProgramPrice;
  92. json['keyboardHeight'] = keyboardHeight;
  93. json['privatyMsgPushSwitch'] = privatyMsgPushSwitch;
  94. json['needRequestPushPermission'] = needRequestPushPermission;
  95. json['newDateSwitch'] = newDateSwitch;
  96. json['applyCheckSwitch'] = applyCheckSwitch;
  97. json['acceptCheckSwitch'] = acceptCheckSwitch;
  98. json['checkPhotoSwitch'] = checkPhotoSwitch;
  99. json['codeSucessSwitch'] = codeSucessSwitch;
  100. json['stationOpenSwitch'] = stationOpenSwitch;
  101. json['myProgramOpenSwitch'] = myProgramOpenSwitch;
  102. json['nearbyOpenSwitch'] = nearbyOpenSwitch;
  103. json['isInChina'] = isInChina;
  104. return json;
  105. }
  106. fromLocalJson(Map<String, dynamic> data) {
  107. language = data['language'];
  108. deviceLanguage = data['deviceLanguage'];
  109. latitude = data['latitude'];
  110. longitude = data['longitude'];
  111. basicInfo = UserInfo.fromLocalJson(json.decode(data['basicInfo']));
  112. totalMoney = data['totalMoney'];
  113. bindCardId = data['bindCardId'];
  114. isCanProgram = data['isCanProgram'];
  115. picNum = data['picNum'];
  116. incomeMoney = data['incomeMoney'];
  117. frozenMoney = data['frozenMoney'];
  118. isFirstTip = data['isFirstTip'];
  119. mobile = data['mobile'];
  120. freeNum = data['freeNum'];
  121. usedNum = data['usedNum'];
  122. haveReview = data['haveReview'];
  123. memberEndTime = data['memberEndTime'];
  124. isBannerStatus = data['isBannerStatus'];
  125. agentId = data['agentId'];
  126. redPacketSW = data['redPacketSW'];
  127. giftSwitch = data['giftSwitch'];
  128. bannerZF = data['bannerZF'];
  129. sign = data['sign'];
  130. groupQRCode = data['groupQRCode'];
  131. addFdDistanceSwitch = data['addFdDistanceSwitch'];
  132. inviteCodePrice = data['inviteCodePrice'];
  133. accountPrice = data['accountPrice'];
  134. redPhotoPrice = data['redPhotoPrice'];
  135. addProgramPrice = data['addProgramPrice'];
  136. keyboardHeight = data['keyboardHeight'];
  137. privatyMsgPushSwitch = data['privatyMsgPushSwitch'];
  138. needRequestPushPermission = data['needRequestPushPermission'];
  139. newDateSwitch = data['newDateSwitch'];
  140. applyCheckSwitch = data['applyCheckSwitch'];
  141. acceptCheckSwitch = data['acceptCheckSwitch'];
  142. checkPhotoSwitch = data['checkPhotoSwitch'];
  143. codeSucessSwitch = data['codeSucessSwitch'];
  144. stationOpenSwitch = data['stationOpenSwitch'];
  145. myProgramOpenSwitch = data['myProgramOpenSwitch'];
  146. nearbyOpenSwitch = data['nearbyOpenSwitch'];
  147. isInChina = data['isInChina'];
  148. }
  149. bool isMan() {
  150. return UserData().basicInfo.sex == 1;
  151. }
  152. setKeyboardHeight(double newHeight) async {
  153. SharedPreferences prefs = await SharedPreferences.getInstance();
  154. var oldHeight = prefs.getDouble(Constants.KeyboardHeight);
  155. if (oldHeight != newHeight) {
  156. prefs.setDouble(Constants.KeyboardHeight, newHeight);
  157. }
  158. }
  159. getValidHCoin() {
  160. return incomeMoney - frozenMoney;
  161. }
  162. bool get isSuperVip {
  163. return basicInfo.isMember == 2;
  164. }
  165. bool get isVip {
  166. return basicInfo.isMember > 0;
  167. }
  168. int getSessionId(int friendId) {
  169. var myId = basicInfo.userId;
  170. var idStr = myId > friendId
  171. ? friendId.toString() + myId.toString()
  172. : myId.toString() + friendId.toString();
  173. return Crc32Zlib().convert(utf8.encode(idStr));
  174. }
  175. reset() {
  176. basicInfo = new UserInfo();
  177. bindCardId = '';
  178. isCanProgram = true; //用户能否发约会节目
  179. picNum = 0; //用户相册的数量
  180. incomeMoney = 0; //用户收入金额
  181. frozenMoney = 0;
  182. isFirstTip = false; //第一次进来提示完善资料
  183. mobile = 0; //是否绑定手机号
  184. freeNum = 0; //免费次数
  185. usedNum = 0; //使用的次数
  186. haveReview = false; //有照片在审核
  187. memberEndTime = '';
  188. agentId = 0;
  189. isBannerStatus = false;
  190. homemainIndex = 0;
  191. }
  192. getCurrentPosition({callback}) async {
  193. //使用高德定位
  194. var loc = await AMapLocationClient.getLocation(false);
  195. if (loc != null && loc.latitude != null && loc.longitude != null) {
  196. UserData().latitude = loc.latitude;
  197. UserData().longitude = loc.longitude;
  198. SharedPreferences prefs = await SharedPreferences.getInstance();
  199. await prefs.setDouble(Constants.Latitude, UserData().latitude);
  200. await prefs.setDouble(Constants.Longitude, UserData().longitude);
  201. HttpUtil().getAddress(loc.longitude, loc.latitude);
  202. //HttpUtil().getAddress(106.600798525456, 10.7517368433358);
  203. if (callback != null) callback(loc);
  204. }
  205. }
  206. getCurrentCityKey() {
  207. if (UserData().basicInfo.meetPlace == null ||
  208. UserData().basicInfo.meetPlace == "") return 'HoChiMinhCIty';
  209. var list = UserData().basicInfo.meetPlace.split('-');
  210. if (list.length == 2) {
  211. return list[1];
  212. } else {
  213. return 'HoChiMinhCIty';
  214. }
  215. }
  216. }