|
@@ -25,28 +25,31 @@
|
|
|
#import "AppDelegate.h"
|
|
|
#import "CCMain.h"
|
|
|
#import "NCUchardet.h"
|
|
|
+#import <KTVHTTPCache/KTVHTTPCache.h>
|
|
|
+
|
|
|
#import "NCBridgeSwift.h"
|
|
|
|
|
|
#define TOOLBAR_HEIGHT 49.0f
|
|
|
|
|
|
#define alertRequestPasswordPDF 1
|
|
|
|
|
|
-@interface CCDetail ()
|
|
|
+@interface CCDetail () <NCTextDelegate>
|
|
|
{
|
|
|
AppDelegate *appDelegate;
|
|
|
+
|
|
|
+ UIBarButtonItem *buttonModifyTxt;
|
|
|
+ UIBarButtonItem *buttonAction;
|
|
|
+ UIBarButtonItem *buttonShare;
|
|
|
+ UIBarButtonItem *buttonDelete;
|
|
|
|
|
|
- UIToolbar *_toolbar;
|
|
|
-
|
|
|
- UIBarButtonItem *_buttonModifyTxt;
|
|
|
- UIBarButtonItem *_buttonAction;
|
|
|
- UIBarButtonItem *_buttonShare;
|
|
|
- UIBarButtonItem *_buttonDelete;
|
|
|
+ NSInteger indexNowVisible;
|
|
|
+ NSString *fileIDNowVisible;
|
|
|
|
|
|
- NSInteger _indexNowVisible;
|
|
|
- NSString *_fileIDNowVisible;
|
|
|
+ NSMutableOrderedSet *dataSourceDirectoryID;
|
|
|
+ NSString *fileNameExtension;
|
|
|
|
|
|
- NSMutableOrderedSet *_dataSourceDirectoryID;
|
|
|
- NSString *_fileNameExtension;
|
|
|
+ NSURL *videoURLProxy;
|
|
|
+ NSURL *videoURL;
|
|
|
}
|
|
|
@end
|
|
|
|
|
@@ -64,14 +67,13 @@
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backNavigationController) name:@"detailBack" object:nil];
|
|
|
|
|
|
self.metadataDetail = [[tableMetadata alloc] init];
|
|
|
self.photos = [[NSMutableArray alloc] init];
|
|
|
- self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
|
|
|
- _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
|
|
|
- _indexNowVisible = -1;
|
|
|
- _fileIDNowVisible = nil;
|
|
|
+ self.photoDataSource = [NSMutableArray new];
|
|
|
+ dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
|
|
|
+ indexNowVisible = -1;
|
|
|
+ fileIDNowVisible = nil;
|
|
|
|
|
|
appDelegate.activeDetail = self;
|
|
|
}
|
|
@@ -90,9 +92,21 @@
|
|
|
|
|
|
self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
|
|
|
|
|
|
- // Change bar bottom line shadow
|
|
|
+ // Proxy
|
|
|
+ static dispatch_once_t onceToken;
|
|
|
+ dispatch_once(&onceToken, ^{
|
|
|
+ [self setupHTTPCache];
|
|
|
+ });
|
|
|
+
|
|
|
+ // Change bar bottom line shadow and remove title back button <"title"
|
|
|
self.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
|
|
|
+ self.navigationController.navigationBar.topItem.title = @"";
|
|
|
|
|
|
+ // TabBar
|
|
|
+ self.tabBarController.tabBar.hidden = YES;
|
|
|
+ self.tabBarController.tabBar.translucent = YES;
|
|
|
+
|
|
|
+ // Open View
|
|
|
if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
|
|
|
|
|
|
// open view
|
|
@@ -100,77 +114,37 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Apparirà
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
{
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
- if (self.splitViewController.isCollapsed) {
|
|
|
-
|
|
|
- self.tabBarController.tabBar.hidden = YES;
|
|
|
- self.tabBarController.tabBar.translucent = YES;
|
|
|
- }
|
|
|
-
|
|
|
- if (self.splitViewController.isCollapsed)
|
|
|
- [appDelegate plusButtonVisibile:false];
|
|
|
+ self.tabBarController.tabBar.hidden = YES;
|
|
|
+ self.tabBarController.tabBar.translucent = YES;
|
|
|
}
|
|
|
|
|
|
-// E' scomparso
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
|
{
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
|
- // remove all
|
|
|
- if (self.isMovingFromParentViewController)
|
|
|
- [self removeAllView];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
|
|
-{
|
|
|
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
|
|
-
|
|
|
- }];
|
|
|
-
|
|
|
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
+ // If AVPlayer in play -> Stop
|
|
|
+ if (appDelegate.player != nil && appDelegate.player.rate != 0) {
|
|
|
+ [appDelegate.player pause];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// remove all view
|
|
|
-- (void)removeAllView
|
|
|
+- (void)changeTheming
|
|
|
{
|
|
|
- // Document
|
|
|
- if (_webView) {
|
|
|
- [_webView removeFromSuperview];
|
|
|
- _webView = nil;
|
|
|
- }
|
|
|
-
|
|
|
- // PDF
|
|
|
- if (_readerPDFViewController) {
|
|
|
- [_readerPDFViewController.view removeFromSuperview];
|
|
|
- _readerPDFViewController.delegate = nil;
|
|
|
- _readerPDFViewController = nil;
|
|
|
- }
|
|
|
-
|
|
|
- // Photo-Video-Audio
|
|
|
- if (_photoBrowser) {
|
|
|
- [_photos removeAllObjects];
|
|
|
- _photoBrowser.delegate = nil;
|
|
|
- _photoBrowser = nil;
|
|
|
- }
|
|
|
+ [appDelegate changeTheming:self];
|
|
|
|
|
|
- // ToolBar
|
|
|
- if (_toolbar) {
|
|
|
- [_toolbar removeFromSuperview];
|
|
|
- _toolbar = nil;
|
|
|
+ if (self.toolbar) {
|
|
|
+ self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
|
|
|
+ self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
|
|
|
}
|
|
|
-
|
|
|
- // Title
|
|
|
- self.title = nil;
|
|
|
}
|
|
|
|
|
|
- (void)backNavigationController
|
|
|
{
|
|
|
- [self removeAllView];
|
|
|
- [self.navigationController popViewControllerAnimated:NO];
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
|
|
|
- (void)changeToDisplayMode
|
|
@@ -179,58 +153,6 @@
|
|
|
[self.readerPDFViewController updateContentViews];
|
|
|
}
|
|
|
|
|
|
-- (void)createToolbar
|
|
|
-{
|
|
|
- CGFloat safeAreaBottom = 0;
|
|
|
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
|
|
|
- if (!serverUrl)
|
|
|
- return;
|
|
|
-
|
|
|
- if (@available(iOS 11, *)) {
|
|
|
- safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
|
|
|
- }
|
|
|
-
|
|
|
- _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
|
|
|
-
|
|
|
- UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
|
|
|
- UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
|
|
|
- fixedSpaceMini.width = 25;
|
|
|
-
|
|
|
- _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
|
|
|
- _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
|
|
|
- _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
|
|
|
- _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
|
|
|
-
|
|
|
- if ([CCUtility isDocumentModifiableExtension:_fileNameExtension]) {
|
|
|
- if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
|
|
|
- [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
|
|
|
- else
|
|
|
- [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
|
|
|
- } else {
|
|
|
- if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
|
|
|
- [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
|
|
|
- else
|
|
|
- [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
|
|
|
- }
|
|
|
-
|
|
|
- [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
|
|
|
-
|
|
|
- _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
|
|
|
- _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
|
|
|
-
|
|
|
- [self.view addSubview:_toolbar];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)changeTheming
|
|
|
-{
|
|
|
- [appDelegate changeTheming:self];
|
|
|
-
|
|
|
- if (_toolbar) {
|
|
|
- _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
|
|
|
- _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== View File =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
@@ -243,31 +165,90 @@
|
|
|
[CCGraphics createNewImageFrom:self.metadataDetail.fileNameView fileID:self.metadataDetail.fileID extension:[self.metadataDetail.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writeImage:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
|
|
|
}
|
|
|
|
|
|
- if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
|
|
|
+ // IMAGE
|
|
|
+ if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
|
|
|
+
|
|
|
+ self.edgesForExtendedLayout = UIRectEdgeAll;
|
|
|
+ [self viewImage];
|
|
|
+ }
|
|
|
+
|
|
|
+ // AUDIO VIDEO
|
|
|
+ if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
|
|
|
|
|
|
self.edgesForExtendedLayout = UIRectEdgeAll;
|
|
|
- [self viewImageVideoAudio];
|
|
|
+ [self createToolbar];
|
|
|
+ [self viewMedia];
|
|
|
+ [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
|
|
|
}
|
|
|
|
|
|
+ // DOCUMENT
|
|
|
if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
|
|
|
|
|
|
- _fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
|
|
|
+ fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
|
|
|
|
|
|
- if ([_fileNameExtension isEqualToString:@"PDF"]) {
|
|
|
+ if ([fileNameExtension isEqualToString:@"PDF"]) {
|
|
|
|
|
|
self.edgesForExtendedLayout = UIRectEdgeBottom;
|
|
|
- [self viewPDF:@""];
|
|
|
[self createToolbar];
|
|
|
+ [self viewPDF:@""];
|
|
|
[appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
-
|
|
|
+
|
|
|
self.edgesForExtendedLayout = UIRectEdgeBottom;
|
|
|
- [self viewDocument];
|
|
|
[self createToolbar];
|
|
|
+ [self viewDocument];
|
|
|
[appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ self.title = _metadataDetail.fileNameView;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma --------------------------------------------------------------------------------------------
|
|
|
+#pragma mark ===== Toolbar =====
|
|
|
+#pragma --------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+- (void)createToolbar
|
|
|
+{
|
|
|
+ CGFloat safeAreaBottom = 0;
|
|
|
+ NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
|
|
|
+ if (!serverUrl)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (@available(iOS 11, *)) {
|
|
|
+ safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
|
|
|
+
|
|
|
+ UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
|
|
|
+ UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
|
|
|
+ fixedSpaceMini.width = 25;
|
|
|
+
|
|
|
+ buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
|
|
|
+ buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
|
|
|
+ buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
|
|
|
+ buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
|
|
|
+
|
|
|
+ if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
|
|
|
+ if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
|
|
|
+ [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonAction, nil]];
|
|
|
+ else
|
|
|
+ [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, buttonAction, nil]];
|
|
|
+ } else {
|
|
|
+ if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
|
|
|
+ [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonAction, nil]];
|
|
|
+ else
|
|
|
+ [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, buttonAction, nil]];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
|
|
|
+
|
|
|
+ self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
|
|
|
+ self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
|
|
|
+
|
|
|
+ [self.view addSubview:self.toolbar];
|
|
|
}
|
|
|
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
@@ -306,7 +287,7 @@
|
|
|
[self.webView setBackgroundColor:[NCBrandColor sharedInstance].backgroundView];
|
|
|
[self.webView setOpaque:NO];
|
|
|
|
|
|
- if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
|
|
|
+ if ( [fileNameExtension isEqualToString:@"CSS"] || [fileNameExtension isEqualToString:@"PY"] || [fileNameExtension isEqualToString:@"XML"] || [fileNameExtension isEqualToString:@"JS"] ) {
|
|
|
|
|
|
NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
|
|
|
|
|
@@ -316,7 +297,7 @@
|
|
|
[self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
|
|
|
}
|
|
|
|
|
|
- } else if ([CCUtility isDocumentModifiableExtension:_fileNameExtension]) {
|
|
|
+ } else if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
|
|
|
|
|
|
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
|
|
@@ -341,21 +322,138 @@
|
|
|
[self.view addSubview:self.webView];
|
|
|
}
|
|
|
|
|
|
+#pragma --------------------------------------------------------------------------------------------
|
|
|
+#pragma mark ===== View Media =====
|
|
|
+#pragma --------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+- (void)viewMedia
|
|
|
+{
|
|
|
+ CGFloat safeAreaBottom = 0;
|
|
|
+
|
|
|
+ if (@available(iOS 11, *)) {
|
|
|
+ safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
|
|
|
+ if (!serverUrl)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if ([CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView]) {
|
|
|
+
|
|
|
+ videoURL = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView]];
|
|
|
+ videoURLProxy = videoURL;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ videoURL = [NSURL URLWithString:[[NSString stringWithFormat:@"%@/%@", serverUrl, _metadataDetail.fileName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
|
|
|
+ videoURLProxy = [KTVHTTPCache proxyURLWithOriginalURL:videoURL];
|
|
|
+
|
|
|
+ NSMutableDictionary *header = [NSMutableDictionary new];
|
|
|
+ NSData *authData = [[NSString stringWithFormat:@"%@:%@", appDelegate.activeUser, appDelegate.activePassword] dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
|
|
|
+ [header setValue:authValue forKey:@"Authorization"];
|
|
|
+ [header setValue:[CCUtility getUserAgent] forKey:@"User-Agent"];
|
|
|
+ [KTVHTTPCache downloadSetAdditionalHeaders:header];
|
|
|
+
|
|
|
+ // Disable Button Action (the file is in download via Proxy Server)
|
|
|
+ buttonAction.enabled = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ appDelegate.player = [AVPlayer playerWithURL:videoURLProxy];
|
|
|
+ appDelegate.playerController = [AVPlayerViewController new];
|
|
|
+
|
|
|
+ appDelegate.playerController.player = appDelegate.player;
|
|
|
+ appDelegate.playerController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
|
|
|
+ appDelegate.playerController.allowsPictureInPicturePlayback = false;
|
|
|
+ [self addChildViewController:appDelegate.playerController];
|
|
|
+ [self.view addSubview:appDelegate.playerController.view];
|
|
|
+ [appDelegate.playerController didMoveToParentViewController:self];
|
|
|
+
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:[appDelegate.player currentItem]];
|
|
|
+ [appDelegate.player addObserver:self forKeyPath:@"rate" options:0 context:nil];
|
|
|
+
|
|
|
+ [appDelegate.player play];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
|
+ if ([keyPath isEqualToString:@"rate"]) {
|
|
|
+ if ([appDelegate.player rate]) {
|
|
|
+ NSLog(@"start");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ NSLog(@"pause");
|
|
|
+ }
|
|
|
+ [self saveCacheToFileProvider];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)itemDidFinishPlaying:(NSNotification *)notification
|
|
|
+{
|
|
|
+ AVPlayerItem *player = [notification object];
|
|
|
+ [player seekToTime:kCMTimeZero];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)saveCacheToFileProvider
|
|
|
+{
|
|
|
+ if (![CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView]) {
|
|
|
+ NSURL *url = [KTVHTTPCache cacheCompleteFileURLIfExistedWithURL:videoURL];
|
|
|
+ if (url) {
|
|
|
+
|
|
|
+ [CCUtility copyFileAtPath:[url path] toPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView]];
|
|
|
+ [[NCManageDatabase sharedInstance] addLocalFileWithMetadata:self.metadataDetail];
|
|
|
+ [KTVHTTPCache cacheDeleteCacheWithURL:videoURL];
|
|
|
+
|
|
|
+ // reload Main
|
|
|
+ [appDelegate.activeMain reloadDatasource];
|
|
|
+
|
|
|
+ // Enabled Button Action (the file is in local)
|
|
|
+ buttonAction.enabled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setupHTTPCache
|
|
|
+{
|
|
|
+ [KTVHTTPCache cacheSetMaxCacheLength:k_maxHTTPCache];
|
|
|
+
|
|
|
+#if TARGET_IPHONE_SIMULATOR
|
|
|
+ [KTVHTTPCache logSetConsoleLogEnable:YES];
|
|
|
+#endif
|
|
|
+
|
|
|
+ NSError * error;
|
|
|
+ [KTVHTTPCache proxyStart:&error];
|
|
|
+ if (error) {
|
|
|
+ NSLog(@"Proxy Start Failure, %@", error);
|
|
|
+ } else {
|
|
|
+ NSLog(@"Proxy Start Success");
|
|
|
+ }
|
|
|
+
|
|
|
+ [KTVHTTPCache tokenSetURLFilter:^NSURL * (NSURL * URL) {
|
|
|
+ NSLog(@"URL Filter reviced URL : %@", URL);
|
|
|
+ return URL;
|
|
|
+ }];
|
|
|
+
|
|
|
+ [KTVHTTPCache downloadSetUnsupportContentTypeFilter:^BOOL(NSURL * URL, NSString * contentType) {
|
|
|
+ NSLog(@"Unsupport Content-Type Filter reviced URL : %@, %@", URL, contentType);
|
|
|
+ return NO;
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== View Image =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
-- (void)viewImageVideoAudio
|
|
|
+- (void)viewImage
|
|
|
{
|
|
|
self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
|
|
|
- _indexNowVisible = -1;
|
|
|
- _fileIDNowVisible = nil;
|
|
|
+ indexNowVisible = -1;
|
|
|
+ fileIDNowVisible = nil;
|
|
|
|
|
|
[self.photos removeAllObjects];
|
|
|
- [_dataSourceDirectoryID removeAllObjects];
|
|
|
+ [dataSourceDirectoryID removeAllObjects];
|
|
|
|
|
|
// if not images, exit
|
|
|
- if ([self.dataSourceImagesVideos count] == 0)
|
|
|
+ if ([self.photoDataSource count] == 0)
|
|
|
return;
|
|
|
|
|
|
// test
|
|
@@ -364,7 +462,7 @@
|
|
|
return;
|
|
|
|
|
|
NSUInteger index = 0;
|
|
|
- for (tableMetadata *metadata in self.dataSourceImagesVideos) {
|
|
|
+ for (tableMetadata *metadata in self.photoDataSource) {
|
|
|
|
|
|
// start from here ?
|
|
|
if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
|
|
@@ -373,7 +471,7 @@
|
|
|
[self.photos addObject:[MWPhoto photoWithImage:nil]];
|
|
|
|
|
|
// add directory
|
|
|
- [_dataSourceDirectoryID addObject:metadata.directoryID];
|
|
|
+ [dataSourceDirectoryID addObject:metadata.directoryID];
|
|
|
index++;
|
|
|
}
|
|
|
|
|
@@ -408,12 +506,12 @@
|
|
|
|
|
|
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
|
|
|
{
|
|
|
- return [self.dataSourceImagesVideos count];
|
|
|
+ return [self.photoDataSource count];
|
|
|
}
|
|
|
|
|
|
- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
|
|
|
{
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
|
|
|
NSString *titleDir = metadata.fileNameView;
|
|
|
self.title = titleDir;
|
|
@@ -423,10 +521,10 @@
|
|
|
|
|
|
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
|
|
|
{
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
|
|
|
- _indexNowVisible = index;
|
|
|
- _fileIDNowVisible = metadata.fileID;
|
|
|
+ indexNowVisible = index;
|
|
|
+ fileIDNowVisible = metadata.fileID;
|
|
|
|
|
|
photoBrowser.toolbar.hidden = NO;
|
|
|
|
|
@@ -451,7 +549,7 @@
|
|
|
UIImage *image;
|
|
|
// UIImage *loadingGIF = [UIImage animatedImageWithAnimatedGIFURL:[[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"]];
|
|
|
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
|
|
|
if (index < self.photos.count) {
|
|
|
|
|
@@ -576,7 +674,7 @@
|
|
|
|
|
|
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
|
|
|
{
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
if (metadata == nil) return;
|
|
|
|
|
|
self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView]]];
|
|
@@ -591,14 +689,14 @@
|
|
|
|
|
|
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
|
|
|
{
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
|
|
|
[appDelegate.activeMain openWindowShare:metadata];
|
|
|
}
|
|
|
|
|
|
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
|
|
|
{
|
|
|
- tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
|
|
|
if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView] == NO) {
|
|
|
|
|
|
[appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
|
|
@@ -629,12 +727,12 @@
|
|
|
|
|
|
- (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
|
|
|
{
|
|
|
- [self removeAllView];
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
|
|
|
- (void)triggerProgressTask:(NSNotification *)notification
|
|
|
{
|
|
|
+ /*
|
|
|
NSDictionary *dict = notification.userInfo;
|
|
|
NSString *fileID = [dict valueForKey:@"fileID"];
|
|
|
//NSString *serverUrl = [dict valueForKey:@"serverUrl"];
|
|
@@ -643,15 +741,20 @@
|
|
|
//long long totalBytes = [[dict valueForKey:@"totalBytes"] longLongValue];
|
|
|
//long long totalBytesExpected = [[dict valueForKey:@"totalBytesExpected"] longLongValue];
|
|
|
|
|
|
-// if ([fileID isEqualToString:_fileIDNowVisible])
|
|
|
-// [_hud progress:progress];
|
|
|
+ if ([fileID isEqualToString:_fileIDNowVisible])
|
|
|
+ [_hud progress:progress];
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
- (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
|
|
|
{
|
|
|
// if a message for a directory of these
|
|
|
- if (![metadata.fileID isEqualToString:_fileIDNowVisible])
|
|
|
+ if (![metadata.fileID isEqualToString:fileIDNowVisible])
|
|
|
return;
|
|
|
+
|
|
|
+ // Title
|
|
|
+ self.navigationItem.titleView = nil;
|
|
|
+ self.title = metadata.fileNameView;
|
|
|
|
|
|
if (errorCode == 0) {
|
|
|
// verifico se esiste l'icona e se la posso creare
|
|
@@ -669,19 +772,18 @@
|
|
|
|
|
|
- (void)downloadPhotoBrowser:(tableMetadata *)metadata
|
|
|
{
|
|
|
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
|
|
|
+ tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] initNewMetadata:metadata];
|
|
|
|
|
|
- if (serverUrl) {
|
|
|
+ metadataForUpload.session = k_download_session;
|
|
|
+ metadataForUpload.sessionError = @"";
|
|
|
+ metadataForUpload.sessionSelector = selectorLoadViewImage;
|
|
|
+ metadataForUpload.status = k_metadataStatusWaitDownload;
|
|
|
|
|
|
- metadata.session = k_download_session;
|
|
|
- metadata.sessionError = @"";
|
|
|
- metadata.sessionSelector = selectorLoadViewImage;
|
|
|
- metadata.status = k_metadataStatusWaitDownload;
|
|
|
-
|
|
|
- // Add Metadata for Download
|
|
|
- (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
|
|
|
- [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
|
|
|
- }
|
|
|
+ // Add Metadata for Download
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
|
|
|
+ [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
|
|
|
+
|
|
|
+ [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] navigationItem:self.navigationItem];
|
|
|
}
|
|
|
|
|
|
- (void)insertGeocoderLocation:(NSNotification *)notification
|
|
@@ -693,12 +795,12 @@
|
|
|
//NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
|
|
|
|
|
|
// test [Chrash V 1.14,15]
|
|
|
- if (_indexNowVisible >= [self.photos count])
|
|
|
+ if (indexNowVisible >= [self.photos count])
|
|
|
return;
|
|
|
|
|
|
- if ([fileID isEqualToString:_fileIDNowVisible]) {
|
|
|
+ if ([fileID isEqualToString:fileIDNowVisible]) {
|
|
|
|
|
|
- MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
|
|
|
+ MWPhoto *photo = [self.photos objectAtIndex:indexNowVisible];
|
|
|
|
|
|
[self setLocationCaptionPhoto:photo fileID:fileID];
|
|
|
|
|
@@ -873,9 +975,9 @@
|
|
|
}
|
|
|
|
|
|
self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
|
|
|
- _toolbar.hidden = !_toolbar.isHidden;
|
|
|
+ self.toolbar.hidden = !self.toolbar.isHidden;
|
|
|
|
|
|
- if (_toolbar.isHidden) {
|
|
|
+ if (self.toolbar.isHidden) {
|
|
|
self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
|
|
|
} else {
|
|
|
self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
|
|
@@ -910,46 +1012,27 @@
|
|
|
// reload Main
|
|
|
[appDelegate.activeMain reloadDatasource];
|
|
|
|
|
|
- // If removed document (web) or PDF close
|
|
|
- if (_webView || _readerPDFViewController)
|
|
|
- [self removeAllView];
|
|
|
+ // Not image
|
|
|
+ if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] == NO) {
|
|
|
|
|
|
- // if a message for a directory of these
|
|
|
- if (![_dataSourceDirectoryID containsObject:metadata.directoryID])
|
|
|
- return;
|
|
|
+ // exit
|
|
|
+ [self backNavigationController];
|
|
|
|
|
|
- // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
|
|
|
- if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadata.fileID]) {
|
|
|
-
|
|
|
- NSArray *viewsToRemove = [self.view subviews];
|
|
|
- for (id element in viewsToRemove) {
|
|
|
-
|
|
|
- if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]])
|
|
|
- [element removeFromSuperview];
|
|
|
- }
|
|
|
-
|
|
|
- self.title = @"";
|
|
|
-
|
|
|
- [self.navigationController popViewControllerAnimated:YES];
|
|
|
-
|
|
|
} else {
|
|
|
|
|
|
- // only photoBrowser if exists
|
|
|
- for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
|
|
|
+ for (NSUInteger index=0; index < [self.photoDataSource count] && _photoBrowser; index++ ) {
|
|
|
|
|
|
- tableMetadata *metadataTemp = [self.dataSourceImagesVideos objectAtIndex:index];
|
|
|
+ tableMetadata *metadataTemp = [self.photoDataSource objectAtIndex:index];
|
|
|
|
|
|
if ([metadata isInvalidated] || [metadataTemp.fileID isEqualToString:metadata.fileID]) {
|
|
|
|
|
|
- [self.dataSourceImagesVideos removeObjectAtIndex:index];
|
|
|
+ [self.photoDataSource removeObjectAtIndex:index];
|
|
|
[self.photos removeObjectAtIndex:index];
|
|
|
[self.photoBrowser reloadData];
|
|
|
|
|
|
- // Title
|
|
|
- if ([self.dataSourceImagesVideos count] == 0) {
|
|
|
-
|
|
|
- self.title = @"";
|
|
|
- [self.navigationController popViewControllerAnimated:YES];
|
|
|
+ // exit
|
|
|
+ if ([self.photoDataSource count] == 0) {
|
|
|
+ [self backNavigationController];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -964,18 +1047,36 @@
|
|
|
#pragma mark ===== ButtonPressed =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
+- (void)dismissTextView
|
|
|
+{
|
|
|
+ if (self.webView) {
|
|
|
+
|
|
|
+ NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
|
|
|
+
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
|
|
|
+ [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
|
|
|
+
|
|
|
+ [self.webView reload];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
- (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
|
|
|
{
|
|
|
- UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
|
|
|
-
|
|
|
- NCText *viewController = (NCText *)navigationController.topViewController;
|
|
|
-
|
|
|
- viewController.metadata = self.metadataDetail;
|
|
|
-
|
|
|
- navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
|
|
|
- navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
|
-
|
|
|
- [self presentViewController:navigationController animated:YES completion:nil];
|
|
|
+ tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", self.metadataDetail.fileID]];
|
|
|
+ if (metadata) {
|
|
|
+
|
|
|
+ UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
|
|
|
+
|
|
|
+ NCText *viewController = (NCText *)navigationController.topViewController;
|
|
|
+
|
|
|
+ viewController.metadata = metadata;
|
|
|
+ viewController.delegate = self;
|
|
|
+
|
|
|
+ navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
|
|
|
+ navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
|
+
|
|
|
+ [self presentViewController:navigationController animated:YES completion:nil];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)actionButtonPressed:(UIBarButtonItem *)sender
|
|
@@ -1017,7 +1118,7 @@
|
|
|
[alertController dismissViewControllerAnimated:YES completion:nil];
|
|
|
}]];
|
|
|
|
|
|
- alertController.popoverPresentationController.barButtonItem = _buttonDelete;
|
|
|
+ alertController.popoverPresentationController.barButtonItem = buttonDelete;
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
|
|
[alertController.view layoutIfNeeded];
|