history_item_info.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'dart:io';
  2. import 'package:eitc_erm_dental_flutter/entity/file_prefix_info.dart';
  3. import '../funcs.dart';
  4. ///历史条目
  5. class HistoryItemInfo {
  6. ///路径
  7. final String path;
  8. ///名称
  9. String name = "";
  10. ///类型,0图片,1视频
  11. final int type;
  12. ///时间
  13. int time = 0;
  14. bool isValid = false;
  15. ///前缀信息
  16. FilePrefixInfo? prefixInfo;
  17. ///是否是选择模式
  18. bool _isSelectMode = false;
  19. ///是否已被选择
  20. bool isSelected = false;
  21. HistoryItemInfo(this.path, this.type) {
  22. try {
  23. int index = path.lastIndexOf("/");
  24. String fileName = path.substring(index + 1);
  25. if (fileName.isEmpty) {
  26. isValid = false;
  27. return;
  28. }
  29. fileName = fileName.replaceAll(
  30. type == 0
  31. ? RegExp(r".jpg")
  32. : RegExp(Platform.isIOS ? r".mov" : r".avi"),
  33. "");
  34. if (fileName.isEmpty) {
  35. isValid = false;
  36. return;
  37. }
  38. List<String> strs = fileName.split(RegExp(r"_"));
  39. String timeStr = strs.last;
  40. DateTime date;
  41. //20240913115441.mov
  42. //目前ios的视频时间戳不是用的毫秒值
  43. if (Platform.isIOS && type == 1) {
  44. date = DateTime(
  45. int.parse(timeStr.substring(0, 4)),
  46. int.parse(timeStr.substring(4, 6)),
  47. int.parse(timeStr.substring(6, 8)),
  48. int.parse(timeStr.substring(8, 10)),
  49. int.parse(timeStr.substring(10, 12)),
  50. int.parse(timeStr.substring(12)));
  51. time = date.millisecondsSinceEpoch;
  52. } else {
  53. time = int.parse(timeStr);
  54. date = DateTime.fromMillisecondsSinceEpoch(time);
  55. }
  56. String year = "${date.year}";
  57. String month = "${date.month}".padLeft(2, "0");
  58. String day = "${date.day}".padLeft(2, "0");
  59. String hour = "${date.hour}".padLeft(2, "0");
  60. String minute = "${date.minute}".padLeft(2, "0");
  61. String second = "${date.second}".padLeft(2, "0");
  62. name = "$year/$month/$day $hour:$minute:$second";
  63. if (strs.length == 2) {
  64. String encode = strs[0];
  65. prefixInfo = FilePrefixInfo();
  66. isValid = prefixInfo!.decode(encode);
  67. }
  68. } catch (e) {
  69. isValid = false;
  70. loge("解析历史条目数据异常", error: e);
  71. }
  72. }
  73. ///是否选择模式
  74. bool get isSelectMode => _isSelectMode;
  75. ///是否选择模式
  76. set isSelectMode(bool value) {
  77. _isSelectMode = value;
  78. isSelected = false;
  79. }
  80. }