CCMain.m 206 KB

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