Browse Source

Add webCloseViewProtocol

Marino Faggiana 7 years ago
parent
commit
76428df713
2 changed files with 35 additions and 0 deletions
  1. 1 0
      iOSClient/Brand/NCBrand.swift
  2. 34 0
      iOSClient/Main/CCMore.swift

+ 1 - 0
iOSClient/Brand/NCBrand.swift

@@ -73,6 +73,7 @@ class NCBrandOptions: NSObject {
     public let loginButtonLabelLink:            String = "https://nextcloud.com/providers"
     public let middlewarePingUrl:               String = ""
     public let webLoginAutenticationProtocol:   String = ""
+    public let webCloseViewProtocol:            String = ""
     public let folderBrandAutoUpload:           String = ""
 
     // Auto Upload default folder

+ 34 - 0
iOSClient/Main/CCMore.swift

@@ -331,12 +331,14 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
             if (self.splitViewController?.isCollapsed)! {
                 
                 let webVC = SwiftWebVC(urlString: item.url, hideToolbar: true)
+                webVC.delegate = self
                 self.navigationController?.pushViewController(webVC, animated: true)
                 self.navigationController?.navigationBar.isHidden = false
                 
             } else {
                 
                 let webVC = SwiftModalWebVC(urlString: item.url)
+                webVC.delegateWeb = self
                 self.present(webVC, animated: true, completion: nil)
             }
             
@@ -375,12 +377,14 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
             if (self.splitViewController?.isCollapsed)! {
                 
                 let webVC = SwiftWebVC(urlString: item.url, hideToolbar: true)
+                webVC.delegate = self
                 self.navigationController?.pushViewController(webVC, animated: true)
                 self.navigationController?.navigationBar.isHidden = false
                 
             } else {
                 
                 let webVC = SwiftModalWebVC(urlString: item.url)
+                webVC.delegateWeb = self
                 self.present(webVC, animated: true, completion: nil)
             }
         }
@@ -401,6 +405,36 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
     }
 }
 
+extension CCMore: SwiftModalWebVCDelegate, SwiftWebVCDelegate{
+    
+    public func didStartLoading() {
+        print("Started loading.")
+    }
+    
+    public func didReceiveServerRedirectForProvisionalNavigation(url: URL) {
+        
+        let urlString: String = url.absoluteString
+        
+        // Protocol close webVC
+        if (urlString.contains(NCBrandOptions.sharedInstance.webCloseViewProtocol) == true) {
+            
+            if (self.presentingViewController != nil) {
+                self.dismiss(animated: true, completion: nil)
+            } else {
+                self.navigationController?.popToRootViewController(animated: true)
+            }
+        }
+    }
+    
+    public func didFinishLoading(success: Bool) {
+        print("Finished loading. Success: \(success).")
+    }
+    
+    public func didFinishLoading(success: Bool, url: URL) {
+        print("Finished loading. Success: \(success).")
+    }
+}
+
 class CCCellMore: UITableViewCell {
     
     @IBOutlet weak var labelText: UILabel!