CCMain.m 207 KB

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