CCMain.m 214 KB

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