CCMain.m 205 KB

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