浏览代码

change delate logic al Login

Marino Faggiana 7 年之前
父节点
当前提交
7c89e69b7e

+ 9 - 2
iOSClient/Library/SwiftWebVC/SwiftModalWebVC.swift

@@ -12,7 +12,7 @@ public protocol SwiftModalWebVCDelegate: class {
     func didStartLoading()
     func didReceiveServerRedirectForProvisionalNavigation(url: URL)
     func didFinishLoading(success: Bool, url: URL)
-    func loginClose()
+    func loginWebClose()
 }
 
 public class SwiftModalWebVC: UINavigationController {
@@ -108,9 +108,12 @@ public class SwiftModalWebVC: UINavigationController {
         super.viewWillAppear(false)
     }
     
+    public override func viewWillDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+    }
+
     public override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
-        self.delegateWeb?.loginClose()
     }
 }
 
@@ -131,4 +134,8 @@ extension SwiftModalWebVC: SwiftWebVCDelegate {
     public func didFinishLoading(success: Bool, url: URL) {
         self.delegateWeb?.didFinishLoading(success: success, url: url)
     }
+    
+    public func loginWebClose() {
+        self.delegateWeb?.loginWebClose()
+    }
 }

+ 8 - 0
iOSClient/Library/SwiftWebVC/SwiftWebVC.swift

@@ -13,6 +13,7 @@ public protocol SwiftWebVCDelegate: class {
     func didReceiveServerRedirectForProvisionalNavigation(url: URL)
     func didFinishLoading(success: Bool)
     func didFinishLoading(success: Bool, url: URL)
+    func loginWebClose()
 }
 
 public class SwiftWebVC: UIViewController {
@@ -170,6 +171,13 @@ public class SwiftWebVC: UIViewController {
         UIApplication.shared.isNetworkActivityIndicatorVisible = false
     }
     
+    override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
+        super.dismiss(animated: flag, completion: {
+            self.delegate!.loginWebClose()
+        })        
+    }
+    
+    
     ////////////////////////////////////////////////
     // Toolbar
     

+ 31 - 19
iOSClient/Login/CCLogin.m

@@ -27,10 +27,9 @@
 #import "NCBridgeSwift.h"
 #import "NCNetworkingSync.h"
 
-@interface CCLogin ()
+@interface CCLogin () <CCLoginDelegateWeb>
 {
     AppDelegate *appDelegate;
-
     UIView *rootView;
 }
 @end
@@ -151,9 +150,6 @@
 - (void)viewDidDisappear:(BOOL)animated
 {
     [super viewDidDisappear:animated];
-    
-    if ([self.delegate respondsToSelector:@selector(loginClose)])
-        [self.delegate loginClose];
 }
 
 - (BOOL)textFieldShouldReturn:(UITextField *)textField
@@ -184,6 +180,13 @@
     [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
 }
 
+- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
+{
+    [super dismissViewControllerAnimated:flag completion:completion];
+    
+    [self.delegate loginClose];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark == Chech Server URL ==
 #pragma --------------------------------------------------------------------------------------------
@@ -244,15 +247,12 @@
 
                 } else {
                     
-                    [self dismissViewControllerAnimated:YES completion: ^{
-                        
-                        appDelegate.activeLoginWeb = [CCLoginWeb new];
-                        appDelegate.activeLoginWeb.loginType = _loginType;
-                        appDelegate.activeLoginWeb.delegate = (id<CCLoginDelegateWeb>)self.delegate;
-                        appDelegate.activeLoginWeb.urlBase = urlBase;
+                    appDelegate.activeLoginWeb = [CCLoginWeb new];
+                    appDelegate.activeLoginWeb.loginType = _loginType;
+                    appDelegate.activeLoginWeb.delegate = self;
+                    appDelegate.activeLoginWeb.urlBase = urlBase;
                     
-                        [appDelegate.activeLoginWeb presentModalWithDefaultTheme:(UIViewController *)self.delegate];
-                    }];
+                    [appDelegate.activeLoginWeb presentModalWithDefaultTheme:self];
                 }
             });
         }];
@@ -345,9 +345,7 @@
                 // Setting appDelegate active account
                 [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
 
-                // Dismiss
-                if ([self.delegate respondsToSelector:@selector(loginSuccess:)])
-                    [self.delegate loginSuccess:_loginType];
+                [self.delegate loginSuccess:_loginType];
             
                 [self dismissViewControllerAnimated:YES completion:nil];
             
@@ -433,9 +431,7 @@
             // Setting appDelegate active account
             [appDelegate settingActiveAccount:account.account activeUrl:account.url activeUser:account.user activeUserID:account.userID activePassword:account.password];
     
-            // Ok ! Dismiss
-            if ([self.delegate respondsToSelector:@selector(loginSuccess:)])
-                [self.delegate loginSuccess:_loginType];
+            [self.delegate loginSuccess:_loginType];
         
             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                 [self dismissViewControllerAnimated:YES completion:nil];
@@ -464,6 +460,22 @@
     }
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark === CCLoginDelegateWeb ===
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)loginSuccess:(NSInteger)loginType
+{
+    [self.delegate loginSuccess:_loginType];
+}
+
+- (void)loginWebClose
+{
+    appDelegate.activeLoginWeb = nil;
+   
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark == Action ==
 #pragma --------------------------------------------------------------------------------------------

+ 5 - 3
iOSClient/Login/CCLoginWeb.swift

@@ -10,7 +10,7 @@ import UIKit
 
 @objc protocol CCLoginDelegateWeb: class {
     func loginSuccess(_: NSInteger)
-    func loginClose()
+    func loginWebClose()
 }
 
 public class CCLoginWeb: UIViewController {
@@ -104,6 +104,7 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                         }
                         
                         appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
+                        
                         self.delegate?.loginSuccess(NSInteger(loginType.rawValue))
                         
                         self.viewController?.dismiss(animated: true, completion: nil)
@@ -121,6 +122,7 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                         }
                         
                         appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activeUserID: tableAccount.userID, activePassword: password)
+                        
                         self.delegate?.loginSuccess(NSInteger(loginType.rawValue))
                         
                         self.viewController?.dismiss(animated: true, completion: nil)
@@ -134,8 +136,8 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
         print("Finished loading. Success: \(success).")
     }
     
-    public func loginClose() {
-        self.delegate?.loginClose()
+    public func loginWebClose() {
+        self.delegate?.loginWebClose()
     }
 }
 

+ 4 - 0
iOSClient/Main/CCMain.m

@@ -942,6 +942,10 @@
 - (void)loginClose
 {
     appDelegate.activeLogin = nil;
+}
+
+- (void)loginWebClose
+{
     appDelegate.activeLoginWeb = nil;
 }
 

+ 3 - 0
iOSClient/Main/CCMore.swift

@@ -394,6 +394,9 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
     
     func loginClose() {
         appDelegate.activeLogin = nil
+    }
+    
+    func loginWebClose() {
         appDelegate.activeLoginWeb = nil
     }
 }

+ 4 - 0
iOSClient/Main/CCSplit.m

@@ -199,6 +199,10 @@
 - (void)loginClose
 {
     appDelegate.activeLogin = nil;
+}
+
+- (void)loginWebClose
+{
     appDelegate.activeLoginWeb = nil;
 }
 

+ 4 - 0
iOSClient/Settings/CCManageAccount.m

@@ -198,6 +198,10 @@
 - (void)loginClose
 {
     appDelegate.activeLogin = nil;
+}
+
+- (void)loginWebClose
+{
     appDelegate.activeLoginWeb = nil;
 }