CCMain.m 198 KB

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