CCMain.m 206 KB

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