123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // HomeRecentCourseView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/5/10.
- //
- #import "HomeRecentCourseView.h"
- #import <Lottie/Lottie.h>
- @interface HomeRecentCourseView ()
- @property (nonatomic, strong) LOTAnimationView *animationView;
- @property (weak, nonatomic) IBOutlet UIView *imageBgView;
- @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
- @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
- @property (nonatomic, copy) RecentCourseAction callback;
- @property (nonatomic, strong) RecentCourseModel *courseModel;
- @end
- @implementation HomeRecentCourseView
- + (instancetype)shareInstance {
- HomeRecentCourseView *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeRecentCourseView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)joinRoom:(RecentCourseAction)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (void)configCourseMessage:(RecentCourseModel *)model {
- self.courseModel = model;
- NSDateFormatter *formatter = [NSObject getDateformatter];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *beginDate = [formatter dateFromString:model.courseStartTime];
- NSDate *currentDate = [NSDate date];
- [formatter setDateFormat:@"yyyy-MM-dd"];
- NSString *currentDay = [formatter stringFromDate:currentDate];
- NSString *courseDay = [formatter stringFromDate:beginDate];
- if ([currentDay isEqualToString:courseDay]) {
- [formatter setDateFormat:@"HH:mm"];
- self.timeLabel.text = [NSString stringWithFormat:@"今日 %@", [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]]];
- }
- else {
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
- self.timeLabel.text = [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]];
- }
- NSString *jsonString = @"";
- if ([self.courseModel.courseType isEqualToString:@"LIVE"]) {
- jsonString = @"live_animation.json";
- }
- else if ([self.courseModel.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
- jsonString = @"musicRoom_animation.json";
- }
- else {
- jsonString = @"accomapny_animation.json";
- }
- [self configAnimationView:jsonString];
- }
- - (void)configAnimationView:(NSString *)jsonString {
- if ([self.imageBgView.subviews containsObject:self.animationView]) {
- [self.animationView removeFromSuperview];
- }
- self.animationView = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:jsonString ofType:@"json"]];
- //2.加载后台给的json(url)
- self.animationView.frame = CGRectMake(0, 0, 128, 91);
- self.animationView.loopAnimation = YES;
- self.animationView.contentMode = UIViewContentModeScaleAspectFill;
- self.animationView.animationSpeed = 1.0;
- self.animationView.loopAnimation = YES;
- [self.imageBgView addSubview:self.animationView];
- [self.animationView play];
- }
- - (IBAction)joinRoomAction:(id)sender {
- if (self.callback) {
- RECENTCOURSE_TYPE type;
- if ([self.courseModel.courseType isEqualToString:@"LIVE"]) {
- type = RECENTCOURSE_TYPE_LIVE;
- }
- else if ([self.courseModel.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
- type = RECENTCOURSE_TYPE_MUSICCLASS;
- }
- else /*if ([self.courseModel.courseType isEqualToString:@"PRACTICE"])*/ {
- type = RECENTCOURSE_TYPE_ACCOMPANY;
- }
- self.callback(type, self.courseModel);
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|