EventReminderViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //
  2. // EventReminderViewController.m
  3. // Artimenring
  4. //
  5. // Created by YangJianguo on 4/14/16.
  6. // Copyright © 2016 BaH Cy. All rights reserved.
  7. //
  8. #import "EventReminderViewController.h"
  9. #import "ASWeekSelectorView.h"
  10. #import "EventReminderViewCell.h"
  11. #import "PDTSimpleCalendarViewController.h"
  12. #import "AddEventViewController.h"
  13. #import "ScheduleManager.h"
  14. #import "TimeEventViewController.h"
  15. #import "CustomEventViewController.h"
  16. #import "BirthdayEventViewController.h"
  17. #import <UMMobClick/MobClick.h>
  18. @interface EventReminderViewController ()<ASWeekSelectorViewDelegate, UITableViewDataSource, UITableViewDelegate, PDTSimpleCalendarViewDelegate>
  19. {
  20. NSArray *scheduleArray;
  21. }
  22. @property (nonatomic, weak) IBOutlet UITableView *tableView;
  23. @property(nonatomic, strong) IBOutlet UIButton *mAddBtn;
  24. @property(nonatomic, strong) ASWeekSelectorView *weekSelector;
  25. @property(nonatomic, strong) PDTSimpleCalendarViewController *calendarController;
  26. @end
  27. @implementation EventReminderViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view
  31. UIBarButtonItem *monthBtn = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Schedule.Month", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onClickMonthView)];
  32. self.navigationItem.rightBarButtonItem = monthBtn;
  33. [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];
  34. [self initWeekSelector];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated
  37. {
  38. [super viewWillAppear:animated];
  39. [self.navigationController setNavigationBarHidden:NO];
  40. [self.weekSelector rebuildWeeks];
  41. [self updateTitle:self.weekSelector.selectedDate];
  42. [self getScheduleList];
  43. }
  44. - (void)viewDidLayoutSubviews
  45. {
  46. [super viewDidLayoutSubviews];
  47. }
  48. - (void)viewWillDisappear:(BOOL)animated
  49. {
  50. [super viewWillDisappear:animated];
  51. self.title = @"";
  52. }
  53. - (void)initWeekSelector {
  54. UIScreen *mainScreen = [UIScreen mainScreen];
  55. self.weekSelector = [[ASWeekSelectorView alloc] initWithFrame:CGRectMake(0, 0, mainScreen.bounds.size.width, 92)];
  56. [self.weekSelector setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1]];
  57. self.weekSelector.letterTextColor = [UIColor colorWithRed:0/255.0 green:1/255.0 blue:75/255.0 alpha:0.2];
  58. self.weekSelector.numberTextColor = [UIColor colorWithRed:0/255.0 green:1/255.0 blue:75/255.0 alpha:0.6];
  59. self.weekSelector.letterTextFont = 12;
  60. self.weekSelector.dayNumberFont = 17;
  61. self.weekSelector.delegate = self;
  62. self.weekSelector.selectedDate = [NSDate date];
  63. self.weekSelector.firstWeekday = 1; // monday
  64. self.weekSelector.mIsShowPoint = YES;
  65. self.weekSelector.lineColor = [UIColor clearColor];
  66. [self.view addSubview:self.weekSelector];
  67. self.weekSelector.layer.masksToBounds = NO;
  68. [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];
  69. }
  70. - (void)getScheduleList
  71. {
  72. NSMutableDictionary *param = NSMutableDictionary.new;
  73. NSString *cid = [DataManager shared].mSelectChildModel.cid;
  74. param[@"cid"] = cid;
  75. param[@"operationTime"] = @([[ScheduleManager sharedInstance] getLatestTimeID:cid]);
  76. [self ShowHUBWithText:NSLocalizedString(@"Request.Updating", nil)];
  77. [ERequest httpRequest:param httpURL:URL_EVENT httpMethod:@"GET" onSuccess:^(NSDictionary *result){
  78. [self HiddenHUB];
  79. if([ERequest isSuccessWithResult:result])
  80. {
  81. for (NSDictionary *dict in result[@"data"]) {
  82. ScheduleEventData *schedule = [[ScheduleEventData alloc] initWithDict:dict];
  83. if(schedule.mOperationType == 2)//0-add, 1-modify, 2-delete
  84. {
  85. [[ScheduleManager sharedInstance] removeSchedule:schedule.mID];
  86. }
  87. else
  88. {
  89. [[ScheduleManager sharedInstance] removeSchedule:schedule.mID];
  90. [[ScheduleManager sharedInstance] addNewSchedule:schedule];
  91. }
  92. }
  93. scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:self.weekSelector.selectedDate andChildID:[DataManager shared].mSelectChildModel.cid];
  94. [self.tableView reloadData];
  95. }
  96. else
  97. {
  98. [EasyTextView showErrorText:result[@"message"]];
  99. }
  100. }onFailure:^(NSError *error) {
  101. [self HiddenHUB];
  102. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
  103. }];
  104. }
  105. - (void)simpleCalendarViewController:(PDTSimpleCalendarViewController *)controller didSelectDate:(NSDate *)date
  106. {
  107. [self.navigationController popViewControllerAnimated:YES];
  108. self.weekSelector.selectedDate = date;
  109. }
  110. - (void)onClickMonthView {
  111. if(self.calendarController == nil) {
  112. self.calendarController = [[PDTSimpleCalendarViewController alloc] init];
  113. self.calendarController.delegate = self;
  114. self.calendarController.title = NSLocalizedString(@"Schedule.Month", nil);
  115. }
  116. [self pushViewController:self.calendarController animated:YES];
  117. }
  118. - (void)onClickToday:(id)sender {
  119. self.weekSelector.selectedDate = [NSDate date];
  120. scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:self.weekSelector.selectedDate andChildID:[DataManager shared].mSelectChildModel.cid];
  121. [self.tableView reloadData];
  122. }
  123. - (IBAction)addNewEvent {
  124. AddEventViewController *controller = (AddEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"AddEventVC"];
  125. controller.selectedDate = self.weekSelector.selectedDate;
  126. controller.eventListView = self;
  127. [self pushViewController:controller animated:YES];
  128. }
  129. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  130. {
  131. [self.view isEmptyView:scheduleArray.count <= 0 emptyImageName:@"nodata_remind" top:100 height:300];
  132. return scheduleArray.count;
  133. }
  134. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  135. {
  136. return 1;
  137. }
  138. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  139. return 93;
  140. }
  141. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  142. return 10;
  143. }
  144. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  145. UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
  146. [view setBackgroundColor:[UIColor clearColor]];
  147. return view;
  148. }
  149. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  150. {
  151. static NSString *cellID = @"EventReminderCellID";
  152. EventReminderViewCell *cell = (EventReminderViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  153. if(cell == nil)
  154. {
  155. cell = [[EventReminderViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
  156. }
  157. ScheduleEventData *schedule = [scheduleArray objectAtIndex:indexPath.row];
  158. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  159. [dateFormatter setDateFormat:@"hh:mm a"];
  160. cell.timeLabel.text = [dateFormatter stringFromDate:schedule.time];
  161. if(schedule.mType == EScheduleTypeGetup)
  162. cell.eventLabel.text = NSLocalizedString(@"Schedule.Getup.Title", nil);
  163. else if(schedule.mType == EScheduleTypeSleep)
  164. cell.eventLabel.text = NSLocalizedString(@"Schedule.Sleep.Title", nil);
  165. else if(schedule.mType == EScheduleTypeBirthday)
  166. cell.eventLabel.text = NSLocalizedString(@"Schedule.Birthday.Title", nil);
  167. else
  168. cell.eventLabel.text = schedule.mScheduleName;
  169. NSString* imageName = [NSString stringWithFormat:@"%@%d", @"event_small_",schedule.colorIndex-1];
  170. [cell.colorImgView setImage:[UIImage imageNamed:imageName]];
  171. return cell;
  172. }
  173. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  174. {
  175. ScheduleEventData *schedule = [scheduleArray objectAtIndex:indexPath.row];
  176. if(schedule.mType == EScheduleTypeGetup)
  177. {
  178. [MobClick event:@"ClickEditTimeEventGetup"];
  179. TimeEventViewController *controller = (TimeEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"TimeEventVC"];
  180. controller.scheduelID = schedule.mID;
  181. controller.selectedDate = self.weekSelector.selectedDate;
  182. controller.scheduleType = EScheduleTypeGetup;
  183. controller.eventListView = self;
  184. [self pushViewController:controller animated:YES];
  185. }
  186. else if(schedule.mType == EScheduleTypeSleep)
  187. {
  188. [MobClick event:@"ClickEditTimeEventSleep"];
  189. TimeEventViewController *controller = (TimeEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"TimeEventVC"];
  190. controller.scheduelID = schedule.mID;
  191. controller.selectedDate = self.weekSelector.selectedDate;
  192. controller.scheduleType = EScheduleTypeSleep;
  193. controller.eventListView = self;
  194. [self pushViewController:controller animated:YES];
  195. }
  196. else if(schedule.mType == EScheduleTypeBirthday)
  197. {
  198. [MobClick event:@"ClickEditTimeEventBirthday"];
  199. BirthdayEventViewController *controller = (BirthdayEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"BirthdayEventVC"];
  200. controller.scheduelID = schedule.mID;
  201. controller.eventListView = self;
  202. [self pushViewController:controller animated:YES];
  203. }
  204. else if(schedule.mType == EScheduleTypeCustom)
  205. {
  206. [MobClick event:@"ClickEditTimeEventCustom"];
  207. CustomEventViewController *controller = (CustomEventViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"CustomEventVC"];
  208. controller.scheduelID = schedule.mID;
  209. controller.selectedDate = self.weekSelector.selectedDate;
  210. controller.eventListView = self;
  211. [self pushViewController:controller animated:YES];
  212. }
  213. }
  214. - (void)updateTitle:(NSDate *) date {
  215. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  216. dateFormatter.timeStyle = NSDateFormatterNoStyle;
  217. dateFormatter.dateStyle = kCFDateFormatterMediumStyle;
  218. self.title = [dateFormatter stringFromDate:date];
  219. }
  220. - (void)didReceiveMemoryWarning {
  221. [super didReceiveMemoryWarning];
  222. // Dispose of any resources that can be recreated.
  223. }
  224. #pragma mark - ASWeekSelectorViewDelegate
  225. - (void)weekSelector:(ASWeekSelectorView *)weekSelector willSelectDate:(NSDate *)date
  226. {
  227. [self updateTitle:date];
  228. scheduleArray = [[ScheduleManager sharedInstance] getScheduleForDate:date andChildID:[DataManager shared].mSelectChildModel.cid];
  229. [self.tableView reloadData];
  230. }
  231. /*
  232. #pragma mark - Navigation
  233. // In a storyboard-based application, you will often want to do a little preparation before navigation
  234. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  235. // Get the new view controller using [segue destinationViewController].
  236. // Pass the selected object to the new view controller.
  237. }
  238. */
  239. @end