123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- //
- // CCFavorites.m
- // Crypto Cloud Technology Nextcloud
- //
- // Created by Marino Faggiana on 16/01/17.
- // Copyright (c) 2017 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- #import "CCFavorites.h"
- #import "AppDelegate.h"
- #import "CCSynchronize.h"
- #import "NCBridgeSwift.h"
- @interface CCFavorites () <CCActionsDeleteDelegate, CCActionsSettingFavoriteDelegate>
- {
- NSArray *_dataSource;
- BOOL _reloadDataSource;
-
- CCHud *_hudDeterminate;
- }
- @end
- @implementation CCFavorites
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
-
- app.activeFavorites = self;
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // Custom Cell
- [self.tableView registerNib:[UINib nibWithNibName:@"CCFavoritesCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
- // dataSource
- _dataSource = [NSMutableArray new];
-
- // Metadata
- _metadata = [tableMetadata new];
-
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
- self.tableView.separatorColor = [NCBrandColor sharedInstance].seperator;
- self.tableView.emptyDataSetDelegate = self;
- self.tableView.emptyDataSetSource = self;
- self.tableView.delegate = self;
-
- // calculate _serverUrl
- if (!_serverUrl)
- _serverUrl = nil;
-
- // Title
- if (_titleViewControl)
- self.title = _titleViewControl;
- else
- self.title = NSLocalizedString(@"_favorites_", nil);
- }
- // Apparirà
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // Color
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- // Plus Button
- [app plusButtonVisibile:true];
-
- [self reloadDatasource];
- }
- - (void)changeTheming
- {
- if (self.isViewLoaded && self.view.window)
- [app changeTheming:self];
-
- // Reload Table View
- [self.tableView reloadData];
- }
- - (void)triggerProgressTask:(NSNotification *)notification
- {
- NSDictionary *dict = notification.userInfo;
- float progress = [[dict valueForKey:@"progress"] floatValue];
-
- if (progress == 0)
- [self.navigationController cancelCCProgress];
- else
- [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== DZNEmptyDataSetSource ====
- #pragma --------------------------------------------------------------------------------------------
- - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIColor whiteColor];
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIImage imageNamed:@"favoriteNoFiles"];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_favorite_no_files_", nil)];
-
- NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_favorite_view_", nil)];
-
- NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
- paragraph.lineBreakMode = NSLineBreakByWordWrapping;
- paragraph.alignment = NSTextAlignmentCenter;
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Delete <delegate> =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- NSLog(@"[LOG] Delete error %@", message);
- }
- - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
- {
- [self reloadDatasource];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Favorite <delegate> =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- NSLog(@"[LOG] Remove Favorite error %@", message);
- }
- - (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
- {
- [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadataNet.fileID favorite:[metadataNet.options boolValue]];
-
- [self reloadDatasource];
- }
- - (void)readListingFavorites
- {
- // test
- if (app.activeAccount.length == 0)
- return;
-
- // verify if is already in progress selectorDownloadSynchronize
- if ([[app verifyExistsInQueuesDownloadSelector:selectorDownloadSynchronize] count] > 0)
- return;
-
- [[CCActions sharedInstance] listingFavorites:@"" delegate:self];
- }
- - (void)addFavoriteFolder:(NSString *)serverUrl
- {
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
- if (!directoryID) return;
-
- NSString *selector;
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionReadFolder;
- metadataNet.directoryID = directoryID;
-
- if ([CCUtility getFavoriteOffline])
- selector = selectorReadFolderWithDownload;
- else
- selector = selectorReadFolder;
-
- metadataNet.selector = selector;
- metadataNet.serverUrl = serverUrl;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:[CCSynchronize sharedSynchronize] metadataNet:metadataNet];
- }
- - (void)listingFavoritesSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas
- {
- // verify active user
- tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
-
- if (![record.account isEqualToString:metadataNet.account])
- return;
-
- NSString *father = @"";
- NSMutableArray *filesEtag = [NSMutableArray new];
-
- for (tableMetadata *metadata in metadatas) {
-
- // type of file
- NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
-
- // do not insert cryptated favorite file
- if (typeFilename == k_metadataTypeFilenameCrypto || typeFilename == k_metadataTypeFilenamePlist)
- continue;
-
- // insert for test NOT favorite
- [filesEtag addObject:metadata.fileID];
-
- // Get ServerUrl
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
-
- if (![serverUrl containsString:father]) {
-
- if (metadata.directory) {
-
- NSString *selector;
-
- if ([CCUtility getFavoriteOffline])
- selector = selectorReadFolderWithDownload;
- else
- selector = selectorReadFolder;
-
- [[CCSynchronize sharedSynchronize] synchronizedFolder:serverUrl selector:selector];
-
- } else {
-
- if ([CCUtility getFavoriteOffline])
- [[CCSynchronize sharedSynchronize] synchronizedFile:metadata selector:selectorReadFileWithDownload];
- else
- [[CCSynchronize sharedSynchronize] synchronizedFile:metadata selector:selectorReadFile];
- }
-
- father = serverUrl;
- }
- }
-
- // Verify remove favorite
- NSArray *allRecordFavorite = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND favorite = true", app.activeAccount] sorted:nil ascending:NO];
-
- for (tableMetadata *metadata in allRecordFavorite)
- if (![filesEtag containsObject:metadata.fileID])
- [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadata.fileID favorite:NO];
-
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }
- - (void)listingFavoritesFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- NSLog(@"Read Favorites Failure");
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download Thumbnail <Delegate> ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
- {
- [self reloadDatasource];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download <Delegate> ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
- {
- _metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-
- if ([_metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
-
- //[self performSelector:@selector(unZipFile:) withObject:_metadata.fileID];
- [self openWith:_metadata];
-
- } else if ([_metadata.typeFile isEqualToString: k_metadataTypeFile_unknown]) {
-
- [self openWith:_metadata];
-
- } else {
-
- if ([self shouldPerformSegue])
- [self performSegueWithIdentifier:@"segueDetail" sender:self];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== menu =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)openModel:(tableMetadata *)metadata
- {
- UIViewController *viewController;
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- if (serverUrl) {
-
- if ([metadata.model isEqualToString:@"cartadicredito"])
- viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"bancomat"])
- viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"contocorrente"])
- viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"accountweb"])
- viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"patenteguida"])
- viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"cartaidentita"])
- viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"passaporto"])
- viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- if ([metadata.model isEqualToString:@"note"]) {
-
- viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [self presentViewController:navigationController animated:YES completion:nil];
-
- } else {
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- }
- }
- - (void)openWith:(tableMetadata *)metadata
- {
- NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
-
- [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
- [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
-
- NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
-
- _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
- _docController.delegate = self;
-
- [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
- }
- }
- - (void)requestDeleteMetadata:(tableMetadata *)metadata indexPath:(NSIndexPath *)indexPath
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
- [self reloadDatasource];
- }]];
-
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }]];
-
- alertController.popoverPresentationController.sourceView = self.view;
- alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [alertController.view layoutIfNeeded];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (void)requestMoreMetadata:(tableMetadata *)metadata indexPath:(NSIndexPath *)indexPath
- {
- UIImage *iconHeader;
-
- metadata = [_dataSource objectAtIndex:indexPath.row];
-
- AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
-
- actionSheet.animationDuration = 0.2;
-
- actionSheet.blurRadius = 0.0f;
- actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
-
- actionSheet.buttonHeight = 50.0;
- actionSheet.cancelButtonHeight = 50.0f;
- actionSheet.separatorHeight = 5.0f;
-
- actionSheet.automaticallyTintButtonImages = @(NO);
-
- actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].cryptocloud };
- actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
- actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].brand };
- actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
-
- actionSheet.separatorColor = [NCBrandColor sharedInstance].seperator;
- actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
-
- // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
-
- iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
-
- } else {
-
- if (metadata.directory)
- iconHeader = [CCGraphics changeThemingColorImage:[UIImage imageNamed:metadata.iconName] color:[NCBrandColor sharedInstance].brand];
- else
- iconHeader = [UIImage imageNamed:metadata.iconName];
- }
-
- [actionSheet addButtonWithTitle: metadata.fileNamePrint image: iconHeader backgroundColor: [NCBrandColor sharedInstance].tabBar height: 50.0 type: AHKActionSheetButtonTypeDisabled handler: nil
- ];
- // Share
- if (_metadata.cryptated == NO) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
-
- [app.activeMain openWindowShare:metadata];
- }];
- }
- // NO Directory - NO Template
- if (metadata.directory == NO && [metadata.type isEqualToString:k_metadataType_template] == NO) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetOpenIn"] color:[NCBrandColor sharedInstance].brand] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
- [self.tableView setEditing:NO animated:YES];
- [self openWith:metadata];
- }];
- }
-
- [actionSheet show];
- }
- - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
- {
- CGPoint location = [tapGesture locationInView:self.tableView];
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- tableMetadata *metadata = [_dataSource objectAtIndex:indexPath.row];
- if (metadata)
- [app.activeMain openWindowShare:metadata];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Swipe Tablet -> menu =====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
- {
- return YES;
- }
- - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
- {
- NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
-
- if (direction == MGSwipeDirectionRightToLeft) {
-
- // Delete
- if (index == 0)
- [self requestDeleteMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
-
- // More
- if (index == 1)
- [self requestMoreMetadata:[_dataSource objectAtIndex:indexPath.row] indexPath:indexPath];
- }
-
- if (direction == MGSwipeDirectionLeftToRight) {
-
- tableMetadata *metadata = [_dataSource objectAtIndex:indexPath.row];
- [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
- }
-
- return YES;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Table ====
- #pragma --------------------------------------------------------------------------------------------
- - (tableMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
- {
- tableMetadata *metadata = [_dataSource objectAtIndex:indexPath.row];
-
- return metadata;
- }
- - (void)readFolder:(NSString *)serverUrl
- {
- [self reloadDatasource];
- }
- - (void)reloadDatasource
- {
- NSMutableArray *metadatas = [NSMutableArray new];
- NSArray *recordsTableMetadata ;
-
- NSString *sorted = [CCUtility getOrderSettings];
- if ([sorted isEqualToString:@"fileName"])
- sorted = @"fileNamePrint";
-
- if (!_serverUrl) {
-
- recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND favorite = true", app.activeAccount] sorted:sorted ascending:[CCUtility getAscendingSettings]];
-
- } else {
-
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
-
- if (directoryID)
- recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@", app.activeAccount, directoryID] sorted:sorted ascending:[CCUtility getAscendingSettings]];
- }
-
- CCSectionDataSourceMetadata *sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil activeAccount:app.activeAccount];
-
- NSArray *fileIDs = [sectionDataSource.sectionArrayRow objectForKey:@"_none_"];
- for (NSString *fileID in fileIDs)
- [metadatas addObject:[sectionDataSource.allRecordsDataSource objectForKey:fileID]];
-
- _dataSource = [NSArray arrayWithArray:metadatas];
-
- [self.tableView reloadData];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 60;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_dataSource count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CCFavoritesCell *cell = (CCFavoritesCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
- tableMetadata *metadata;
-
- // variable base
- cell.delegate = self;
- cell.indexPath = indexPath;
-
- // separator
- cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
-
- // Initialize
- cell.status.image = nil;
- cell.favorite.image = nil;
- cell.local.image = nil;
- cell.shared.image = nil;
-
- // change color selection
- UIView *selectionColor = [[UIView alloc] init];
- selectionColor.backgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- cell.selectedBackgroundView = selectionColor;
-
- metadata = [_dataSource objectAtIndex:indexPath.row];
-
- // favorite
- if (_serverUrl == nil)
- cell.favorite.image = [UIImage imageNamed:@"favorite"];
-
- // encrypted color
- if (metadata.cryptated) {
- cell.labelTitle.textColor = [NCBrandColor sharedInstance].cryptocloud;
- } else {
- cell.labelTitle.textColor = [UIColor blackColor];
- }
-
- // filename
- cell.labelTitle.text = metadata.fileNamePrint;
- cell.labelInfoFile.text = @"";
-
- // Shared
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if (!serverUrl)
- return cell;
- NSString *shareLink = [app.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- // Immage
- if (metadata.directory) {
-
- if ([shareLink length] > 0) {
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_public"] color:[NCBrandColor sharedInstance].brand];
- } else if ([shareUserAndGroup length] > 0) {
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_shared_with_me"] color:[NCBrandColor sharedInstance].brand];
- } else {
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:metadata.iconName] color:[NCBrandColor sharedInstance].brand];
- }
-
- } else {
-
- if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
-
- if ([shareLink length] > 0)
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"shareLink"] color:[NCBrandColor sharedInstance].brand];
- else
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
- [tap setNumberOfTapsRequired:1];
- cell.shared.userInteractionEnabled = YES;
- [cell.shared addGestureRecognizer:tap];
- }
-
- cell.file.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
-
- if (cell.file.image == nil) {
-
- cell.file.image = [UIImage imageNamed:metadata.iconName];
-
- if (metadata.thumbnailExists)
- [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
- }
- }
-
- // it's encrypted ???
- if (metadata.cryptated && [metadata.type isEqualToString: k_metadataType_template] == NO)
- cell.status.image = [UIImage imageNamed:@"lock"];
-
- // text and length
- if (metadata.directory) {
-
- cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
- //cell.accessoryType = UITableViewCellAccessoryNone;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
- } else {
-
- NSString *date = [CCUtility dateDiff:metadata.date];
- NSString *length = [CCUtility transformedSize:metadata.size];
-
- if ([metadata.type isEqualToString: k_metadataType_template])
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
-
- if ([metadata.type isEqualToString: k_metadataType_file]) {
-
- BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
-
- if (fileExists)
- cell.local.image = [UIImage imageNamed:@"local"];
- else
- cell.local.image = nil;
-
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", date, length];
- }
-
- cell.accessoryType = UITableViewCellAccessoryNone;
-
- }
-
- // ======== MGSwipe ========
-
- //configure left buttons : ONLY Root Favorites : Remove file/folder Favorites
-
- if (_serverUrl == nil) {
- cell.leftButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_unfavorite_", nil)] icon:[UIImage imageNamed:@"swipeUnfavorite"] backgroundColor:[UIColor colorWithRed:242.0/255.0 green:220.0/255.0 blue:132.0/255.0 alpha:1.000]]];
- cell.leftExpansion.buttonIndex = 0;
- cell.leftExpansion.fillOnTrigger = NO;
-
- //centerIconOverText
- MGSwipeButton *favoriteButton = (MGSwipeButton *)[cell.leftButtons objectAtIndex:0];
- [favoriteButton centerIconOverText];
- }
-
- //configure right buttons
- cell.rightButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_delete_", nil)] icon:[UIImage imageNamed:@"swipeDelete"] backgroundColor:[UIColor redColor]], [MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_more_", nil)] icon:[UIImage imageNamed:@"swipeMore"] backgroundColor:[UIColor lightGrayColor]]];
- cell.rightSwipeSettings.transition = MGSwipeTransitionBorder;
-
- //centerIconOverText
- MGSwipeButton *deleteButton = (MGSwipeButton *)[cell.rightButtons objectAtIndex:0];
- MGSwipeButton *moreButton = (MGSwipeButton *)[cell.rightButtons objectAtIndex:1];
- [deleteButton centerIconOverText];
- [moreButton centerIconOverText];
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // deselect row
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- _metadata = [self setSelfMetadataFromIndexPath:indexPath];
-
- // if is in download [do not touch]
- if ([_metadata.session length] > 0 && [_metadata.session containsString:@"download"])
- return;
-
- // File
- if (([_metadata.type isEqualToString: k_metadataType_file]) && _metadata.directory == NO) {
-
- // File do not exists
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- if (serverUrl) {
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
-
- [self downloadFileSuccess:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:nil];
-
- } else {
-
- [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
- }
- }
- }
-
- // Model
- if ([self.metadata.type isEqualToString: k_metadataType_template])
- [self openModel:self.metadata];
-
- // Directory
- if (_metadata.directory)
- [self performSegueDirectoryWithControlPasscode];
- }
- -(void)performSegueDirectoryWithControlPasscode
- {
- CCFavorites *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCFavorites"];
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- if (serverUrl) {
-
- vc.serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
- vc.titleViewControl = _metadata.fileNamePrint;
-
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Navigation ====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)shouldPerformSegue
- {
- // if i am in background -> exit
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
-
- // if i am not window -> exit
- if (self.view.window == NO)
- return NO;
-
- // Collapsed but i am in detail -> exit
- if (self.splitViewController.isCollapsed)
- if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
-
- // Video in run -> exit
- if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
-
- return YES;
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- id viewController = segue.destinationViewController;
-
- if ([viewController isKindOfClass:[UINavigationController class]]) {
- UINavigationController *nav = viewController;
- _detailViewController = (CCDetail *)nav.topViewController;
- } else {
- _detailViewController = segue.destinationViewController;
- }
-
- NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
-
- for (tableMetadata *metadata in _dataSource) {
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
- [allRecordsDataSourceImagesVideos addObject:metadata];
- }
-
- _detailViewController.metadataDetail = _metadata;
- _detailViewController.dateFilterQuery = nil;
- _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
-
- [_detailViewController setTitle:_metadata.fileNamePrint];
- }
- @end
|