CCMain.m 206 KB

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