HomeRecentCourseView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // HomeRecentCourseView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/5/10.
  6. //
  7. #import "HomeRecentCourseView.h"
  8. #import <Lottie/Lottie.h>
  9. @interface HomeRecentCourseView ()
  10. @property (nonatomic, strong) LOTAnimationView *animationView;
  11. @property (weak, nonatomic) IBOutlet UIView *imageBgView;
  12. @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
  13. @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
  14. @property (nonatomic, copy) RecentCourseAction callback;
  15. @property (nonatomic, strong) RecentCourseModel *courseModel;
  16. @end
  17. @implementation HomeRecentCourseView
  18. + (instancetype)shareInstance {
  19. HomeRecentCourseView *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeRecentCourseView" owner:nil options:nil] firstObject];
  20. return view;
  21. }
  22. - (void)joinRoom:(RecentCourseAction)callback {
  23. if (callback) {
  24. self.callback = callback;
  25. }
  26. }
  27. - (void)configCourseMessage:(RecentCourseModel *)model {
  28. self.courseModel = model;
  29. NSDateFormatter *formatter = [NSObject getDateformatter];
  30. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  31. NSDate *beginDate = [formatter dateFromString:model.courseStartTime];
  32. NSDate *currentDate = [NSDate date];
  33. [formatter setDateFormat:@"yyyy-MM-dd"];
  34. NSString *currentDay = [formatter stringFromDate:currentDate];
  35. NSString *courseDay = [formatter stringFromDate:beginDate];
  36. if ([currentDay isEqualToString:courseDay]) {
  37. [formatter setDateFormat:@"HH:mm"];
  38. self.timeLabel.text = [NSString stringWithFormat:@"今日 %@", [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]]];
  39. }
  40. else {
  41. [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
  42. self.timeLabel.text = [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]];
  43. }
  44. NSString *jsonString = @"";
  45. if ([self.courseModel.courseType isEqualToString:@"LIVE"]) {
  46. jsonString = @"live_animation.json";
  47. }
  48. else if ([self.courseModel.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
  49. jsonString = @"musicRoom_animation.json";
  50. }
  51. else {
  52. jsonString = @"accomapny_animation.json";
  53. }
  54. [self configAnimationView:jsonString];
  55. }
  56. - (void)configAnimationView:(NSString *)jsonString {
  57. if ([self.imageBgView.subviews containsObject:self.animationView]) {
  58. [self.animationView removeFromSuperview];
  59. }
  60. self.animationView = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:jsonString ofType:@"json"]];
  61. //2.加载后台给的json(url)
  62. self.animationView.frame = CGRectMake(0, 0, 128, 91);
  63. self.animationView.loopAnimation = YES;
  64. self.animationView.contentMode = UIViewContentModeScaleAspectFill;
  65. self.animationView.animationSpeed = 1.0;
  66. self.animationView.loopAnimation = YES;
  67. [self.imageBgView addSubview:self.animationView];
  68. [self.animationView play];
  69. }
  70. - (IBAction)joinRoomAction:(id)sender {
  71. if (self.callback) {
  72. RECENTCOURSE_TYPE type;
  73. if ([self.courseModel.courseType isEqualToString:@"LIVE"]) {
  74. type = RECENTCOURSE_TYPE_LIVE;
  75. }
  76. else if ([self.courseModel.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
  77. type = RECENTCOURSE_TYPE_MUSICCLASS;
  78. }
  79. else /*if ([self.courseModel.courseType isEqualToString:@"PRACTICE"])*/ {
  80. type = RECENTCOURSE_TYPE_ACCOMPANY;
  81. }
  82. self.callback(type, self.courseModel);
  83. }
  84. }
  85. /*
  86. // Only override drawRect: if you perform custom drawing.
  87. // An empty implementation adversely affects performance during animation.
  88. - (void)drawRect:(CGRect)rect {
  89. // Drawing code
  90. }
  91. */
  92. @end