123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- //
- // CourseViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "CourseViewController.h"
- #import "FSCalendar.h"
- #import "CourseNavView.h"
- #import "LTSCalendarBottomView.h"
- #import "KSFullDatePicker.h"
- #import "AccompanyCourseCell.h"
- #import "LiveCourseCell.h"
- @interface CourseViewController ()<UITableViewDataSource,UITableViewDelegate,FSCalendarDataSource,FSCalendarDelegate,UIGestureRecognizerDelegate>
- {
- void * _KVOContext;
- }
- @property (nonatomic, strong) CourseNavView *navHeadView;
- @property (nonatomic, strong) NSString *chooseMonth;
- @property (nonatomic, strong) NSString *chooseDay;
- @property (nonatomic,strong) FSCalendar *calendar;
- @property (strong, nonatomic) NSCalendar *gregorian;
- @property (nonatomic, strong) UITableView *tableView;
- @property (strong, nonatomic) UIPanGestureRecognizer *scopeGesture;
- @property (strong, nonatomic) NSDateFormatter *dateFormatter;
- @property (nonatomic, strong) LTSCalendarBottomView *calendarBottom;
- @property (nonatomic, assign) BOOL cancleRequest;
- @end
- @implementation CourseViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- [self configUI];
- [self loadCalendarInfo];
- }
- - (void)loadCalendarInfo {
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.timeZone = [NSTimeZone systemTimeZone];
- [formatter setDateFormat:@"yyyy-MM"];
- NSDate *date = [NSDate date];
- self.chooseMonth = [formatter stringFromDate:date];
- self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:date]];
- [self.calendar selectDate:date];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- [self loadMonthCourse:self.chooseMonth];
- if (![NSString isEmptyString:self.chooseDay]) {
- [self getCourseByDate:self.chooseDay];
- }
- }
- - (void)configUI {
- [self.view addSubview:self.navHeadView];
- [self.navHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navHeadView.mas_bottom);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
-
- UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
- containerView.backgroundColor = [UIColor clearColor];
- [self.scrollView addSubview:containerView];
- [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(self.scrollView);
- make.width.mas_equalTo(self.scrollView);
- }];
-
- self.calendar = [[FSCalendar alloc] init];
- [self configCalendar];
- [containerView addSubview:self.calendar];
- [self.calendar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(containerView);
- make.top.mas_equalTo(containerView.mas_top);
- make.height.mas_equalTo(300);
- }];
- self.calendarBottom = [LTSCalendarBottomView shareInstance];
- MJWeakSelf;
- [self.calendarBottom changeDisplay:^{
- [weakSelf changeDisplay];
- }];
- [containerView addSubview:self.calendarBottom];
- [self.calendarBottom mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(containerView);
- make.top.mas_equalTo(self.calendar.mas_bottom);
- make.height.mas_equalTo(40);
- }];
-
- [containerView addSubview:self.tableView];
- CGFloat tableHeight = kScreenHeight - kNaviBarHeight - kTabBarHeight - 300 - 40;
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.calendarBottom.mas_bottom);
- make.height.mas_equalTo(tableHeight);
- }];
- [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.tableView.mas_bottom);
- }];
-
- UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.calendar action:@selector(handleScopeGesture:)];
- panGesture.delegate = self;
- panGesture.minimumNumberOfTouches = 1;
- panGesture.maximumNumberOfTouches = 2;
- [self.scrollView addGestureRecognizer:panGesture];
- self.scopeGesture = panGesture;
- [self.tableView.panGestureRecognizer requireGestureRecognizerToFail:panGesture];
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf.calendar setToday:[NSDate date]];
- [weakSelf loadMonthCourse:weakSelf.chooseMonth];
- if (![NSString isEmptyString:weakSelf.chooseDay]) {
- [weakSelf getCourseByDate:weakSelf.chooseDay];
- }
- }];
- if (@available(iOS 11.0, *)) {
- self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- }
- - (void)endRefresh {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.scrollView.mj_header endRefreshing];
- });
- }
- #pragma mark ---- calender action
- // 收起或展开日历
- - (void)changeDisplay {
- FSCalendarScope selectedScope = self.calendar.scope == FSCalendarScopeMonth ? FSCalendarScopeWeek : FSCalendarScopeMonth;
- [self.calendar setScope:selectedScope animated:YES];
- NSString *imgName = selectedScope == FSCalendarScopeWeek ? @"arrow_down" : @"arrow_up";
- [self.calendarBottom.arrowImage setImage:[UIImage imageNamed:imgName]];
- #warning ---- 测试有课日期
- self.calendar.highlightDates = [NSMutableArray arrayWithArray:@[@"2022-04-12 00:00:00",@"2022-04-15 00:00:00"]];
- [self.calendar reloadData];
- }
- - (void)configCalendar {
- self.calendar.backgroundColor = [UIColor whiteColor];
- self.calendar.appearance.titleFont = [UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium];
- self.calendar.appearance.titleDefaultColor = HexRGB(0x444444);
- self.calendar.appearance.titleTodayColor = HexRGB(0x444444);
- self.calendar.appearance.titleSelectionColor = [UIColor whiteColor];
- self.calendar.appearance.selectionColor = THEMECOLOR;
- self.calendar.appearance.weekdayFont = [UIFont systemFontOfSize:14.0f];
- self.calendar.appearance.weekdayTextColor = HexRGB(0x777777);
- self.calendar.appearance.titleWeekendColor = THEMECOLOR;
- self.calendar.appearance.todaySelectionColor = THEMECOLOR;
- self.calendar.appearance.todayColor = [UIColor whiteColor];
- self.calendar.appearance.todayBorderColor = [UIColor whiteColor];
- self.calendar.appearance.borderRadius = 0.2f;
- self.calendar.appearance.borderDefaultColor = [UIColor whiteColor];
- self.calendar.appearance.titleHightlightColor = HexRGB(0x444444);
- self.calendar.appearance.backgoundHightlightColor = HexRGBAlpha(0xffd7a6, 0.21);
- self.calendar.appearance.subtitleFont = [UIFont systemFontOfSize:10.0f];
- self.calendar.appearance.subtitleOffset = CGPointMake(0, 3);
- self.calendar.appearance.subtitleTodayColor = HexRGB(0xff6363);
- self.calendar.appearance.subtitleDefaultColor = HexRGB(0xff6363);
- self.calendar.appearance.subtitleSelectionColor = [UIColor whiteColor];
- self.calendar.dataSource = self;
- self.calendar.delegate = self;
- // self.calendar.firstWeekday = 2;
- self.calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase|FSCalendarCaseOptionsHeaderUsesUpperCase;
- self.calendar.calendarHeaderView.hidden = YES;
- self.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
- [self.calendar addObserver:self forKeyPath:@"scope" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:_KVOContext];
- self.calendar.placeholderType = FSCalendarPlaceholderTypeNone;
- self.calendar.scope = FSCalendarScopeMonth;
- [self.calendar selectDate:[NSDate date] scrollToDate:YES];
- }
- #pragma mark - FSCalendarDataSource
- - (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date {
- // 判断有课的日期显示subtitle
- if ([calendar.highlightDates containsObject:date]) {
- return @"有课";
- }
- return nil;
-
-
- }
- #pragma mark - FSCalendarDelegate
- - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
- {
- [calendar mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(bounds.size.height);
- // Do other updates
- }];
- [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(kScreenHeight - kTabBarHeight - bounds.size.height - kNaviBarHeight - 40);
- }];
- [self.view layoutIfNeeded];
- }
- - (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
- {
- NSLog(@"did select date %@",[self.dateFormatter stringFromDate:date]);
-
- NSMutableArray *selectedDates = [NSMutableArray arrayWithCapacity:calendar.selectedDates.count];
- [calendar.selectedDates enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- [selectedDates addObject:[self.dateFormatter stringFromDate:obj]];
- }];
- self.navHeadView.navTitle.text = [self.dateFormatter stringFromDate:date];
- NSLog(@"selected dates is %@",selectedDates);
- if (monthPosition == FSCalendarMonthPositionNext || monthPosition == FSCalendarMonthPositionPrevious) {
- [calendar setCurrentPage:date animated:YES];
- }
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.timeZone = [NSTimeZone systemTimeZone];
- [formatter setDateFormat:@"yyyy-MM-dd"];
- NSString *dateStr = [formatter stringFromDate:date];
- dateStr = [NSString stringWithFormat:@"%@ 00:00:00", dateStr];
- self.chooseDay = dateStr;
- [self getCourseByDate:dateStr];
- }
- - (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
- {
- self.navHeadView.navTitle.text = [self.dateFormatter stringFromDate:calendar.currentPage];
- NSLog(@"%s %@", __FUNCTION__, [self.dateFormatter stringFromDate:calendar.currentPage]);
- // 获取当前月份信息
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.timeZone = [NSTimeZone systemTimeZone];
- [formatter setDateFormat:@"yyyy-MM"];
- NSString *month = [formatter stringFromDate:calendar.currentPage];
- if (![_chooseMonth isEqualToString:month]) {
- _chooseMonth = month;
- [self loadMonthCourse:month];
- }
- [formatter setDateFormat:@"yyyy-MM-dd"];
- NSString *chooseDay = [formatter stringFromDate:calendar.currentPage];
- self.chooseDay = chooseDay;
- [self.calendar selectDate:calendar.currentPage];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSString *currentDate = [formatter stringFromDate:calendar.currentPage];
- [self getCourseByDate:currentDate];
- }
- #pragma mark --- 获取当前月份有课日期
- - (void)loadMonthCourse:(NSString *)month {
-
- }
- #pragma mark --- 获取当日课程
- - (void)getCourseByDate:(NSString *)date {
-
- }
- #pragma mark - <UIGestureRecognizerDelegate>
- // Whether scope gesture should begin
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
- {
- BOOL shouldBegin = self.tableView.contentOffset.y <= -self.tableView.contentInset.top;
- if (shouldBegin) {
- CGPoint velocity = [self.scopeGesture velocityInView:self.view];
- switch (self.calendar.scope) {
- case FSCalendarScopeMonth:
- return velocity.y < 0;
- case FSCalendarScopeWeek:
- return velocity.y > 0;
- }
- }
- return shouldBegin;
- }
- #pragma mark - KVO
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
- {
- if (context == _KVOContext) {
- FSCalendarScope oldScope = [change[NSKeyValueChangeOldKey] unsignedIntegerValue];
- FSCalendarScope newScope = [change[NSKeyValueChangeNewKey] unsignedIntegerValue];
- NSLog(@"From %@ to %@",(oldScope==FSCalendarScopeWeek?@"week":@"month"),(newScope==FSCalendarScopeWeek?@"week":@"month"));
- } else {
- [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
- }
- }
- #pragma mark --- table data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
- return cell;
- }
- #pragma mark --- lazying
- - (CourseNavView *)navHeadView {
- if (!_navHeadView) {
- _navHeadView = [CourseNavView shareInstance];
- MJWeakSelf;
- [_navHeadView chooseNavCallback:^{
- [weakSelf displayMounthPicker];
- }];
-
- }
- return _navHeadView;
- }
- - (void)displayMounthPicker {
-
- }
- - (NSDateFormatter *)dateFormatter {
- if (!_dateFormatter) {
- _dateFormatter = [[NSDateFormatter alloc] init];
- _dateFormatter.timeZone = [NSTimeZone systemTimeZone];
- _dateFormatter.dateFormat = @"yyyy年MM月";
- }
- return _dateFormatter;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.estimatedRowHeight = 130;
- [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"LiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LiveCourseCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
- bottomView.backgroundColor = [UIColor clearColor];
- _tableView.tableFooterView = bottomView;
-
- }
- return _tableView;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|