HomeCourseTipsView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // HomeCourseTipsView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/4/22.
  6. //
  7. #import "HomeCourseTipsView.h"
  8. @interface HomeCourseTipsView ()
  9. @property (weak, nonatomic) IBOutlet UIImageView *teacherAvatar;
  10. @property (weak, nonatomic) IBOutlet UILabel *courseName;
  11. @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
  12. @property (nonatomic, copy) HomeCourseCallback callback;
  13. @property (nonatomic, strong) RecentCourseModel *courseModel;
  14. @end
  15. @implementation HomeCourseTipsView
  16. + (instancetype)shareInstance {
  17. HomeCourseTipsView *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeCourseTipsView" owner:nil options:nil] firstObject];
  18. return view;
  19. }
  20. - (void)configWithCourseMessage:(RecentCourseModel *)source {
  21. self.courseModel = source;
  22. self.courseName.text = [NSString stringWithFormat:@"%@即将开始",[NSString returnNoNullStringWithString:source.courseGroupName]];
  23. NSDateFormatter *formatter = [NSObject getDateformatter];
  24. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  25. NSDate *beginDate = [formatter dateFromString:source.courseStartTime];
  26. NSDate *currentDate = [NSDate date];
  27. [formatter setDateFormat:@"yyyy-MM-dd"];
  28. NSString *currentDay = [formatter stringFromDate:currentDate];
  29. NSString *courseDay = [formatter stringFromDate:beginDate];
  30. if ([currentDay isEqualToString:courseDay]) {
  31. [formatter setDateFormat:@"HH:mm"];
  32. self.timeLabel.text = [NSString stringWithFormat:@"今日 %@", [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]]];
  33. }
  34. else {
  35. [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
  36. self.timeLabel.text = [NSString returnNoNullStringWithString:[formatter stringFromDate:beginDate]];
  37. }
  38. [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[source.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  39. }
  40. - (void)joinRoomCallback:(HomeCourseCallback)callback {
  41. if (callback) {
  42. self.callback = callback;
  43. }
  44. }
  45. - (IBAction)joinRoomAction:(id)sender {
  46. if (self.callback) {
  47. COURSETYPE type;
  48. if ([self.courseModel.courseType isEqualToString:@"LIVE"]) {
  49. type = COURSETYPE_LIVE;
  50. }
  51. else if ([self.courseModel.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
  52. type = COURSETYPE_MUSICROOM;
  53. }
  54. else {
  55. type = COURSETYPE_ACCOMPANY;
  56. }
  57. self.callback(type, self.courseModel);
  58. }
  59. }
  60. + (CGFloat)getViewHeight {
  61. return 80.0f;
  62. }
  63. /*
  64. // Only override drawRect: if you perform custom drawing.
  65. // An empty implementation adversely affects performance during animation.
  66. - (void)drawRect:(CGRect)rect {
  67. // Drawing code
  68. }
  69. */
  70. @end