CCControlCenterActivity.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. @interface CCControlCenterActivity ()
  12. {
  13. // Datasource
  14. CCSectionDataSourceActivity *_sectionDataSource;
  15. }
  16. @end
  17. @implementation CCControlCenterActivity
  18. #pragma --------------------------------------------------------------------------------------------
  19. #pragma mark ===== Init =====
  20. #pragma --------------------------------------------------------------------------------------------
  21. - (id)initWithCoder:(NSCoder *)aDecoder
  22. {
  23. if (self = [super initWithCoder:aDecoder]) {
  24. app.controlCenterActivity = self;
  25. }
  26. return self;
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. _sectionDataSource = [CCSectionDataSourceActivity new];
  31. // empty Data Source
  32. /*
  33. _tableView.delegate = self;
  34. _tableView.dataSource = self;
  35. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. _tableView.backgroundColor = [UIColor clearColor];
  37. */
  38. }
  39. // Apparirà
  40. - (void)viewWillAppear:(BOOL)animated
  41. {
  42. [super viewWillAppear:animated];
  43. [self reloadDatasource];
  44. }
  45. // E' arrivato
  46. - (void)viewDidAppear:(BOOL)animated
  47. {
  48. [super viewDidAppear:animated];
  49. }
  50. - (void)didReceiveMemoryWarning {
  51. [super didReceiveMemoryWarning];
  52. }
  53. #pragma --------------------------------------------------------------------------------------------
  54. #pragma mark - ==== Datasource ====
  55. #pragma --------------------------------------------------------------------------------------------
  56. - (void)reloadDatasource
  57. {
  58. // test
  59. if (app.activeAccount.length == 0)
  60. return;
  61. if (app.controlCenter.isOpen) {
  62. NSArray *records = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]];
  63. _sectionDataSource = [CCSectionActivity creataDataSourseSectionActivity:records activeAccount:app.activeAccount];
  64. if ([records count] == 0) {
  65. app.controlCenter.noRecord.text = NSLocalizedString(@"_no_activity_",nil);
  66. app.controlCenter.noRecord.hidden = NO;
  67. } else {
  68. app.controlCenter.noRecord.hidden = YES;
  69. }
  70. }
  71. [self.collectionView reloadData];
  72. [app updateApplicationIconBadgeNumber];
  73. }
  74. #pragma --------------------------------------------------------------------------------------------
  75. #pragma mark - ==== Table ====
  76. #pragma --------------------------------------------------------------------------------------------
  77. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  78. {
  79. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  80. }
  81. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  82. {
  83. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  84. }
  85. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  86. {
  87. if (kind == UICollectionElementKindSectionHeader) {
  88. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
  89. //headerView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  90. UILabel *titleLabel = (UILabel *)[headerView viewWithTag:100];
  91. titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
  92. titleLabel.text = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  93. return headerView;
  94. }
  95. return nil;
  96. }
  97. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  100. cell.backgroundColor = [UIColor clearColor];
  101. NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  102. TableActivity *activity = [metadatasForKey objectAtIndex:indexPath.row];
  103. return cell;
  104. }
  105. @end