CCControlCenterActivity.m 7.0 KB

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