Browse Source

clear code

Marino Faggiana 6 years ago
parent
commit
4b697e113b

+ 2 - 32
iOSClient/Main/CCDetail.m

@@ -184,7 +184,7 @@
         
         self.edgesForExtendedLayout = UIRectEdgeAll;
         [self createToolbar];
-        [self viewMedia];
+        [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail detail:self];
     }
     
     // DOCUMENT
@@ -237,8 +237,8 @@
         }
         
         self.edgesForExtendedLayout = UIRectEdgeBottom;
+        [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
         [self createToolbar];
-        [self viewDocument];
     }
 }
 
@@ -290,36 +290,6 @@
     [self.view addSubview:self.toolbar];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== View Document =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)viewDocument
-{
-    CGFloat safeAreaBottom = 0;
-    
-    if (@available(iOS 11, *)) {
-        safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
-    }
-    
-    [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self width:self.view.bounds.size.width height:self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== View Media =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)viewMedia
-{
-    CGFloat safeAreaBottom = 0;
-    
-    if (@available(iOS 11, *)) {
-        safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
-    }
-    
-    [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail viewDetail:self width:self.view.bounds.size.width height:self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== View Image =====
 #pragma --------------------------------------------------------------------------------------------

+ 11 - 75
iOSClient/Viewer/NCViewerDocumentWeb.swift

@@ -31,14 +31,23 @@ class NCViewerDocumentWeb: NSObject {
     }()
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var safeAreaBottom: Int = 0
     
-    @objc func viewDocumentWebAt(_ metadata: tableMetadata, detail: CCDetail, width: Int, height: Int) {
+    @objc func viewDocumentWebAt(_ metadata: tableMetadata, detail: CCDetail) {
         
         if !CCUtility.fileProviderStorageExists(metadata.fileID, fileNameView: metadata.fileNameView) {
             detail.navigationController?.popViewController(animated: true)
             return
         }
         
+        guard let rootView = UIApplication.shared.keyWindow else {
+            return
+        }
+        
+        if #available(iOS 11.0, *) {
+            safeAreaBottom = Int(rootView.safeAreaInsets.bottom)
+        }
+        
         let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
         let fileNameExtension = (metadata.fileNameView as NSString).pathExtension.uppercased()
 
@@ -61,7 +70,7 @@ class NCViewerDocumentWeb: NSObject {
         preferences.javaScriptEnabled = true
         configuration.preferences = preferences
         
-        let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: width, height: height), configuration: configuration)
+        let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: Int(rootView.bounds.size.width), height: Int(rootView.bounds.size.height) - Int(k_detail_Toolbar_Height) - safeAreaBottom), configuration: configuration)
         webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
         webView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
         webView.isOpaque = false
@@ -114,77 +123,4 @@ class NCViewerDocumentWeb: NSObject {
         
         detail.view.addSubview(webView)
     }
-    
-    func createToolbar(detail: CCDetail) {
-
-        var safeAreaBottom: CGFloat = 0
-        
-        guard let rootView = UIApplication.shared.keyWindow else {
-            return
-        }
-        if #available(iOS 11.0, *) {
-            safeAreaBottom = rootView.safeAreaInsets.bottom
-        }
-        
-        guard let detailView = detail.view else {
-            return
-        }
-
-        let toolbar = UITabBar(frame: CGRect(x: 0 as CGFloat, y: detailView.bounds.size.height - CGFloat(k_detail_Toolbar_Height) - safeAreaBottom, width: detailView.bounds.size.width, height: CGFloat(k_detail_Toolbar_Height)))
-        
-        let flexible = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: detail, action: nil)
-        let fixedSpaceMini = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: detail, action: nil)
-        fixedSpaceMini.width = 25
-        
-       
-        
-        
-    }
-    
-    
-    /*
- - (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:)];
- if (![NCBrandOptions sharedInstance].disable_openin_file) {
- self.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, self.buttonAction,  nil]];
- else
- [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction,  nil]];
- } else {
- if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
- [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, self.buttonAction,  nil]];
- else
- [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction,  nil]];
- }
- 
- [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
- 
- self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
- self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
- 
- [self.view addSubview:self.toolbar];
- }
- */
 }

+ 20 - 11
iOSClient/Viewer/NCViewerMedia.swift

@@ -17,22 +17,31 @@ class NCViewerMedia: NSObject {
         return viewMedia
     }()
 
-    var viewDetail: CCDetail!
+    var detail: CCDetail!
     var metadata: tableMetadata!
     var videoURL: URL!
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    
-    @objc func viewMedia(_ metadata: tableMetadata, viewDetail: CCDetail, width: Int, height: Int) {
+    var safeAreaBottom: Int = 0
+
+    @objc func viewMedia(_ metadata: tableMetadata, detail: CCDetail) {
         
         var videoURLProxy: URL!
 
-        self.viewDetail = viewDetail
+        self.detail = detail
         self.metadata = metadata
         
         guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
             return
         }
         
+        guard let rootView = UIApplication.shared.keyWindow else {
+            return
+        }
+        
+        if #available(iOS 11.0, *) {
+            safeAreaBottom = Int(rootView.safeAreaInsets.bottom)
+        }
+        
         if CCUtility.fileProviderStorageExists(metadata.fileID, fileNameView: metadata.fileNameView) {
         
             self.videoURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView))
@@ -55,18 +64,18 @@ class NCViewerMedia: NSObject {
             KTVHTTPCache.downloadSetAdditionalHeaders(["Authorization":authValue, "User-Agent":CCUtility.getUserAgent()])
             
             // Disable Button Action (the file is in download via Proxy Server)
-            viewDetail.buttonAction.isEnabled = false
+            detail.buttonAction.isEnabled = false
         }
         
         appDelegate.player = AVPlayer(url: videoURLProxy)
         appDelegate.playerController = AVPlayerViewController()
         
         appDelegate.playerController.player = appDelegate.player
-        appDelegate.playerController.view.frame = CGRect(x: 0, y: 0, width: width, height: height)
+        appDelegate.playerController.view.frame = CGRect(x: 0, y: 0, width: Int(rootView.bounds.size.width), height: Int(rootView.bounds.size.height) - Int(k_detail_Toolbar_Height) - safeAreaBottom)
         appDelegate.playerController.allowsPictureInPicturePlayback = false
-        viewDetail.addChild(appDelegate.playerController)
-        viewDetail.view.addSubview(appDelegate.playerController.view)
-        appDelegate.playerController.didMove(toParent: viewDetail)
+        detail.addChild(appDelegate.playerController)
+        detail.view.addSubview(appDelegate.playerController.view)
+        appDelegate.playerController.didMove(toParent: detail)
         
         NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: nil) { (notification) in
             let player = notification.object as! AVPlayerItem
@@ -75,7 +84,7 @@ class NCViewerMedia: NSObject {
         
         appDelegate.player.addObserver(self, forKeyPath: "rate", options: [], context: nil)
         
-        viewDetail.isMediaObserver = true
+        detail.isMediaObserver = true
         
         appDelegate.player.play()
     }
@@ -104,7 +113,7 @@ class NCViewerMedia: NSObject {
                 NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: NCManageDatabase.sharedInstance.getServerUrl(self.metadata.directoryID), fileID: self.metadata.fileID, action: k_action_MOD)
                 
                 // Enabled Button Action (the file is in local)
-                self.viewDetail.buttonAction.isEnabled = true
+                self.detail.buttonAction.isEnabled = true
             }
         }
     }