CCMain.m 198 KB

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