123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // EventReminderViewController.m
- // Artimenring
- //
- // Created by YangJianguo on 4/14/16.
- // Copyright © 2016 BaH Cy. All rights reserved.
- //
- #import "EventReminderViewController.h"
- #import "ASWeekSelectorView.h"
- #import "EventReminderViewCell.h"
- #import "PDTSimpleCalendarViewController.h"
- #import "AddEventViewController.h"
- #import "ScheduleManager.h"
- #import "TimeEventViewController.h"
- #import "CustomEventViewController.h"
- #import "BirthdayEventViewController.h"
- #import <UMMobClick/MobClick.h>
- @interface EventReminderViewController ()<ASWeekSelectorViewDelegate, UITableViewDataSource, UITableViewDelegate, PDTSimpleCalendarViewDelegate>
- {
- NSArray *scheduleArray;
- }
- @property (nonatomic, weak) IBOutlet UITableView *tableView;
- @property(nonatomic, strong) IBOutlet UIButton *mAddBtn;
- @property(nonatomic, strong) ASWeekSelectorView *weekSelector;
- @property(nonatomic, strong) PDTSimpleCalendarViewController *calendarController;
- @end
- @implementation EventReminderViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view
-
- UIBarButtonItem *monthBtn = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Schedule.Month", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onClickMonthView)];
- self.navigationItem.rightBarButtonItem = monthBtn;
-
- [EUtil setViewShadow:self.mAddBtn color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 8) opacity:1 radius:10];
-
- [self initWeekSelector];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- [self.navigationController setNavigationBarHidden:NO];
- [self.weekSelector rebuildWeeks];
-
- [self updateTitle:self.weekSelector.selectedDate];
-
- [self getScheduleList];
- }
- - (void)viewDidLayoutSubviews
- {
- [super viewDidLayoutSubviews];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- self.title = @"";
- }
- - (void)initWeekSelector {
-
- UIScreen *mainScreen = [UIScreen mainScreen];
- self.weekSelector = [[ASWeekSelectorView alloc] initWithFrame:CGRectMake(0, 0, mainScreen.bounds.size.width, 92)];
- [self.weekSelector setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1]];
- self.weekSelector.letterTextColor = [UIColor colorWithRed:0/255.0 green:1/255.0 blue:75/255.0 alpha:0.2];
- self.weekSelector.numberTextColor = [UIColor colorWithRed:0/255.0 green:1/255.0 blue:75/255.0 alpha:0.6];
- self.weekSelector.letterTextFont = 12;
- self.weekSelector.dayNumberFont = 17;
- self.weekSelector.delegate = self;
- self.weekSelector.selectedDate = [NSDate date];
- self.weekSelector.firstWeekday = 1; // monday
- self.weekSelector.mIsShowPoint = YES;
- self.weekSelector.lineColor = [UIColor clearColor];
- [self.view addSubview:self.weekSelector];
-
- self.weekSelector.layer.masksToBounds = NO;
- [EUtil setViewShadow:self.weekSelector color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.12] offset:CGSizeMake(0, 2) opacity:1 radius:4];
- }
- - (void)getScheduleList
- {
- NSMutableDictionary *param = NSMutableDictionary.new;
- NSString *cid = [DataManager shared].mSelectChildModel.cid;
- param[@"cid"] = cid;
- param[@"operationTime"] = @([[ScheduleManager sharedInstance] getLatestTimeID:cid]);
-
- [self ShowHUBWithText:NSLocalizedString(@"Request.Updating", nil)];
- [ERequest httpRequest:param httpURL:URL_EVENT httpMethod:@"GET" onSuccess:^(NSDictionary *result){
- [self HiddenHUB];
- if([ERequest isSuccessWithResult:result])
- {
- for (NSDictionary *dict in result[@"data"]) {
- ScheduleEventData *schedule = [[ScheduleEventData alloc] initWithDict:dict];
-
- if(schedule.mOperationType == 2)//0-add, 1-modify, 2-delete
- {
- [[ScheduleManager sharedInstance] removeSchedule:schedule.mID];
- }
- else
- {
- [[ScheduleManager sharedInstance] removeSchedule:schedule.mID];
- [[ScheduleManager sharedInstance] addNewSchedule:schedule];
- }
- }
-
- scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:self.weekSelector.selectedDate andChildID:[DataManager shared].mSelectChildModel.cid];
- [self.tableView reloadData];
- }
- else
- {
- [EasyTextView showErrorText:result[@"message"]];
- }
- }onFailure:^(NSError *error) {
- [self HiddenHUB];
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
- }];
- }
- - (void)simpleCalendarViewController:(PDTSimpleCalendarViewController *)controller didSelectDate:(NSDate *)date
- {
- [self.navigationController popViewControllerAnimated:YES];
-
- self.weekSelector.selectedDate = date;
- }
- - (void)onClickMonthView {
- if(self.calendarController == nil) {
- self.calendarController = [[PDTSimpleCalendarViewController alloc] init];
- self.calendarController.delegate = self;
- self.calendarController.title = NSLocalizedString(@"Schedule.Month", nil);
- }
-
- [self pushViewController:self.calendarController animated:YES];
- }
- - (void)onClickToday:(id)sender {
- self.weekSelector.selectedDate = [NSDate date];
-
- scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:self.weekSelector.selectedDate andChildID:[DataManager shared].mSelectChildModel.cid];
- [self.tableView reloadData];
- }
- - (IBAction)addNewEvent {
- AddEventViewController *controller = (AddEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"AddEventVC"];
- controller.selectedDate = self.weekSelector.selectedDate;
- controller.eventListView = self;
- [self pushViewController:controller animated:YES];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- [self.view isEmptyView:scheduleArray.count <= 0 emptyImageName:@"nodata_remind" top:100 height:300];
- return scheduleArray.count;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 93;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 10;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
- [view setBackgroundColor:[UIColor clearColor]];
- return view;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellID = @"EventReminderCellID";
- EventReminderViewCell *cell = (EventReminderViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
- if(cell == nil)
- {
- cell = [[EventReminderViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
- }
-
- ScheduleEventData *schedule = [scheduleArray objectAtIndex:indexPath.row];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"hh:mm a"];
- cell.timeLabel.text = [dateFormatter stringFromDate:schedule.time];
-
- if(schedule.mType == EScheduleTypeGetup)
- cell.eventLabel.text = NSLocalizedString(@"Schedule.Getup.Title", nil);
- else if(schedule.mType == EScheduleTypeSleep)
- cell.eventLabel.text = NSLocalizedString(@"Schedule.Sleep.Title", nil);
- else if(schedule.mType == EScheduleTypeBirthday)
- cell.eventLabel.text = NSLocalizedString(@"Schedule.Birthday.Title", nil);
- else
- cell.eventLabel.text = schedule.mScheduleName;
-
- NSString* imageName = [NSString stringWithFormat:@"%@%d", @"event_small_",schedule.colorIndex-1];
- [cell.colorImgView setImage:[UIImage imageNamed:imageName]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- ScheduleEventData *schedule = [scheduleArray objectAtIndex:indexPath.row];
- if(schedule.mType == EScheduleTypeGetup)
- {
- [MobClick event:@"ClickEditTimeEventGetup"];
- TimeEventViewController *controller = (TimeEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"TimeEventVC"];
- controller.scheduelID = schedule.mID;
- controller.selectedDate = self.weekSelector.selectedDate;
- controller.scheduleType = EScheduleTypeGetup;
- controller.eventListView = self;
- [self pushViewController:controller animated:YES];
- }
- else if(schedule.mType == EScheduleTypeSleep)
- {
- [MobClick event:@"ClickEditTimeEventSleep"];
- TimeEventViewController *controller = (TimeEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"TimeEventVC"];
- controller.scheduelID = schedule.mID;
- controller.selectedDate = self.weekSelector.selectedDate;
- controller.scheduleType = EScheduleTypeSleep;
- controller.eventListView = self;
- [self pushViewController:controller animated:YES];
- }
- else if(schedule.mType == EScheduleTypeBirthday)
- {
- [MobClick event:@"ClickEditTimeEventBirthday"];
- BirthdayEventViewController *controller = (BirthdayEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"BirthdayEventVC"];
- controller.scheduelID = schedule.mID;
- controller.eventListView = self;
- [self pushViewController:controller animated:YES];
- }
- else if(schedule.mType == EScheduleTypeCustom)
- {
- [MobClick event:@"ClickEditTimeEventCustom"];
- CustomEventViewController *controller = (CustomEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"CustomEventVC"];
- controller.scheduelID = schedule.mID;
- controller.selectedDate = self.weekSelector.selectedDate;
- controller.eventListView = self;
- [self pushViewController:controller animated:YES];
- }
- }
- - (void)updateTitle:(NSDate *) date {
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- dateFormatter.timeStyle = NSDateFormatterNoStyle;
- dateFormatter.dateStyle = kCFDateFormatterMediumStyle;
- self.title = [dateFormatter stringFromDate:date];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - ASWeekSelectorViewDelegate
- - (void)weekSelector:(ASWeekSelectorView *)weekSelector willSelectDate:(NSDate *)date
- {
- [self updateTitle:date];
-
- scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:date andChildID:[DataManager shared].mSelectChildModel.cid];
-
- [self.tableView reloadData];
- }
- /*
- #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
|