Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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