CCControlCenterActivity.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // CCControlCenterActivity.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/03/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. #import "CCControlCenterActivity.h"
  9. #import "AppDelegate.h"
  10. #import "CCSection.h"
  11. #define fontSizeData [UIFont systemFontOfSize:16]
  12. #define fontSizeAction [UIFont systemFontOfSize:15]
  13. #define fontSizeNote [UIFont systemFontOfSize:14]
  14. @interface CCControlCenterActivity ()
  15. {
  16. // Datasource
  17. NSArray *_sectionDataSource;
  18. }
  19. @end
  20. @implementation CCControlCenterActivity
  21. #pragma --------------------------------------------------------------------------------------------
  22. #pragma mark ===== Init =====
  23. #pragma --------------------------------------------------------------------------------------------
  24. - (id)initWithCoder:(NSCoder *)aDecoder
  25. {
  26. if (self = [super initWithCoder:aDecoder]) {
  27. app.controlCenterActivity = self;
  28. }
  29. return self;
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. _sectionDataSource = [NSArray new];
  34. [self reloadDatasource];
  35. }
  36. // Apparirà
  37. - (void)viewWillAppear:(BOOL)animated
  38. {
  39. [super viewWillAppear:animated];
  40. app.controlCenter.labelMessageNoRecord.hidden = YES;
  41. }
  42. // E' arrivato
  43. - (void)viewDidAppear:(BOOL)animated
  44. {
  45. [super viewDidAppear:animated];
  46. [self reloadDatasource];
  47. }
  48. - (void)didReceiveMemoryWarning {
  49. [super didReceiveMemoryWarning];
  50. }
  51. #pragma --------------------------------------------------------------------------------------------
  52. #pragma mark - ==== Datasource ====
  53. #pragma --------------------------------------------------------------------------------------------
  54. - (void)reloadDatasource
  55. {
  56. // test
  57. if (app.activeAccount.length == 0)
  58. return;
  59. if (app.controlCenter.isOpen) {
  60. //_sectionDataSource = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (idActivity != 0)", app.activeAccount]];
  61. _sectionDataSource = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]];
  62. if ([[app.controlCenter getActivePage] isEqualToString:k_pageControlCenterActivity]) {
  63. if ([_sectionDataSource count] == 0) {
  64. app.controlCenter.labelMessageNoRecord.text = NSLocalizedString(@"_no_activity_",nil);
  65. app.controlCenter.labelMessageNoRecord.hidden = NO;
  66. } else {
  67. app.controlCenter.labelMessageNoRecord.hidden = YES;
  68. }
  69. }
  70. }
  71. [self.collectionView reloadData];
  72. }
  73. #pragma --------------------------------------------------------------------------------------------
  74. #pragma mark - ==== Table ====
  75. #pragma --------------------------------------------------------------------------------------------
  76. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  77. {
  78. return [_sectionDataSource count];
  79. }
  80. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  81. {
  82. /*
  83. TableActivity *activity = [_sectionDataSource objectAtIndex:section];
  84. if ([activity.file length] > 0)
  85. return 1;
  86. else
  87. return 0;
  88. */
  89. return 0;
  90. }
  91. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  92. {
  93. TableActivity *activity = [_sectionDataSource objectAtIndex:section];
  94. UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, collectionView.frame.size.width , CGFLOAT_MAX)];
  95. noteLabel.numberOfLines = 0;
  96. [noteLabel setFont:fontSizeNote];
  97. noteLabel.text = activity.note;
  98. noteLabel.lineBreakMode = NSLineBreakByWordWrapping;
  99. int heighNoteLabel = [self getLabelHeight:noteLabel];
  100. int heightView = 80 + heighNoteLabel + (heighNoteLabel/5);
  101. if (heightView < 80)
  102. heightView = 80;
  103. return CGSizeMake(collectionView.frame.size.width, heightView);
  104. }
  105. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  106. {
  107. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
  108. TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.section];
  109. NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:activity.date];
  110. NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];
  111. UILabel *dateLabel = (UILabel *)[headerView viewWithTag:100];
  112. UILabel *actionLabel = (UILabel *)[headerView viewWithTag:101];
  113. UILabel *noteLabel = (UILabel *)[headerView viewWithTag:102];
  114. UIImageView *typeImage = (UIImageView *) [headerView viewWithTag:103];
  115. [dateLabel setFont:fontSizeData];
  116. dateLabel.textColor = [UIColor colorWithRed:130.0/255.0 green:130.0/255.0 blue:130.0/255.0 alpha:1.0];
  117. dateLabel.text = [CCUtility getTitleSectionDate:date];
  118. [actionLabel setFont:fontSizeAction];
  119. actionLabel.text = [NSString stringWithFormat:@"%@ %@", activity.action, activity.file];
  120. if ([activity.type length] == 0 || [activity.type isEqualToString:k_activityTypeInfo]) {
  121. actionLabel.textColor = COLOR_BRAND;
  122. typeImage.image = [UIImage imageNamed:@"activityTypeInfo"];
  123. }
  124. if ([activity.type isEqualToString:k_activityTypeSucces]) {
  125. actionLabel.textColor = [UIColor greenColor];
  126. typeImage.image = [UIImage imageNamed:@"activityTypeSuccess"];
  127. }
  128. if ([activity.type isEqualToString:k_activityTypeFailure]) {
  129. actionLabel.textColor = [UIColor redColor];
  130. typeImage.image = [UIImage imageNamed:@"activityTypeFailure"];
  131. }
  132. [noteLabel setFont:fontSizeNote];
  133. noteLabel.textColor = COLOR_TEXT_ANTHRACITE;
  134. noteLabel.numberOfLines = 0;
  135. noteLabel.lineBreakMode = NSLineBreakByWordWrapping;
  136. noteLabel.text = activity.note;
  137. //headerView.backgroundColor = [UIColor blueColor];
  138. return headerView;
  139. }
  140. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  141. {
  142. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  143. cell.backgroundColor = [UIColor clearColor];
  144. TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.section];
  145. NSString *dir = [activity.file stringByDeletingLastPathComponent];
  146. NSString *fileName = [activity.file lastPathComponent];
  147. if ([dir length] > 0 && [fileName length] > 0) {
  148. }
  149. return cell;
  150. }
  151. #pragma --------------------------------------------------------------------------------------------
  152. #pragma mark - ==== Utility ====
  153. #pragma --------------------------------------------------------------------------------------------
  154. - (CGFloat)getLabelHeight:(UILabel*)label
  155. {
  156. CGSize constraint = CGSizeMake(self.collectionView.frame.size.width, CGFLOAT_MAX);
  157. NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
  158. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  159. NSDictionary *attributes = @{NSFontAttributeName : label.font, NSParagraphStyleAttributeName: paragraph};
  160. NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
  161. CGSize boundingBox = [label.text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:context].size;
  162. CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
  163. return size.height;
  164. }
  165. @end