CCControlCenterActivity.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "CCControlCenterActivityCell.h"
  11. @interface CCControlCenterActivity ()
  12. {
  13. // Datasource
  14. NSArray *_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 = [NSArray new];
  31. // Custom Cell
  32. [_tableView registerNib:[UINib nibWithNibName:@"CCControlCenterActivityCell" bundle:nil] forCellReuseIdentifier:@"ControlCenterActivityCell"];
  33. _tableView.delegate = self;
  34. _tableView.dataSource = self;
  35. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. _tableView.backgroundColor = [UIColor clearColor];
  37. }
  38. // Apparirà
  39. - (void)viewWillAppear:(BOOL)animated
  40. {
  41. [super viewWillAppear:animated];
  42. [self reloadDatasource];
  43. }
  44. // E' arrivato
  45. - (void)viewDidAppear:(BOOL)animated
  46. {
  47. [super viewDidAppear:animated];
  48. }
  49. - (void)didReceiveMemoryWarning {
  50. [super didReceiveMemoryWarning];
  51. }
  52. #pragma --------------------------------------------------------------------------------------------
  53. #pragma mark - ==== Datasource ====
  54. #pragma --------------------------------------------------------------------------------------------
  55. - (void)reloadDatasource
  56. {
  57. // test
  58. if (app.activeAccount.length == 0)
  59. return;
  60. if (app.controlCenter.isOpen) {
  61. _sectionDataSource = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]];
  62. if ([_sectionDataSource count] == 0) {
  63. app.controlCenter.noRecord.text = NSLocalizedString(@"_no_recent_",nil);
  64. app.controlCenter.noRecord.hidden = NO;
  65. } else {
  66. app.controlCenter.noRecord.hidden = YES;
  67. }
  68. }
  69. [_tableView reloadData];
  70. [app updateApplicationIconBadgeNumber];
  71. }
  72. #pragma --------------------------------------------------------------------------------------------
  73. #pragma mark - ==== Table ====
  74. #pragma --------------------------------------------------------------------------------------------
  75. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. return 50;
  78. }
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  80. {
  81. return 1;
  82. }
  83. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  84. {
  85. return [_sectionDataSource count];
  86. }
  87. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  88. {
  89. CCControlCenterActivityCell *cell = (CCControlCenterActivityCell *)[tableView dequeueReusableCellWithIdentifier:@"ControlCenterActivityCell" forIndexPath:indexPath];
  90. cell.backgroundColor = [UIColor clearColor];
  91. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  92. TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.row];
  93. cell.labelTitle.text = activity.subject;
  94. cell.labelInfoFile.text = [CCUtility dateDiff:activity.date];
  95. return cell;
  96. }
  97. @end