CCMain.m 201 KB

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