CCMain.m 197 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087
  1. //
  2. // CCMain.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import <JDStatusBarNotification/JDStatusBarNotification.h>
  24. #import "CCMain.h"
  25. #import "AppDelegate.h"
  26. #import "CCSynchronize.h"
  27. #import "OCActivity.h"
  28. #import "OCNotifications.h"
  29. #import "OCNotificationsAction.h"
  30. #import "OCFrameworkConstants.h"
  31. #import "OCCapabilities.h"
  32. #import "NCAutoUpload.h"
  33. #import "NCBridgeSwift.h"
  34. #import "NCNetworkingEndToEnd.h"
  35. #import "PKDownloadButton.h"
  36. @interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, NCSelectDelegate, UITextFieldDelegate>
  37. {
  38. AppDelegate *appDelegate;
  39. BOOL _isRoot;
  40. BOOL _isViewDidLoad;
  41. NSMutableDictionary *_selectedocIdsMetadatas;
  42. NSUInteger _numSelectedocIdsMetadatas;
  43. UIImageView *_imageTitleHome;
  44. NSUInteger _failedAttempts;
  45. NSDate *_lockUntilDate;
  46. UIRefreshControl *refreshControl;
  47. CCHud *_hud;
  48. // Datasource
  49. CCSectionDataSourceMetadata *sectionDataSource;
  50. NSDate *_dateReadDataSource;
  51. // Search
  52. BOOL _isSearchMode;
  53. NSString *_searchFileName;
  54. NSMutableArray *_searchResultMetadatas;
  55. NSString *_noFilesSearchTitle;
  56. NSString *_noFilesSearchDescription;
  57. NSTimer *_timerWaitInput;
  58. // Automatic Upload Folder
  59. NSString *_autoUploadFileName;
  60. NSString *_autoUploadDirectory;
  61. // Folder
  62. BOOL _loadingFolder;
  63. tableMetadata *_metadataFolder;
  64. }
  65. @end
  66. @implementation CCMain
  67. #pragma --------------------------------------------------------------------------------------------
  68. #pragma mark ===== Init =====
  69. #pragma --------------------------------------------------------------------------------------------
  70. - (id)initWithCoder:(NSCoder *)aDecoder
  71. {
  72. if (self = [super initWithCoder:aDecoder]) {
  73. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  74. appDelegate.activeMain = self;
  75. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
  76. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
  77. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
  78. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  79. }
  80. return self;
  81. }
  82. #pragma --------------------------------------------------------------------------------------------
  83. #pragma mark ===== View =====
  84. #pragma --------------------------------------------------------------------------------------------
  85. - (void)viewDidLoad
  86. {
  87. [super viewDidLoad];
  88. // init object
  89. self.metadata = [tableMetadata new];
  90. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  91. _selectedocIdsMetadatas = [NSMutableDictionary new];
  92. _isViewDidLoad = YES;
  93. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  94. _searchResultMetadatas = [NSMutableArray new];
  95. _searchFileName = @"";
  96. _noFilesSearchTitle = @"";
  97. _noFilesSearchDescription = @"";
  98. _cellFavouriteImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:[UIColor whiteColor]];
  99. _cellTrashImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor whiteColor]];
  100. // delegate
  101. self.tableView.delegate = self;
  102. self.tableView.tableFooterView = [UIView new];
  103. self.tableView.emptyDataSetDelegate = self;
  104. self.tableView.emptyDataSetSource = self;
  105. self.searchController.delegate = self;
  106. self.searchController.searchBar.delegate = self;
  107. // Register cell
  108. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  109. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  110. // long press recognizer TableView
  111. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  112. [self.tableView addGestureRecognizer:longPressRecognizer];
  113. // Pull-to-Refresh
  114. [self createRefreshControl];
  115. // Register for 3D Touch Previewing if available
  116. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
  117. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  118. }
  119. // reMenu Background
  120. _reMenuBackgroundView = [UIView new];
  121. _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  122. // if this is not Main (the Main uses inizializeMain)
  123. if (_isRoot == NO && appDelegate.activeAccount.length > 0) {
  124. // Read (File) Folder
  125. [self readFileReloadFolder];
  126. }
  127. // Title
  128. [self setTitle];
  129. // changeTheming
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  131. [self changeTheming];
  132. }
  133. - (void)viewWillAppear:(BOOL)animated
  134. {
  135. [super viewWillAppear:animated];
  136. // test
  137. if (appDelegate.activeAccount.length == 0)
  138. return;
  139. if (_isSelectedMode)
  140. [self setUINavigationBarSelected];
  141. else
  142. [self setUINavigationBarDefault];
  143. // If not editing mode remove _selectedocIds
  144. if (!self.tableView.editing)
  145. [_selectedocIdsMetadatas removeAllObjects];
  146. // Search Bar
  147. if ([CCUtility isFolderEncrypted:self.serverUrl account:appDelegate.activeAccount]) {
  148. [self searchEnabled:NO];
  149. } else {
  150. [self searchEnabled:YES];
  151. }
  152. // Get Shares
  153. appDelegate.shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount serverUrl:self.serverUrl];
  154. // Query data source
  155. if (!_isSearchMode) {
  156. [self queryDatasourceWithReloadData:YES serverUrl:self.serverUrl];
  157. }
  158. }
  159. - (void)viewDidAppear:(BOOL)animated
  160. {
  161. [super viewDidAppear:animated];
  162. // Active Main
  163. appDelegate.activeMain = self;
  164. // Test viewDidLoad
  165. if (_isViewDidLoad) {
  166. _isViewDidLoad = NO;
  167. } else {
  168. if (appDelegate.activeAccount.length > 0 && [_selectedocIdsMetadatas count] == 0) {
  169. // Read (file) Folder
  170. [self readFileReloadFolder];
  171. }
  172. }
  173. // Title
  174. [self setTitle];
  175. }
  176. - (void)viewWillDisappear:(BOOL)animated
  177. {
  178. [super viewWillDisappear:animated];
  179. [self closeAllMenu];
  180. }
  181. - (void)didReceiveMemoryWarning
  182. {
  183. [super didReceiveMemoryWarning];
  184. // Dispose of any resources that can be recreated.
  185. }
  186. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  187. {
  188. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  189. [self closeAllMenu];
  190. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  191. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  192. // Portrait
  193. } else {
  194. // Landscape
  195. }
  196. [self.tableView reloadData];
  197. }];
  198. }
  199. - (BOOL)prefersStatusBarHidden
  200. {
  201. return NO;
  202. }
  203. // detect scroll for remove keyboard in search mode
  204. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  205. {
  206. if (_isSearchMode && scrollView == self.tableView) {
  207. [self.searchController.searchBar endEditing:YES];
  208. }
  209. }
  210. - (void)changeTheming
  211. {
  212. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:false];
  213. // createImagesThemingColor
  214. [[NCMainCommon sharedInstance] createImagesThemingColor];
  215. // Refresh control
  216. refreshControl.tintColor = NCBrandColor.sharedInstance.brandText;
  217. refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand;
  218. // color searchbar
  219. self.searchController.searchBar.barTintColor = NCBrandColor.sharedInstance.brand;
  220. self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.brand;
  221. // color searchbbar button text (cancel)
  222. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  223. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  224. [searchButton setTitleColor:NCBrandColor.sharedInstance.brandText forState:UIControlStateNormal];
  225. }
  226. // color textview searchbbar
  227. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  228. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  229. searchTextView.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  230. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  231. }
  232. // Title
  233. [self setTitle];
  234. // Reload Table View
  235. [self tableViewReloadData];
  236. }
  237. #pragma --------------------------------------------------------------------------------------------
  238. #pragma mark ===== Initialization =====
  239. #pragma --------------------------------------------------------------------------------------------
  240. //
  241. // Callers :
  242. //
  243. // ChangeDefaultAccount (delegate)
  244. // Split : inizialize
  245. // Settings Advanced : removeAllFiles
  246. //
  247. - (void)initializeMain:(NSNotification *)notification
  248. {
  249. _dateReadDataSource = nil;
  250. // test
  251. if (appDelegate.activeAccount.length == 0)
  252. return;
  253. if ([appDelegate.listMainVC count] == 0 || _isRoot) {
  254. // This is Root home main add list
  255. appDelegate.homeMain = self;
  256. _isRoot = YES;
  257. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  258. [appDelegate.listMainVC setObject:self forKey:_serverUrl];
  259. // go Home
  260. [self.navigationController popToRootViewControllerAnimated:NO];
  261. // Remove search mode
  262. [self cancelSearchBar];
  263. // Clear error certificate
  264. [CCUtility setCertificateError:appDelegate.activeAccount error:NO];
  265. // Setting Theming
  266. [appDelegate settingThemingColorBrand];
  267. // Detail
  268. // If AVPlayer in play -> Stop
  269. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  270. [appDelegate.player pause];
  271. }
  272. for (UIView *view in [appDelegate.activeDetail.view subviews]) {
  273. if ([view isKindOfClass:[UIImageView class]] == NO) { // View Image Nextcloud
  274. [view removeFromSuperview];
  275. }
  276. }
  277. appDelegate.activeDetail.title = nil;
  278. // remove all Notification Messages
  279. [appDelegate.listOfNotifications removeAllObjects];
  280. // Not Photos Video in library ? then align and Init Auto Upload
  281. NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
  282. if ([recordsPhotoLibrary count] == 0) {
  283. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  284. }
  285. [[NCAutoUpload sharedInstance] initStateAutoUpload];
  286. NSLog(@"[LOG] Request Service Server Nextcloud");
  287. [[NCService sharedInstance] startRequestServicesServer];
  288. // Clear datasorce
  289. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  290. // Read this folder
  291. [self readFileReloadFolder];
  292. } else {
  293. // reload datasource
  294. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl ocId:nil action:k_action_NULL];
  295. }
  296. // Registeration push notification
  297. [appDelegate pushNotification];
  298. // Registeration domain File Provider
  299. if (@available(iOS 11, *) ) {
  300. [FileProviderDomain.sharedInstance registerDomain];
  301. }
  302. }
  303. #pragma --------------------------------------------------------------------------------------------
  304. #pragma mark ==== DZNEmptyDataSetSource ====
  305. #pragma --------------------------------------------------------------------------------------------
  306. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
  307. {
  308. if (_loadingFolder)
  309. return NO;
  310. else
  311. return YES;
  312. }
  313. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  314. {
  315. return NCBrandColor.sharedInstance.backgroundView;
  316. }
  317. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  318. {
  319. if (_isSearchMode)
  320. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"search"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  321. else
  322. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] width:300 height:300 color:NCBrandColor.sharedInstance.brandElement];
  323. }
  324. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
  325. {
  326. if (_loadingFolder && refreshControl.isRefreshing == NO) {
  327. UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  328. activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  329. activityView.color = NCBrandColor.sharedInstance.brandElement;
  330. [activityView startAnimating];
  331. return activityView;
  332. }
  333. return nil;
  334. }
  335. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  336. {
  337. NSString *text;
  338. if (_isSearchMode) {
  339. text = _noFilesSearchTitle;
  340. } else {
  341. text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
  342. }
  343. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  344. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  345. }
  346. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  347. {
  348. NSString *text;
  349. if (_isSearchMode) {
  350. text = _noFilesSearchDescription;
  351. } else {
  352. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
  353. }
  354. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  355. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  356. paragraph.alignment = NSTextAlignmentCenter;
  357. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  358. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  359. }
  360. #pragma --------------------------------------------------------------------------------------------
  361. #pragma mark ===== Text Field =====
  362. #pragma --------------------------------------------------------------------------------------------
  363. - (void)minCharTextFieldDidChange:(UITextField *)sender
  364. {
  365. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  366. if (alertController)
  367. {
  368. UITextField *fileName = alertController.textFields.firstObject;
  369. UIAlertAction *okAction = alertController.actions.lastObject;
  370. okAction.enabled = fileName.text.length > 0;
  371. }
  372. }
  373. - (void)textFieldDidBeginEditing:(UITextField *)textField
  374. {
  375. [CCUtility selectFileNameFrom:textField];
  376. }
  377. #pragma --------------------------------------------------------------------------------------------
  378. #pragma mark ===== Graphic Window =====
  379. #pragma --------------------------------------------------------------------------------------------
  380. - (void)createRefreshControl
  381. {
  382. refreshControl = [UIRefreshControl new];
  383. if (@available(iOS 10, *)) {
  384. _tableView.refreshControl = refreshControl;
  385. } else {
  386. [_tableView addSubview:refreshControl];
  387. }
  388. refreshControl.tintColor = NCBrandColor.sharedInstance.brandText;
  389. refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand;
  390. [refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
  391. }
  392. - (void)deleteRefreshControl
  393. {
  394. [refreshControl endRefreshing];
  395. for (UIView *subview in [_tableView subviews]) {
  396. if (subview == refreshControl)
  397. [subview removeFromSuperview];
  398. }
  399. if (@available(iOS 10, *)) {
  400. self.tableView.refreshControl = nil;
  401. }
  402. refreshControl = nil;
  403. }
  404. - (void)refreshControlTarget
  405. {
  406. [self readFolder:_serverUrl];
  407. // Actuate `Peek` feedback (weak boom)
  408. AudioServicesPlaySystemSound(1519);
  409. }
  410. - (void)setTitle
  411. {
  412. if (_isSelectedMode) {
  413. NSUInteger totali = [sectionDataSource.allRecordsDataSource count];
  414. NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
  415. self.navigationItem.titleView = nil;
  416. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
  417. } else {
  418. // we are in home : LOGO BRAND
  419. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  420. self.navigationItem.title = nil;
  421. UIImage *image = [self getImageLogoHome];
  422. _imageTitleHome = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; // IMAGE = 120 x 60
  423. _imageTitleHome.contentMode = UIViewContentModeScaleAspectFill;
  424. _imageTitleHome.translatesAutoresizingMaskIntoConstraints = NO;
  425. _imageTitleHome.image = image;
  426. // backbutton
  427. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
  428. [_imageTitleHome setUserInteractionEnabled:YES];
  429. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuLogo:)];
  430. [singleTap setNumberOfTapsRequired:1];
  431. [_imageTitleHome addGestureRecognizer:singleTap];
  432. self.navigationItem.titleView = _imageTitleHome;
  433. } else {
  434. self.navigationItem.title = _titleMain;
  435. self.navigationItem.titleView = nil;
  436. }
  437. }
  438. }
  439. - (UIImage *)getImageLogoHome
  440. {
  441. UIImage *image = [UIImage imageNamed:@"themingLogo"];
  442. if ([NCBrandOptions sharedInstance].use_themingLogo) {
  443. image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@-themingLogo.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl]]];
  444. if (image == nil) image = [UIImage imageNamed:@"themingLogo"];
  445. }
  446. if ([appDelegate.reachability isReachable] == NO) {
  447. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"nonetwork"] width:50 height:50 color:NCBrandColor.sharedInstance.icon];
  448. } else {
  449. return image;
  450. }
  451. }
  452. - (void)setUINavigationBarDefault
  453. {
  454. UIBarButtonItem *buttonMore, *buttonNotification;
  455. // =
  456. buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
  457. buttonMore.enabled = true;
  458. // <
  459. self.navigationController.navigationBar.hidden = NO;
  460. // Notification
  461. if ([appDelegate.listOfNotifications count] > 0) {
  462. buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"notification"] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
  463. buttonNotification.tintColor = NCBrandColor.sharedInstance.brandText;
  464. buttonNotification.enabled = true;
  465. }
  466. if (buttonNotification)
  467. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
  468. else
  469. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  470. self.navigationItem.leftBarButtonItem = nil;
  471. }
  472. - (void)setUINavigationBarSelected
  473. {
  474. UIImage *icon = [UIImage imageNamed:@"navigationControllerMenu"];
  475. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
  476. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
  477. self.navigationItem.leftBarButtonItem = leftButton;
  478. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  479. }
  480. - (void)cancelSelect
  481. {
  482. [self tableViewSelect:NO];
  483. [appDelegate.reSelectMenu close];
  484. }
  485. - (void)closeAllMenu
  486. {
  487. // close Menu
  488. [appDelegate.reSelectMenu close];
  489. [appDelegate.reMainMenu close];
  490. // Close Menu Logo
  491. [CCMenuAccount dismissMenu];
  492. }
  493. #pragma --------------------------------------------------------------------------------------------
  494. #pragma mark ===== Document Picker =====
  495. #pragma --------------------------------------------------------------------------------------------
  496. - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
  497. {
  498. NSLog(@"[LOG] Cancelled");
  499. }
  500. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
  501. {
  502. NSLog(@"[LOG] Cancelled");
  503. }
  504. - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
  505. {
  506. documentPicker.delegate = self;
  507. [self presentViewController:documentPicker animated:YES completion:nil];
  508. }
  509. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
  510. {
  511. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  512. NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
  513. __block NSError *error;
  514. [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
  515. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  516. NSString *fileName = [[NCUtility sharedInstance] createFileName:[url lastPathComponent] serverUrl:serverUrl account:appDelegate.activeAccount];
  517. NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
  518. NSData *data = [NSData dataWithContentsOfURL:newURL];
  519. if (data && error == nil) {
  520. if ([data writeToFile:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
  521. tableMetadata *metadataForUpload = [tableMetadata new];
  522. metadataForUpload.account = appDelegate.activeAccount;
  523. metadataForUpload.date = [NSDate new];
  524. metadataForUpload.ocId = ocId;
  525. metadataForUpload.fileName = fileName;
  526. metadataForUpload.fileNameView = fileName;
  527. metadataForUpload.serverUrl = serverUrl;
  528. metadataForUpload.session = k_upload_session;
  529. metadataForUpload.sessionSelector = selectorUploadFile;
  530. metadataForUpload.size = data.length;
  531. metadataForUpload.status = k_metadataStatusWaitUpload;
  532. // Check il file already exists
  533. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileName]];
  534. if (metadata) {
  535. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  536. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  537. // NO OVERWITE
  538. }];
  539. UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  540. // Remove record metadata
  541. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  542. // Add Medtadata for upload
  543. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  544. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  545. [appDelegate startLoadAutoDownloadUpload];
  546. }];
  547. [alertController addAction:cancelAction];
  548. [alertController addAction:overwriteAction];
  549. UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  550. alertWindow.rootViewController = [[UIViewController alloc]init];
  551. alertWindow.windowLevel = UIWindowLevelAlert + 1;
  552. [alertWindow makeKeyAndVisible];
  553. [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
  554. } else {
  555. // Add Medtadata for upload
  556. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  557. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  558. [appDelegate startLoadAutoDownloadUpload];
  559. }
  560. } else {
  561. [appDelegate messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  562. }
  563. } else {
  564. [appDelegate messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  565. }
  566. }];
  567. }
  568. }
  569. - (void)openImportDocumentPicker
  570. {
  571. UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
  572. documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
  573. documentProviderMenu.popoverPresentationController.sourceView = self.tabBarController.tabBar;
  574. documentProviderMenu.popoverPresentationController.sourceRect = self.tabBarController.tabBar.bounds;
  575. documentProviderMenu.delegate = self;
  576. [self presentViewController:documentProviderMenu animated:YES completion:nil];
  577. }
  578. #pragma --------------------------------------------------------------------------------------------
  579. #pragma mark ===== Assets Picker =====
  580. #pragma --------------------------------------------------------------------------------------------
  581. -(void)dismissFormUploadAssets
  582. {
  583. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  584. }
  585. - (void)openAssetsPickerController
  586. {
  587. NCPhotosPickerViewController *viewController = [[NCPhotosPickerViewController alloc] init:self];
  588. [viewController openPhotosPickerViewControllerWithPhAssets:^(NSArray<PHAsset *> * _Nonnull assets) {
  589. if (assets.count > 0) {
  590. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  591. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  592. NCCreateFormUploadAssets *form = [[NCCreateFormUploadAssets alloc] initWithServerUrl:serverUrl assets:(NSMutableArray *)assets cryptated:NO session:k_upload_session delegate:self];
  593. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
  594. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  595. [self presentViewController:navigationController animated:YES completion:nil];
  596. });
  597. }
  598. }];
  599. }
  600. #pragma --------------------------------------------------------------------------------------------
  601. #pragma mark ===== Save selected File =====
  602. #pragma --------------------------------------------------------------------------------------------
  603. - (void)saveToPhotoAlbum:(tableMetadata *)metadata
  604. {
  605. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
  606. PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
  607. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
  608. UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
  609. if (image)
  610. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  611. else
  612. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  613. }
  614. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
  615. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
  616. UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  617. } else {
  618. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  619. }
  620. }
  621. if (status != PHAuthorizationStatusAuthorized) {
  622. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
  623. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  624. [alertController addAction:okAction];
  625. [self presentViewController:alertController animated:YES completion:nil];
  626. }
  627. }
  628. - (void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  629. {
  630. if (error)
  631. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  632. else
  633. [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  634. }
  635. - (void)saveSelectedFiles
  636. {
  637. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  638. return;
  639. NSLog(@"[LOG] Start download selected files ...");
  640. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  641. NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  642. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  643. for (tableMetadata *metadata in metadatas) {
  644. if (metadata.directory == NO && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
  645. metadata.session = k_download_session;
  646. metadata.sessionError = @"";
  647. metadata.sessionSelector = selectorSave;
  648. metadata.status = k_metadataStatusWaitDownload;
  649. // Add Metadata for Download
  650. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  651. [appDelegate startLoadAutoDownloadUpload];
  652. }
  653. }
  654. [_hud hideHud];
  655. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  656. });
  657. [self tableViewSelect:NO];
  658. }
  659. #pragma --------------------------------------------------------------------------------------------
  660. #pragma mark ==== View Notification ====
  661. #pragma --------------------------------------------------------------------------------------------
  662. - (void)viewNotification
  663. {
  664. if ([appDelegate.listOfNotifications count] > 0) {
  665. CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
  666. [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
  667. [self presentViewController:notificationVC animated:YES completion:nil];
  668. }
  669. }
  670. #pragma mark -
  671. #pragma --------------------------------------------------------------------------------------------
  672. #pragma mark ===== Peek & Pop =====
  673. #pragma --------------------------------------------------------------------------------------------
  674. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  675. {
  676. CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];
  677. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
  678. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  679. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  680. if (cell) {
  681. previewingContext.sourceRect = cell.frame;
  682. CCPeekPop *viewController = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  683. viewController.metadata = metadata;
  684. viewController.imageFile = cell.file.image;
  685. viewController.showOpenIn = true;
  686. viewController.showShare = true;
  687. return viewController;
  688. }
  689. return nil;
  690. }
  691. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  692. {
  693. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  694. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  695. }
  696. #pragma --------------------------------------------------------------------------------------------
  697. #pragma mark ==== Download ====
  698. #pragma --------------------------------------------------------------------------------------------
  699. - (void)downloadSelectedFilesFolders
  700. {
  701. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  702. return;
  703. NSLog(@"[LOG] Start download selected ...");
  704. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  705. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  706. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  707. for (tableMetadata *metadata in selectedMetadatas) {
  708. if (metadata.directory) {
  709. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  710. } else {
  711. [[CCSynchronize sharedSynchronize] readFile:metadata.ocId fileName:metadata.fileName serverUrl:metadata.serverUrl selector:selectorReadFileWithDownload account:appDelegate.activeAccount];
  712. }
  713. }
  714. [_hud hideHud];
  715. });
  716. [self tableViewSelect:NO];
  717. }
  718. #pragma --------------------------------------------------------------------------------------------
  719. #pragma mark ===== Upload new Photos/Videos =====
  720. #pragma --------------------------------------------------------------------------------------------
  721. //
  722. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  723. //
  724. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  725. {
  726. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  727. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
  728. // if request create the folder for Auto Upload & the subfolders
  729. if ([autoUploadPath isEqualToString:serverUrl])
  730. if (![[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
  731. return;
  732. dispatch_async(dispatch_get_main_queue(), ^{
  733. [self uploadFileAsset:assets serverUrl:serverUrl autoUploadPath:autoUploadPath useSubFolder:useSubFolder session:session];
  734. });
  735. });
  736. }
  737. - (void)uploadFileAsset:(NSArray *)assets serverUrl:(NSString *)serverUrl autoUploadPath:(NSString *)autoUploadPath useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  738. {
  739. for (PHAsset *asset in assets) {
  740. tableMetadata *metadata;
  741. NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType keyFileNameOriginal:k_keyFileNameOriginal];
  742. NSDate *assetDate = asset.creationDate;
  743. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  744. // Create serverUrl if use sub folder
  745. if (useSubFolder) {
  746. [formatter setDateFormat:@"yyyy"];
  747. NSString *yearString = [formatter stringFromDate:assetDate];
  748. [formatter setDateFormat:@"MM"];
  749. NSString *monthString = [formatter stringFromDate:assetDate];
  750. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
  751. }
  752. // Check if is in upload
  753. NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", appDelegate.activeAccount, serverUrl, fileName] sorted:nil ascending:NO];
  754. if ([isRecordInSessions count] > 0)
  755. continue;
  756. // Prepare record metadata
  757. tableMetadata *metadataForUpload = [tableMetadata new];
  758. metadataForUpload.account = appDelegate.activeAccount;
  759. metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
  760. metadataForUpload.date = [NSDate new];
  761. metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
  762. metadataForUpload.fileName = fileName;
  763. metadataForUpload.fileNameView = fileName;
  764. metadataForUpload.serverUrl = serverUrl;
  765. metadataForUpload.session = session;
  766. metadataForUpload.sessionSelector = selectorUploadFile;
  767. metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
  768. metadataForUpload.status = k_metadataStatusWaitUpload;
  769. NSString *fileNameExtension = [fileName pathExtension];
  770. NSString *fileNameWithoutExtension = [fileName stringByDeletingPathExtension];
  771. if ([[fileNameExtension lowercaseString] isEqualToString:@"heic"] && [CCUtility getFormatCompatibility]) {
  772. NSString *fileNameCompatibility = [fileNameWithoutExtension stringByAppendingString:@".jpg"];
  773. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileNameCompatibility]];
  774. } else {
  775. metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileName]];
  776. }
  777. // Check il file already exists
  778. if (metadata) {
  779. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileNameWithoutExtension message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  780. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }];
  781. UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  782. // Remove record metadata
  783. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  784. // Add Medtadata for upload
  785. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  786. [appDelegate startLoadAutoDownloadUpload];
  787. }];
  788. [alertController addAction:cancelAction];
  789. [alertController addAction:overwriteAction];
  790. UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  791. alertWindow.rootViewController = [[UIViewController alloc]init];
  792. alertWindow.windowLevel = UIWindowLevelAlert + 1;
  793. [alertWindow makeKeyAndVisible];
  794. [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
  795. } else {
  796. // Add Medtadata for upload
  797. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  798. [appDelegate startLoadAutoDownloadUpload];
  799. }
  800. }
  801. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  802. }
  803. #pragma --------------------------------------------------------------------------------------------
  804. #pragma mark ==== Read File ====
  805. #pragma --------------------------------------------------------------------------------------------
  806. - (void)readFileReloadFolder
  807. {
  808. if (!_serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode)
  809. return;
  810. // Load Datasource
  811. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  812. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  813. });
  814. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:_serverUrl fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
  815. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  816. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  817. // Read folder: No record, Change etag or BLINK
  818. if ([sectionDataSource.allRecordsDataSource count] == 0 || [metadata.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
  819. [self readFolder:metadata.serverUrl];
  820. }
  821. } else if (errorCode != 0) {
  822. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  823. } else {
  824. NSLog(@"[LOG] It has been changed user during networking process, error.");
  825. }
  826. }];
  827. }
  828. #pragma --------------------------------------------------------------------------------------------
  829. #pragma mark ==== Read Folder ====
  830. #pragma --------------------------------------------------------------------------------------------
  831. - (void)insertMetadatasWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas
  832. {
  833. // stoprefresh
  834. [refreshControl endRefreshing];
  835. // save metadataFolder
  836. _metadataFolder = metadataFolder;
  837. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
  838. if (tableAccount == nil) {
  839. return;
  840. }
  841. if (_isSearchMode == NO) {
  842. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag ocId:metadataFolder.ocId encrypted:metadataFolder.e2eEncrypted account:account];
  843. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide]];
  844. [[NCManageDatabase sharedInstance] setDateReadDirectoryWithServerUrl:serverUrl account:account];
  845. }
  846. NSArray *metadatasInDownload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError] sorted:nil ascending:NO];
  847. // insert in Database
  848. NSMutableArray *metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatas];
  849. // insert in Database the /
  850. if (metadataFolder != nil) {
  851. _metadataFolder = [[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
  852. }
  853. // reinsert metadatas in Download
  854. if (metadatasInDownload) {
  855. (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload];
  856. }
  857. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  858. // File is changed ??
  859. if (!_isSearchMode && metadatasToInsertInDB)
  860. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:serverUrl account:account withDownload:NO];
  861. });
  862. // Search Mode
  863. if (_isSearchMode) {
  864. // Fix managed -> Unmanaged _searchResultMetadatas
  865. if (metadatasToInsertInDB)
  866. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
  867. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  868. }
  869. // this is the same directory
  870. if ([serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
  871. // reload
  872. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  873. [self tableViewReloadData];
  874. }
  875. // E2EE Is encrypted folder get metadata
  876. if (_metadataFolder.e2eEncrypted) {
  877. NSString *metadataFolderocId = metadataFolder.ocId;
  878. // Read Metadata
  879. if ([CCUtility isEndToEndEnabled:account]) {
  880. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  881. NSString *metadata;
  882. NSError *error = [[NCNetworkingEndToEnd sharedManager] getEndToEndMetadata:&metadata ocId:metadataFolderocId user:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] url:tableAccount.url];
  883. dispatch_async(dispatch_get_main_queue(), ^{
  884. if (error) {
  885. if (error.code != kOCErrorServerPathNotFound)
  886. [appDelegate messageNotification:@"_e2e_error_get_metadata_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  887. } else {
  888. if ([[NCEndToEndMetadata sharedInstance] decoderMetadata:metadata privateKey:[CCUtility getEndToEndPrivateKey:account] serverUrl:self.serverUrl account:account url:tableAccount.url] == false)
  889. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_decode_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  890. else
  891. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
  892. }
  893. });
  894. });
  895. } else {
  896. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  897. }
  898. }
  899. // rewrite title
  900. [self setTitle];
  901. }
  902. - (void)readFolder:(NSString *)serverUrl
  903. {
  904. // init control
  905. if (!serverUrl || !appDelegate.activeAccount || appDelegate.maintenanceMode) {
  906. [refreshControl endRefreshing];
  907. return;
  908. }
  909. // Search Mode
  910. if (_isSearchMode) {
  911. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  912. _searchFileName = @""; // forced reload searchg
  913. [self updateSearchResultsForSearchController:self.searchController];
  914. return;
  915. }
  916. _loadingFolder = YES;
  917. [self tableViewReloadData];
  918. [[OCNetworking sharedManager] readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
  919. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  920. [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
  921. } else if (errorCode != 0) {
  922. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  923. } else {
  924. NSLog(@"[LOG] It has been changed user during networking process, error.");
  925. }
  926. _loadingFolder = NO;
  927. }];
  928. }
  929. #pragma mark -
  930. #pragma --------------------------------------------------------------------------------------------
  931. #pragma mark ===== Search =====
  932. #pragma --------------------------------------------------------------------------------------------
  933. - (void)searchEnabled:(BOOL)enabled
  934. {
  935. if (enabled) {
  936. if (self.tableView.tableHeaderView != nil)
  937. return;
  938. self.definesPresentationContext = YES;
  939. self.searchController.searchResultsUpdater = self;
  940. self.searchController.dimsBackgroundDuringPresentation = NO;
  941. self.searchController.searchBar.translucent = NO;
  942. [self.searchController.searchBar sizeToFit];
  943. self.searchController.searchBar.delegate = self;
  944. self.searchController.searchBar.barTintColor = NCBrandColor.sharedInstance.brand;
  945. self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.brand;
  946. self.searchController.searchBar.backgroundImage = [UIImage new];
  947. // color searchbbar button text (cancel)
  948. UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
  949. if (searchButton && [searchButton isKindOfClass:[UIButton class]]) {
  950. [searchButton setTitleColor:NCBrandColor.sharedInstance.brandText forState:UIControlStateNormal];
  951. }
  952. // color textview searchbbar
  953. UITextField *searchTextView = [self.searchController.searchBar valueForKey:@"searchField"];
  954. if (searchTextView && [searchTextView isKindOfClass:[UITextField class]]) {
  955. searchTextView.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  956. searchTextView.textColor = NCBrandColor.sharedInstance.textView;
  957. }
  958. self.tableView.tableHeaderView = self.searchController.searchBar;
  959. [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
  960. } else {
  961. self.tableView.tableHeaderView = nil;
  962. }
  963. }
  964. - (void)searchStartTimer
  965. {
  966. NSString *startDirectory = [CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl];
  967. [[OCNetworking sharedManager] searchWithAccount:appDelegate.activeAccount fileName:_searchFileName serverUrl:startDirectory contentType:nil lteDateLastModified:nil gteDateLastModified:nil depth:@"infinity" completion:^(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode) {
  968. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  969. #if TARGET_OS_SIMULATOR
  970. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:account];
  971. if (capabilities.isFulltextsearchEnabled) {
  972. [[OCNetworking sharedManager] fullTextSearchWithAccount:appDelegate.activeAccount text:_searchFileName page:1 completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
  973. NSLog(@"x");
  974. }];
  975. }
  976. #endif
  977. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
  978. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  979. } else {
  980. if (errorCode != 0) {
  981. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  982. } else {
  983. NSLog(@"[LOG] It has been changed user during networking process, error.");
  984. }
  985. _searchFileName = @"";
  986. }
  987. }];
  988. _noFilesSearchTitle = @"";
  989. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  990. [self.tableView reloadEmptyDataSet];
  991. }
  992. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  993. {
  994. // Color text "Cancel"
  995. [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:NCBrandColor.sharedInstance.brandText];
  996. _isSearchMode = YES;
  997. [self deleteRefreshControl];
  998. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  999. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1000. _searchFileName = fileName;
  1001. // First : filter
  1002. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView CONTAINS[cd] %@", appDelegate.activeAccount, _serverUrl, fileName] sorted:nil ascending:NO];
  1003. [_searchResultMetadatas removeAllObjects];
  1004. for (tableMetadata *record in records)
  1005. [_searchResultMetadatas addObject:record];
  1006. [self insertMetadatasWithAccount:appDelegate.activeAccount serverUrl:_serverUrl metadataFolder:nil metadatas:_searchResultMetadatas];
  1007. // Version >= 12
  1008. if ([[NCManageDatabase sharedInstance] getServerVersionWithAccount:appDelegate.activeAccount] >= 12) {
  1009. [_timerWaitInput invalidate];
  1010. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1011. }
  1012. }
  1013. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1014. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1015. }
  1016. }
  1017. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1018. {
  1019. [self cancelSearchBar];
  1020. [self readFolder:_serverUrl];
  1021. }
  1022. - (void)cancelSearchBar
  1023. {
  1024. if (self.searchController.active) {
  1025. [self.searchController setActive:NO];
  1026. [self createRefreshControl];
  1027. _isSearchMode = NO;
  1028. _searchFileName = @"";
  1029. _dateReadDataSource = nil;
  1030. _searchResultMetadatas = [NSMutableArray new];
  1031. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1032. }
  1033. //[self setNeedsStatusBarAppearanceUpdate];
  1034. }
  1035. #pragma mark -
  1036. #pragma --------------------------------------------------------------------------------------------
  1037. #pragma mark ===== Delete File or Folder =====
  1038. #pragma --------------------------------------------------------------------------------------------
  1039. - (void)deleteFile
  1040. {
  1041. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1042. return;
  1043. NSArray *metadatas;
  1044. if ([_selectedocIdsMetadatas count] > 0) {
  1045. metadatas = [_selectedocIdsMetadatas allValues];
  1046. } else {
  1047. metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
  1048. }
  1049. // remove optimization
  1050. _dateReadDataSource = nil;
  1051. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:metadatas e2ee:_metadataFolder.e2eEncrypted serverUrl:self.serverUrl folderocId:_metadataFolder.ocId completion:^(NSInteger errorCode, NSString *message) {
  1052. // Reload
  1053. if (_isSearchMode)
  1054. [self readFolder:self.serverUrl];
  1055. else
  1056. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1057. }];
  1058. // End Select Table View
  1059. [self tableViewSelect:NO];
  1060. }
  1061. #pragma --------------------------------------------------------------------------------------------
  1062. #pragma mark ===== Rename =====
  1063. #pragma --------------------------------------------------------------------------------------------
  1064. - (void)renameFile:(NSArray *)arguments
  1065. {
  1066. tableMetadata *metadata = [arguments objectAtIndex:0];
  1067. NSString *fileName = [arguments objectAtIndex:1];
  1068. // E2EE
  1069. if (_metadataFolder.e2eEncrypted) {
  1070. // verify if exists the new fileName
  1071. if ([[NCManageDatabase sharedInstance] getE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.activeAccount, self.serverUrl, fileName]]) {
  1072. [appDelegate messageNotification:@"_error_e2ee_" description:@"_file_already_exists_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  1073. return;
  1074. }
  1075. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  1076. NSError *error = [[NCNetworkingEndToEnd sharedManager] sendEndToEndMetadataOnServerUrl:self.serverUrl fileNameRename:metadata.fileName fileNameNewRename:fileName account:appDelegate.activeAccount user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1077. if (error) {
  1078. dispatch_async(dispatch_get_main_queue(), ^{
  1079. [appDelegate messageNotification:@"_error_e2ee_" description:@"_e2e_error_send_metadata_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1080. });
  1081. } else {
  1082. [[NCManageDatabase sharedInstance] setMetadataFileNameViewWithServerUrl:metadata.serverUrl fileName:metadata.fileName newFileNameView:fileName account:appDelegate.activeAccount];
  1083. // Move file system
  1084. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileNameView];
  1085. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileName];
  1086. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1087. [[NSFileManager defaultManager] moveItemAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileName] error:nil];
  1088. }
  1089. // Unlock
  1090. tableE2eEncryptionLock *tableLock = [[NCManageDatabase sharedInstance] getE2ETokenLockWithServerUrl:self.serverUrl];
  1091. if (tableLock != nil) {
  1092. NSError *error = [[NCNetworkingEndToEnd sharedManager] unlockEndToEndFolderEncryptedOnServerUrl:self.serverUrl ocId:_metadataFolder.ocId token:tableLock.token user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1093. if (error) {
  1094. dispatch_async(dispatch_get_main_queue(), ^{
  1095. [appDelegate messageNotification:@"_e2e_error_unlock_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1096. });
  1097. }
  1098. }
  1099. dispatch_async(dispatch_get_main_queue(), ^{
  1100. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1101. });
  1102. });
  1103. } else {
  1104. // Plain
  1105. NSString *fileNameNew = [CCUtility removeForbiddenCharactersServer:fileName];
  1106. if ([fileName length] == 0 || [fileName isEqualToString:metadata.fileNameView]) {
  1107. return;
  1108. }
  1109. // Verify if exists the fileName TO
  1110. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:metadata.serverUrl fileName:fileNameNew completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1111. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1112. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1113. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }];
  1114. [alert addAction:ok];
  1115. [self presentViewController:alert animated:YES completion:nil];
  1116. } else if (errorCode != 0) {
  1117. if (errorCode == kOCErrorServerPathNotFound) {
  1118. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1119. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
  1120. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1121. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1122. // Rename metadata
  1123. (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:fileNameNew ocId:metadata.ocId];
  1124. if (metadata.directory) {
  1125. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  1126. NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:fileNameNew];
  1127. tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
  1128. if (directoryTable == nil) {
  1129. [appDelegate messageNotification:@"_rename_" description:@"Internal error, ServerUrl not found" visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  1130. return;
  1131. }
  1132. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:@"" ocId:nil encrypted:directoryTable.e2eEncrypted account:appDelegate.activeAccount];
  1133. } else {
  1134. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:metadata.ocId date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:fileNameNew etag:nil];
  1135. // Move file system
  1136. NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], metadata.fileName];
  1137. NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageOcId:metadata.ocId], fileNameNew];
  1138. [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
  1139. NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileName];
  1140. NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:fileNameNew];
  1141. [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
  1142. }
  1143. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1144. } else if (errorCode != 0) {
  1145. [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1146. } else {
  1147. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1148. }
  1149. }];
  1150. } else {
  1151. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1152. }
  1153. } else {
  1154. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1155. }
  1156. }];
  1157. }
  1158. }
  1159. #pragma --------------------------------------------------------------------------------------------
  1160. #pragma mark ===== Move =====
  1161. #pragma --------------------------------------------------------------------------------------------
  1162. - (void)moveFileOrFolderMetadata:(tableMetadata *)metadata serverUrlTo:(NSString *)serverUrlTo numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1163. {
  1164. [[OCNetworking sharedManager] readFileWithAccount:appDelegate.activeAccount serverUrl:serverUrlTo fileName:metadata.fileName completion:^(NSString *account, tableMetadata *metadataReadFile, NSString *message, NSInteger errorCode) {
  1165. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1166. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1167. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1168. }];
  1169. [alert addAction:ok];
  1170. [self presentViewController:alert animated:YES completion:nil];
  1171. // End Select Table View
  1172. [self tableViewSelect:NO];
  1173. // reload Datasource
  1174. [self readFileReloadFolder];
  1175. } else if (errorCode != 0) {
  1176. if (errorCode == kOCErrorServerPathNotFound) {
  1177. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  1178. NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
  1179. [[OCNetworking sharedManager] moveFileOrFolderWithAccount:appDelegate.activeAccount fileName:fileNamePath fileNameTo:fileNameToPath completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1180. [_hud hideHud];
  1181. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1182. if (metadata.directory) {
  1183. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] account:account];
  1184. }
  1185. [[NCManageDatabase sharedInstance] moveMetadataWithOcId:metadata.ocId serverUrlTo:serverUrlTo];
  1186. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:account];
  1187. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrlTo account:account];
  1188. // next
  1189. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  1190. if ([_selectedocIdsMetadatas count] > 0) {
  1191. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1192. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrlTo numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1193. } else {
  1194. // End Select Table View
  1195. [self tableViewSelect:NO];
  1196. // reload Datasource
  1197. if (_isSearchMode)
  1198. [self readFolder:metadata.serverUrl];
  1199. else
  1200. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1201. }
  1202. } else if (errorCode != 0) {
  1203. [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1204. // End Select Table View
  1205. [self tableViewSelect:NO];
  1206. // reload Datasource
  1207. if (_isSearchMode)
  1208. [self readFolder:metadata.serverUrl];
  1209. else
  1210. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:nil action:k_action_NULL];
  1211. } else {
  1212. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1213. }
  1214. }];
  1215. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1216. } else {
  1217. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1218. }
  1219. } else {
  1220. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1221. }
  1222. }];
  1223. }
  1224. // DELEGATE : Select
  1225. - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type
  1226. {
  1227. if (serverUrl == nil) {
  1228. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1229. } else {
  1230. // E2EE DENIED
  1231. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) {
  1232. [appDelegate messageNotification:@"_move_" description:@"Not possible move files to encrypted directory" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  1233. return;
  1234. }
  1235. if ([_selectedocIdsMetadatas count] > 0) {
  1236. _numSelectedocIdsMetadatas = [_selectedocIdsMetadatas count];
  1237. NSArray *metadatas = [_selectedocIdsMetadatas allValues];
  1238. [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrl numFile:[_selectedocIdsMetadatas count] ofFile:_numSelectedocIdsMetadatas];
  1239. } else {
  1240. _numSelectedocIdsMetadatas = 1;
  1241. [self moveFileOrFolderMetadata:self.metadata serverUrlTo:serverUrl numFile:1 ofFile:_numSelectedocIdsMetadatas];
  1242. }
  1243. }
  1244. }
  1245. - (void)moveOpenWindow:(NSArray *)indexPaths
  1246. {
  1247. if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
  1248. return;
  1249. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCSelect" bundle:nil] instantiateInitialViewController];
  1250. NCSelect *viewController = (NCSelect *)navigationController.topViewController;
  1251. viewController.delegate = self;
  1252. viewController.hideButtonCreateFolder = false;
  1253. viewController.selectFile = false;
  1254. viewController.includeDirectoryE2EEncryption = false;
  1255. viewController.includeImages = false;
  1256. viewController.type = @"";
  1257. viewController.titleButtonDone = NSLocalizedString(@"_move_", nil);
  1258. viewController.layoutViewSelect = k_layout_view_move;
  1259. [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
  1260. [self presentViewController:navigationController animated:YES completion:nil];
  1261. }
  1262. #pragma --------------------------------------------------------------------------------------------
  1263. #pragma mark ===== Create folder =====
  1264. #pragma --------------------------------------------------------------------------------------------
  1265. - (void)createFolder
  1266. {
  1267. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  1268. NSString *message;
  1269. UIAlertController *alertController;
  1270. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]]) {
  1271. message = @"/";
  1272. } else {
  1273. message = [serverUrl lastPathComponent];
  1274. }
  1275. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  1276. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1277. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  1278. textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
  1279. }];
  1280. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1281. NSLog(@"[LOG] Cancel action");
  1282. }];
  1283. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1284. UITextField *fileName = alertController.textFields.firstObject;
  1285. [self createFolder:fileName.text serverUrl:serverUrl];
  1286. }];
  1287. okAction.enabled = NO;
  1288. [alertController addAction:cancelAction];
  1289. [alertController addAction:okAction];
  1290. [self presentViewController:alertController animated:YES completion:nil];
  1291. }
  1292. - (void)createFolder:(NSString *)fileNameFolder serverUrl:(NSString *)serverUrl
  1293. {
  1294. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1295. if (![fileNameFolder length]) return;
  1296. NSString *ocIdTemp = [[NSUUID UUID] UUIDString];
  1297. // Create Directory (temp) on metadata
  1298. tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:YES ocId:ocIdTemp serverUrl:serverUrl fileName:fileNameFolder etag:@"" size:0 status:k_metadataStatusNormal url:@""];
  1299. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1300. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl account:appDelegate.activeAccount];
  1301. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1302. // Creeate folder Networking
  1303. [[OCNetworking sharedManager] createFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileNameFolder completion:^(NSString *account, NSString *ocId, NSDate *date, NSString *message, NSInteger errorCode) {
  1304. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  1305. // Delete Temp Dir
  1306. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1307. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrl, fileNameFolder];
  1308. if (_metadataFolder.e2eEncrypted) {
  1309. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1310. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:newDirectory ocId:ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  1311. dispatch_async(dispatch_get_main_queue(), ^{
  1312. if (error) {
  1313. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  1314. }
  1315. [self readFolder:self.serverUrl];
  1316. });
  1317. });
  1318. } else {
  1319. [self readFolder:self.serverUrl];
  1320. }
  1321. } else {
  1322. // Delete Temp Dir
  1323. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocIdTemp]];
  1324. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1325. if (errorCode != 0) {
  1326. [appDelegate messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1327. } else {
  1328. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1329. }
  1330. }
  1331. }];
  1332. }
  1333. #pragma --------------------------------------------------------------------------------------------
  1334. #pragma mark ===== Progress & Task Button =====
  1335. #pragma --------------------------------------------------------------------------------------------
  1336. - (void)triggerProgressTask:(NSNotification *)notification
  1337. {
  1338. if (sectionDataSource.ocIdIndexPath != nil) {
  1339. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
  1340. }
  1341. }
  1342. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1343. {
  1344. UITouch *touch = [[event allTouches] anyObject];
  1345. CGPoint location = [touch locationInView:self.tableView];
  1346. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1347. if ([self indexPathIsValid:indexPath]) {
  1348. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1349. if (metadataSection) {
  1350. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataSection.ocId]];
  1351. if (metadata)
  1352. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  1353. }
  1354. }
  1355. }
  1356. - (void)cancelAllTask:(id)sender
  1357. {
  1358. CGPoint location = [sender locationInView:self.tableView];
  1359. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1360. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1361. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1362. [NCUtility.sharedInstance startActivityIndicatorWithView:self.view bottom:0];
  1363. [[NCMainCommon sharedInstance] cancelAllTransfer];
  1364. [NCUtility.sharedInstance stopActivityIndicator];
  1365. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:nil ocId:nil action:k_action_NULL];
  1366. }]];
  1367. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  1368. alertController.popoverPresentationController.sourceView = self.tableView;
  1369. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  1370. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  1371. [alertController.view layoutIfNeeded];
  1372. [self presentViewController:alertController animated:YES completion:nil];
  1373. }
  1374. #pragma --------------------------------------------------------------------------------------------
  1375. #pragma mark ===== Tap =====
  1376. #pragma --------------------------------------------------------------------------------------------
  1377. - (void)tapActionComment:(UITapGestureRecognizer *)tapGesture
  1378. {
  1379. CGPoint location = [tapGesture locationInView:self.tableView];
  1380. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1381. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1382. if (metadata) {
  1383. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:1];
  1384. }
  1385. }
  1386. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  1387. {
  1388. CGPoint location = [tapGesture locationInView:self.tableView];
  1389. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1390. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1391. if (metadata) {
  1392. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  1393. }
  1394. }
  1395. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  1396. {
  1397. CGPoint location = [tapGesture locationInView:self.tableView];
  1398. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  1399. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1400. if (metadata) {
  1401. }
  1402. }
  1403. #pragma --------------------------------------------------------------------------------------------
  1404. #pragma mark ===== Favorite =====
  1405. #pragma --------------------------------------------------------------------------------------------
  1406. - (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite
  1407. {
  1408. NSString *fileNameServerUrl = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
  1409. [[OCNetworking sharedManager] settingFavoriteWithAccount:appDelegate.activeAccount fileName:fileNameServerUrl favorite:favorite completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  1410. if (errorCode == 0 && [appDelegate.activeAccount isEqualToString:account]) {
  1411. [[NCManageDatabase sharedInstance] setMetadataFavoriteWithOcId:metadata.ocId favorite:favorite];
  1412. _dateReadDataSource = nil;
  1413. if (_isSearchMode)
  1414. [self readFolder:self.serverUrl];
  1415. else
  1416. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1417. if (metadata.directory && favorite) {
  1418. NSString *selector;
  1419. if ([CCUtility getFavoriteOffline])
  1420. selector = selectorReadFolderWithDownload;
  1421. else
  1422. selector = selectorReadFolder;
  1423. [[CCSynchronize sharedSynchronize] readFolder:[CCUtility stringAppendServerUrl:self.serverUrl addFileName:metadata.fileName] selector:selector account:appDelegate.activeAccount];
  1424. }
  1425. if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
  1426. metadata.favorite = favorite;
  1427. metadata.session = k_download_session;
  1428. metadata.sessionError = @"";
  1429. metadata.sessionSelector = selectorDownloadSynchronize;
  1430. metadata.status = k_metadataStatusWaitDownload;
  1431. // Add Metadata for Download
  1432. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1433. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1434. [appDelegate startLoadAutoDownloadUpload];
  1435. }
  1436. } else if (errorCode != 0) {
  1437. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1438. } else {
  1439. NSLog(@"[LOG] It has been changed user during networking process, error.");
  1440. }
  1441. }];
  1442. }
  1443. #pragma --------------------------------------------------------------------------------------------
  1444. #pragma mark ==== Menu LOGO ====
  1445. #pragma --------------------------------------------------------------------------------------------
  1446. - (void)menuLogo:(UIGestureRecognizer *)theGestureRecognizer
  1447. {
  1448. if (appDelegate.reSelectMenu.isOpen || appDelegate.reMainMenu.isOpen)
  1449. return;
  1450. // Brand
  1451. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  1452. return;
  1453. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  1454. NSMutableArray *menuArray = [NSMutableArray new];
  1455. for (NSString *account in listAccount) {
  1456. CCMenuItem *item = [[CCMenuItem alloc] init];
  1457. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  1458. item.argument = account;
  1459. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
  1460. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
  1461. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  1462. if (avatar) {
  1463. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(25, 25) isAspectRation:YES];
  1464. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  1465. CGSize imageSize = avatarImageView.bounds.size;
  1466. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1467. CGContextRef context = UIGraphicsGetCurrentContext();
  1468. [avatarImageView.layer renderInContext:context];
  1469. avatar = UIGraphicsGetImageFromCurrentImageContext();
  1470. UIGraphicsEndImageContext();
  1471. } else {
  1472. avatar = [UIImage imageNamed:@"menuLogoUser"];
  1473. }
  1474. item.image = avatar;
  1475. item.target = self;
  1476. if ([account isEqualToString:appDelegate.activeAccount]) {
  1477. item.action = nil;
  1478. [menuArray insertObject:item atIndex:0];
  1479. } else {
  1480. item.action = @selector(changeDefaultAccount:);
  1481. [menuArray addObject:item];
  1482. }
  1483. }
  1484. // Add + new account
  1485. CCMenuItem *item = [[CCMenuItem alloc] init];
  1486. item.title = NSLocalizedString(@"_add_account_", nil);
  1487. item.argument = @"";
  1488. item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] width:50 height:50 color:NCBrandColor.sharedInstance.textView];
  1489. item.target = self;
  1490. item.action = @selector(addNewAccount:);
  1491. [menuArray addObject:item];
  1492. OptionalConfiguration options;
  1493. Color backgroundColor;
  1494. const CGFloat *componentsBackgroundColor = CGColorGetComponents(NCBrandColor.sharedInstance.backgroundForm.CGColor);
  1495. backgroundColor.R = componentsBackgroundColor[0];
  1496. backgroundColor.G = componentsBackgroundColor[1];
  1497. backgroundColor.B = componentsBackgroundColor[2];
  1498. options.arrowSize = 9;
  1499. options.marginXSpacing = 7;
  1500. options.marginYSpacing = 10;
  1501. options.intervalSpacing = 20;
  1502. options.menuCornerRadius = 6.5;
  1503. options.maskToBackground = NO;
  1504. options.shadowOfMenu = YES;
  1505. options.hasSeperatorLine = YES;
  1506. options.seperatorLineHasInsets = YES;
  1507. options.textColor = NCBrandColor.sharedInstance.textView;
  1508. options.menuBackgroundColor = backgroundColor;
  1509. options.separatorColor = NCBrandColor.sharedInstance.separator;
  1510. CGRect rect = self.view.frame;
  1511. CGFloat locationY = [theGestureRecognizer locationInView: self.navigationController.navigationBar].y;
  1512. CGFloat safeAreaTop = 0;
  1513. CGFloat offsetY = 35;
  1514. if (@available(iOS 11, *)) {
  1515. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top / 2;
  1516. }
  1517. rect.origin.y = locationY + safeAreaTop + offsetY;
  1518. rect.size.height = rect.size.height - locationY - safeAreaTop - offsetY;
  1519. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  1520. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  1521. }
  1522. - (void)changeDefaultAccount:(CCMenuItem *)sender
  1523. {
  1524. // LOGOUT
  1525. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  1526. if (tableAccount) {
  1527. // LOGIN
  1528. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  1529. // go to home sweet home
  1530. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  1531. }
  1532. }
  1533. - (void)addNewAccount:(CCMenuItem *)sender
  1534. {
  1535. [appDelegate openLoginView:self selector:k_intro_login openLoginWeb:false];
  1536. }
  1537. #pragma --------------------------------------------------------------------------------------------
  1538. #pragma mark ==== ReMenu ====
  1539. #pragma --------------------------------------------------------------------------------------------
  1540. - (void)createReMenuBackgroundView:(REMenu *)menu
  1541. {
  1542. CGFloat safeAreaBottom = 0;
  1543. CGFloat safeAreaTop = 0;
  1544. CGFloat statusBar = 0;
  1545. if (@available(iOS 11, *)) {
  1546. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  1547. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  1548. }
  1549. if ([UIApplication sharedApplication].isStatusBarHidden) {
  1550. statusBar = 13;
  1551. }
  1552. CGFloat computeNavigationBarOffset = [menu computeNavigationBarOffset];
  1553. UIViewController *rootController = [[[[UIApplication sharedApplication]delegate] window] rootViewController];
  1554. CGRect globalPositionMenu = [menu.menuView convertRect:menu.menuView.bounds toView:rootController.view];
  1555. _reMenuBackgroundView.frame = CGRectMake(0, computeNavigationBarOffset, globalPositionMenu.size.width, rootController.view.frame.size.height);
  1556. [UIView animateWithDuration:0.2 animations:^{
  1557. CGFloat minimum = safeAreaBottom + self.tabBarController.tabBar.frame.size.height;
  1558. CGFloat y = rootController.view.frame.size.height - menu.menuView.frame.size.height - globalPositionMenu.origin.y + statusBar;
  1559. if (y>minimum) {
  1560. _reMenuBackgroundView.frame = CGRectMake(0, rootController.view.frame.size.height, globalPositionMenu.size.width, - y);
  1561. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  1562. }
  1563. }];
  1564. }
  1565. - (void)createReMainMenu
  1566. {
  1567. NSString *title;
  1568. NSString *groupBy = [CCUtility getGroupBySettings];
  1569. NSString *sorted = [CCUtility getOrderSettings];
  1570. BOOL ascending = [CCUtility getAscendingSettings];
  1571. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  1572. appDelegate.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectLight"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1573. if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
  1574. }];
  1575. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  1576. if ([sorted isEqualToString:@"fileName"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_a_z_", nil)]; }
  1577. else title = NSLocalizedString(@"_order_by_name_a_z_", nil);
  1578. appDelegate.sortFileNameAZItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameAZ"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1579. [CCUtility setOrderSettings:@"fileName"];
  1580. [CCUtility setAscendingSettings:true];
  1581. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1582. }];
  1583. if ([sorted isEqualToString:@"fileName"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_name_z_a_", nil)]; }
  1584. else title = NSLocalizedString(@"_order_by_name_z_a_", nil);
  1585. appDelegate.sortFileNameZAItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortFileNameZA"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1586. [CCUtility setOrderSettings:@"fileName"];
  1587. [CCUtility setAscendingSettings:false];
  1588. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1589. }];
  1590. if ([sorted isEqualToString:@"date"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_more_recent_", nil)]; }
  1591. else title = NSLocalizedString(@"_order_by_date_more_recent_", nil);
  1592. appDelegate.sortDateMoreRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateMoreRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1593. [CCUtility setOrderSettings:@"date"];
  1594. [CCUtility setAscendingSettings:false];
  1595. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1596. }];
  1597. if ([sorted isEqualToString:@"date"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_date_less_recent_", nil)]; }
  1598. else title = NSLocalizedString(@"_order_by_date_less_recent_", nil);
  1599. appDelegate.sortDateLessRecentItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortDateLessRecent"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1600. [CCUtility setOrderSettings:@"date"];
  1601. [CCUtility setAscendingSettings:true];
  1602. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1603. }];
  1604. if ([sorted isEqualToString:@"size"] && ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_smallest_", nil)]; }
  1605. else title = NSLocalizedString(@"_order_by_size_smallest_", nil);
  1606. appDelegate.sortSmallestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortSmallest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1607. [CCUtility setOrderSettings:@"size"];
  1608. [CCUtility setAscendingSettings:true];
  1609. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1610. }];
  1611. if ([sorted isEqualToString:@"size"] && !ascending) { title = [NSString stringWithFormat:@"✓ %@", NSLocalizedString(@"_order_by_size_largest_", nil)]; }
  1612. else title = NSLocalizedString(@"_order_by_size_largest_", nil);
  1613. appDelegate.sortLargestItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"sortLargest"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1614. [CCUtility setOrderSettings:@"size"];
  1615. [CCUtility setAscendingSettings:false];
  1616. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1617. }];
  1618. // ITEM GROUP ALPHABETIC -----------------------------------------------------------------------------------------------------
  1619. if ([groupBy isEqualToString:@"alphabetic"]) { title = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  1620. else { title = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  1621. appDelegate.alphabeticItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1622. if ([groupBy isEqualToString:@"alphabetic"]) [CCUtility setGroupBySettings:@"none"];
  1623. else [CCUtility setGroupBySettings:@"alphabetic"];
  1624. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1625. }];
  1626. // ITEM GROUP TYPEFILE -------------------------------------------------------------------------------------------------------
  1627. if ([groupBy isEqualToString:@"typefile"]) { title = NSLocalizedString(@"_group_typefile_yes_", nil); }
  1628. else { title = NSLocalizedString(@"_group_typefile_no_", nil); }
  1629. appDelegate.typefileItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1630. if ([groupBy isEqualToString:@"typefile"]) [CCUtility setGroupBySettings:@"none"];
  1631. else [CCUtility setGroupBySettings:@"typefile"];
  1632. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1633. }];
  1634. // ITEM GROUP DATE -------------------------------------------------------------------------------------------------------
  1635. if ([groupBy isEqualToString:@"date"]) { title = NSLocalizedString(@"_group_date_yes_", nil); }
  1636. else { title = NSLocalizedString(@"_group_date_no_", nil); }
  1637. appDelegate.dateItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1638. if ([groupBy isEqualToString:@"date"]) [CCUtility setGroupBySettings:@"none"];
  1639. else [CCUtility setGroupBySettings:@"date"];
  1640. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1641. }];
  1642. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  1643. if ([CCUtility getDirectoryOnTop]) { title = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  1644. else { title = NSLocalizedString(@"_directory_on_top_no_", nil); }
  1645. appDelegate.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:title subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"foldersOnTop"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1646. if ([CCUtility getDirectoryOnTop]) [CCUtility setDirectoryOnTop:NO];
  1647. else [CCUtility setDirectoryOnTop:YES];
  1648. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  1649. }];
  1650. // REMENU --------------------------------------------------------------------------------------------------------------
  1651. appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem,appDelegate.alphabeticItem, appDelegate.typefileItem, appDelegate.dateItem, appDelegate.directoryOnTopItem]];
  1652. appDelegate.reMainMenu.itemHeight = 40;
  1653. appDelegate.reMainMenu.imageOffset = CGSizeMake(5, -1);
  1654. appDelegate.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1655. appDelegate.reMainMenu.imageOffset = CGSizeMake(0, 0);
  1656. appDelegate.reMainMenu.waitUntilAnimationIsComplete = NO;
  1657. appDelegate.reMainMenu.separatorHeight = 0.5;
  1658. appDelegate.reMainMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1659. appDelegate.reMainMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1660. appDelegate.reMainMenu.textColor = NCBrandColor.sharedInstance.textView;
  1661. appDelegate.reMainMenu.textAlignment = NSTextAlignmentLeft;
  1662. appDelegate.reMainMenu.textShadowColor = nil;
  1663. appDelegate.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  1664. appDelegate.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  1665. appDelegate.reMainMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1666. appDelegate.reMainMenu.highlightedSeparatorColor = nil;
  1667. appDelegate.reMainMenu.highlightedTextColor = [UIColor blackColor];
  1668. appDelegate.reMainMenu.highlightedTextShadowColor = nil;
  1669. appDelegate.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1670. appDelegate.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  1671. appDelegate.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1672. appDelegate.reMainMenu.subtitleTextShadowColor = nil;
  1673. appDelegate.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1674. appDelegate.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1675. appDelegate.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1676. appDelegate.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1677. appDelegate.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  1678. appDelegate.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1679. appDelegate.reMainMenu.borderWidth = 0;
  1680. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1681. appDelegate.reMainMenu.animationDuration = 0.2;
  1682. appDelegate.reMainMenu.closeAnimationDuration = 0.2;
  1683. appDelegate.reMainMenu.bounce = NO;
  1684. __weak typeof(self) weakSelf = self;
  1685. [appDelegate.reMainMenu setClosePreparationBlock:^{
  1686. // Backgroun reMenu (Gesture)
  1687. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1688. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1689. }];
  1690. }
  1691. - (void)toggleReMainMenu
  1692. {
  1693. if (appDelegate.reMainMenu.isOpen) {
  1694. [appDelegate.reMainMenu close];
  1695. } else {
  1696. [self createReMainMenu];
  1697. [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
  1698. // Backgroun reMenu & (Gesture)
  1699. [self createReMenuBackgroundView:appDelegate.reMainMenu];
  1700. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  1701. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1702. }
  1703. }
  1704. - (void)createReSelectMenu
  1705. {
  1706. // ITEM SELECT ALL --------------------------------------------------------------------------------------------------
  1707. appDelegate.selectAllItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_all_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectFull"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1708. [self didSelectAll];
  1709. }];
  1710. // ITEM MOVE --------------------------------------------------------------------------------------------------------
  1711. appDelegate.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1712. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  1713. }];
  1714. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  1715. appDelegate.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_folders_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"downloadSelectedFiles"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1716. [self downloadSelectedFilesFolders];
  1717. }];
  1718. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  1719. appDelegate.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"saveSelectedFiles"] multiplier:2 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1720. [self saveSelectedFiles];
  1721. }];
  1722. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  1723. appDelegate.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
  1724. [self deleteFile];
  1725. }];
  1726. // E2EE
  1727. if (_metadataFolder.e2eEncrypted) {
  1728. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1729. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1730. } else {
  1731. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1732. }
  1733. } else {
  1734. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1735. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.deleteItem]];
  1736. } else {
  1737. appDelegate.reSelectMenu = [[REMenu alloc] initWithItems:@[appDelegate.selectAllItem, appDelegate.moveItem, appDelegate.downloadItem, appDelegate.saveItem, appDelegate.deleteItem]];
  1738. }
  1739. }
  1740. appDelegate.reSelectMenu.itemHeight = 50;
  1741. appDelegate.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  1742. appDelegate.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  1743. appDelegate.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  1744. appDelegate.reSelectMenu.waitUntilAnimationIsComplete = NO;
  1745. appDelegate.reSelectMenu.separatorHeight = 0.5;
  1746. appDelegate.reSelectMenu.separatorColor = NCBrandColor.sharedInstance.separator;
  1747. appDelegate.reSelectMenu.backgroundColor = NCBrandColor.sharedInstance.backgroundForm;
  1748. appDelegate.reSelectMenu.textColor = NCBrandColor.sharedInstance.textView;
  1749. appDelegate.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  1750. appDelegate.reSelectMenu.textShadowColor = nil;
  1751. appDelegate.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  1752. appDelegate.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  1753. appDelegate.reSelectMenu.highlightedBackgroundColor = NCBrandColor.sharedInstance.select;
  1754. appDelegate.reSelectMenu.highlightedSeparatorColor = nil;
  1755. appDelegate.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  1756. appDelegate.reSelectMenu.highlightedTextShadowColor = nil;
  1757. appDelegate.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  1758. appDelegate.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  1759. appDelegate.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  1760. appDelegate.reSelectMenu.subtitleTextShadowColor = nil;
  1761. appDelegate.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  1762. appDelegate.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  1763. appDelegate.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  1764. appDelegate.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  1765. appDelegate.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  1766. appDelegate.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  1767. appDelegate.reMainMenu.borderWidth = 0;
  1768. appDelegate.reMainMenu.borderColor = NCBrandColor.sharedInstance.backgroundForm;
  1769. appDelegate.reSelectMenu.closeAnimationDuration = 0.2;
  1770. appDelegate.reSelectMenu.animationDuration = 0.2;
  1771. appDelegate.reSelectMenu.bounce = NO;
  1772. __weak typeof(self) weakSelf = self;
  1773. [appDelegate.reSelectMenu setClosePreparationBlock:^{
  1774. // Backgroun reMenu (Gesture)
  1775. [weakSelf.reMenuBackgroundView removeFromSuperview];
  1776. [weakSelf.reMenuBackgroundView removeGestureRecognizer:weakSelf.singleFingerTap];
  1777. }];
  1778. }
  1779. - (void)toggleReSelectMenu
  1780. {
  1781. if (appDelegate.reSelectMenu.isOpen) {
  1782. [appDelegate.reSelectMenu close];
  1783. } else {
  1784. [self createReSelectMenu];
  1785. [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
  1786. // Backgroun reMenu & (Gesture)
  1787. [self createReMenuBackgroundView:appDelegate.reSelectMenu];
  1788. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  1789. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  1790. }
  1791. }
  1792. #pragma --------------------------------------------------------------------------------------------
  1793. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  1794. #pragma --------------------------------------------------------------------------------------------
  1795. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  1796. {
  1797. if (recognizer.state == UIGestureRecognizerStateBegan) {
  1798. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  1799. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  1800. if ([self indexPathIsValid:indexPath])
  1801. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  1802. else
  1803. self.metadata = nil;
  1804. [self becomeFirstResponder];
  1805. UIMenuController *menuController = [UIMenuController sharedMenuController];
  1806. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  1807. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  1808. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  1809. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  1810. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  1811. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  1812. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, pasteFileItem, pasteFilesItem, nil]];
  1813. } else {
  1814. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  1815. }
  1816. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  1817. [menuController setMenuVisible:YES animated:YES];
  1818. }
  1819. }
  1820. - (BOOL)canBecomeFirstResponder
  1821. {
  1822. return YES;
  1823. }
  1824. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  1825. {
  1826. // For copy file, copy files, Open in ... :
  1827. //
  1828. // NO Directory
  1829. // NO Error Passcode
  1830. // NO In Session mode (download/upload)
  1831. // NO Template
  1832. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  1833. if (_isSelectedMode == NO && self.metadata && !self.metadata.directory && self.metadata.status == k_metadataStatusNormal) return YES;
  1834. else return NO;
  1835. }
  1836. if (@selector(copyFiles:) == action) {
  1837. if (_isSelectedMode) {
  1838. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1839. for (tableMetadata *metadata in selectedMetadatas) {
  1840. if (!metadata.directory && metadata.status == k_metadataStatusNormal)
  1841. return YES;
  1842. }
  1843. }
  1844. return NO;
  1845. }
  1846. if (@selector(pasteFile:) == action) {
  1847. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1848. NSArray *items = [pasteboard items];
  1849. if ([items count] == 1) {
  1850. // Value : (NSData) ocId
  1851. NSDictionary *dic = [items objectAtIndex:0];
  1852. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1853. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1854. if (ocId) {
  1855. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1856. if (metadata) {
  1857. return [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView];
  1858. } else {
  1859. return NO;
  1860. }
  1861. }
  1862. }
  1863. return NO;
  1864. }
  1865. if (@selector(pasteFiles:) == action) {
  1866. BOOL isValid = NO;
  1867. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1868. NSArray *items = [pasteboard items];
  1869. if ([items count] <= 1) return NO;
  1870. for (NSDictionary *dic in items) {
  1871. // Value : (NSData) ocId
  1872. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1873. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1874. if (ocId) {
  1875. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1876. if (metadata) {
  1877. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1878. isValid = YES;
  1879. } else {
  1880. isValid = NO;
  1881. break;
  1882. }
  1883. } else {
  1884. isValid = NO;
  1885. break;
  1886. }
  1887. } else {
  1888. isValid = NO;
  1889. break;
  1890. }
  1891. }
  1892. return isValid;
  1893. }
  1894. return NO;
  1895. }
  1896. /************************************ COPY ************************************/
  1897. - (void)copyFile:(id)sender
  1898. {
  1899. // Remove all item
  1900. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1901. pasteboard.items = [[NSArray alloc] init];
  1902. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  1903. [self copyFileToPasteboard:self.metadata];
  1904. } else {
  1905. self.metadata.session = k_download_session;
  1906. self.metadata.sessionError = @"";
  1907. self.metadata.sessionSelector = selectorLoadCopy;
  1908. self.metadata.status = k_metadataStatusWaitDownload;
  1909. // Add Metadata for Download
  1910. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  1911. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  1912. [appDelegate startLoadAutoDownloadUpload];
  1913. }
  1914. }
  1915. - (void)copyFiles:(id)sender
  1916. {
  1917. // Remove all item
  1918. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1919. pasteboard.items = [[NSArray alloc] init];
  1920. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1921. for (tableMetadata *metadata in selectedMetadatas) {
  1922. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1923. [self copyFileToPasteboard:metadata];
  1924. } else {
  1925. metadata.session = k_download_session;
  1926. metadata.sessionError = @"";
  1927. metadata.sessionSelector = selectorLoadCopy;
  1928. metadata.status = k_metadataStatusWaitDownload;
  1929. // Add Metadata for Download
  1930. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1931. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:metadata.ocId action:k_action_MOD];
  1932. [appDelegate startLoadAutoDownloadUpload];
  1933. }
  1934. }
  1935. [self tableViewSelect:NO];
  1936. }
  1937. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  1938. {
  1939. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1940. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  1941. // Value : (NSData) ocId
  1942. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.ocId], k_metadataKeyedUnarchiver,nil];
  1943. [items addObject:item];
  1944. [pasteboard setItems:items];
  1945. }
  1946. /************************************ OPEN IN ... ******************************/
  1947. - (void)openinFile:(id)sender
  1948. {
  1949. [[NCMainCommon sharedInstance] downloadOpenInMetadata:self.metadata];
  1950. }
  1951. /************************************ PASTE ************************************/
  1952. - (void)pasteFile:(id)sender
  1953. {
  1954. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1955. [self uploadFilePasteArray:[pasteboard items]];
  1956. }
  1957. - (void)pasteFiles:(id)sender
  1958. {
  1959. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1960. [self uploadFilePasteArray:[pasteboard items]];
  1961. }
  1962. - (void)uploadFilePasteArray:(NSArray *)items
  1963. {
  1964. for (NSDictionary *dic in items) {
  1965. // Value : (NSData) ocId
  1966. NSData *dataocId = [dic objectForKey: k_metadataKeyedUnarchiver];
  1967. NSString *ocId = [NSKeyedUnarchiver unarchiveObjectWithData:dataocId];
  1968. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  1969. if (metadata) {
  1970. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  1971. NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView serverUrl:self.serverUrl account:appDelegate.activeAccount];
  1972. NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:self.serverUrl fileNameView:fileName directory:false];
  1973. [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName]];
  1974. tableMetadata *metadataForUpload = [tableMetadata new];
  1975. metadataForUpload.account = appDelegate.activeAccount;
  1976. metadataForUpload.date = [NSDate new];
  1977. metadataForUpload.ocId = ocId;
  1978. metadataForUpload.fileName = fileName;
  1979. metadataForUpload.fileNameView = fileName;
  1980. metadataForUpload.serverUrl = self.serverUrl;
  1981. metadataForUpload.session = k_upload_session;
  1982. metadataForUpload.sessionSelector = selectorUploadFile;
  1983. metadataForUpload.size = metadata.size;
  1984. metadataForUpload.status = k_metadataStatusWaitUpload;
  1985. // Add Medtadata for upload
  1986. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
  1987. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1988. }
  1989. }
  1990. }
  1991. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  1992. [appDelegate startLoadAutoDownloadUpload];
  1993. }
  1994. #pragma --------------------------------------------------------------------------------------------
  1995. #pragma mark ===== Lock Passcode =====
  1996. #pragma --------------------------------------------------------------------------------------------
  1997. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  1998. {
  1999. return _failedAttempts;
  2000. }
  2001. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2002. {
  2003. return _lockUntilDate;
  2004. }
  2005. - (void)passcodeViewCloseButtonPressed:(id)sender
  2006. {
  2007. [self dismissViewControllerAnimated:YES completion:nil];
  2008. }
  2009. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2010. {
  2011. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2012. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2013. _lockUntilDate = nil;
  2014. _failedAttempts = 0;
  2015. aResultHandler(YES);
  2016. } else aResultHandler(NO);
  2017. } else aResultHandler(YES);
  2018. }
  2019. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2020. {
  2021. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2022. switch (aViewController.type) {
  2023. case BKPasscodeViewControllerCheckPasscodeType: {
  2024. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2025. // possiamo procedere alla prossima directory
  2026. [self performSegueDirectoryWithControlPasscode:false metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2027. // avviamo la sessione Passcode Lock con now
  2028. appDelegate.sessionePasscodeLock = [NSDate date];
  2029. }
  2030. // disattivazione lock cartella
  2031. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2032. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2033. if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO account:appDelegate.activeAccount]) {
  2034. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2035. }
  2036. [self tableViewReloadData];
  2037. }
  2038. }
  2039. break;
  2040. default:
  2041. break;
  2042. }
  2043. }
  2044. - (void)comandoLockPassword
  2045. {
  2046. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2047. // se non è abilitato il Lock Passcode esci
  2048. if ([[CCUtility getBlockCode] length] == 0) {
  2049. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) preferredStyle:UIAlertControllerStyleAlert];
  2050. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  2051. [alertController addAction:okAction];
  2052. [self presentViewController:alertController animated:YES completion:nil];
  2053. return;
  2054. }
  2055. // se è richiesta la disattivazione si chiede la password
  2056. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2057. if (directory.lock) {
  2058. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2059. viewController.delegate = self;
  2060. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2061. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2062. viewController.inputViewTitlePassword = YES;
  2063. if ([CCUtility getSimplyBlockCode]) {
  2064. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2065. viewController.passcodeInputView.maximumLength = 6;
  2066. } else {
  2067. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2068. viewController.passcodeInputView.maximumLength = 64;
  2069. }
  2070. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  2071. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2072. viewController.touchIDManager = touchIDManager;
  2073. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2074. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2075. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  2076. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2077. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  2078. [self presentViewController:navigationController animated:YES completion:nil];
  2079. return;
  2080. }
  2081. // ---------------- ACTIVATE PASSWORD
  2082. if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES account:appDelegate.activeAccount]) {
  2083. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:self.metadata.ocId];
  2084. if ([self indexPathIsValid:indexPath])
  2085. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2086. } else {
  2087. [appDelegate messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2088. }
  2089. }
  2090. #pragma mark -
  2091. #pragma --------------------------------------------------------------------------------------------
  2092. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  2093. #pragma --------------------------------------------------------------------------------------------
  2094. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  2095. {
  2096. if (metadata == nil || _metadataFolder == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || metadata.status != k_metadataStatusNormal || [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])
  2097. return NO;
  2098. // E2EE
  2099. if (_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO)
  2100. return NO;
  2101. return YES;
  2102. }
  2103. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  2104. {
  2105. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2106. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2107. return [self canOpenMenuAction:metadata];
  2108. }
  2109. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  2110. {
  2111. }
  2112. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  2113. {
  2114. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  2115. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2116. if (direction == MGSwipeDirectionRightToLeft) {
  2117. [self actionDelete:indexPath];
  2118. }
  2119. if (direction == MGSwipeDirectionLeftToRight) {
  2120. if (self.metadata.favorite)
  2121. [self settingFavorite:self.metadata favorite:NO];
  2122. else
  2123. [self settingFavorite:self.metadata favorite:YES];
  2124. }
  2125. return YES;
  2126. }
  2127. - (void)actionDelete:(NSIndexPath *)indexPath
  2128. {
  2129. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2130. // Directory locked ?
  2131. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:metadata.fileName];
  2132. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2133. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2134. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) {
  2135. [appDelegate messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  2136. return;
  2137. }
  2138. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  2139. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2140. [self performSelector:@selector(deleteFile) withObject:nil];
  2141. }]];
  2142. if (localFile) {
  2143. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2144. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  2145. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] error:nil];
  2146. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2147. }]];
  2148. }
  2149. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2150. }]];
  2151. alertController.popoverPresentationController.sourceView = self.tableView;
  2152. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  2153. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2154. [alertController.view layoutIfNeeded];
  2155. [self presentViewController:alertController animated:YES completion:nil];
  2156. }
  2157. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  2158. {
  2159. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  2160. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  2161. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2162. NSString *titoloLock, *titleFavorite;
  2163. if (self.metadata.favorite) {
  2164. titleFavorite = NSLocalizedString(@"_remove_favorites_", nil);
  2165. } else {
  2166. titleFavorite = NSLocalizedString(@"_add_favorites_", nil);
  2167. }
  2168. if (self.metadata.directory) {
  2169. // calcolo lockServerUrl
  2170. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2171. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl]];
  2172. if (directory.lock)
  2173. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  2174. else
  2175. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  2176. }
  2177. // ******************************************* AHKActionSheet *******************************************
  2178. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
  2179. actionSheet.animationDuration = 0.2;
  2180. actionSheet.buttonHeight = 50.0;
  2181. actionSheet.cancelButtonHeight = 50.0f;
  2182. actionSheet.separatorHeight = 5.0f;
  2183. actionSheet.automaticallyTintButtonImages = @(NO);
  2184. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.encrypted };
  2185. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2186. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:17], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2187. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:NCBrandColor.sharedInstance.textView };
  2188. actionSheet.separatorColor = NCBrandColor.sharedInstance.separator;
  2189. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  2190. actionSheet.cancelButtonBackgroudColor = NCBrandColor.sharedInstance.backgroundForm;
  2191. // ******************************************* DIRECTORY *******************************************
  2192. if (self.metadata.directory) {
  2193. BOOL lockDirectory = NO;
  2194. BOOL isOffline = NO;
  2195. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  2196. BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] account:appDelegate.activeAccount];
  2197. // Directory bloccata ?
  2198. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl]];
  2199. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil) lockDirectory = YES;
  2200. if (directory.offline) isOffline = YES;
  2201. [actionSheet addButtonWithTitle:self.metadata.fileNameView
  2202. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:NCBrandColor.sharedInstance.brandElement]
  2203. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2204. height:50.0
  2205. type:AHKActionSheetButtonTypeDisabled
  2206. handler:nil
  2207. ];
  2208. [actionSheet addButtonWithTitle: titleFavorite
  2209. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2210. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2211. height: 50.0
  2212. type: AHKActionSheetButtonTypeDefault
  2213. handler: ^(AHKActionSheet *as) {
  2214. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2215. else [self settingFavorite:self.metadata favorite:YES];
  2216. }];
  2217. if (!lockDirectory && !isFolderEncrypted) {
  2218. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2219. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2220. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2221. height:50.0
  2222. type:AHKActionSheetButtonTypeDefault
  2223. handler:^(AHKActionSheet *as) {
  2224. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2225. }];
  2226. }
  2227. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !self.metadata.e2eEncrypted) {
  2228. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2229. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2230. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2231. height:50.0
  2232. type:AHKActionSheetButtonTypeDefault
  2233. handler:^(AHKActionSheet *as) {
  2234. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2235. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2236. textField.text = self.metadata.fileNameView;
  2237. textField.delegate = self;
  2238. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2239. }];
  2240. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2241. NSLog(@"[LOG] Cancel action");
  2242. }];
  2243. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2244. UITextField *fileName = alertController.textFields.firstObject;
  2245. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2246. }];
  2247. okAction.enabled = NO;
  2248. [alertController addAction:cancelAction];
  2249. [alertController addAction:okAction];
  2250. [self presentViewController:alertController animated:YES completion:nil];
  2251. }];
  2252. }
  2253. if (!([self.metadata.fileName isEqualToString:_autoUploadFileName] == YES && [self.metadata.serverUrl isEqualToString:_autoUploadDirectory] == YES) && !lockDirectory && !isFolderEncrypted) {
  2254. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2255. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2256. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2257. height:50.0
  2258. type:AHKActionSheetButtonTypeDefault
  2259. handler:^(AHKActionSheet *as) {
  2260. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2261. }];
  2262. }
  2263. if (!isFolderEncrypted) {
  2264. NSString *title;
  2265. if (isOffline) {
  2266. title = NSLocalizedString(@"_remove_available_offline_", nil);
  2267. } else {
  2268. title = NSLocalizedString(@"_set_available_offline_", nil);
  2269. }
  2270. [actionSheet addButtonWithTitle:title
  2271. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2272. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2273. height:50.0
  2274. type:AHKActionSheetButtonTypeDefault
  2275. handler:^(AHKActionSheet *as) {
  2276. if (isOffline) {
  2277. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:false account:appDelegate.activeAccount];
  2278. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2279. } else {
  2280. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:dirServerUrl offline:true account:appDelegate.activeAccount];
  2281. [[CCSynchronize sharedSynchronize] readFolder:dirServerUrl selector:selectorReadFolderWithDownload account:appDelegate.activeAccount];
  2282. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2283. }
  2284. }];
  2285. }
  2286. [actionSheet addButtonWithTitle:titoloLock
  2287. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2288. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2289. height:50.0
  2290. type:AHKActionSheetButtonTypeDefault
  2291. handler:^(AHKActionSheet *as) {
  2292. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  2293. }];
  2294. if (!self.metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2295. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_set_folder_encrypted_", nil)
  2296. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2297. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2298. height:50.0
  2299. type:AHKActionSheetButtonTypeDefault
  2300. handler:^(AHKActionSheet *as) {
  2301. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  2302. NSError *error = [[NCNetworkingEndToEnd sharedManager] markEndToEndFolderEncryptedOnServerUrl:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] ocId:self.metadata.ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  2303. dispatch_async(dispatch_get_main_queue(), ^{
  2304. if (error) {
  2305. [appDelegate messageNotification:@"_e2e_error_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2306. } else {
  2307. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2308. [self readFolder:self.serverUrl];
  2309. }
  2310. });
  2311. });
  2312. }];
  2313. }
  2314. if (self.metadata.e2eEncrypted && !_metadataFolder.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2315. [actionSheet addButtonWithTitle:NSLocalizedString(@"_e2e_remove_folder_encrypted_", nil)
  2316. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2317. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2318. height:50.0
  2319. type:AHKActionSheetButtonTypeDefault
  2320. handler:^(AHKActionSheet *as) {
  2321. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2322. NSError *error = [[NCNetworkingEndToEnd sharedManager] deletemarkEndToEndFolderEncryptedOnServerUrl:[NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName] ocId:self.metadata.ocId user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl];
  2323. dispatch_async(dispatch_get_main_queue(), ^{
  2324. if (error) {
  2325. [appDelegate messageNotification:@"_e2e_error_delete_mark_folder_" description:error.localizedDescription visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  2326. } else {
  2327. [[NCManageDatabase sharedInstance] deleteE2eEncryptionWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, [NSString stringWithFormat:@"%@/%@", self.serverUrl, self.metadata.fileName]]];
  2328. [self readFolder:self.serverUrl];
  2329. }
  2330. });
  2331. });
  2332. }];
  2333. }
  2334. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2335. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2336. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2337. height:50.0
  2338. type:AHKActionSheetButtonTypeDestructive
  2339. handler:^(AHKActionSheet *as) {
  2340. [self actionDelete:indexPath];
  2341. }];
  2342. [actionSheet show];
  2343. }
  2344. // ******************************************* FILE *******************************************
  2345. if (!self.metadata.directory) {
  2346. UIImage *iconHeader;
  2347. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  2348. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]])
  2349. iconHeader = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]];
  2350. else
  2351. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  2352. [actionSheet addButtonWithTitle: self.metadata.fileNameView
  2353. image: iconHeader
  2354. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2355. height: 50.0
  2356. type: AHKActionSheetButtonTypeDisabled
  2357. handler: nil
  2358. ];
  2359. [actionSheet addButtonWithTitle: titleFavorite
  2360. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] multiplier:2 color:NCBrandColor.sharedInstance.yellowFavorite]
  2361. backgroundColor: NCBrandColor.sharedInstance.backgroundForm
  2362. height: 50.0
  2363. type: AHKActionSheetButtonTypeDefault
  2364. handler: ^(AHKActionSheet *as) {
  2365. if (self.metadata.favorite) [self settingFavorite:self.metadata favorite:NO];
  2366. else [self settingFavorite:self.metadata favorite:YES];
  2367. }];
  2368. if (!_metadataFolder.e2eEncrypted) {
  2369. [actionSheet addButtonWithTitle:NSLocalizedString(@"_details_", nil)
  2370. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"details"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2371. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2372. height: 50.0
  2373. type:AHKActionSheetButtonTypeDefault
  2374. handler:^(AHKActionSheet *as) {
  2375. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadata indexPage:0];
  2376. }];
  2377. }
  2378. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  2379. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  2380. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"openFile"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2381. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2382. height: 50.0
  2383. type:AHKActionSheetButtonTypeDefault
  2384. handler:^(AHKActionSheet *as) {
  2385. [self performSelector:@selector(openinFile:) withObject:nil];
  2386. }];
  2387. }
  2388. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  2389. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2390. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2391. height: 50.0
  2392. type:AHKActionSheetButtonTypeDefault
  2393. handler:^(AHKActionSheet *as) {
  2394. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  2395. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  2396. textField.text = self.metadata.fileNameView;
  2397. textField.delegate = self;
  2398. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  2399. }];
  2400. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2401. NSLog(@"[LOG] Cancel action");
  2402. }];
  2403. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2404. UITextField *fileName = alertController.textFields.firstObject;
  2405. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:self.metadata,fileName.text, nil] waitUntilDone:NO];
  2406. }];
  2407. okAction.enabled = NO;
  2408. [alertController addAction:cancelAction];
  2409. [alertController addAction:okAction];
  2410. [self presentViewController:alertController animated:YES completion:nil];
  2411. }];
  2412. if (!_metadataFolder.e2eEncrypted) {
  2413. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  2414. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"move"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2415. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2416. height:50.0
  2417. type:AHKActionSheetButtonTypeDefault
  2418. handler:^(AHKActionSheet *as) {
  2419. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  2420. }];
  2421. }
  2422. if ([NCUtility.sharedInstance isEditImage:self.metadata.fileNameView] != nil && !_metadataFolder.e2eEncrypted && self.metadata.status == k_metadataStatusNormal) {
  2423. [actionSheet addButtonWithTitle:NSLocalizedString(@"_modify_photo_", nil)
  2424. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"modifyPhoto"] width:50 height:50 color:NCBrandColor.sharedInstance.icon]
  2425. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2426. height:50.0
  2427. type:AHKActionSheetButtonTypeDefault
  2428. handler:^(AHKActionSheet *as) {
  2429. self.metadata.session = k_download_session;
  2430. self.metadata.sessionError = @"";
  2431. self.metadata.sessionSelector = selectorDownloadEditPhoto;
  2432. self.metadata.status = k_metadataStatusWaitDownload;
  2433. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2434. [appDelegate startLoadAutoDownloadUpload];
  2435. }];
  2436. }
  2437. if (!_metadataFolder.e2eEncrypted) {
  2438. NSString *title;
  2439. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", self.metadata.ocId]];
  2440. if (localFile == nil || localFile.offline == false) { title = NSLocalizedString(@"_set_available_offline_", nil); }
  2441. else { title = NSLocalizedString(@"_remove_available_offline_", nil); }
  2442. [actionSheet addButtonWithTitle:title
  2443. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"offline"] multiplier:2 color:NCBrandColor.sharedInstance.icon]
  2444. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2445. height:50.0
  2446. type:AHKActionSheetButtonTypeDefault
  2447. handler:^(AHKActionSheet *as) {
  2448. if (localFile == nil || ![CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2449. self.metadata.session = k_download_session;
  2450. self.metadata.sessionError = @"";
  2451. self.metadata.sessionSelector = selectorLoadOffline;
  2452. self.metadata.status = k_metadataStatusWaitDownload;
  2453. // Add Metadata for Download
  2454. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2455. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2456. [appDelegate startLoadAutoDownloadUpload];
  2457. } else if (localFile.offline == false) {
  2458. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:true];
  2459. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2460. } else {
  2461. [[NCManageDatabase sharedInstance] setLocalFileWithOcId:self.metadata.ocId offline:false];
  2462. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  2463. }
  2464. }];
  2465. }
  2466. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil)
  2467. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]]
  2468. backgroundColor:NCBrandColor.sharedInstance.backgroundForm
  2469. height:50.0
  2470. type:AHKActionSheetButtonTypeDestructive
  2471. handler:^(AHKActionSheet *as) {
  2472. [self actionDelete:indexPath];
  2473. }];
  2474. [actionSheet show];
  2475. }
  2476. }
  2477. #pragma --------------------------------------------------------------------------------------------
  2478. #pragma mark - ==== Datasource ====
  2479. #pragma --------------------------------------------------------------------------------------------
  2480. - (void)clearDateReadDataSource:(NSNotification *)notification
  2481. {
  2482. _dateReadDataSource = Nil;
  2483. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
  2484. }
  2485. - (void)reloadDatasource:(NSString *)serverUrl ocId:(NSString *)ocId action:(NSInteger)action
  2486. {
  2487. // test
  2488. if (appDelegate.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil || self.view.window == nil)
  2489. return;
  2490. // Search Mode
  2491. if (_isSearchMode) {
  2492. // Create metadatas
  2493. NSMutableArray *metadatas = [NSMutableArray new];
  2494. for (tableMetadata *resultMetadata in _searchResultMetadatas) {
  2495. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", resultMetadata.ocId]];
  2496. if (metadata) {
  2497. [metadatas addObject:metadata];
  2498. }
  2499. }
  2500. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:@"fileName" ascending:NO activeAccount:appDelegate.activeAccount];
  2501. [self tableViewReloadData];
  2502. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  2503. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  2504. _noFilesSearchDescription = @"";
  2505. }
  2506. if ([sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  2507. _noFilesSearchTitle = @"";
  2508. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  2509. }
  2510. [self.tableView reloadEmptyDataSet];
  2511. return;
  2512. }
  2513. // Se non siamo nella dir appropriata esci
  2514. if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil) {
  2515. return;
  2516. }
  2517. // Controllo data lettura Data Source
  2518. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  2519. if (tableDirectory == nil) {
  2520. return;
  2521. }
  2522. // Get MetadataFolder
  2523. if ([serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]])
  2524. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, k_serverUrl_root]];
  2525. else
  2526. _metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", tableDirectory.ocId]];
  2527. // Remove optimization for encrypted directory
  2528. if (_metadataFolder.e2eEncrypted)
  2529. _dateReadDataSource = nil;
  2530. NSDate *dateDateRecordDirectory = tableDirectory.dateReadDirectory;
  2531. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  2532. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  2533. _dateReadDataSource = [NSDate date];
  2534. // Data Source
  2535. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2536. CCSectionDataSourceMetadata *sectionDataSourceTemp = [self queryDatasourceWithReloadData:NO serverUrl:serverUrl];
  2537. dispatch_async(dispatch_get_main_queue(), ^{
  2538. sectionDataSource = sectionDataSourceTemp;
  2539. [self tableViewReloadData];
  2540. });
  2541. });
  2542. } else {
  2543. [self tableViewReloadData];
  2544. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  2545. }
  2546. // BLINK
  2547. if (self.blinkFileNamePath != nil) {
  2548. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2549. for (NSString *key in sectionDataSource.allRecordsDataSource) {
  2550. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:key];
  2551. NSString *metadataFileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
  2552. if ([metadataFileNamePath isEqualToString:self.blinkFileNamePath]) {
  2553. for (NSString *key in sectionDataSource.ocIdIndexPath) {
  2554. if ([key isEqualToString:metadata.ocId]) {
  2555. NSIndexPath *indexPath = [sectionDataSource.ocIdIndexPath objectForKey:key];
  2556. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  2557. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  2558. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  2559. if (cell) {
  2560. self.blinkFileNamePath = nil;
  2561. [[NCUtility sharedInstance] blinkWithCell:cell];
  2562. }
  2563. });
  2564. }
  2565. }
  2566. }
  2567. }
  2568. });
  2569. }
  2570. }
  2571. - (CCSectionDataSourceMetadata *)queryDatasourceWithReloadData:(BOOL)withReloadData serverUrl:(NSString *)serverUrl
  2572. {
  2573. // test
  2574. if (appDelegate.activeAccount.length == 0 || serverUrl == nil) {
  2575. return nil;
  2576. }
  2577. // get auto upload folder
  2578. _autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  2579. _autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
  2580. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  2581. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND status != %i", appDelegate.activeAccount, serverUrl, k_metadataStatusHide] sorted:nil ascending:NO];
  2582. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:[CCUtility getGroupBySettings] filterocId:appDelegate.filterocId filterTypeFileImage:NO filterTypeFileVideo:NO sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings] activeAccount:appDelegate.activeAccount];
  2583. if (withReloadData) {
  2584. sectionDataSource = sectionDataSourceTemp;
  2585. [self tableViewReloadData];
  2586. }
  2587. return sectionDataSourceTemp;
  2588. }
  2589. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  2590. {
  2591. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  2592. if (selectedRows.count > 0) {
  2593. for (NSIndexPath *selectionIndex in selectedRows) {
  2594. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  2595. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2596. [metadatas addObject:metadata];
  2597. }
  2598. }
  2599. return metadatas;
  2600. }
  2601. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  2602. {
  2603. NSInteger totSections =[sectionDataSource.sections count] ;
  2604. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  2605. return nil;
  2606. }
  2607. id valueSection = [sectionDataSource.sections objectAtIndex:section];
  2608. return [sectionDataSource.sectionArrayRow objectForKey:valueSection];
  2609. }
  2610. #pragma --------------------------------------------------------------------------------------------
  2611. #pragma mark - ==== Table ====
  2612. #pragma --------------------------------------------------------------------------------------------
  2613. - (void)tableViewSelect:(BOOL)edit
  2614. {
  2615. // chiudiamo eventuali swipe aperti
  2616. if (edit)
  2617. [self.tableView setEditing:NO animated:NO];
  2618. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  2619. [self.tableView setEditing:edit animated:YES];
  2620. _isSelectedMode = edit;
  2621. if (edit)
  2622. [self setUINavigationBarSelected];
  2623. else
  2624. [self setUINavigationBarDefault];
  2625. [_selectedocIdsMetadatas removeAllObjects];
  2626. [self setTitle];
  2627. }
  2628. - (void)tableViewReloadData
  2629. {
  2630. // store selected cells before relod
  2631. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  2632. // reload table view
  2633. [self.tableView reloadData];
  2634. // selected cells stored
  2635. for (NSIndexPath *path in indexPaths)
  2636. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  2637. [self setTableViewFooter];
  2638. if (self.tableView.editing)
  2639. [self setTitle];
  2640. [self.tableView reloadEmptyDataSet];
  2641. }
  2642. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  2643. {
  2644. if (tableView.editing == 1) {
  2645. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2646. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  2647. return NO;
  2648. if (metadata == nil || metadata.status != k_metadataStatusNormal)
  2649. return NO;
  2650. else
  2651. return YES;
  2652. } else {
  2653. [_selectedocIdsMetadatas removeAllObjects];
  2654. }
  2655. return YES;
  2656. }
  2657. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  2658. {
  2659. return 60;
  2660. }
  2661. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2662. {
  2663. return [[sectionDataSource.sectionArrayRow allKeys] count];
  2664. }
  2665. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2666. {
  2667. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  2668. }
  2669. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2670. {
  2671. NSArray *sections = [sectionDataSource.sectionArrayRow allKeys];
  2672. NSString *sectionTitle = [sections objectAtIndex:section];
  2673. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  2674. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  2675. if ([[CCUtility getGroupBySettings] isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  2676. return 20.f;
  2677. }
  2678. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2679. {
  2680. float shift;
  2681. UIVisualEffectView *visualEffectView;
  2682. NSString *titleSection;
  2683. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  2684. return nil;
  2685. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  2686. titleSection = [sectionDataSource.sections objectAtIndex:section];
  2687. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  2688. titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  2689. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  2690. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  2691. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  2692. else titleSection = NSLocalizedString(titleSection,nil);
  2693. // Format title
  2694. UIVisualEffect *blurEffect;
  2695. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  2696. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  2697. visualEffectView.backgroundColor = [NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.2];
  2698. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"]) {
  2699. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  2700. shift = - 35;
  2701. else
  2702. shift = - 20;
  2703. } else shift = - 10;
  2704. // Title
  2705. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  2706. titleLabel.backgroundColor = [UIColor clearColor];
  2707. titleLabel.textColor = NCBrandColor.sharedInstance.textView;
  2708. titleLabel.font = [UIFont systemFontOfSize:12];
  2709. titleLabel.textAlignment = NSTextAlignmentLeft;
  2710. titleLabel.text = titleSection;
  2711. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2712. [visualEffectView.contentView addSubview:titleLabel];
  2713. // Elements
  2714. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  2715. elementLabel.backgroundColor = [UIColor clearColor];
  2716. elementLabel.textColor = NCBrandColor.sharedInstance.textView;
  2717. elementLabel.font = [UIFont systemFontOfSize:12];
  2718. elementLabel.textAlignment = NSTextAlignmentRight;
  2719. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2720. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  2721. NSUInteger rowsCount = [metadatas count];
  2722. if (rowsCount == 0) return nil;
  2723. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  2724. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  2725. [visualEffectView.contentView addSubview:elementLabel];
  2726. return visualEffectView;
  2727. }
  2728. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  2729. {
  2730. return [sectionDataSource.sections indexOfObject:title];
  2731. }
  2732. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  2733. {
  2734. if ([[CCUtility getGroupBySettings] isEqualToString:@"alphabetic"])
  2735. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  2736. else
  2737. return nil;
  2738. }
  2739. /*
  2740. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  2741. {
  2742. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  2743. }
  2744. }
  2745. */
  2746. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2747. {
  2748. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2749. tableShare *shareCell;
  2750. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata] || (_metadataFolder != nil && [[NCManageDatabase sharedInstance] isTableInvalidated:_metadataFolder])) {
  2751. return [CCCellMain new];
  2752. }
  2753. for (tableShare *share in appDelegate.shares) {
  2754. if ([share.serverUrl isEqualToString:metadata.serverUrl] && [share.fileName isEqualToString:metadata.fileName]) {
  2755. shareCell = share;
  2756. break;
  2757. }
  2758. }
  2759. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:_metadataFolder serverUrl:self.serverUrl autoUploadFileName:_autoUploadFileName autoUploadDirectory:_autoUploadDirectory tableShare:shareCell];
  2760. // NORMAL - > MAIN
  2761. if ([cell isKindOfClass:[CCCellMain class]]) {
  2762. // Comment tap
  2763. if (metadata.commentsUnread) {
  2764. UITapGestureRecognizer *tapComment = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionComment:)];
  2765. [tapComment setNumberOfTapsRequired:1];
  2766. ((CCCellMain *)cell).comment.userInteractionEnabled = YES;
  2767. [((CCCellMain *)cell).comment addGestureRecognizer:tapComment];
  2768. }
  2769. // Share add Tap
  2770. UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  2771. [tapShare setNumberOfTapsRequired:1];
  2772. ((CCCellMain *)cell).viewShared.userInteractionEnabled = YES;
  2773. [((CCCellMain *)cell).viewShared addGestureRecognizer:tapShare];
  2774. // More
  2775. if ([self canOpenMenuAction:metadata]) {
  2776. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  2777. [tapMore setNumberOfTapsRequired:1];
  2778. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  2779. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  2780. }
  2781. // MGSwipeButton
  2782. ((CCCellMain *)cell).delegate = self;
  2783. // LEFT
  2784. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellFavouriteImage backgroundColor:NCBrandColor.sharedInstance.yellowFavorite padding:25]];
  2785. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  2786. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  2787. //centerIconOverText
  2788. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  2789. [favoriteButton centerIconOverText];
  2790. // RIGHT
  2791. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:self.cellTrashImage backgroundColor:[UIColor redColor] padding:25]];
  2792. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  2793. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  2794. //centerIconOverText
  2795. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  2796. [deleteButton centerIconOverText];
  2797. }
  2798. // TRANSFER
  2799. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  2800. // gesture Transfer
  2801. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  2802. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  2803. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  2804. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  2805. }
  2806. return cell;
  2807. }
  2808. - (void)setTableViewFooter
  2809. {
  2810. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2811. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2812. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  2813. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  2814. UIFont *appFont = [UIFont systemFontOfSize:12];
  2815. footerLabel.font = appFont;
  2816. footerLabel.textColor = [UIColor grayColor];
  2817. footerLabel.backgroundColor = [UIColor clearColor];
  2818. footerLabel.textAlignment = NSTextAlignmentCenter;
  2819. NSString *folders;
  2820. NSString *files;
  2821. NSString *footerText;
  2822. if (sectionDataSource.directories > 1) {
  2823. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  2824. } else if (sectionDataSource.directories == 1){
  2825. folders = [NSString stringWithFormat:@"%ld %@", (long)sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  2826. } else {
  2827. folders = @"";
  2828. }
  2829. if (sectionDataSource.files > 1) {
  2830. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2831. } else if (sectionDataSource.files == 1){
  2832. files = [NSString stringWithFormat:@"%ld %@ %@", (long)sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:sectionDataSource.totalSize]];
  2833. } else {
  2834. files = @"";
  2835. }
  2836. if ([folders isEqualToString:@""]) {
  2837. footerText = files;
  2838. } else if ([files isEqualToString:@""]) {
  2839. footerText = folders;
  2840. } else {
  2841. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  2842. }
  2843. footerLabel.text = footerText;
  2844. [footerView addSubview:footerLabel];
  2845. [self.tableView setTableFooterView:footerView];
  2846. }
  2847. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2848. {
  2849. CCCellMain *cell = [tableView cellForRowAtIndexPath:indexPath];
  2850. // settiamo il record file.
  2851. self.metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2852. if (!self.metadata)
  2853. return;
  2854. // se non può essere selezionata deseleziona
  2855. if ([cell isEditing] == NO)
  2856. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  2857. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  2858. if (self.tableView.editing) {
  2859. [_selectedocIdsMetadatas setObject:self.metadata forKey:self.metadata.ocId];
  2860. [self setTitle];
  2861. return;
  2862. }
  2863. // se è in corso una sessione
  2864. if (self.metadata.status != k_metadataStatusNormal)
  2865. return;
  2866. // file
  2867. if (self.metadata.directory == NO) {
  2868. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  2869. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  2870. [[NCNetworkingMain sharedInstance] downloadFileSuccessFailure:self.metadata.fileName ocId:self.metadata.ocId serverUrl:self.metadata.serverUrl selector:selectorLoadFileView errorMessage:@"" errorCode:0];
  2871. } else {
  2872. if (_metadataFolder.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.activeAccount]) {
  2873. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  2874. } else {
  2875. if (([self.metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_audio] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_image]) && _metadataFolder.e2eEncrypted == NO) {
  2876. [self shouldPerformSegue:self.metadata];
  2877. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility sharedInstance] isRichDocument:self.metadata]) {
  2878. if (appDelegate.reachability.isReachable) {
  2879. [self shouldPerformSegue:self.metadata];
  2880. } else {
  2881. [appDelegate messageNotification:@"_info_" description:@"_go_online_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  2882. }
  2883. } else {
  2884. self.metadata.session = k_download_session;
  2885. self.metadata.sessionError = @"";
  2886. self.metadata.sessionSelector = selectorLoadFileView;
  2887. self.metadata.status = k_metadataStatusWaitDownload;
  2888. // Add Metadata for Download
  2889. (void)[[NCManageDatabase sharedInstance] addMetadata:self.metadata];
  2890. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:self.metadata.ocId action:k_action_MOD];
  2891. [appDelegate startLoadAutoDownloadUpload];
  2892. }
  2893. }
  2894. }
  2895. }
  2896. if (self.metadata.directory) {
  2897. [self performSegueDirectoryWithControlPasscode:true metadata:self.metadata blinkFileNamePath:self.blinkFileNamePath];
  2898. }
  2899. }
  2900. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  2901. {
  2902. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2903. [_selectedocIdsMetadatas removeObjectForKey:metadata.ocId];
  2904. [self setTitle];
  2905. }
  2906. - (void)didSelectAll
  2907. {
  2908. for (int i = 0; i < self.tableView.numberOfSections; i++) {
  2909. for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
  2910. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  2911. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  2912. [_selectedocIdsMetadatas setObject:metadata forKey:metadata.ocId];
  2913. [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  2914. }
  2915. }
  2916. [self setTitle];
  2917. }
  2918. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  2919. {
  2920. if (!indexPath)
  2921. return NO;
  2922. NSInteger section = indexPath.section;
  2923. NSInteger row = indexPath.row;
  2924. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  2925. if (section > lastSectionIndex || lastSectionIndex < 0)
  2926. return NO;
  2927. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  2928. if (rowCount < 0)
  2929. return NO;
  2930. return row <= rowCount;
  2931. }
  2932. #pragma --------------------------------------------------------------------------------------------
  2933. #pragma mark ===== Navigation ====
  2934. #pragma --------------------------------------------------------------------------------------------
  2935. - (void)shouldPerformSegue:(tableMetadata *)metadata
  2936. {
  2937. // if background return
  2938. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  2939. if (self.view.window == NO)
  2940. return;
  2941. // Collapsed ma siamo già in detail esci
  2942. if (self.splitViewController.isCollapsed)
  2943. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return;
  2944. // Metadata for push detail
  2945. self.metadataForPushDetail = metadata;
  2946. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  2947. }
  2948. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  2949. {
  2950. id viewController = segue.destinationViewController;
  2951. tableMetadata *metadata;
  2952. if ([viewController isKindOfClass:[UINavigationController class]]) {
  2953. UINavigationController *nav = viewController;
  2954. _detailViewController = (CCDetail *)nav.topViewController;
  2955. } else {
  2956. _detailViewController = segue.destinationViewController;
  2957. }
  2958. NSMutableArray *photoDataSource = [NSMutableArray new];
  2959. if ([sender isKindOfClass:[tableMetadata class]]) {
  2960. metadata = sender;
  2961. [photoDataSource addObject:sender];
  2962. } else {
  2963. metadata = self.metadataForPushDetail;
  2964. for (NSString *ocId in sectionDataSource.allOcId) {
  2965. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  2966. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  2967. [photoDataSource addObject:metadata];
  2968. }
  2969. }
  2970. _detailViewController.metadataDetail = metadata;
  2971. _detailViewController.photoDataSource = photoDataSource;
  2972. _detailViewController.dateFilterQuery = nil;
  2973. [_detailViewController setTitle:metadata.fileNameView];
  2974. }
  2975. // can i go to next viewcontroller
  2976. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode metadata:(tableMetadata *)metadata blinkFileNamePath:(NSString *)blinkFileNamePath
  2977. {
  2978. NSString *nomeDir;
  2979. if (self.tableView.editing == NO) {
  2980. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  2981. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", metadata.account, lockServerUrl]];
  2982. // SE siamo in presenza di una directory bloccata E è attivo il block E la sessione password Lock è senza data ALLORA chiediamo la password per procedere
  2983. if (directory.lock && [[CCUtility getBlockCode] length] && appDelegate.sessionePasscodeLock == nil && controlPasscode) {
  2984. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2985. viewController.delegate = self;
  2986. viewController.fromType = CCBKPasscodeFromLockDirectory;
  2987. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2988. viewController.inputViewTitlePassword = YES;
  2989. if ([CCUtility getSimplyBlockCode]) {
  2990. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2991. viewController.passcodeInputView.maximumLength = 6;
  2992. } else {
  2993. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2994. viewController.passcodeInputView.maximumLength = 64;
  2995. }
  2996. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  2997. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2998. viewController.touchIDManager = touchIDManager;
  2999. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  3000. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3001. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  3002. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3003. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  3004. [self presentViewController:navigationController animated:YES completion:nil];
  3005. return;
  3006. }
  3007. // E2EE Check enable
  3008. if (metadata.e2eEncrypted && [CCUtility isEndToEndEnabled:appDelegate.activeAccount] == NO) {
  3009. [appDelegate messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  3010. return;
  3011. }
  3012. nomeDir = metadata.fileName;
  3013. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:nomeDir];
  3014. CCMain *viewController = [appDelegate.listMainVC objectForKey:serverUrlPush];
  3015. if (!viewController) {
  3016. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMain"];
  3017. viewController.serverUrl = serverUrlPush;
  3018. viewController.titleMain = metadata.fileName;
  3019. viewController.blinkFileNamePath = blinkFileNamePath;
  3020. // save self
  3021. [appDelegate.listMainVC setObject:viewController forKey:serverUrlPush];
  3022. [self.navigationController pushViewController:viewController animated:YES];
  3023. } else {
  3024. if (viewController.isViewLoaded) {
  3025. viewController.titleMain = metadata.fileName;
  3026. viewController.blinkFileNamePath = blinkFileNamePath;
  3027. // Fix : Application tried to present modally an active controller
  3028. if ([self.navigationController isBeingPresented]) {
  3029. // being presented
  3030. } else if ([self.navigationController isMovingToParentViewController]) {
  3031. // being pushed
  3032. } else {
  3033. [self.navigationController pushViewController:viewController animated:YES];
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. @end