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