Hibok
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

438 satır
14 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/models/ref_name_provider.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:provider/provider.dart';
  8. class InfoType {
  9. static const int Apply = 1;
  10. static const int Evaluation = 2;
  11. static const int System = 3;
  12. static const int Radio = 4;
  13. static const int Money = 5;
  14. static const int IncomeMoney = 6;
  15. static const int MyMoney = 7;
  16. }
  17. class TitleItem {
  18. String title = '';
  19. String name = '';
  20. String value = '';
  21. TitleItem({this.title, this.name, this.value});
  22. }
  23. class RichTitle {
  24. static List<InlineSpan> getRichText(TitleItem titleItem,
  25. {titleStyle, nameStyle}) {
  26. if (nameStyle == null) {
  27. nameStyle = TextStyle(
  28. fontWeight: FontWeight.w500, color: Constants.BlackTextColor);
  29. }
  30. if (titleStyle == null) {
  31. titleStyle = TextStyle(color: Constants.GreyTextColor);
  32. }
  33. titleItem.title = titleItem.title == null ? '' : titleItem.title;
  34. List list = titleItem.title.split('/s1');
  35. titleItem.name = titleItem.name == null ? '' : titleItem.name;
  36. List<InlineSpan> child;
  37. if (list == null) {
  38. child = [
  39. TextSpan(text: titleItem.title, style: titleStyle),
  40. ];
  41. } else {
  42. child = list.length > 1
  43. ? [
  44. TextSpan(text: list[0] == '' ? '' : list[0], style: titleStyle),
  45. TextSpan(text: titleItem.name, style: nameStyle),
  46. TextSpan(text: list[1], style: titleStyle),
  47. ]
  48. : [
  49. TextSpan(text: titleItem.name, style: nameStyle),
  50. TextSpan(text: list[0], style: titleStyle),
  51. ];
  52. }
  53. return child;
  54. }
  55. static String getNormalText(TitleItem titleItem) {
  56. List list = titleItem.title.split('/s1');
  57. titleItem.name = titleItem.name == null ? '' : titleItem.name;
  58. String res = '';
  59. if (list == null) {
  60. res = titleItem.title;
  61. } else {
  62. list.length > 1
  63. ? res = (list[0] == '' ? list[0] : list[0]) + titleItem.name + list[1]
  64. : res = titleItem.name + list[0];
  65. }
  66. return res;
  67. }
  68. //申请
  69. static TitleItem _delApplyTitle(userInfo, BuildContext context) {
  70. print(userInfo);
  71. bool isMyself = userInfo['ApplyUserId'] == UserData().basicInfo.userId;
  72. String name = isMyself
  73. ? Provider.of<RefNameProvider>(context)
  74. .getRefName(userInfo['UserId'], userInfo['UserName'])
  75. : Provider.of<RefNameProvider>(context)
  76. .getRefName(userInfo['ApplyUserId'], userInfo['ApplyName']);
  77. String title = isMyself
  78. ? userInfo['Status'] == 1
  79. ? I18n.of(context).l15_days
  80. : I18n.of(context).reject_reply
  81. : I18n.of(context).view_application2;
  82. if (userInfo['Type'] == 1) {
  83. title = isMyself
  84. ? I18n.of(context).applyed_friends
  85. : I18n.of(context).apply_friends;
  86. }
  87. return TitleItem(title: title, name: name);
  88. }
  89. //评价
  90. static TitleItem _delEvaluateTitle(userInfo, BuildContext context) {
  91. String name = WebData().getEvaluation(context, userInfo['Value']);
  92. String title = '';
  93. if (userInfo['Status'] == 2) {
  94. title = I18n.of(context).successful_appeal;
  95. } else if (userInfo['Status'] == 3) {
  96. title = I18n.of(context).successful_appeal1;
  97. } else {
  98. title = UserData().isMan()
  99. ? I18n.of(context).received_evaluation
  100. : I18n.of(context).received_evaluation2;
  101. }
  102. return TitleItem(title: title, name: name);
  103. }
  104. //电台
  105. static TitleItem _delRadioTitle(data, BuildContext context) {
  106. bool isProgram = data['ProgramType'] == 0;
  107. String title;
  108. switch (data['Type']) {
  109. case 1:
  110. title = isProgram
  111. ? I18n.of(context).thumbs_up2
  112. : I18n.of(context).thumbs_up;
  113. break;
  114. case 2:
  115. title =
  116. isProgram ? I18n.of(context).comment2 : I18n.of(context).comment1;
  117. break;
  118. case 3:
  119. title = I18n.of(context).signed_up;
  120. break;
  121. case 4:
  122. title = isProgram
  123. ? I18n.of(context).favorite_user
  124. : I18n.of(context).favorite_user2;
  125. break;
  126. case 5:
  127. title = I18n.of(context).replied_comment;
  128. break;
  129. default:
  130. }
  131. return TitleItem(
  132. title: title,
  133. name: Provider.of<RefNameProvider>(context)
  134. .getRefName(data['UserId'], data['UserName']));
  135. }
  136. //系统
  137. static TitleItem _delSystemTitle(data, BuildContext context) {
  138. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  139. bool isPass = data['Status'] == 1;
  140. String title = '';
  141. String name = Provider.of<RefNameProvider>(context)
  142. .getRefName(data['ReportedUserId'], data['ReportedUserName']);
  143. switch (data['Type']) {
  144. case 1:
  145. title = isPass
  146. ? I18n.of(context).upload_success
  147. : I18n.of(context).re_upload;
  148. break;
  149. case 2:
  150. title = isPass
  151. ? I18n.of(context).successful_authentication
  152. : I18n.of(context).authentication_failed;
  153. break;
  154. case 3:
  155. if (isMyself) {
  156. title = data['Status'] == 1
  157. ? I18n.of(context).report_success
  158. : I18n.of(context).report_failure;
  159. } else {
  160. title = I18n.of(context).coin_returen;
  161. }
  162. break;
  163. case 4:
  164. title = data['Status'] == 1
  165. ? I18n.of(context).successful_application
  166. : I18n.of(context).application_failed;
  167. name = data['Status'] == 1 ? data['Content'].toString() : null;
  168. break;
  169. case 5:
  170. title = '代理会员推送相关';
  171. break;
  172. default:
  173. }
  174. return TitleItem(title: title, name: name);
  175. }
  176. //钱包
  177. static TitleItem _delMoneyTitle(data, BuildContext context) {
  178. String title = '';
  179. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  180. String name = Provider.of<RefNameProvider>(context)
  181. .getRefName(data['ChangeUserId'], data['UserName']);
  182. switch (data['DetailType'] == 10 ? data['Status'] : data['DetailType']) {
  183. case 1:
  184. title = I18n.of(context).get_coin2;
  185. name = data['Value'].toString();
  186. break;
  187. case 2:
  188. title = I18n.of(context).buy_vip;
  189. name = data['Value'].toString();
  190. break;
  191. case 3:
  192. title = isMyself
  193. ? I18n.of(context)
  194. .paid_you4
  195. .replaceFirst('/s2', data['Value'].toString())
  196. : I18n.of(context)
  197. .paid_you
  198. .replaceFirst('/s2', data['Value'].toString());
  199. break;
  200. case 4:
  201. title = isMyself
  202. ? I18n.of(context)
  203. .paid_you5
  204. .replaceFirst('/s2', data['Value'].toString())
  205. : I18n.of(context)
  206. .paid_you2
  207. .replaceFirst('/s2', data['Value'].toString());
  208. break;
  209. case 5:
  210. title = I18n.of(context).buy_program;
  211. name = data['Value'].toString();
  212. break;
  213. case 6:
  214. if (data['Status'] == 0) {
  215. title = I18n.of(context).del_add_money;
  216. } else if (data['Status'] == 1) {
  217. title = I18n.of(context).adding_money;
  218. } else {
  219. title = I18n.of(context).withdraw_fail;
  220. }
  221. name = data['Value'].toString();
  222. break;
  223. case 7:
  224. title =
  225. isMyself ? I18n.of(context).paid_you6 : I18n.of(context).paid_you3;
  226. break;
  227. case 8:
  228. title = isMyself
  229. ? I18n.of(context)
  230. .give_other_money
  231. .replaceFirst('/s2', data['Value'].toString())
  232. : I18n.of(context)
  233. .get_other_money
  234. .replaceFirst('/s2', data['Value'].toString());
  235. break;
  236. case 9:
  237. title = isMyself
  238. ? I18n.of(context)
  239. .give_red_money
  240. .replaceFirst('/s2', data['Value'].toString())
  241. : I18n.of(context)
  242. .get_red_money
  243. .replaceFirst('/s2', data['Value'].toString());
  244. break;
  245. case 11:
  246. title = I18n.of(context).Redeem;
  247. name = data['Value'].toString();
  248. break;
  249. }
  250. return TitleItem(title: title, name: name);
  251. }
  252. //收入金额
  253. static TitleItem _delInMoneyTitle(data, BuildContext context) {
  254. String title = '';
  255. String name = Provider.of<RefNameProvider>(context)
  256. .getRefName(data['UserId'], data['UserName']);
  257. switch (data['DetailType']) {
  258. case 1:
  259. if (data['Status'] == 0) {
  260. title = I18n.of(context).del_add_money;
  261. } else if (data['Status'] == 1) {
  262. title = I18n.of(context).withdraw_fail;
  263. } else {
  264. title = I18n.of(context).adding_money;
  265. }
  266. name = data['Value'].toString();
  267. break;
  268. case 2:
  269. title = I18n.of(context).change_h_coin;
  270. name = data['Value'].toString();
  271. break;
  272. case 3:
  273. title = I18n.of(context)
  274. .get_other_money
  275. .replaceFirst('/s2', data['Value'].toString());
  276. break;
  277. case 4:
  278. title = I18n.of(context)
  279. .get_red_money
  280. .replaceFirst('/s2', data['Value'].toString());
  281. break;
  282. case 5:
  283. title = I18n.of(context).paid_you3;
  284. break;
  285. case 6:
  286. title = I18n.of(context)
  287. .paid_you
  288. .replaceFirst('/s2', data['Value'].toString());
  289. break;
  290. case 7:
  291. title = I18n.of(context)
  292. .paid_you2
  293. .replaceFirst('/s2', data['Value'].toString());
  294. break;
  295. case 8:
  296. title = I18n.of(context).Representation_succes;
  297. break;
  298. case 9:
  299. title = I18n.of(context).system_give;
  300. break;
  301. case 10:
  302. title = I18n.of(context).exchange_fail;
  303. break;
  304. }
  305. return TitleItem(title: title, name: name);
  306. }
  307. //我的余额
  308. static TitleItem _delMyMoneyTitle(data, BuildContext context) {
  309. String title = '';
  310. String name = Provider.of<RefNameProvider>(context)
  311. .getRefName(data['UserId'], data['UserName']);
  312. switch (data['DetailType']) {
  313. case 1:
  314. title = I18n.of(context).get_coin2;
  315. name = data['Value'].toString();
  316. break;
  317. case 2:
  318. title = I18n.of(context).hibok_exchange;
  319. name = data['Value'].toString();
  320. break;
  321. case 3:
  322. title = I18n.of(context).bind_code_success;
  323. break;
  324. case 4:
  325. title = I18n.of(context)
  326. .give_other_money
  327. .replaceFirst('/s2', data['Value'].toString());
  328. break;
  329. case 5:
  330. title = I18n.of(context)
  331. .give_red_money
  332. .replaceFirst('/s2', data['Value'].toString());
  333. break;
  334. case 6:
  335. title = I18n.of(context)
  336. .paid_you6
  337. .replaceFirst('/s2', data['Value'].toString());
  338. break;
  339. case 7:
  340. title = I18n.of(context)
  341. .paid_you4
  342. .replaceFirst('/s2', data['Value'].toString());
  343. break;
  344. case 8:
  345. title = I18n.of(context)
  346. .paid_you5
  347. .replaceFirst('/s2', data['Value'].toString());
  348. break;
  349. case 9:
  350. title = I18n.of(context).buy_vip;
  351. name = data['Value'].toString();
  352. break;
  353. case 10:
  354. title = I18n.of(context).translate_money;
  355. name = data['Value'].toString();
  356. break;
  357. case 11:
  358. title = I18n.of(context).buy_program;
  359. name = data['Value'].toString();
  360. break;
  361. case 12:
  362. title = I18n.of(context).Representation_succes;
  363. break;
  364. case 13:
  365. title = I18n.of(context).system_back;
  366. break;
  367. case 14:
  368. title = I18n.of(context).system_give;
  369. break;
  370. }
  371. return TitleItem(title: title, name: name);
  372. }
  373. static TitleItem _getTypeTitleItem(userInfo, BuildContext context, int type) {
  374. var tileItem = TitleItem();
  375. switch (type) {
  376. case InfoType.Apply:
  377. tileItem = _delApplyTitle(userInfo, context);
  378. break;
  379. case InfoType.Radio:
  380. tileItem = _delRadioTitle(userInfo, context);
  381. break;
  382. case InfoType.System:
  383. tileItem = _delSystemTitle(userInfo, context);
  384. break;
  385. case InfoType.Money:
  386. tileItem = _delMoneyTitle(userInfo, context);
  387. break;
  388. case InfoType.IncomeMoney:
  389. tileItem = _delInMoneyTitle(userInfo, context);
  390. break;
  391. case InfoType.MyMoney:
  392. tileItem = _delMyMoneyTitle(userInfo, context);
  393. break;
  394. case InfoType.Evaluation:
  395. tileItem = _delEvaluateTitle(userInfo, context);
  396. break;
  397. default:
  398. }
  399. return tileItem;
  400. }
  401. static Widget getRichTitleWidget(userInfo, BuildContext context, int type,
  402. {titleStyle, nameStyle}) {
  403. var tileItem = _getTypeTitleItem(userInfo, context, type);
  404. return RichText(
  405. text: TextSpan(
  406. children: getRichText(tileItem,
  407. titleStyle: titleStyle, nameStyle: nameStyle)));
  408. }
  409. static String normalTitle(userInfo, BuildContext context, int type) {
  410. if (userInfo == null) {
  411. return '';
  412. }
  413. var tileItem = _getTypeTitleItem(userInfo, context, type);
  414. var res = getNormalText(tileItem);
  415. int maxlength = 17;
  416. return res.length > maxlength ? res.substring(0, maxlength) + '...' : res;
  417. }
  418. }