CCMain.m 201 KB

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