// // CCControlCenterActivity.m // Nextcloud // // Created by Marino Faggiana on 01/03/17. // Copyright © 2017 TWS. All rights reserved. // #import "CCControlCenterActivity.h" #import "AppDelegate.h" #import "CCControlCenterActivityCell.h" @interface CCControlCenterActivity () { // Datasource NSArray *_sectionDataSource; } @end @implementation CCControlCenterActivity #pragma -------------------------------------------------------------------------------------------- #pragma mark ===== Init ===== #pragma -------------------------------------------------------------------------------------------- - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { app.controlCenterActivity = self; } return self; } - (void)viewDidLoad { [super viewDidLoad]; _sectionDataSource = [NSArray new]; // Custom Cell [_tableView registerNib:[UINib nibWithNibName:@"CCControlCenterActivityCell" bundle:nil] forCellReuseIdentifier:@"ControlCenterActivityCell"]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.backgroundColor = [UIColor clearColor]; } // Apparirà - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self reloadDatasource]; } // E' arrivato - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma -------------------------------------------------------------------------------------------- #pragma mark - ==== Datasource ==== #pragma -------------------------------------------------------------------------------------------- - (void)reloadDatasource { // test if (app.activeAccount.length == 0) return; if (app.controlCenter.isOpen) { _sectionDataSource = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]]; if ([_sectionDataSource count] == 0) { app.controlCenter.noRecord.text = NSLocalizedString(@"_no_recent_",nil); app.controlCenter.noRecord.hidden = NO; } else { app.controlCenter.noRecord.hidden = YES; } } [_tableView reloadData]; [app updateApplicationIconBadgeNumber]; } #pragma -------------------------------------------------------------------------------------------- #pragma mark - ==== Table ==== #pragma -------------------------------------------------------------------------------------------- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_sectionDataSource count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CCControlCenterActivityCell *cell = (CCControlCenterActivityCell *)[tableView dequeueReusableCellWithIdentifier:@"ControlCenterActivityCell" forIndexPath:indexPath]; cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.row]; cell.labelTitle.text = activity.subject; cell.labelInfoFile.text = [CCUtility dateDiff:activity.date]; return cell; } @end