CCControlCenterActivity.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 == %@)", 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. return 0;
  82. }
  83. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  84. {
  85. TableActivity *activity = [_sectionDataSource objectAtIndex:section];
  86. UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, collectionView.frame.size.width , CGFLOAT_MAX)];
  87. subjectLabel.numberOfLines = 0;
  88. [subjectLabel setFont:fontSizeSubject];
  89. subjectLabel.text = [activity.subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  90. subjectLabel.lineBreakMode = NSLineBreakByWordWrapping;
  91. int heightView = 50 + [self getLabelHeight:subjectLabel];
  92. if (heightView < 60)
  93. heightView = 60;
  94. return CGSizeMake(collectionView.frame.size.width, heightView);
  95. }
  96. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  97. {
  98. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
  99. TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.section];
  100. NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:activity.date];
  101. NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];
  102. UILabel *dataLabel = (UILabel *)[headerView viewWithTag:100];
  103. UILabel *subjectLabel = (UILabel *)[headerView viewWithTag:101];
  104. UIImageView *typeImage = (UIImageView *) [headerView viewWithTag:102];
  105. dataLabel.textColor = [UIColor colorWithRed:130.0/255.0 green:130.0/255.0 blue:130.0/255.0 alpha:1.0];
  106. dataLabel.text = [CCUtility getTitleSectionDate:date];
  107. [dataLabel setFont:fontSizeData];
  108. if ([activity.type length] == 0 )
  109. typeImage.image = [UIImage imageNamed:image_user];
  110. subjectLabel.textColor = COLOR_TEXT_ANTHRACITE;
  111. subjectLabel.numberOfLines = 0;
  112. [subjectLabel setFont:fontSizeSubject];
  113. subjectLabel.text = activity.subject;
  114. subjectLabel.lineBreakMode = NSLineBreakByWordWrapping;
  115. //headerView.backgroundColor = [UIColor blueColor];
  116. return headerView;
  117. }
  118. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  121. cell.backgroundColor = [UIColor clearColor];
  122. return cell;
  123. }
  124. #pragma --------------------------------------------------------------------------------------------
  125. #pragma mark - ==== Utility ====
  126. #pragma --------------------------------------------------------------------------------------------
  127. - (CGFloat)getLabelHeight:(UILabel*)label
  128. {
  129. CGSize constraint = CGSizeMake(self.collectionView.frame.size.width, CGFLOAT_MAX);
  130. NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
  131. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  132. NSDictionary *attributes = @{NSFontAttributeName : label.font, NSParagraphStyleAttributeName: paragraph};
  133. NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
  134. CGSize boundingBox = [label.text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:context].size;
  135. CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
  136. return size.height;
  137. }
  138. @end